public OperandContext operand()
    {
        OperandContext _localctx = new OperandContext(Context, State);

        EnterRule(_localctx, 6, RULE_operand);
        int _la;

        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 32;
                _la   = TokenStream.LA(1);
                if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << VARIABLE) | (1L << NUMBER) | (1L << STRING))) != 0)))
                {
                    ErrorHandler.RecoverInline(this);
                }
                else
                {
                    ErrorHandler.ReportMatch(this);
                    Consume();
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
 private bool operand_sempred(OperandContext _localctx, int predIndex)
 {
     switch (predIndex)
     {
     case 0: return(Precpred(Context, 1));
     }
     return(true);
 }
Exemplo n.º 3
0
    public OperandContext operand()
    {
        OperandContext _localctx = new OperandContext(Context, State);

        EnterRule(_localctx, 2, RULE_operand);
        int _la;

        try {
            State = 22;
            ErrorHandler.Sync(this);
            switch (TokenStream.LA(1))
            {
            case DIGIT:
                EnterOuterAlt(_localctx, 1);
                {
                    State = 11; Match(DIGIT);
                }
                break;

            case LPAREN:
                EnterOuterAlt(_localctx, 2);
                {
                    State = 12; Match(LPAREN);
                    State = 13; operand();
                    State = 16;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    do
                    {
                        {
                            {
                                State = 14; Match(OPERATOR);
                                State = 15; operand();
                            }
                        }
                        State = 18;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                    } while (_la == OPERATOR);
                    State = 20; Match(RPAREN);
                }
                break;

            default:
                throw new NoViableAltException(this);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
Exemplo n.º 4
0
 public override bool Consume(OperandContext ctx)
 {
     if (Operator == ArithmeticOperators.Define)
     {
         ctx.Variables[((VariableNode)Left).VariableName] = Right.Evaluate(ctx);
         return true;
     }
     return false;
 }
 public abstract double Evaluate(OperandContext ctx);
 public virtual bool Consume(OperandContext ctx)
 {
     return false;
 }
Exemplo n.º 7
0
 public override double Evaluate(OperandContext ctx)
 {
     if (Left == null || (Right == null && Precedence != Precedence.Unary))
         throw new Exception("Trying to evaluate operator withouth any operands");
     return Algebra.ArithmeticEvaluators[Operator](Left.Evaluate(ctx), Right.Evaluate(ctx));
 }
    private OperandContext operand(int _p)
    {
        ParserRuleContext _parentctx = Context;
        int            _parentState  = State;
        OperandContext _localctx     = new OperandContext(Context, _parentState);
        OperandContext _prevctx      = _localctx;
        int            _startState   = 8;

        EnterRecursionRule(_localctx, 8, RULE_operand, _p);
        try {
            int _alt;
            EnterOuterAlt(_localctx, 1);
            {
                State = 38;
                ErrorHandler.Sync(this);
                switch (TokenStream.LA(1))
                {
                case IDENTIFIER:
                {
                    _localctx = new Expr_identContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;

                    State = 36; Match(IDENTIFIER);
                }
                break;

                case UINT:
                {
                    _localctx = new Expr_uintContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 37; Match(UINT);
                }
                break;

                default:
                    throw new NoViableAltException(this);
                }
                Context.Stop = TokenStream.LT(-1);
                State        = 45;
                ErrorHandler.Sync(this);
                _alt = Interpreter.AdaptivePredict(TokenStream, 5, Context);
                while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                {
                    if (_alt == 1)
                    {
                        if (ParseListeners != null)
                        {
                            TriggerExitRuleEvent();
                        }
                        _prevctx = _localctx;
                        {
                            {
                                _localctx = new Expr_indexedContext(new OperandContext(_parentctx, _parentState));
                                ((Expr_indexedContext)_localctx).baseOpe = _prevctx;
                                PushNewRecursionContext(_localctx, _startState, RULE_operand);
                                State = 40;
                                if (!(Precpred(Context, 1)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 1)");
                                }
                                State = 41; Match(COLON);
                                State = 42; ((Expr_indexedContext)_localctx).indexOpe = operand(2);
                            }
                        }
                    }
                    State = 47;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 5, Context);
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            UnrollRecursionContexts(_parentctx);
        }
        return(_localctx);
    }
 public Expr_indexedContext(OperandContext context)
 {
     CopyFrom(context);
 }
 public Expr_identContext(OperandContext context)
 {
     CopyFrom(context);
 }
 public virtual void CopyFrom(OperandContext context)
 {
     base.CopyFrom(context);
 }
Exemplo n.º 12
0
        public override double Evaluate(OperandContext ctx)
        {
            if (string.IsNullOrEmpty(VariableName))
                throw new UndefinedVariableException("Attempt to reference unnamed variable");

            if (!ctx.Variables.ContainsKey(VariableName))
                throw new UndefinedVariableException("Undefined variable '" + VariableName + "' referenced");

            return ctx.Variables[VariableName];
        }
Exemplo n.º 13
0
 public override double Evaluate(OperandContext ctx)
 {
     return Value;
 }