public void TestLookback()
{
Grammar g = new Grammar(
"lexer grammar t;\n" +
"ID : 'a'..'z'+;\n" +
"INT : '0'..'9'+;\n" +
"SEMI : ';';\n" +
"ASSIGN : '=';\n" +
"PLUS : '+';\n" +
"MULT : '*';\n" +
"WS : ' '+;\n");
// Tokens: 012345678901234567
// Input: x = 3 * 0 + 2 * 0;
ICharStream input = new ANTLRStringStream("x = 3 * 0 + 2 * 0;");
Interpreter lexEngine = new Interpreter(g, input);
BufferedTokenStream tokens = new BufferedTokenStream(lexEngine);
tokens.Consume(); // get x into buffer
IToken t = tokens.LT(-1);
Assert.AreEqual("x", t.Text);
tokens.Consume();
tokens.Consume(); // consume '='
t = tokens.LT(-3);
Assert.AreEqual("x", t.Text);
t = tokens.LT(-2);
Assert.AreEqual(" ", t.Text);
t = tokens.LT(-1);
Assert.AreEqual("=", t.Text);
}