def p_increment_decrement_identifiers(p): ''' expression : identifier DOUBLE_PLUS | identifier DOUBLE_MINUS ''' if p[2] == '++': p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), '+') else: p[0] = ast.BinaryOperation(p[1], ast.Primitive(1), '-')
def p_primitive(p): ''' primitive : NUM_INT | NUM_FLOAT | STRING | boolean ''' if isinstance(p[1], ast.BaseExpression): p[0] = p[1] else: p[0] = ast.Primitive(p[1])
def p_for_loop_infinite(p): ''' statement : FOR LBRACK statement_list RBRACK ''' p[0] = ast.While(ast.Primitive(True), p[3])
def p_boolean(p): ''' boolean : TRUE | FALSE ''' p[0] = ast.Primitive(p[1])
def p_paren(p): ''' expression : LPAREN expression RPAREN ''' p[0] = p[2] if isinstance(p[2], ast.BaseExpression) else ast.Primitive(p[2])