def parse_exp7(lexer): exp = ExpParser.parse_exp6(lexer) while lexer.look_ahead() == TokenKind.OP_BAND: line, op, _ = lexer.get_next_token() bor = lua_exp.BinopExp(line, op, exp, ExpParser.parse_exp8(lexer)) exp = Optimizer.optimize_bitwise_binary_op(bor) return exp
def parse_exp11(lexer): exp = ExpParser.parse_exp10(lexer) while lexer.look_ahead() == TokenKind.OP_AND: line, op, _ = lexer.get_next_token() lor = lua_exp.BinopExp(line, op, exp, ExpParser.parse_exp10(lexer)) exp = Optimizer.optimize_logical_and(lor) return exp
def parse_exp6(lexer): exp = ExpParser.parse_exp5(lexer) if lexer.look_ahead() in (TokenKind.OP_SHL, TokenKind.OP_SHR): line, op, _ = lexer.get_next_token() shx = lua_exp.BinopExp(line, op, exp, ExpParser.parse_exp5(lexer)) exp = Optimizer.optimize_bitwise_binary_op(shx) else: return exp return exp
def parse_exp10(lexer): exp = ExpParser.parse_exp9(lexer) while True: kind = lexer.look_ahead() if kind in (TokenKind.OP_LT, TokenKind.OP_GT, TokenKind.OP_NE, TokenKind.OP_LE, TokenKind.OP_GE, TokenKind.OP_EQ): line, op, _ = lexer.get_next_token() exp = lua_exp.BinopExp(line, op, exp, ExpParser.parse_exp9(lexer)) else: return exp
def parse_exp4(lexer): exp = ExpParser.parse_exp3(lexer) while True: if lexer.look_ahead() in (TokenKind.OP_ADD, TokenKind.OP_SUB): line, op, _ = lexer.get_next_token() arith = lua_exp.BinopExp(line, op, exp, ExpParser.parse_exp3(lexer)) exp = Optimizer.optimize_arith_binary_op(arith) else: break return exp
def parse_exp1(lexer): exp = ExpParser.parse_exp0(lexer) if lexer.look_ahead() == TokenKind.OP_POW: line, op, _ = lexer.get_next_token() exp = lua_exp.BinopExp(line, op, exp, ExpParser.parse_exp2(lexer)) return Optimizer.optimize_pow(exp)