Package beaver

Class 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 Detail

      • TokenStream

        public TokenStream​(Scanner scanner)
      • TokenStream

        public TokenStream​(Scanner scanner,
                           Symbol first_symbol)
    • Method Detail

      • 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 inserted
        t1 - 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