[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Forcing multiple parse stacks to 'reduce'

From: Laurence Finston
Subject: Re: Forcing multiple parse stacks to 'reduce'
Date: Tue, 1 Mar 2005 11:18:16 +0100 (MET)

> Derek M Jones wrote:
> > >>I have written a parser for C that processes
> > >>a single statement or declaration at a time.
> > >>So after each statement/declaration yyparse
> > >>returns.
> > >

I think you might be able to simplify matters by just using
`statement' as your start symbol and calling `yyparse()'
in a loop.  If that doesn't work, it might help to define your start
symbol as follows:

program: statement END

and pass `END' to `yylex()' from the actions for the rules
with `statement' as the left-hand side for immediate return to
`yyparse()'.  In order to do something similar, I pass a parameter to
`yyparse()' which is passed in turn to `yylex()'.  It is of a class type
which contains a data member called `rescan_stack'.  Put in a somewhat
oversimplified way, if it's not empty, it contains one or more tokens, and
`yylex()' immediately pops the top token from the stack and returns it to
`yyparse()'.  You could use another data member of the parameter to
indicate whether you've reached the end of the file.  In my parser, an EOF
never reaches `yyparse()'.

Laurence Finston

reply via email to

[Prev in Thread] Current Thread [Next in Thread]