help-bison
[Top][All Lists]
Advanced

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

Re: Feature request


From: Fernando Ferreira
Subject: Re: Feature request
Date: Wed, 20 Jun 2007 20:07:08 +0100
User-agent: Thunderbird 2.0.0.0 (X11/20070525)

Evan Lavelle wrote:
Fernando Ferreira wrote:

The reason for my request is that, as bison generates LR parsers, there is no way to, for instance, execute an action before a rule is reduced, only after.

I've never tried an action at the start of a rule, but I'm pretty sure that you can do it. Look up 'embedded actions' in the O'Reilly lex&yacc book, or 3.5.5 'Actions in mid-rule' in the Bison 2.0 manual. It may be difficult to avoid conflicts, though. According to the O'Reilly book, yacc implements embedded actions using the technique described at the end of 3.5.5 ("Another solution is to bury the action inside a nonterminal symbol which serves as a subroutine...").

Evan


_______________________________________________
address@hidden http://lists.gnu.org/mailman/listinfo/help-bison

But that would mean that I would have to add the same action for every rule. My intention is to have a way to execute an single action before any and every rule gets executed, similarly to YY_USER_ACTION on Flex.

An example would be to print the name of the rule that is about to be reduced, using something like yy_reduce_print_ uses, "cout<< yytname_[yyr2_[yyn]]". That's a silly example, there are other truly marvelous uses for this feature which this margin is too narrow to contain (hehe).




reply via email to

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