Beispiel #1
0
        /// <summary>String literal scan.</summary>
        public static void ScanString()
        {
            //Current character = "
            Text.NextCh();             //Skip "
            string octal = "01234567";

            if (Text.Ch() == '"')
            {
                Text.NextCh();
                _lex = Lex.STRINGLITERAL;
            }
            else
            {
                while (Text.Ch() != '"' && Text.ChNext() != '\n' && Text.ChNext() != '\r' && Text.Ch() != Text.ChEOT)
                {
                    if (Text.Ch() == '\\')
                    {
                        Text.NextCh();
                        if (Text.Ch() == 'u')
                        {
                            CharAnalysis.UnicodeString();
                        }
                        else if (Text.Ch() == 't' || Text.Ch() == 'r' || Text.Ch() == 'f' || Text.Ch() == 'b' || Text.Ch() == 'n')
                        {
                            Text.NextCh();
                        }
                        else if (Text.Ch() == '\\' || Text.Ch() == '"')
                        {
                            Text.NextCh();
                        }
                        else if (octal.Contains(Text.Ch()))
                        {
                            CharAnalysis.OctalCharScan();
                        }
                        else
                        {
                            Error.LexError("Неправильная запись ");
                        }
                    }
                    else
                    {
                        Text.NextCh();
                    }
                }
                if (Text.Ch() == '"')
                {
                    Text.NextCh();
                    _lex = Lex.STRINGLITERAL;
                }
                else
                {
                    Error.LexError("Кавычка не закрыта");
                }
            }
        }
Beispiel #2
0
        /// <summary>Character lex scan. </summary>
        public static void ScanChar()
        {
            //Current character = "'".
            Text.NextCh();             //Skip '

            if (Text.Ch() == '\\')
            {
                _lex = CharAnalysis.EscapeSequence();
            }
            else
            {
                _lex = CharAnalysis.SingleChar();
            }
        }