View Javadoc

1   /*
2    * This file is part of hyphenType. hyphenType is free software: you can
3    * redistribute it and/or modify it under the terms of the GNU General Public
4    * License as published by the Free Software Foundation, either version 3 of the
5    * License, or (at your option) any later version. hyphenType is distributed in
6    * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
8    * the GNU General Public License for more details. You should have received a
9    * copy of the GNU General Public License along with hyphenType. If not, see
10   * <http://www.gnu.org/licenses/>.
11   */
12  package org.hyphenType.lexerparser;
13  
14  import java.util.List;
15  
16  import org.hyphenType.datastructure.lexer.LexToken;
17  
18  /**
19   * @author Aurelio Akira M. Matsui
20   */
21  public class LexTokenStream {
22  
23      private int index = 0;
24      private final List<LexToken> tokens;
25  
26      public LexTokenStream(List<LexToken> tokens) {
27          this.tokens = tokens;
28      }
29  
30      public boolean hasFutureToken() {
31          return tokens.size() > index;
32      }
33  
34      public LexToken futureToken() {
35          return tokens.get(index);
36      }
37  
38      public LexToken currentToken() {
39          if (index - 1 > -1)
40              return tokens.get(index - 1);
41          else
42              return null;
43      }
44  
45      public LexToken consume() {
46          LexToken token = tokens.get(index);
47          index++;
48          return token;
49      }
50  }