def rvalue(): debug('rvalue') if (lexer.lookahead().type == 'OPEN_PARANTHESIS'): expect_symbol('OPEN_PARANTHESIS') rvalue() expect_symbol('CLOSE_PARANTHESIS') elif (lexer.lookahead().type == 'CONSTANT'): expect_symbol('CONSTANT') else: lvalue() debug_end()
def statement_list(): debug('statement_list') if (not lexer.empty() and lexer.lookahead().type in block_first): block() else: statement() statement_list1() debug_end()
def lvalue1(): debug('lvalue1') follow = [ 'SEMICOLON', 'BINARY_OPERATOR', 'CLOSE_PARANTHESIS', 'COMMA' ] if (not lexer.empty() and lexer.lookahead().type in follow): return else: expect_symbol('UNARY_OPERATOR') debug_end()
def var_decl_list1(): debug('var_decl_list1') follow = [ 'SEMICOLON' ] if (lexer.lookahead().type in follow): return expect_symbol('COMMA') var_decl_list1() debug_end()
def statement_list1(): debug('statement_list1') follow = [ 'CLOSE_BRACE' ] if (not lexer.empty() and lexer.lookahead().type in follow): return statement() statement_list1() debug_end()
def expression1(): debug('expression1') follow = [ 'SEMICOLON', 'CLOSE_PARANTHESIS', 'COMMA' ] if (lexer.lookahead().type in follow): return expect_symbol('BINARY_OPERATOR') expression() debug_end()
def lvalue(): debug('lvalue') lookahead = lexer.lookahead() if (lookahead.type == 'ID'): expect_symbol('ID') lvalue1() else: expect_symbol('UNARY_OPERATOR') expect_symbol('ID') debug_end()
def control_statement(): debug('control_statement') lookahead = lexer.lookahead() if (lookahead.type in if_statement_first): if_statement() elif (lookahead.type in while_statement_first): while_statement() #elif (lookahead.type in for_statement_first): # for_statement() debug_end()
def statement(): debug('statement') lookahead = lexer.lookahead() if (lookahead.type in control_statement_first): control_statement() elif (lookahead.type in expression_statement_first): expression_statement() elif (lookahead.type in return_statement_first): return_statement() elif (lookahead.type in variable_declaration_first): variable_declaration() debug_end()