コード例 #1
0
 def test_p7(self):
     simple_program_string = """
                                [ Rozklad liczby na czynniki pierwsze ]
                                 DECLARE
                                     n, m, reszta, potega, dzielnik
                                 BEGIN
                                     READ n;
                                     dzielnik ASSIGN 2;
                                     m ASSIGN dzielnik TIMES dzielnik;
                                     WHILE n GEQ m DO
                                         potega ASSIGN 0;
                                         reszta ASSIGN n MOD dzielnik;
                                         WHILE reszta EQ 0 DO
                                             n ASSIGN n DIV dzielnik;
                                             potega ASSIGN potega PLUS 1;
                                             reszta ASSIGN n MOD dzielnik;
                                         ENDWHILE
                                         IF potega GE 0 THEN [ czy znaleziono dzielnik ]
                                             WRITE dzielnik;
                                             WRITE potega;
                                         ELSE
                                             dzielnik ASSIGN dzielnik PLUS 1;
                                             m ASSIGN dzielnik TIMES dzielnik;
                                         ENDIF
                                     ENDWHILE
                                     IF n NEQ 1 THEN [ ostatni dzielnik ]
                                         WRITE n;
                                         WRITE 1;
                                     ENDIF
                                 END
                                   """
     ptree = parse(simple_program_string)
     execute_static_analysis(ptree)
コード例 #2
0
    def test_p6(self):
        simple_program_string = """
                                                                         [ sito Eratostenesa ]
                                    DECLARE
                                        n, j, sito(2:100)
                                    BEGIN
                                        n ASSIGN 100;
                                        FOR i FROM n DOWNTO 2 DO
                                            sito(i) ASSIGN 1;
                                        ENDFOR
                                        FOR i FROM 2 TO n DO
                                            IF sito(i) NEQ 0 THEN
                                                j ASSIGN i PLUS i;
                                                WHILE j LEQ n DO
                                                    sito(j) ASSIGN 0;
                                                    j ASSIGN j PLUS i;
                                                ENDWHILE
                                                WRITE i;
                                            ENDIF
                                        ENDFOR
                                    END

                                      """
        ptree = parse(simple_program_string)
        execute_static_analysis(ptree)
コード例 #3
0
 def test_arr_equal_range(self):
     simple_program_string = """
                          DECLARE a(0:0) BEGIN
                          READ a(0);
                          END
                          """
     ptree = parse(simple_program_string)
     execute_static_analysis(ptree)
コード例 #4
0
 def test_assignment_of_not_initialized_variable(self):
     simple_program_string = """
                             DECLARE a, b BEGIN
                             b ASSIGN a;
                             END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #5
0
 def test_accessing_invalid_array_range_positive(self):
     simple_program_string = """
                             DECLARE a(3:4), b BEGIN
                                 READ a(5);
                                 END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #6
0
 def test_variable_as_array_in_read(self):
     simple_program_string = """
                             DECLARE a BEGIN
                                 READ a(0);
                             END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #7
0
 def test_variable_assign_as_array(self):
     simple_program_string = """
                             DECLARE a BEGIN
                                 a(5) ASSIGN 10;
                             END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #8
0
 def test_assignment_of_array_without_braces(self):
     simple_program_string = """
                                  DECLARE a(2:10) BEGIN
                                  a ASSIGN 20;
                                  END
                                  """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #9
0
 def test_write_of_not_initialized_variable(self):
     simple_program_string = """
                                DECLARE a BEGIN
                                WRITE a;
                                END
                                """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #10
0
 def test_varvar_redeclaration(self):
     simple_program_string = """
                    DECLARE a, b, a BEGIN
                    READ a;
                    END
                    """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #11
0
 def test_arr_invalid_range_negative(self):
     simple_program_string = """
                       DECLARE a(-3:-4) BEGIN
                       READ a(1);
                       END
                       """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #12
0
 def test_undeclared_variable(self):
     simple_program_string = """
                          DECLARE a BEGIN
                          READ a;
                          b ASSIGN a;
                          END
                          """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #13
0
 def test_variable_expression_as_array_2nd(self):
     simple_program_string = """
                                 DECLARE a,b BEGIN
                                 READ a;
                                 b ASSIGN 35 MOD  a(4);
                                 END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #14
0
 def test_write_of_array_without_braces(self):
     simple_program_string = """
                                    DECLARE a(0:1) BEGIN
                                    READ a(0);
                                    READ a(1);
                                    WRITE a;
                                    END
                                    """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #15
0
 def test_uninitialized_variable_in_loop_cond(self):
     simple_program_string = """
                             DECLARE a BEGIN
                                 WHILE a NEQ 2 DO
                                     WRITE 50;
                                 ENDWHILE
                             END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #16
