public override ExprNode VisitInfixExpr(ExprParser.InfixExprContext context) { InfixNode node; switch (context.op.Type) { case ExprLexer.OP_ADD: node = new AddNode(); break; case ExprLexer.OP_SUB: node = new SubNode(); break; case ExprLexer.OP_DIV: node = new DivNode(); break; case ExprLexer.OP_MUL: node = new MulNode(); break; case ExprLexer.OP_POW: node = new PowNode(); break; default: throw new NotSupportedException($"Operation type {context.op.Type} is not supported"); } node.Left = Visit(context.left); node.Right = Visit(context.right); return(node); }
/// <summary> /// Exit a parse tree produced by the <c>infixExpr</c> /// labeled alternative in <see cref="ExprParser.expr"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitInfixExpr([NotNull] ExprParser.InfixExprContext context) { }
/// <summary> /// Visit a parse tree produced by the <c>infixExpr</c> /// labeled alternative in <see cref="ExprParser.expr"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitInfixExpr([NotNull] ExprParser.InfixExprContext context) { return(VisitChildren(context)); }