public class Parser.TokenStream extends Object
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 and Description |
---|
TokenStream(Scanner scanner) |
TokenStream(Scanner scanner,
Symbol first_symbol) |
Modifier and Type | Method and Description |
---|---|
void |
alloc(int size)
Prepare a stream to accumulate tokens.
|
void |
insert(Symbol t0,
Symbol t1)
Insert two tokens at the beginning of a stream.
|
Symbol |
nextToken() |
Symbol |
remove(int i)
Removes a token from the accumulator.
|
void |
rewind()
Prepare accumulated tokens to be reread by a next simulation run
or by a recovered parser.
|
public TokenStream(Scanner scanner)
public Symbol nextToken() throws IOException
IOException
public void alloc(int size)
size
- number of shifted tokens to accumulatepublic void rewind()
public void insert(Symbol t0, Symbol t1)
t0
- first token to be insertedt1
- second token to be insertedpublic Symbol remove(int i)
i
- index of a token in the accumulator.Copyright © 2021 Soot OSS. All rights reserved.