Package beaver
Class Parser.TokenStream
- java.lang.Object
-
- beaver.Parser.TokenStream
-
- Enclosing class:
- Parser
public class Parser.TokenStream extends Object
This class wraps a Scanner and provides a token "accumulator" for a parsing simulation.If a source that is being parsed does not have syntax errors this wrapper only adds one indirection while it delivers the next token. However when parser needs to recover from a syntax error this wrapper accumulates tokens shifted by a forward parsing simulation and later feeds them to the recovered parser.
-
-
Constructor Summary
Constructors Constructor Description TokenStream(Scanner scanner)TokenStream(Scanner scanner, Symbol first_symbol)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidalloc(int size)Prepare a stream to accumulate tokens.voidinsert(Symbol t0, Symbol t1)Insert two tokens at the beginning of a stream.SymbolnextToken()Symbolremove(int i)Removes a token from the accumulator.voidrewind()Prepare accumulated tokens to be reread by a next simulation run or by a recovered parser.
-
-
-
Method Detail
-
nextToken
public Symbol nextToken() throws IOException
- Throws:
IOException
-
alloc
public void alloc(int size)
Prepare a stream to accumulate tokens.- Parameters:
size- number of shifted tokens to accumulate
-
rewind
public void rewind()
Prepare accumulated tokens to be reread by a next simulation run or by a recovered parser.
-
insert
public void insert(Symbol t0, Symbol t1)
Insert two tokens at the beginning of a stream.- Parameters:
t0- first token to be insertedt1- second token to be inserted
-
remove
public Symbol remove(int i)
Removes a token from the accumulator.- Parameters:
i- index of a token in the accumulator.- Returns:
- removed token
-
-