help-bison
[Top][All Lists]
Advanced

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

Re: Choosing your grammar rule dynamically


From: Joel E. Denny
Subject: Re: Choosing your grammar rule dynamically
Date: Thu, 4 Feb 2010 11:46:15 -0500 (EST)
User-agent: Alpine 1.00 (DEB 882 2007-12-20)

On Thu, 4 Feb 2010, address@hidden wrote:

> I have a bison grammar file, and I would like to enable/disable certain 
> rules based on a variable.
> 
> So for example:
> 
> rule1 : rule2 | rule3 | rule4
> rule2: A B C
> rule3: D E F rule2
> rule4: rule2 | G
> 
> On a certain day I only want rule 4 disabled. Is there a possibility to 
> do such a thing in bison?

Not in general.  The parser actions are hard-coded into the parser tables 
by Bison.

If there are alternative ways to parse the same input, you can use 
%glr-parser with %merge to provide code that decides how to merge the 
semantic values resulting from multiple rules.  It could select one of the 
rule's values based on some variable.  The rules whose values it doesn't 
select are thus, in some sense, disabled.

Be forewarned that GLR is tricky.  See the Bison manual for details.




reply via email to

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