Esempio n. 1
0
        public override Lexem ReadNextLexem(SourceCodeIterator iterator)
        {
            bool hasDecimalPoint = false;

            while (true)
            {
                if (Char.IsDigit(iterator.CurrentSymbol))
                {
                    if (!iterator.MoveNext())
                    {
                        var lex = new Lexem()
                        {
                            Type    = LexemType.NumberLiteral,
                            Content = iterator.GetContents()
                        };

                        return(lex);
                    }
                }
                else if (SpecialChars.IsDelimiter(iterator.CurrentSymbol))
                {
                    if (iterator.CurrentSymbol == '.')
                    {
                        if (!hasDecimalPoint)
                        {
                            hasDecimalPoint = true;
                            iterator.MoveNext();
                            continue;
                        }
                        else
                        {
                            throw CreateExceptionOnCurrentLine("Некорректно указана десятичная точка в числе", iterator);
                        }
                    }

                    var lex = new Lexem()
                    {
                        Type    = LexemType.NumberLiteral,
                        Content = iterator.GetContents()
                    };

                    return(lex);
                }
                else
                {
                    throw CreateExceptionOnCurrentLine("Некорректный символ", iterator);
                }
            }
        }
Esempio n. 2
0
        private LexerState SelectState()
        {
            char cs = _iterator.CurrentSymbol;

            if (Char.IsLetter(cs) || cs == SpecialChars.Underscore)
            {
                _state = _wordState;
            }
            else if (Char.IsDigit(cs))
            {
                _state = _numberState;
            }
            else if (cs == SpecialChars.DateQuote)
            {
                _state = _dateState;
            }
            else if (cs == SpecialChars.StringQuote)
            {
                _state = _stringState;
            }
            else if (SpecialChars.IsOperatorChar(cs))
            {
                _state = CommentOrOperatorState(cs);
            }
            else if (cs == SpecialChars.EndOperator)
            {
                SetFixedState(LexemType.EndOperator, Token.Semicolon);
            }
            else if (cs == SpecialChars.QuestionMark)
            {
                SetFixedState(LexemType.Operator, Token.Question);
            }
            else if (cs == SpecialChars.Preprocessor)
            {
                _state = _directiveState;
            }
            else if (cs == SpecialChars.Annotation)
            {
                _iterator.GetContents();
                _iterator.MoveNext();
                _state = _annotationState;
            }
            else
            {
                var cp  = _iterator.GetPositionInfo();
                var exc = new SyntaxErrorException(cp, string.Format("Неизвестный символ {0}", cs));
                if (!HandleError(exc))
                {
                    throw exc;
                }
            }

            return(_state);
        }
Esempio n. 3
0
        public override Lexem ReadNextLexem(SourceCodeIterator iterator)
        {
            var numbers = new StringBuilder();

            while (iterator.MoveNext())
            {
                var cs = iterator.CurrentSymbol;
                if (cs == SpecialChars.DateQuote)
                {
                    iterator.GetContents(1, 1);
                    iterator.MoveNext();

                    try
                    {
                        var lex = new Lexem()
                        {
                            Type    = LexemType.DateLiteral,
                            Content = FullDateTimeString(numbers)
                        };

                        return(lex);
                    }
                    catch (FormatException)
                    {
                        throw CreateExceptionOnCurrentLine("Некорректный литерал даты", iterator);
                    }
                }

                if (Char.IsDigit(cs))
                {
                    numbers.Append(cs);
                }

                if (numbers.Length > 14)
                {
                    throw CreateExceptionOnCurrentLine("Некорректный литерал даты", iterator);
                }
            }

            throw CreateExceptionOnCurrentLine("Незавершенный литерал даты", iterator);
        }