//check lhs and rhs are the same and assign node type based on lhs or rhs type public void VisitNode(ArithmeticExpression node) { AbstractNode expr1 = node.Child; AbstractNode expr2 = expr1.Sib; expr1.Accept(this); expr2.Accept(this); if (Assignable(expr1.TypeRef, expr2.TypeRef)) { node.TypeRef = expr1.TypeRef; } else { Console.WriteLine("Right hand side expression is not assignable to left hand side"); node.TypeRef = new ErrorTypeDescriptor(); } }
public void VisitNode(ArithmeticExpression node) { AbstractNode expr1 = node.Child; AbstractNode expr2 = expr1.Sib; VisitChildren(node); using (FileStream fs = File.Open(GlobalVar.PATH, FileMode.Append)) { using (StreamWriter sw = new StreamWriter(fs)) { switch (node.GetType().ToString()) { case ("ASTBuilder.Plus"): sw.WriteLine("add"); break; case ("ASTBuilder.Minus"): sw.WriteLine("sub"); break; case ("ASTBuilder.Multiply"): sw.WriteLine("mul"); break; case ("ASTBuilder.Division"): sw.WriteLine("div"); break; } } } }