help-bison
[Top][All Lists]
Advanced

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

Re: Finding out when a token is consumed


From: Hans Aberg
Subject: Re: Finding out when a token is consumed
Date: Wed, 30 Apr 2003 15:10:03 +0200

At 13:33 +0200 2003/04/30, Frank Heckenbach wrote:
>I have a bison parser, and I'd like to do something whenever a token
>is consumed (used in a rule). More precisely, before an action is
>run, something should be done for each terminal used in the rule.

[Please reply to/cc address@hidden

You are too unspecific about this "something" you want to do and why you
want to do it. The Bison generated parser is tricky, because it may or may
not need a lookahead token, depending what the grammars looks like.

The simplest way is to put as much work in the actions of the lexer/parser
rules, and only do extra tweaking as necessary. For example, you might
record the token names in the lexer rules, and then in the parser rule
action you examine those names, doing that special thing you want. If the
special thing is an environmental context, then one can let the rules
perhaps via midrule actions set/pop those contexts in the form a stacked
lookup table. Then the lexer rule can make a lookup in that table stack,
and give that as $n value to the parser.

  Hans Aberg






reply via email to

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