Exemplo n.º 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);
        }
Exemplo n.º 2
0
 public override double Visit(MulNode node)
 {
     return(Visit(node.Left) * Visit(node.Right));
 }