def parse_statement(self): node = self.parse_base_statement() while self.current_raw is ';': self.consume_token() rhs = self.parse_base_statement() node = ast.BinaryOperator(node, ';', rhs, 'PUNCTUATION') return node
def parse_expression(self): node = self.parse_term() while self.current_raw is '+': self.consume_token() node = ast.BinaryOperator(node, '+', self.parse_term(), 'PUNCTUATION') return node
def parse_term(self): node = self.parse_factor() while self.current_raw is '-': self.consume_token() node = ast.BinaryOperator(node, '-', self.parse_factor(), 'PUNCTUATION') return node
def parse_piece(self): node = self.parse_element() while self.current_raw is '*': self.consume_token() node = ast.BinaryOperator(node, '*', self.parse_element(), 'PUNCTUATION') return node
def parse_while_statement(self): predicate = self.parse_expression() if self.current_raw == "do": self.consume_token() loop_state = self.parse_statement() self.consume_token() if self.current_raw == "endwhile": node = ast.BinaryOperator(predicate, 'while', loop_state, 'KEYWORD') self.consume_token() return node self.error()
def parse_assignment(self, lhs): rhs = self.parse_expression() node = ast.BinaryOperator(lhs, ':=', rhs, 'PUNCTUATION') return node
def expr_binop(s): return ast.BinaryOperator(s[1].getstr(), s[0], s[2])
def parse(self, parser, tokens, left): token = tokens.consume_expected('OPERATOR') right = Expression().parse(parser, tokens, self.get_precedence(token)) if right is None: raise ParserError('Expected expression'.format(token.value), tokens.consume()) return ast.BinaryOperator(token.value, left, right)