Closed mingodad closed 2 years ago
Also lemon uses rule precedence to resolve reduce/reduce conflicts.
Hello @mingodad, thank you for asking.
In unicc, the precedence of a production is resolved similarly to yacc: The precedence of the rightmost symbol with a precedence setting will be used. Instead of only terminal symbols, unicc also uses the precedence settings of nonterminal symbols.
The corresponding position in the code is here. unicc2 has the corresponding algorithm here.
Thank you for reply ! Looking through the code you've pointed out it seems that this comment is misleading https://github.com/phorward/unicc/blob/85ec57b3edeb6fe79cf0dbe7fc93def3928413c5/src/rewrite.c#L425 because it's using the same procedure as the next loop to look for the rightmost .
You're right, the comment is wrong here.
Comparing
yacc/bison
andlemon
on how they use rule precedence to resolve grammar conflicts they differ on how to do it as show bellow:%prec
will use the precedence assigned (if any) to the last terminal on the rule.[prec]
will use the precedence assigned to the first terminal on the rule that has precedence assigned.Can this have a bit of explanation ?