def nud(self, lex): lex.eat() subresult = parser.expression(0, lex) if not isinstance(lex.curr(), RPar): raise ValueError("Missing ) in expression") lex.eat() return subresult
def led(self, left, lex): lex.eat() return left / parser.expression(self.lbp(), lex)
import lexer import parser lex = lexer.Lexer("1*1*3+2*7-(2+16*(6*2-(8-1)))/3*2-1") print(parser.expression(0, lex))