help-bison
[Top][All Lists]
Advanced

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

Re: Reusing a sub-grammar (by setting %start at runtime?)


From: Marcus Holland-Moritz
Subject: Re: Reusing a sub-grammar (by setting %start at runtime?)
Date: Sat, 8 Apr 2006 15:56:11 +0200

On 2006-04-06, at 18:49:20 +0200, Akim Demaille wrote:

> >>> "Marcus" == Marcus Holland-Moritz <address@hidden> writes:
> 
>  > Hi,
>  > I'm using bison for a C parser [1], for which I'm currently rewriting
>  > the part that parses expressions.
> 
>  > While being at it, I wondered if it's possible to reuse a certain part
>  > of a bison generated parser, e.g. by setting a different %start token
>  > at runtime.
> 
> I use the following technique.
> 
> Suppose you want to branch on nonterminals foo and bar.  Introduce
> fresh tokens START_FOO and START_BAR, and use the following real
> axiom:
> 
> start:
>   START_FOO foo
> | START_BAR bar
> 
> then the trick is to have your scanner pass either START token first.

Cool, it seems like that was just what I was looking for.
I'll have a closer look when I've overcome my jetlag...

> If you have a bleeding edge bison supporting push parsers, that's
> trivial :)  If you wrote yylex yourself, it shouldn't be too hard.

Yes, I wrote my own yylex.

Thank you very much for your help!

Marcus

-- 
Sattinger's Law:
        It works better if you plug it in.




reply via email to

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