예제 #1
0
파일: Lexer.cs 프로젝트: m2sf/m2sharp
        } /* end GetPrefixedNumber */

/* ---------------------------------------------------------------------------
 * private method GetSuffixedNumber()
 * ------------------------------------------------------------------------ */

        private char GetSuffixedNumber(out Token token)
        {
            Token intermediate;
            uint  charCount0to7 = 0;
            uint  charCount8to9 = 0;
            uint  charCountAtoF = 0;
            char  nextChar, lastChar;

            infile.MarkLexeme();
            lastChar = ASCII.NUL;
            nextChar = infile.NextChar();

            /* consume any characters '0' to '9' and 'A' to 'F' */
            while (ASCII.IsDigit(nextChar) || ASCII.IsAtoF(nextChar))
            {
                if ((nextChar >= '0') && (nextChar <= '7'))
                {
                    charCount0to7++;
                }
                else if ((nextChar == '8') || (nextChar == '9'))
                {
                    charCount8to9++;
                }
                else
                {
                    charCountAtoF++;
                } /* end if */

                lastChar = nextChar;
                nextChar = infile.ConsumeChar();
            } /* end while */

            if /* base-16 integer found */ (nextChar == 'H')
            {
                nextChar     = infile.ConsumeChar();
                intermediate = Token.IntLiteral;
            }
            else if /* base-10 integer or real number found */
            (charCountAtoF == 0)
            {
                if /* real number literal found */
                ((nextChar == '.') && (infile.LA2Char() != '.'))
                {
                    nextChar = GetNumberLiteralFractionalPart(out intermediate);
                }
                else /* decimal integer found */
                {
                    intermediate = Token.IntLiteral;
                } /* end if */
            }
            else if /* base-8 integer found */
            (CompilerOptions.OctalLiterals() &&
             (charCount8to9 == 0) && (charCountAtoF == 1) &&
             ((lastChar == 'B') || (lastChar == 'C')))
            {
                if (lastChar == 'B')
                {
                    intermediate = Token.IntLiteral;
                }
                else /* last_char == 'C' */
                {
                    intermediate = Token.CharLiteral;
                } /* end if */
            }
            else  /* malformed base-16 integer */
            {
                intermediate = Token.MalformedInteger;
            } /* end if */

            lookaheadSym.lexeme = infile.ReadMarkedLexeme();

            token = intermediate;

            return(nextChar);
        } /* end GetSuffixedNumber */