Esempio n. 1
0
        public Operator ReadFunction()
        {
            Token    oTok;
            Operator obj, obj1;

            oTok = _Lexer.PeekToken();
            if (oTok != null && oTok.ID != TokenID.FUNCTION)
            {
                return(null);
            }

            oTok = _Lexer.GetToken();
            obj  = new FunctionOperator(oTok.Text);

            oTok = _Lexer.PeekToken();
            if (oTok != null && oTok.ID != TokenID.LPAREN)
            {
                MissingItemError("ReadFunction", "(");
            }
            else
            {
                _Lexer.GetToken();                 //Consume (
            }
            oTok = _Lexer.GetToken();
            while (oTok != null && oTok.ID != TokenID.RPAREN)
            {
                _Lexer.PutToken(oTok);
                obj1 = ReadArgument();

                if (obj1 == null)
                {
                    ArgumentExpectedError("ReadFunction");
                }

                obj.AddChildObject(obj1);
                oTok = _Lexer.GetToken();

                if (oTok != null && oTok.ID == TokenID.COMMA)
                {
                    oTok = _Lexer.GetToken();
                }
            }

            return(obj);
        }
Esempio n. 2
0
        public Operator ReadFactor()
        {
            Token    oTok;
            string   sText;
            Operator obj;

            oTok = _Lexer.GetToken();
            if (oTok == null)
            {
                ArgumentExpectedError("Token not found");
            }

            sText = oTok.Text;
            string sUtext = sText.ToUpper();

            switch (oTok.ID)
            {
            case TokenID.DOUBLE:
                if (sText.StartsWith("."))
                {
                    sText = "0" + sText;
                }

                double dValue = System.Convert.ToDouble(sText);
                obj = new Constant(sText, dValue);
                //ReadUnits(obj);
                break;

            case TokenID.INTEGER:
                try
                {
                    int iValue = System.Convert.ToInt32(sText);
                    obj = new Constant(sText, iValue);
                }
                catch (OverflowException)
                {
                    obj = new Constant(sText, System.Convert.ToDouble(sText));
                }
                //ReadUnits(obj);
                break;

            case TokenID.STRING:
                if (oTok.Class == TokenClass.QUOTED)
                {
                    obj = new Constant(sText, sText);
                }
                else
                {
                    obj = LiteralOrReference(sText);
                }
                break;

            case TokenID.TRUE:
            case TokenID.FALSE:
            case TokenID.YES:
            case TokenID.NO:
                obj = new Constant(sText.ToLower());
                break;

            case TokenID.MINUS:                     //Unary operators
                obj = new FunctionOperator("Negate");
                obj.AddChildObject(ReadFactor());
                break;

            case TokenID.PLUS:
                obj = new FunctionOperator("NoOp");
                obj.AddChildObject(ReadFactor());
                break;

//				case TokenID.QUOTE:  // "" found in a string
//					break;

            case TokenID.LPAREN:
                _Lexer.PutToken(oTok);
                obj = ReadGroup();
                break;

            case TokenID.LBRACE:
                _Lexer.PutToken(oTok);
                obj = ReadSet();
                break;

            case TokenID.FUNCTION:
                _Lexer.PutToken(oTok);
                obj = ReadFunction();
                break;

            case TokenID.LBRACK:
                _Lexer.PutToken(oTok);
                obj = ReadFieldReference();
                break;

            case TokenID.ATSIGN:
            case TokenID.QUESTIONMARK:
                _Lexer.PutToken(oTok);
                obj = ReadEvaluatedComponentReference();
                break;

            case TokenID.IDENTIFIER:
                if (sUtext == "PI" || sUtext == "TRUE" || sUtext == "FALSE")
                {
                    obj = new Constant(sText);
                }
                else if (OnlyLiterials == false)
                {
                    _Lexer.PutToken(oTok);
                    obj = ReadEvaluatedValueReference();
                }
                else if (Common.IsNumber(sText) == true)
                {
                    obj = new Constant(sText, System.Convert.ToDouble(sText));
                }
                else
                {
                    obj = new Constant(sText, sText);
                }
                break;

            default:
                switch (oTok.Class)
                {
                case TokenClass.CONTROL:
                    _Lexer.PutToken(oTok);
                    obj = ReadControl();
                    break;

                default:
                    obj = null;
                    break;
                }
                break;
            }
            return(obj);
        }