Help understanding Shift-Reduce conflict

Sep 30, 2015 at 2:26 PM
Thanks to help with reduce-reduce, I believe I understand what is causing this conflict and I understand that I likely just need a PreferShiftHere() call in the place(s), I just can't figure out where that is. I have the following rules
expression.Rule = primaryExpression + ReduceHere() | conditionalExpression | binOpExpression | assignmentExpression | scatteringAssignmentExpression;
            primaryExpression.Rule =
                identifier
                | unaryExpression
                | parenthesizedExpression
                | builtinFunctionCall
                | indexMemberAccess
                | objectMemberAccess
                | preIncrDecrExpression
                | postIncrDecrExpression
                | literal;
binOp.Rule = ToTerm("<") | "||" | "&&" | "^" | "==" | "!=" | ">" | "<=" | ">=" | "<<" | ">>" | "+" | "-" | "*" | "/" | "%" | "in";
binOpExpression.Rule = expression + binOp + expression;
incrOrDecr.Rule = ToTerm("++") | "--";
preIncrDecrExpression.Rule = incrOrDecr + expression;
conditionalExpression.Rule = expression + qmark + expression + ToTerm("|") + expression;
assignmentOperator.Rule = ToTerm("=") | "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=";
assignmentLeft.Rule = identifier | objectMemberAccess;
assignmentRight = expression;
assignmentExpression.Rule = assignmentLeft + assignmentOperator + assignmentRight;
indexMemberAccess.Rule = expression + indexExpression;
indexArgument.Rule = expression | "$";
indexRangeExpression.Rule = indexArgument + ".." + indexArgument;
indexSpecifier.Rule = indexArgument | indexRangeExpression;
indexExpression.Rule = lbrk + indexSpecifier + rbrk;
The moment I introduced the indexMemberAccess rule I got 4 shift-reduce conflicts. I'm fairly certain this is because while the conditional, pre increment/decrement, assigment and binary operations all end with an expression, they can also be an expression as a whole. This means that
"foo" + "bar"[1..2]
could also be seen as
("foo" + "bar")[1..2]
thus the shift-reduce conflicts. I'm hoping someone can simply tell me where the PreferShiftHere() call(s) will go and that will solve the issue. I have been trying a number of different spots that I thought it would be and none have resolved any of the four conflicts.
Sep 30, 2015 at 3:11 PM
Ok, I found it through process of elimination by just pasting and cutting a PreferShiftHere() call all throughout all involved rules until I finally got a positive result. The answer was to change the IndexExpression as follows:
indexExpression.Rule = PreferShiftHere() + lbrk + indexSpecifier + rbrk;
Hopefully this will help anyone else who runs into a similar issue in troubleshooting their grammar.
Marked as answer by WiredWiz on 9/30/2015 at 7:11 AM