def wrapOperand(token): if token["type"] == "T": return ast.TrueNode() if token["type"] == "F": return ast.FalseNode() if token["type"] == "variable": return ast.VariableNode(token["index"])
def parse_atom(self): token = self.get_current_token() if token.lexme_type == LexmeType.Variable: if self.lookup_for_n(1).word == '[': self.move_for_n(2) index_expr_node = self.parse_expr() right_bracket = self.get_current_token() if right_bracket.word == ']': self.move_for_n(1) return ast.ArrayVariableNode(self.context, token, index_expr_node) else: raise cmexception.SyntaxException(right_bracket, [']']) elif self.lookup_for_n(1).word == '(': self.move_for_n(2) valuelist = self.parse_array_value_list() right_brace = self.get_current_token() if right_brace.word == ')': self.move_for_n(1) return ast.FunctionCallNode(self.context, token, valuelist) else: raise cmexception.SyntaxException(right_brace, [')']) else: self.move_for_n(1) return ast.VariableNode(self.context, token) elif token.word == '(': lookup1 = self.lookup_for_n(1) if lookup1.is_type(): lookup2 = self.lookup_for_n(2) if lookup2.word == ')': self.move_for_n(3) expr_node = self.parse_expr() return ast.CastExprNode(self.context, expr_node, lookup1) else: self.move_for_n(1) expr_node = self.parse_expr() right_brace = self.get_current_token() if right_brace.word == ')': self.move_for_n(1) return expr_node else: raise cmexception.SyntaxException(right_brace, [')']) elif token.lexme_type == LexmeType.Double: self.move_for_n(1) return ast.ConstantNode(self.context, token) elif token.lexme_type == LexmeType.Integer: self.move_for_n(1) return ast.ConstantNode(self.context, token) elif token.lexme_type == LexmeType.Char: self.move_for_n(1) return ast.ConstantNode(self.context, token) else: raise cmexception.SyntaxException(token, [ '<legal identifier>', '(', '<legal number>', '<ascii character>' ])
def p_variable(p): '''expression : VARIABLE''' p[0] = ast.VariableNode(p[1])
def p_stmt_ariarithh_eq(p): """stmt : VAR EQUALS value arithmetic_op value""" p[0] = ast.EqNode(ast.VariableNode(p[1]), ast.ArithExprNode(p[4], p[3], p[5]))
def p_stmt_cmp_eq(p): """stmt : VAR EQUALS value comparison_op value""" p[0] = ast.EqNode(ast.VariableNode(p[1]), ast.CmpExprNode(p[4], p[3], p[5]))
def p_stmt_eq(p): """stmt : VAR EQUALS value""" p[0] = ast.EqNode(ast.VariableNode(p[1]), p[3])
def p_value_var(p): """value : VAR""" p[0] = ast.VariableNode(p[1])
def p_var_list(p): """var_list : VAR var_list""" p[0] = p[2] p[0].insert(0, ast.VariableNode(p[1]))