llvmir some opt
This commit is contained in:
42
frontend/lexer/TokenStream.java
Normal file
42
frontend/lexer/TokenStream.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package frontend.lexer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TokenStream {
|
||||
private ArrayList<Token> tokens;
|
||||
private int currentIndex;
|
||||
|
||||
public TokenStream(ArrayList<Token> tokens) {
|
||||
this.tokens = tokens;
|
||||
}
|
||||
|
||||
public Token read() {
|
||||
if (currentIndex < tokens.size()) {
|
||||
return tokens.get(currentIndex++);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void recall() {
|
||||
if (currentIndex > 0) {
|
||||
currentIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentIndex() {
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
public void resetIndex(int index) {
|
||||
currentIndex = index;
|
||||
}
|
||||
|
||||
public Token peek(int step) {
|
||||
if (currentIndex + step < tokens.size()) {
|
||||
return tokens.get(currentIndex + step);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user