help-bison
[Top][All Lists]
Advanced

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

Re: How to change default outcome of shift/reduce conflict?


From: Anthony DeRobertis
Subject: Re: How to change default outcome of shift/reduce conflict?
Date: Tue, 15 Jan 2002 06:27:59 -0500

Hans Aberg writes:
I thought "OR" was a terminal, and "expr" a nonterminal that may expand to
contain "OR" by the rule you listed as
  expr -> expr OR expr

Yes, that's correct. But that's not the full story. I've posted it before, but here it is again:
answer_statement: ANSWER expr answer_btn_list
                ...
;
answer_btn_list: WITH answer_btn_list_oneplus
             | /* empty */
;
answer_btn_list_oneplus: answer_btn_list_oneplus OR expr
                     | expr     %prec PSEUDO_MAX
; expr contains a lot of things, expr OR expr is one of them.
Which is causing the shift/reduce conflicts. Your answer gives me the
impression that you may not understand how a grammar works.

Correct me if I'm wrong, but given: answer "Hello" with "Cancel" or "OK" the shift-reduce conflict is on the token "OR" after "Cancel". Bison could, due to the ambiguous grammar, either shift OR (leading to reduction by expr OR expr -> expr) or reduce (expr -> answer_btn_list_oneplus). By default, it decided on shift. I didn't like that, so I now have that %prec in there, which tells bison to reduce.

The question is really: How do you want the rules
  expr -> expr OR expr
  x -> ANSWER expr WITH expr OR expr
to be applied when the expression
  ANSWER expr WITH expr OR expr OR expr OR expr
appears on top of the stack?

I hope the above answers that.
But you have not told us whether
  answer "Hello" OR "world" with "Cancel" or "OK" or "Bye"
is legal.

Well, syntacticly (is that a word?) it's legal. It would display a dialogue with three buttons, except for the runtime error from "hello" and "world" not being boolean values.
So then you must have yet another rule you have not told us, either
  x -> ANSWER expr WITH "(" expr ")"
  x -> ANSWER expr WITH expr

Actually, it's one of the many things in expr: '(' expr ')'.
I can only give my hunch of what the grammar might be (leaving it to Akim
finding an efficient one):

I've tried changing the expr above to expr_orless and then adding a seperate expr: expr_orless | expr OR expr, but that led to reduce-reduce conflicts. I honestly didn't spend much time thinking about why.

Attachment: pgpiOUhLjfkNe.pgp
Description: PGP signature


reply via email to

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