예제 #1
0
        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);
        }
예제 #2
0
 public override double Visit(AddNode node)
 {
     return(Visit(node.Left) + Visit(node.Right));
 }