This project is read-only.

Default semantic action for reductions isn't $1


In the documentation pdf, it states:
For production right-hand-sides of all non-zero lengths, the default action
is equivalent to “$$=$1”.
However, it seems to mistakenly use "$$ = $n".

It seems to be a problem with ShiftReduceParser<>.Reduce(), when rule.RightHandSide.Length > 1:
// Default action: $$ = $1;
CurrentSemanticValue = valueStack.TopElement();
//  Default action "@$ = @1.Merge(@N)" for location info.
should be
// Default action: $$ = $1;
CurrentSemanticValue = valueStack[valueStack.Depth - rule.RightHandSide.Length];
//  Default action "@$ = @1.Merge(@N)" for location info.
In particular, this causes problems with the built-in $accept rule, which will always return the value passed by the lexer with the EOF token, rather than the value returned from the %start rule.


k_john_gough wrote Jul 10, 2013 at 12:16 PM

Hi. you are quite right. This code appears to have been wrong since day 1. Your suggested "should be" code is correct. I have made the change in the source repository, but it may be a few weeks before I get a refreshed distribution out. Thanks for finding the error.