public bool TryScan(Pointer pointer, out Token token)
        {
            token = null;

            if (pointer.Current != PLUS && pointer.Current != MINUS && !IsNumeric(pointer.Current))
            {
                return(false);
            }

            if ((pointer.Current == PLUS || pointer.Current == MINUS) && !IsNumeric(pointer.Next))
            {
                return(false);
            }

            string numericString = ScanNumericString(pointer, out bool isFloat);

            if (isFloat)
            {
                token = new RealToken(float.Parse(numericString));
            }
            else
            {
                token = new IntegerToken(int.Parse(numericString));
            }

            return(true);
        }
Esempio n. 2
0
        private Expression Factor()
        {
            Expression expr = null;

            switch (look.Tag)
            {
            case '(':
                Move();
                expr = Bool();
                Match(')');
                return(expr);

            case Tags.NUMBER:
                IntegerToken token = (IntegerToken)look;
                expr = new IntConstantExpression(token.Value);
                Move();
                return(expr);

            case Tags.REAL:
                RealToken realToken = (RealToken)look;
                expr = new FloatConstantExpression(realToken.Value);
                Move();
                return(expr);

            case Tags.TRUE:
                Move();
                return(BoolConstantExpression.True);;

            case Tags.FALSE:
                Move();
                return(BoolConstantExpression.False);

            case Tags.ID:
                Move();

                if (look.Tag == '(')
                {
                    return(FuncCallExpression());
                }
                else
                {
                    VariableUseExpression varUseExpr = VariableUseExpression();
                    if (look.Tag == Tags.INCR)
                    {
                        Expression incrExpr = UnaryArithmeticExpression.CreatePostIncrement(varUseExpr);
                        Move();
                        return(incrExpr);
                    }
                    if (look.Tag == Tags.DECR)
                    {
                        Expression decrExpr = UnaryArithmeticExpression.CreatePostDecrement(varUseExpr);
                        Move();
                        return(decrExpr);
                    }
                    if (look.Tag == '=')
                    {
                        Move();
                        return(new VariableAssignExpression(varUseExpr, Bool()));
                    }

                    return(varUseExpr);
                }
            }

            Error("Syntax error");
            return(null);
        }
Esempio n. 3
0
 public IEnumerable <Tuple <T, StreamSequenceToken> > GetEvents <T>()
 {
     return(Payload.OfType <T>().Select((e, i) => Tuple.Create(e, (StreamSequenceToken)RealToken.CreateSequenceTokenForEvent(i))));
 }