[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Line-by-line evaluation or all at once?
On Friday, Feb. 23 2001 18:15 Etienne M. Gagnon wrote:
> Michael Kerry wrote:
> > My question is mostly conceptual, I think. I believe that I have a two
> > choices on how to implement this:...
>
> Both approaches look OK to me. I'm not so sure that creating a new
> parser is very expensive. The parse tables are loaded once [static
> initializer], not on every instantiation.
The main reason that one can't use the same parser again is that the
parse-method doesn't finish with empty stack: with push(0, null, false) will
be always a new symbol be pushed. In case of an error the iterator (stack)
is also not reset, which will again lead to unused elements in the
LinkedList.
This problem can be solved by intoducing a (final) LinkedList element (say
listStack) to the class, removing the final modifier of the stack Iterator
and inserting the statement
stack = listStack.listIterator();
as the first instruction to the parse-method.
By overriding the filter-method of the Lexer one can provide a EOF token as
needed.
This would allow to use the same parser in an interactive enviroment
(line-by-line evaluation) or where the input is a stream of parseable texts.
This approach might be an alternative to always create a new parser object,
since the entries in the LinkedList can be reused and must not be newly
created.
Any comments to this idea?
Marco
--
mailto:Marco.Ladermann@gmx.de