SmaCC: Shift/Reduce Conflict
John Brant
brant at refactory.com
Mon Apr 23 15:10:47 UTC 2007
Alexandre Bergel wrote:
> Dear all,
>
> I bumped into a conflict while writing a small grammar. Would be great
> to know why. The problem seems to come from the Assignment
> I wish to parse the following:
> myfunction (a, b, c){
> 3 + 10
> var z
> z = 50 + foo()
> }
How do you wish to parse:
myfunction (a, b, c) {
var z
z = 1 + 2
}
You can parse "z = 1 + 2" multiple ways:
(z = 1) + 2
or
z = (1 + 2)
The default behavior of SmaCC picks the shift action over the reduce
action, so the second choice is the one that it picks.
To fix this problem you can
A) ignore it, if you want the second choice
B) change your grammar to remove the ambiguity
C) add a precedence rule to tell SmaCC the priority of the +, -, and =
tokens
The SmaCC tutorial has an example of both B & C.
John Brant
More information about the Squeak-dev
mailing list
|