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: Hans Aberg
Subject: Re: How to change default outcome of shift/reduce conflict?
Date: Wed, 16 Jan 2002 01:38:02 +0100

At 16:35 -0500 2002/01/15, Anthony DeRobertis wrote:
>> This is what looks wrong to me: That both
>> answer_btn_list_oneplus and expr
>> contains OR.
>
>Yes, that's correct. They have to -- it means two different
>things. Compare it to calling a C function where you can
>certainly do:
>
>answer(a || b, c, d || e).
>
>In HyperTalk "||" becomes "or". Unfortunately, in the case of
>answer's button list, "," also becomes "or".

It is also possible to implement it semantically, by using the grammar
  answer_statement:
      ANSWER expression                 {...}
    | ANSWER expression WITH expression {...}

  expression:
      expression OR expression { $$ = $1 | $3; }
    | "(" expression ")"       {...}
    ...

Here, the action $1 | $3 would check the types of $1 and $3, and if they
are combinable into a Boolean value it would do so; otherwise, it would
combine them into a list object. (Think on for example C++ operator
function name overloading based on argument type.)

Then, at the time one arrives at the rule
    answer_statement: ANSWER expression WITH expression {...}
the action will check the types of $2 and $4: If $2 is not a Boolean,
error, if $4 is not list, a single button, else a sequence of buttons.

>From the theoretical point of view, we merely give up trying to capture the
language (specifically, the distinction between the two different "or"'s)
using a context free grammar alone: If we would want the grammar to capture
this construction, it would lead to an attribute grammar or something. But
instead we stay with the context free grammar, and tweak it via its actions.

  Hans Aberg





reply via email to

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