help-bison
[Top][All Lists]
Advanced

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

Re: Shift reduce errors due to embedded actions


From: Hans Aberg
Subject: Re: Shift reduce errors due to embedded actions
Date: Wed, 10 Oct 2001 11:58:43 +0200

At 19:24 +0200 2001/10/09, Axel Kittenberger wrote:
>> from the embedded actions in the rules section of bison, i invoke a
>> function to generate cross reference information about the variables in the
>> program, which leads to shift reduce errors.
>
>> how can i avoid getting the shift reduce errors due to embedded actions in
>> the rules section of bison?
>
>> is there any way where i can do away with embedded actions while achieving
>> the purpose of generating the cross reference information?

>... the parser has something like
>A B C {action1}
>A B D {action2}
>
>there is no problem...
>but if it has
>A {action1} B C
>A {action2} B D
>
>The parser cannot decide when it looked at A (and looked forward to B) if it
>shall execute action1 or action2,

Bison implments this by introducing implicit extra empty variables aith an
action:

A @1 B C
A @2 B D

@1:  {action1}
@2:  {action2}

The bset way around this problem is probably to collect the semantic
information that A and B produces and then use that when appyling C or D.
For example:

A_B: A B { /* collect information from A and B in yylval */ }

my_variable:
  A_B C {action1}
  A_B D {action2}

But in this case also
my_variable:
  A_B {action1} C { action3 }
  A_B {action2} D { action3 }
might work.

>as far I understood parser stuff, this is a limition of bisons LALR
>algorithm, which is LR(1). (1 look ahead), LR(n) is theoretically possibly,
>but I don't know of a open implementation of it. Altough I don't know too
>much about this parser theory stuff, so please correct :o)

LR(n) grammars can be rewritten as LR(1) grammars, but I do not know how
that works when out when having to take actios into account.

  Hans Aberg





reply via email to

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