Esempio n. 1
0
 def p_expression_constant(p):
     """ expression : INT
                    | FLOAT
                    | STRING
                    | bool
     """
     p[0] = AST.ConstantExpression(p.linespan(0), p[1])
Esempio n. 2
0
 def p_statement_assignment_with_operator(p):
     """ statement : variable ASSIGN_PLUS expression SEMICOLON
                   | variable ASSIGN_MINUS expression SEMICOLON
                   | variable ASSIGN_TIMES expression SEMICOLON
                   | variable ASSIGN_DIVIDE expression SEMICOLON
     """
     p[0] = AST.AssignmentWithOperatorStatement(p.linespan(0), p[2], p[1],
                                                p[3])
Esempio n. 3
0
 def p_expression_binary_operator(p):
     """ expression : expression PLUS expression
                    | expression MINUS expression
                    | expression TIMES expression
                    | expression DIVIDE expression
                    | expression GREATER expression
                    | expression LESS expression
                    | expression GREATER_EQUAL expression
                    | expression LESS_EQUAL expression
                    | expression EQUALS expression
                    | expression NOT_EQUALS expression
                    | expression DOT_PLUS expression
                    | expression DOT_MINUS expression
                    | expression DOT_TIMES expression
                    | expression DOT_DIVIDE expression
     """
     p[0] = AST.OperatorExpression(p.linespan(0), p[2], [p[1], p[3]])
Esempio n. 4
0
 def p_statement_if(p):
     """ statement : IF BRACKET_ROUND_L expression BRACKET_ROUND_R statement %prec SIMPLE_IF
                   | IF BRACKET_ROUND_L expression BRACKET_ROUND_R statement ELSE statement
     """
     p[0] = AST.IfStatement(p.linespan(0), p[3], p[5],
                            p[7] if len(p) > 7 else None)
Esempio n. 5
0
 def p_statement_for(p):
     """ statement : FOR ID ASSIGN range statement """
     p[0] = AST.ForStatement(p.linespan(0),
                             AST.Identifier(p.linespan(0), p[2]), p[4],
                             p[5])
Esempio n. 6
0
 def p_statement_while(p):
     """ statement : WHILE BRACKET_ROUND_L expression BRACKET_ROUND_R statement """
     p[0] = AST.WhileStatement(p.linespan(0), p[3], p[5])
Esempio n. 7
0
 def p_statement_return(p):
     """ statement : RETURN expression SEMICOLON """
     p[0] = AST.InstructionStatement(p.linespan(0), p[1], [p[2]])
Esempio n. 8
0
 def p_statement_continue(p):
     """ statement : CONTINUE SEMICOLON """
     p[0] = AST.InstructionStatement(p.linespan(0), p[1], [])
Esempio n. 9
0
 def p_program_head(p):
     """ program : """
     p[0] = AST.ProgramStatement(p.linespan(0), [])
Esempio n. 10
0
 def p_expression_right_unary_operator(p):
     """ expression : expression APOSTROPHE """
     p[0] = AST.OperatorExpression(p.linespan(0), p[2], [p[1]])
Esempio n. 11
0
 def p_statement_assignment(p):
     """ statement : variable ASSIGN expression SEMICOLON
     """
     p[0] = AST.AssignmentStatement(p.linespan(0), p[1], p[3])
Esempio n. 12
0
 def p_range(p):
     """ range : expression COLON expression """
     p[0] = AST.RangeExpression(p.linespan(0), p[1], p[3])
Esempio n. 13
0
 def p_program_tail(p):
     """ program : statement program """
     p[0] = AST.ProgramStatement(p.linespan(0), [p[1]] + p[2].statements)
Esempio n. 14
0
 def p_vector(p):
     """ vector : BRACKET_SQUARE_L comma_list BRACKET_SQUARE_R """
     p[0] = AST.VectorExpression(p.linespan(0), p[2])
Esempio n. 15
0
 def p_variable_selector(p):
     """ variable : ID vector """
     p[0] = AST.Selector(p.linespan(0), AST.Identifier(p.linespan(1), p[1]),
                         p[2])
Esempio n. 16
0
 def p_variable_id(p):
     """ variable : ID """
     p[0] = AST.Identifier(p.linespan(0), p[1])
Esempio n. 17
0
 def p_expression_unary_minus(p):
     """ expression : MINUS expression %prec UNARY_MINUS """
     p[0] = AST.OperatorExpression(p.linespan(0), 'u-', [p[2]])
Esempio n. 18
0
 def p_statement_print(p):
     """ statement : PRINT comma_list SEMICOLON """
     p[0] = AST.InstructionStatement(p.linespan(0), p[1], p[2])
Esempio n. 19
0
 def p_statement_break(p):
     """ statement : BREAK SEMICOLON """
     p[0] = AST.InstructionStatement(p.linespan(0), p[1], [])
Esempio n. 20
0
 def p_expression_function(p):
     """ expression : function BRACKET_ROUND_L comma_list BRACKET_ROUND_R """
     p[0] = AST.FunctionExpression(p.linespan(0), p[1], p[3])