Пример #1
0
 /// <summary>
 /// Ignores the rest of a string.
 /// </summary>
 /// <param name="charStream">The SimpleCharStream object.</param>
 /// <param name="curChar">The last character read. Set to '\0' to ignore.</param>
 private void IgnoreRest(SimpleCharStream charStream, char curChar)
 {
     while (curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
            curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#')
     {
         curChar = charStream.ReadChar();
     }
     charStream.Backup(1);
 }
Пример #2
0
        private void IgnoreString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char curChar;

            do
            {
                curChar = charStream.ReadChar();
            }while(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
                   curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#');
            charStream.Backup(1);
        }
Пример #3
0
        private bool MatchString(SimpleCharStream charStream, String str)
        {
            IgnoreSpace(charStream);

            char curChar;

            for (int i = 0; i < str.Length; i++)
            {
                curChar = charStream.ReadChar();
                if (curChar != str[i])
                {
                    charStream.Backup(i + 1);       // unread chars
                    return(false);
                }
            }
            curChar = charStream.ReadChar();
            if (curChar != ' ' && curChar != '\t' && curChar != '\n' && curChar != '\r')
            {
                charStream.Backup(str.Length + 1);  // unread chars
                return(false);
            }
            return(true);
        }
Пример #4
0
        private void IgnoreSpace(SimpleCharStream charStream)
        {
            char curChar;

            do
            {
                curChar = charStream.ReadChar();
                if (curChar == '/')
                {
                    IgnoreComment(charStream);
                    curChar = ' ';
                    continue;
                }
            }while(curChar == ' ' || curChar == '\t' || curChar == '\n' || curChar == '\r');
            charStream.Backup(1);
        }
Пример #5
0
        private void IgnoreOther(SimpleCharStream charStream)
        {
            char curChar;

            do
            {
                curChar = charStream.ReadChar();
                if (curChar == '/')
                {
                    IgnoreComment(charStream);
                    curChar = ' ';
                    continue;
                }
            }while(!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
                     curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'));
            charStream.Backup(1);
        }
Пример #6
0
        private String ReadString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char          curChar;
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                curChar = charStream.ReadChar();
                if (!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z' ||
                      curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'))
                {
                    break;
                }
                sb.Append(curChar);
            }
            charStream.Backup(1);
            return(sb.ToString());
        }
Пример #7
0
        /// <summary>Get the next Token.</summary>
        public Token GetNextToken()
        {
            Token matchedToken;
            int   curPos = 0;

            for (;;)
            {
                try
                {
                    curChar = input_stream.BeginToken();
                }
                catch (System.IO.IOException)
                {
                    jjmatchedKind = 0;
                    matchedToken  = JjFillToken();
                    return(matchedToken);
                }

                switch (curLexState)
                {
                case 0:
                    jjmatchedKind = 0x7fffffff;
                    jjmatchedPos  = 0;
                    curPos        = JjMoveStringLiteralDfa0_0();
                    break;

                case 1:
                    jjmatchedKind = 0x7fffffff;
                    jjmatchedPos  = 0;
                    curPos        = JjMoveStringLiteralDfa0_1();
                    break;
                }
                if (jjmatchedKind != 0x7fffffff)
                {
                    if (jjmatchedPos + 1 < curPos)
                    {
                        input_stream.Backup(curPos - jjmatchedPos - 1);
                    }
                    matchedToken = JjFillToken();
                    if (jjnewLexState[jjmatchedKind] != -1)
                    {
                        curLexState = jjnewLexState[jjmatchedKind];
                    }
                    return(matchedToken);
                }
                int    error_line   = input_stream.GetEndLine();
                int    error_column = input_stream.GetEndColumn();
                string error_after  = null;
                bool   EOFSeen      = false;
                try { input_stream.ReadChar(); input_stream.Backup(1); }
                catch (System.IO.IOException)
                {
                    EOFSeen     = true;
                    error_after = curPos <= 1 ? "" : input_stream.GetImage();
                    if (curChar == '\n' || curChar == '\r')
                    {
                        error_line++;
                        error_column = 0;
                    }
                    else
                    {
                        error_column++;
                    }
                }
                if (!EOFSeen)
                {
                    input_stream.Backup(1);
                    error_after = curPos <= 1 ? "" : input_stream.GetImage();
                }
                throw new TokenManagerException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenManagerException.ErrorCodes.LexicalError);
            }
        }
