/// <summary> /// Returns the next token after the Token passed here /// </summary> /// <param name="peekToken">The PeekToken token returned from a previous Peek() call</param> /// <seealso cref="Peek()" /> public virtual PeekToken Peek(PeekToken peekToken) { int oldIndex = _index; _index = peekToken.TokenIndex; if (_index >= _inputString.Length) { _index = oldIndex; return(null); } foreach (KeyValuePair <Tokens, string> pair in _tokens) { Regex r = new Regex(pair.Value); Match m = r.Match(_inputString, _index); if (m.Success && m.Index == _index) { _index += m.Length; PeekToken pt = new PeekToken(_index, new Token(pair.Key, m.Value)); _index = oldIndex; return(pt); } } PeekToken pt2 = new PeekToken(_index + 1, new Token(Tokens.Undefined, (_inputString[_index]).ToString())); _index = oldIndex; return(pt2); }
public PascalParser(PeekToken peekToken, NextToken nextToken, PeekAndNext peekAndNext, NextAndPeek nextAndPeek) { PeekToken = peekToken; NextToken = nextToken; PeekAndNext = peekAndNext; NextAndPeek = nextAndPeek; }
public PeekToken Peek(PeekToken peekToken) { int oldIndex = _index; _index = peekToken.TokenIndex; if (_index >= _inputString.Length) { _index = oldIndex; return null; } foreach (KeyValuePair<Tokens, string> pair in _tokens) { var r = new Regex(pair.Value); Match m = r.Match(_inputString, _index); if (m.Success && m.Index == _index) { _index += m.Length; var pt = new PeekToken(_index, new Token(pair.Key, m.Value)); _index = oldIndex; return pt; } } var pt2 = new PeekToken(_index + 1, new Token(Tokens.UNDEFINED, string.Empty)); _index = oldIndex; return pt2; }
public PeekToken Peek(PeekToken peekToken) { var index = _index; _index = peekToken.TokenIndex; PeekToken result; if (_index >= _inputString.Length) { _index = index; result = null; } else { foreach (var current in _tokens) { var regex = new Regex(current.Value); var match = regex.Match(_inputString, _index); if (match.Success && match.Index == _index) { _index += match.Length; var peekToken2 = new PeekToken(_index, new Token(current.Key, match.Value)); _index = index; result = peekToken2; return result; } } var peekToken3 = new PeekToken(_index + 1, new Token(Tokens.UNDEFINED, string.Empty)); _index = index; result = peekToken3; } return result; }