Пример #1
0
        private STToken ParseTokenInternal()
        {
            do
            {
                mCancelToken.ThrowIfCancellationRequested();

                if (mMatch.Success)
                {
                    if (mMatch.Index != mPosition)
                    {
                        throw new STException(string.Format(Properties.Resources.NoRecognizeStError, mText[mPosition]), mLine, mPosition);
                    }

                    var pGr = mMatch.Groups[1];

                    if (pGr.Success)
                    {
                        mPosition = pGr.Index + pGr.Length;
                    }

                    pGr = null;
                    STToken pSt = null;

                    if ((pGr = mMatch.Groups[grNumber]).Success)
                    {
                        pSt = new STTokenStr {
                            Token = ESTToken.Number, Line = mLine, Position = pGr.Index, Text = pGr.Value
                        };
                        mSymbol = null;
                    }
                    else if ((pGr = mMatch.Groups[grWord]).Success)
                    {
                        pSt = new STTokenStr {
                            Token = ESTToken.Word, Line = mLine, Position = pGr.Index, Text = pGr.Value
                        };
                        mSymbol = null;
                    }
                    else if ((pGr = mMatch.Groups[grSymbol]).Success)
                    {
                        mSymbol = pGr.Value;
                    }
                    else
                    {
                        throw new STException(string.Format(Properties.Resources.NoRecognizeStError, mText[mPosition]), mLine, mPosition);
                    }

                    if (pGr != null)
                    {
                        mPosition = pGr.Index + pGr.Length;
                    }
                    mMatch = mMatch.NextMatch();

                    return(pSt);
                }
            } while (ReadNextLine());

            mSymbol = null;

            return(null);
        }
Пример #2
0
        private bool ParseToken(out STToken argToken, out char argCar)
        {
            mCancelToken.ThrowIfCancellationRequested();
            while (mLastChar.HasValue && char.IsWhiteSpace(mLastChar.Value))
            {
                ReadChar();
            }

            if (!mLastChar.HasValue)
            {
                argToken = null;
                argCar   = '\x0';

                return(false);
            }

            int pIni, pFin, pLen = 0;
            var pCar = mLastChar.Value;

            pIni = pFin = mPosition;

            switch (pCar)
            {
            case STTokenChars.Terminate:
            case STTokenChars.TerminateNoShowOut:
                argToken = null;
                argCar   = pCar;

                return(true);

            default:
                if (char.IsDigit(pCar))
                {
                    do
                    {
                        ReadChar();
                        pLen++;
                    } while (mLastChar.HasValue && char.IsDigit(mLastChar.Value));

                    argToken = new STTokenStr {
                        Token = ESTToken.Numeric, Position = pIni, Text = mText.Substring(pIni, pLen)
                    };
                    argCar = '\x0';

                    return(true);
                }
                break;
            }

            throw new STException(string.Format(Properties.Resources.NoRecognizeStError, pCar), pIni);
        }