📄 tokenbuffer.java
字号:
/**
* Course - CS601 OO Programming
* Instructor - Terence Parr
* Assignment - 4
*
* Ideas represented in this class have been recycled from Terence Parr's
* http://www.antlr.org/book/byhand.pdf. Thanks Terence
*/
public class TokenBuffer {
private Lexer _lexer;
private int _lookahead;
private Token[] _tokens;
/**
* Constructs a buffer of tokens from the lexer.
* @param lexer Lexer is the stream of tokens used for this token buffer
* @param lookAhead lookAhead is how far in advance to grab tokens from the
* lexer
*/
public TokenBuffer(Lexer lexer, int lookAhead) {
this._lexer = lexer;
this._lookahead = lookAhead;
_tokens = new Token[lookAhead];
for (int i = 0; i < lookAhead; i++) {
_tokens[i] = lexer.getToken();
if (_tokens[i].getType() == Token.EOT) break;
}
}
/**
*
* @param i I is the 1 based token index.
* @return Returns the token at the specified (1 based) position in this buffer
*/
public Token LA(int i) {
return _tokens[i-1];
}
/**
* removes token at position 1 and advances the buffer by 1
*
*/
public void consume() {
for (int i = 1; i < _lookahead; i++) {
_tokens[i-1] = _tokens[i];
}
_tokens[_lookahead-1]= _lexer.getToken();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -