>>> "Marcus" == Marcus Holland-Moritz <[EMAIL PROTECTED]> 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.
If you have a bleeding edge bison supporting push parsers, that's
trivial :) If you wrote yylex yourself, it shouldn't be too hard. If
you use a lex generated scanner, there is a simple means to acheive
this: introduce a variable initial_token, and right after the first
%%, insert something like
%{
if (initial_token)
{
int t = initial_token;
initial_token = 0;
return t;
}
%}
_______________________________________________
[email protected] http://lists.gnu.org/mailman/listinfo/help-bison