Пример #8
0
    public Token GetNextToken()
    {
        int   kind;
        Token specialToken = null;
        Token matchedToken;
        int   curPos = 0;

        for (;;)
        {
            try {
                curChar = input_stream.BeginToken();
            } catch (System.IO.IOException) {
                mccmatchedKind = 0;
                matchedToken   = mccFillToken();
                return(matchedToken);
            }

            mccmatchedKind = Int32.MaxValue;
            mccmatchedPos  = 0;
            curPos         = mccMoveStringLiteralDfa0_0();
            if (mccmatchedKind != Int32.MaxValue)
            {
                if (mccmatchedPos + 1 < curPos)
                {
                    input_stream.Backup(curPos - mccmatchedPos - 1);
                }
                if ((mcctoToken[mccmatchedKind >> 6] & (1L << (mccmatchedKind & 63))) != 0L)
                {
                    matchedToken = mccFillToken();
                    return(matchedToken);
                }
                else
                {
                    goto EOFLoop;
                }
            }
            int    error_line   = input_stream.EndLine;
            int    error_column = input_stream.EndColumn;
            string error_after  = null;
            bool   EOFSeen      = false;
            try { input_stream.ReadChar(); input_stream.Backup(1); }
            catch (System.IO.IOException) {
                EOFSeen     = true;
                error_after = curPos <= 1 ? "" : input_stream.GetImage();
                if (curChar == '\n' || curChar == '\r')
                {
                    error_line++;
                    error_column = 0;
                }
                else
                {
                    error_column++;
                }
            }
            if (!EOFSeen)
            {
                input_stream.Backup(1);
                error_after = curPos <= 1 ? "" : input_stream.GetImage();
            }
            throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LexicalError);
            EOFLoop :;
        }
    }
Пример #9
0
        private bool MatchString(SimpleCharStream charStream, String str)
        {
            IgnoreSpace(charStream);

            char curChar;
            for(int i = 0; i < str.Length; i++)
            {
                curChar = charStream.ReadChar();
                if(curChar != str[i])
                {
                    charStream.Backup(i + 1);       // unread chars
                    return false;
                }
            }
            curChar = charStream.ReadChar();
            if(curChar != ' ' && curChar != '\t' && curChar != '\n' && curChar != '\r')
            {
                charStream.Backup(str.Length + 1);  // unread chars
                return false;
            }
            return true;
        }
Пример #10
0
        private String ReadString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char curChar;
            StringBuilder sb = new StringBuilder();
            while(true)
            {
                curChar = charStream.ReadChar();
                if(!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
						|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'))
                    break;
                sb.Append(curChar);
            }
            charStream.Backup(1);
            return sb.ToString();
        }
Пример #11
0
        /// <summary>
        /// Ignores the rest of a string.
        /// </summary>
        /// <param name="charStream">The SimpleCharStream object.</param>
        /// <param name="curChar">The last character read. Set to '\0' to ignore.</param>
        private void IgnoreRest(SimpleCharStream charStream, char curChar)
        {
            while(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
					|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#')
            {
                curChar = charStream.ReadChar();
            }
            charStream.Backup(1);
        }
Пример #12
0
        private void IgnoreString(SimpleCharStream charStream)
        {
            IgnoreSpace(charStream);

            char curChar;
            do
            {
                curChar = charStream.ReadChar();
            }
            while(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
					|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#');
            charStream.Backup(1);
        }
Пример #13
0
        private void IgnoreOther(SimpleCharStream charStream)
        {
            char curChar;
            do
            {
                curChar = charStream.ReadChar();
                if(curChar == '/')
                {
                    IgnoreComment(charStream);
                    curChar = ' ';
                    continue;
                }
            }
            while(!(curChar >= 'A' && curChar <= 'Z' || curChar >= 'a' && curChar <= 'z'
					|| curChar >= '0' && curChar <= '9' || curChar == '_' || curChar == '#'));
            charStream.Backup(1);
        }
Пример #14
0
 private void IgnoreSpace(SimpleCharStream charStream)
 {
     char curChar;
     do
     {
         curChar = charStream.ReadChar();
         if(curChar == '/')
         {
             IgnoreComment(charStream);
             curChar = ' ';
             continue;
         }
     }
     while(curChar == ' ' || curChar == '\t' || curChar == '\n' || curChar == '\r');
     charStream.Backup(1);
 }