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); } } }
public override Lexem ReadNextLexem(SourceCodeIterator iterator) { bool isEndOfText = false; char cs = '\0'; int currentLine = iterator.CurrentLine; while (true) { if (!isEndOfText) { cs = iterator.CurrentSymbol; } if (SpecialChars.IsDelimiter(cs) || isEndOfText) { var content = iterator.GetContents(); Lexem lex; if (LanguageDef.IsLogicalOperatorString(content)) { lex = new Lexem() { Type = LexemType.Operator, Token = LanguageDef.GetToken(content), Content = content, LineNumber = currentLine }; } else if (LanguageDef.IsBooleanLiteralString(content)) { lex = new Lexem() { Type = LexemType.BooleanLiteral, Content = content, LineNumber = currentLine }; } else if (LanguageDef.IsUndefinedString(content)) { lex = new Lexem() { Type = LexemType.UndefinedLiteral, Content = content, LineNumber = currentLine }; } else if (LanguageDef.IsNullString(content)) { lex = new Lexem() { Type = LexemType.NullLiteral, Content = content, LineNumber = currentLine }; } else { lex = new Lexem() { Type = LexemType.Identifier, Content = content, Token = LanguageDef.GetToken(content), LineNumber = currentLine }; if (LanguageDef.IsBuiltInFunction(lex.Token)) { iterator.SkipSpaces(); if (iterator.CurrentSymbol != '(') { lex.Token = Token.NotAToken; } } } return(lex); } if (!iterator.MoveNext()) { isEndOfText = true; } } }