0
 def test_local_iterator_name_same_as_global(self):
     simple_program_string = """
                                   DECLARE a BEGIN
                                       FOR a FROM 0 TO 100 DO
                                       WRITE 10;
                                       ENDFOR
                                   END
                                   """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #17
0
 def test_usage_of_array_without_braces_in_expression(self):
     simple_program_string = """
                                      DECLARE a(2:10), b, c BEGIN
                                          READ b;
                                          READ c;
                                          b ASSIGN b PLUS a;
                                      END
                                                   """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #18
0
 def test_loop_iterator_in_array_range_downto(self):
     simple_program_string = """
                               DECLARE a(0:10), b BEGIN
                                   FOR i FROM i DOWNTO 0 DO
                                   WRITE 10;
                                   ENDFOR
                                   END
                               """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #19
0
 def test_uninitialized_variable_in_loop_body(self):
     simple_program_string = """
                             DECLARE a BEGIN
                                 FOR i FROM 0 TO 100 DO
                                     WRITE a;
                                 ENDFOR
                             END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #20
0
 def test_local_iterator_changes_value_read(self):
     simple_program_string = """
                                         DECLARE a BEGIN
                                            READ a;
                                             FOR i FROM 0 TO 100 DO
                                                 READ i;
                                                 ENDFOR
                                         END
                                         """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #21
0
 def test_variable_for_downto_loop_to_as_array(self):
     simple_program_string = """
                                      DECLARE a BEGIN
                                      READ a;
                                      FOR i FROM 0 DOWNTO a(13) DO 
                                      WRITE 50;
                                      ENDFOR
                                      END
                                      """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #22
0
 def test_variable_if_condition_as_array(self):
     simple_program_string = """
                             DECLARE a BEGIN
                             READ a;
                             IF a(4) GE 10 THEN
                                 WRITE 100;
                             ENDIF
                             END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #23
0
 def test_usage_of_array_without_braces_in_for_downto_loop_in_DOWNTO_clause(self):
     simple_program_string = """
                                              DECLARE a(2:10) BEGIN
                                              a(0) ASSIGN 5;
                                              FOR i FROM 0 DOWNTO a DO 
                                                  WRITE 5;
                                              ENDFOR
                                              END
                                              """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #24
0
 def test_variable_while_condition_as_array(self):
     simple_program_string = """
                             DECLARE a BEGIN
                             READ a;
                             WHILE a(-10) NEQ 10 DO
                                 WRITE 100;
                             ENDWHILE
                             END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #25
0
 def test_usage_of_array_without_braces_in_if_condition(self):
     simple_program_string = """
                                 DECLARE a(2:10) BEGIN
                                     READ a(0);
                                     IF a EQ 50 THEN
                                     WRITE 20;
                                     ENDIF
                                 END
                                              """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #26
0
 def test_p3(self):
     simple_program_string = """
                                  DECLARE a(0:3) BEGIN
                                   READ a(0);
                                   READ a(3);
                                   FOR i FROM a(0) TO a(3) DO
                                   WRITE 2;
                                   ENDFOR
                                   END
                                   """
     ptree = parse(simple_program_string)
     execute_static_analysis(ptree)
コード例 #27
0
 def test_local_variable_double_declaration(self):
     simple_program_string = """
                                   DECLARE a BEGIN
                                       FOR i FROM 0 TO 100 DO
                                        FOR i FROM 0 TO 100 DO
                                        WRITE 20;
                                            ENDFOR
                                       ENDFOR
                                   END
                                   """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #28
0
 def test_MUST_ASSIGN_assignment_of_local_scope_variable_nested(self):
     simple_program_string = """
                             DECLARE a BEGIN
                             FOR b FROM 0 TO 100 DO
                                 FOR a FROM 0 TO 100 DO
                                     WRITE 10;
                                 ENDFOR
                             ENDFOR
                             END
                             """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #29
0
 def test_usage_of_local_variable_out_of_scope_because_in_global(self):
     simple_program_string = """
                                BEGIN
                                FOR a FROM 0 TO 100 DO
                                    FOR b FROM 0 TO 100 DO
                                        WRITE 10;
                                    ENDFOR
                                ENDFOR
                                b ASSIGN 10; [this should fail]
                                END
                                """
     ptree = parse(simple_program_string)
     with pytest.raises(GebalangException):
         execute_static_analysis(ptree)
コード例 #30
0
 def test_p4(self):
     simple_program_string = """
                                  DECLARE a(0:3) BEGIN
                                   
                                   FOR i FROM 0 TO 10 DO
                                   READ a(i);
                                   ENDFOR
                                   WRITE a(0);
                                   WRITE a(1);
                                   WRITE a(2);
                                   WRITE a(3);
                                   END
                                   """
     ptree = parse(simple_program_string)
     execute_static_analysis(ptree)