コード例 #1
0
        public override ExpressionNode VisitInfixExpr(CoronaParser.InfixExprContext context)
        {
            // Get infix expression node type
            InfixExpressionNode node = context.op.GetText() switch
            {
                "+" => new AdditionNode(),
                "-" => new SubstractionNode(),
                "*" => new MultiplicationNode(),
                "/" => new DivisionNode(),
                _ => throw new ArgumentOutOfRangeException("context", "Unknown operator in switch statement - VisitInfixExpr")
            };

            // Visit the left and  of the node
            node.Left  = Visit(context.left);
            node.Right = Visit(context.right);

            return(node);
        }
コード例 #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>InfixExpr</c>
 /// labeled alternative in <see cref="CoronaParser.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] CoronaParser.InfixExprContext context)
 {
     return(VisitChildren(context));
 }
コード例 #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>InfixExpr</c>
 /// labeled alternative in <see cref="CoronaParser.expr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitInfixExpr([NotNull] CoronaParser.InfixExprContext context)
 {
 }