package frontend.lexer; import java.util.ArrayList; public class TokenStream { private ArrayList tokens; private int currentIndex; public TokenStream(ArrayList 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; } } }