expression -> expression OPER expression
expression -> PREFIX expression
expression -> expression POSTFIX
expression -> expression ‘?’ expression ‘:’ expression
expression -> expression ‘[’ expression ‘]’
expression -> expression ‘(’ expression ‘)’
expression -> ID
expression -> CONSTANT
expression ->‘(’ expression ‘)’
Which are the reduce-reduce and shift-reduce conflicts in this grammar during analysis by LR parser?
There is no reduce-reduce conflict in that excerpt, but there are certainly shift-reduce conflicts all over the place. All of them have the same cause: the grammar makes no attempt to define the precedence of the various operators, with the result that any expression with more than one operator is ambiguous.
For example,
PREFIX ID POSTFIX
could be parsed as though written(PREFIX ID) POSTFIX
or asPREFIX (ID POSTFIX)
. This clearly creates a shift-reduce conflict after theID
is reduced toexpression
:At this point, the parser could reduce the stack to
expression
usingexpression -> PREFIX expression
. But it could also shiftPOStFIX
from the input onto the stack, in preparation for the reductionexpression -> expression POSTFIX
.The same ambiguity will be find with every other operator.