/// <inheritdoc /> public ILexer <EndOfLine> Create() { var carriageReturnLexer = carriageReturnLexerFactory.Create(); var lineFeedLexer = lineFeedLexerFactory.Create(); var endOfLineSequenceLexer = concatenationLexerFactory.Create(carriageReturnLexer, lineFeedLexer); return(new EndOfLineLexer(endOfLineSequenceLexer)); }
/// <inheritdoc /> public ILexer <WhiteSpace> Create() { var sp = spaceLexerFactory.Create(); var htab = horizontalTabLexerFactory.Create(); var innerLexer = alternativeLexerFactory.Create(sp, htab); return(new WhiteSpaceLexer(innerLexer)); }
public ILexer <Integer> Create() { var signLexer = signLexerFactory.Create(); var optionalSignLexer = optionLexerFactory.Create(signLexer); var digitLexer = digitLexerFactory.Create(); var manyDigitsLexer = repetitionLexerFactory.Create(digitLexer, 1, int.MaxValue); var innerLexer = concatenationLexerFactory.Create(optionalSignLexer, manyDigitsLexer); return(new IntegerLexer(innerLexer)); }
/// <inheritdoc /> public ILexer <LinearWhiteSpace> Create() { var endOfLineLexer = endOfLineLexerFactory.Create(); var whiteSpaceLexer = whiteSpaceLexerFactory.Create(); var foldLexer = concatenationLexerFactory.Create(endOfLineLexer, whiteSpaceLexer); var breakingWhiteSpaceLexer = alternativeLexerFactory.Create(whiteSpaceLexer, foldLexer); var innerLexer = repetitionLexerFactory.Create(breakingWhiteSpaceLexer, 0, int.MaxValue); return(new LinearWhiteSpaceLexer(innerLexer)); }
public ICollection <int> Parse(string code) { // base initialize ICollection <int> resTokens = new List <int>(); AntlrInputStream inputStream = new AntlrInputStream(code); var cppLexer = _lexerFactory.Create(inputStream); var tokens = cppLexer.GetAllTokens(); foreach (var token in tokens) { // trying to get type of the token // keyword? if (KeyWords.Contains(token.Text)) { resTokens.Add(LexerConstants.KeyWordsStart + Array.IndexOf(KeyWords, token.Text)); } // operator? else if (Operators.Contains(token.Text)) { resTokens.Add(LexerConstants.OpStart + Array.IndexOf(Operators, token.Text)); } // string/char? else if (token.Text.Last() == '\"' || token.Text.Last() == '\'') { resTokens.Add(LexerConstants.String); } else if (char.IsDigit(token.Text.First())) { // int? if (token.Text.Contains('.')) { resTokens.Add(LexerConstants.Real); } // real? else { resTokens.Add(LexerConstants.Number); } } // id? else if (char.IsLetter(token.Text.First()) || token.Text.First() == '_') { resTokens.Add(LexerConstants.Id); } // ????? else { resTokens.Add(LexerConstants.Unknown); } } return(resTokens); }
/// <inheritdoc /> public ILexer <HexadecimalDigit> Create() { var hexadecimalDigitAlternativeLexer = alternativeLexerFactory.Create( digitLexerFactory.Create(), terminalLexerFactory.Create("A", StringComparer.OrdinalIgnoreCase), terminalLexerFactory.Create("B", StringComparer.OrdinalIgnoreCase), terminalLexerFactory.Create("C", StringComparer.OrdinalIgnoreCase), terminalLexerFactory.Create("D", StringComparer.OrdinalIgnoreCase), terminalLexerFactory.Create("E", StringComparer.OrdinalIgnoreCase), terminalLexerFactory.Create("F", StringComparer.OrdinalIgnoreCase)); return(new HexadecimalDigitLexer(hexadecimalDigitAlternativeLexer)); }