public override Lexem ReadNextLexem(ParseIterator iterator) { var numbers = new StringBuilder(); while (iterator.MoveNext()) { var cs = iterator.CurrentSymbol; if (cs == SpecialChars.DateQuote) { iterator.GetContents(1, 1); iterator.MoveNext(); var lex = new Lexem() { Type = LexemType.DateLiteral, Content = numbers.ToString() }; return(lex); } else if (Char.IsDigit(cs)) { numbers.Append(cs); } if (numbers.Length > 14) { throw CreateExceptionOnCurrentLine("Некорректный литерал даты", iterator); } } throw CreateExceptionOnCurrentLine("Незавершенный литерал даты", iterator); }
public override Lexem ReadNextLexem(ParseIterator iterator) { while (iterator.MoveNext()) { var cs = iterator.CurrentSymbol; if (cs == SpecialChars.DateQuote) { var lex = new Lexem() { Type = LexemType.DateLiteral, Content = iterator.GetContents(1, 1).content }; iterator.MoveNext(); return(lex); } else if (!Char.IsDigit(cs)) { throw CreateExceptionOnCurrentLine("Незавершенный литерал даты", iterator); } } throw CreateExceptionOnCurrentLine("Незавершенный литерал даты", iterator); }
private void SkipSpacesAndComments(ParseIterator iterator) { while (true) { /* Пропускаем все пробелы и комментарии */ iterator.SkipSpaces(); if (iterator.CurrentSymbol == '/') { if (!iterator.MoveNext()) { throw CreateExceptionOnCurrentLine("Некорректный символ", iterator); } if (iterator.CurrentSymbol != '/') { throw CreateExceptionOnCurrentLine("Некорректный символ", iterator); } do { if (!iterator.MoveNext()) { break; } } while (iterator.CurrentSymbol != '\n'); } else { break; } } }
public override Lexem ReadNextLexem(ParseIterator iterator) { var numbers = new StringBuilder(); while (iterator.MoveNext()) { var cs = iterator.CurrentSymbol; if (cs == SpecialChars.DateQuote) { iterator.GetContents(1, 1); iterator.MoveNext(); var lex = new Lexem() { Type = LexemType.DateLiteral, Content = numbers.ToString() }; return lex; } else if(Char.IsDigit(cs)) { numbers.Append(cs); } if (numbers.Length > 14) throw CreateExceptionOnCurrentLine("Некорректный литерал даты", iterator); } throw CreateExceptionOnCurrentLine("Незавершенный литерал даты", iterator); }
public override Lexem ReadNextLexem(ParseIterator iterator) { StringBuilder ContentBuilder = new StringBuilder(); while (iterator.MoveNext()) { var cs = iterator.CurrentSymbol; if (cs == SpecialChars.StringQuote) { iterator.MoveNext(); if (iterator.CurrentSymbol == SpecialChars.StringQuote) { /* Двойная кавычка */ ContentBuilder.Append("\""); continue; } /* Завершение строки */ SkipSpacesAndComments(iterator); if (iterator.CurrentSymbol == SpecialChars.StringQuote) { /* Сразу же началась новая строка */ ContentBuilder.Append('\n'); continue; } var lex = new Lexem { Type = LexemType.StringLiteral, Content = ContentBuilder.ToString() }; return(lex); } else if (cs == '\r') { continue; } else if (cs == '\n') { iterator.MoveNext(); SkipSpacesAndComments(iterator); if (iterator.CurrentSymbol != '|') { throw CreateExceptionOnCurrentLine("Некорректный строковый литерал!", iterator); } ContentBuilder.Append('\n'); continue; } else { ContentBuilder.Append(cs); } } throw CreateExceptionOnCurrentLine("Незавершённый строковой интервал!", iterator); }
public override Lexem ReadNextLexem(ParseIterator iterator) { var word = new WordParserState(); var lexem = word.ReadNextLexem(iterator); lexem.Type = LexemType.Annotation; return(lexem); }
private static Lexem ExtractOperatorContent(ParseIterator iterator) { Lexem lex; var content = iterator.GetContents().content; lex = new Lexem() { Type = LexemType.Operator, Content = content, Token = LanguageDef.GetToken(content) }; return(lex); }
public override Lexem ReadNextLexem(ParseIterator iterator) { bool hasDecimalPoint = false; while (true) { if (Char.IsDigit(iterator.CurrentSymbol)) { if (!iterator.MoveNext()) { var lex = new Lexem() { Type = LexemType.NumberLiteral, Content = iterator.GetContents().content }; 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().content }; return(lex); } else { throw CreateExceptionOnCurrentLine("Некорректный символ", iterator); } } }
public override Lexem ReadNextLexem(ParseIterator iterator) { System.Diagnostics.Debug.Assert(iterator.CurrentSymbol == SpecialChars.Directive); iterator.MoveNext(); if (!iterator.MoveToContent()) { throw CreateExceptionOnCurrentLine("Ожидается директива", iterator); } var wps = new WordParserState(); var lex = wps.ReadNextLexem(iterator); if (lex.Type == LexemType.Identifier && lex.Token == Token.NotAToken) { lex.Type = LexemType.Directive; } else { throw CreateExceptionOnCurrentLine("Ожидается директива", iterator); } return(lex); }
public override Lexem ReadNextLexem(ParseIterator iterator) { if(iterator.CurrentSymbol == '<') { if (iterator.MoveNext()) { var next = iterator.CurrentSymbol; if (next != '>' && next != '=') { iterator.MoveBack(); } else { iterator.MoveNext(); return ExtractOperatorContent(iterator); } } } else if(iterator.CurrentSymbol == '>') { if (iterator.MoveNext()) { var next = iterator.CurrentSymbol; if (next != '=') { iterator.MoveBack(); } else { iterator.MoveNext(); return ExtractOperatorContent(iterator); } } } else if (iterator.CurrentSymbol == '/') { if (iterator.MoveNext()) { if (iterator.CurrentSymbol == '/') { // это комментарий while (iterator.MoveNext()) { if (iterator.CurrentSymbol == '\n') { iterator.GetContents(); return Lexem.Empty(); } } iterator.GetContents(); return Lexem.EndOfText(); } else { iterator.MoveBack(); } } } var lex = ExtractOperatorContent(iterator); iterator.MoveNext(); return lex; }
private static Lexem ExtractOperatorContent(ParseIterator iterator) { Lexem lex; var content = iterator.GetContents().content; lex = new Lexem() { Type = LexemType.Operator, Content = content, Token = LanguageDef.GetToken(content) }; return lex; }
public void Start() { _iterator = new ParseIterator(_code); }
public override Lexem ReadNextLexem(ParseIterator iterator) { StringBuilder ContentBuilder = new StringBuilder(); while (iterator.MoveNext()) { var cs = iterator.CurrentSymbol; if (cs == SpecialChars.StringQuote) { iterator.MoveNext(); if (iterator.CurrentSymbol == SpecialChars.StringQuote) { /* Двойная кавычка */ ContentBuilder.Append("\""); continue; } /* Завершение строки */ SkipSpacesAndComments(iterator); if (iterator.CurrentSymbol == SpecialChars.StringQuote) { /* Сразу же началась новая строка */ ContentBuilder.Append('\n'); continue; } var lex = new Lexem { Type = LexemType.StringLiteral, Content = ContentBuilder.ToString() }; return lex; } else if(cs == '\r') { continue; } else if (cs == '\n') { iterator.MoveNext(); SkipSpacesAndComments(iterator); if (iterator.CurrentSymbol != '|') throw CreateExceptionOnCurrentLine("Некорректный строковый литерал!", iterator); ContentBuilder.Append('\n'); continue; } else ContentBuilder.Append(cs); } throw CreateExceptionOnCurrentLine("Незавершённый строковой интервал!", iterator); }
public override Lexem ReadNextLexem(ParseIterator iterator) { bool isEndOfText = false; Char cs = '\0'; while (true) { if (!isEndOfText) { cs = iterator.CurrentSymbol; } if (SpecialChars.IsDelimiter(cs) || isEndOfText) { var content = iterator.GetContents().content; Lexem lex; if(_booleanOperators.Contains(content)) { lex = new Lexem() { Type = LexemType.Operator, Token = LanguageDef.GetToken(content), Content = content }; } else if (_booleanLiterals.Contains(content)) { lex = new Lexem() { Type = LexemType.BooleanLiteral, Content = content }; } else if (_undefined.Contains(content)) { lex = new Lexem() { Type = LexemType.UndefinedLiteral, Content = content }; } else if (String.Compare(content, "null", true) == 0) { lex = new Lexem() { Type = LexemType.NullLiteral, Content = content }; } else { lex = new Lexem() { Type = LexemType.Identifier, Content = content, Token = LanguageDef.GetToken(content) }; if (LanguageDef.IsBuiltInFunction(lex.Token)) { iterator.SkipSpaces(); if (iterator.CurrentSymbol != '(') { lex.Token = Token.NotAToken; } } } return lex; } if (!iterator.MoveNext()) { if (isEndOfText) { break; } else { isEndOfText = true; } } } return Lexem.Empty(); }
private void SkipSpacesAndComments(ParseIterator iterator) { while (true) { /* Пропускаем все пробелы и комментарии */ iterator.SkipSpaces(); if (iterator.CurrentSymbol == '/') { if (!iterator.MoveNext()) throw CreateExceptionOnCurrentLine("Некорректный символ", iterator); if (iterator.CurrentSymbol != '/') throw CreateExceptionOnCurrentLine("Некорректный символ", iterator); do { if (!iterator.MoveNext()) break; } while (iterator.CurrentSymbol != '\n'); } else break; } }
public ParserException CreateExceptionOnCurrentLine(string message, ParseIterator iterator) { var cp = iterator.GetPositionInfo(iterator.CurrentLine); return new ParserException(cp, message); }
public override Lexem ReadNextLexem(ParseIterator iterator) { if (iterator.CurrentSymbol == '<') { if (iterator.MoveNext()) { var next = iterator.CurrentSymbol; if (next != '>' && next != '=') { iterator.MoveBack(); } else { iterator.MoveNext(); return(ExtractOperatorContent(iterator)); } } } else if (iterator.CurrentSymbol == '>') { if (iterator.MoveNext()) { var next = iterator.CurrentSymbol; if (next != '=') { iterator.MoveBack(); } else { iterator.MoveNext(); return(ExtractOperatorContent(iterator)); } } } else if (iterator.CurrentSymbol == '/') { if (iterator.MoveNext()) { if (iterator.CurrentSymbol == '/') { // это комментарий while (iterator.MoveNext()) { if (iterator.CurrentSymbol == '\n') { iterator.GetContents(); return(Lexem.Empty()); } } iterator.GetContents(); return(Lexem.EndOfText()); } else { iterator.MoveBack(); } } } var lex = ExtractOperatorContent(iterator); iterator.MoveNext(); return(lex); }
abstract public Lexem ReadNextLexem(ParseIterator iterator);
public ParserException CreateExceptionOnCurrentLine(string message, ParseIterator iterator) { var cp = iterator.GetPositionInfo(iterator.CurrentLine); return(new ParserException(cp, message)); }
public override Lexem ReadNextLexem(ParseIterator iterator) { return(Lexem.Empty()); }
public override Lexem ReadNextLexem(ParseIterator iterator) { bool isEndOfText = false; Char cs = '\0'; while (true) { if (!isEndOfText) { cs = iterator.CurrentSymbol; } if (SpecialChars.IsDelimiter(cs) || isEndOfText) { var content = iterator.GetContents().content; Lexem lex; if (_booleanOperators.Contains(content)) { lex = new Lexem() { Type = LexemType.Operator, Token = LanguageDef.GetToken(content), Content = content }; } else if (_booleanLiterals.Contains(content)) { lex = new Lexem() { Type = LexemType.BooleanLiteral, Content = content }; } else if (_undefined.Contains(content)) { lex = new Lexem() { Type = LexemType.UndefinedLiteral, Content = content }; } else if (String.Compare(content, "null", true) == 0) { lex = new Lexem() { Type = LexemType.NullLiteral, Content = content }; } else { lex = new Lexem() { Type = LexemType.Identifier, Content = content, Token = LanguageDef.GetToken(content) }; if (LanguageDef.IsBuiltInFunction(lex.Token)) { iterator.SkipSpaces(); if (iterator.CurrentSymbol != '(') { lex.Token = Token.NotAToken; } } } return(lex); } if (!iterator.MoveNext()) { if (isEndOfText) { break; } else { isEndOfText = true; } } } return(Lexem.Empty()); }
public override Lexem ReadNextLexem(ParseIterator iterator) { bool hasDecimalPoint = false; while (true) { if (Char.IsDigit(iterator.CurrentSymbol)) { if (!iterator.MoveNext()) { var lex = new Lexem() { Type = LexemType.NumberLiteral, Content = iterator.GetContents().content }; 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().content }; return lex; } else { throw CreateExceptionOnCurrentLine("Некорректный символ", iterator); } } }
public override Lexem ReadNextLexem(ParseIterator iterator) { return Lexem.Empty(); }
public override Lexem ReadNextLexem(ParseIterator iterator) { System.Diagnostics.Debug.Assert(iterator.CurrentSymbol == SpecialChars.Directive); iterator.MoveNext(); if (!iterator.MoveToContent()) throw CreateExceptionOnCurrentLine("Ожидается директива", iterator); var wps = new WordParserState(); var lex = wps.ReadNextLexem(iterator); if (lex.Type == LexemType.Identifier && lex.Token == Token.NotAToken) { lex.Type = LexemType.Directive; } else throw CreateExceptionOnCurrentLine("Ожидается директива", iterator); return lex; }