// Returns NExprAdd or any of subproduction nodes public Node ExprAdd() { Node resultingNode = ExprMul(); while (CurrentToken == TokenCategory.SUBTRACTION || CurrentToken == TokenCategory.ADDITION) { NExprAdd tmp = new NExprAdd(); tmp.Add(resultingNode); resultingNode = tmp; switch (CurrentToken) { case TokenCategory.SUBTRACTION: { resultingNode.AnchorToken = Expect(TokenCategory.SUBTRACTION); resultingNode.Add(ExprMul()); break; } case TokenCategory.ADDITION: { resultingNode.AnchorToken = Expect(TokenCategory.ADDITION); resultingNode.Add(ExprMul()); break; } // Default case would be unreachable } } return(resultingNode); }
public string Visit(NExprAdd nExprAdd) { string retVal = ""; if (nExprAdd.children.Count == 1) { retVal += Visit((dynamic)nExprAdd[0]); } else { switch (nExprAdd.AnchorToken.Lexeme) { case "+": { retVal += Visit((dynamic)nExprAdd[0]); retVal += Visit((dynamic)nExprAdd[1]); retVal += "\t\tadd\n"; break; } case "-": { retVal += Visit((dynamic)nExprAdd[0]); retVal += Visit((dynamic)nExprAdd[1]); retVal += "\t\tsub\n"; break; } } } return(retVal); }
//----------------------------------------------------------- public void Visit(NExprAdd node) { Console.WriteLine($"+++++++++++++++ NExprAdd ++++++++++++++++"); VisitBinaryOperator('+', node /*, Type.INT*/); }
public void Visit(NExprAdd nExprAdd) { GenericChildVisitor(nExprAdd); }