You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would result as the following shift-reduce conflict:
The following symbols can be reduced in two ways:
"let" var "=" ETop "in" E ";" E0
They could be reduced like so:
"let" var "=" ETop "in" E ╷ ";" E0
│ └─ETop─┤ │
├─E0───────────────────────────┤ │
├─E────────────────────────────┘ │
└─E───────────────────────────────────┘
Alternatively, they could be reduced like so:
"let" var "=" ETop "in" E ";" E0
│ ├─E────┤
│ └─ETop─┤
└─E0───────────────────────────┘
However we also can't place the let ... in ... production rule as a lower precedence to everything else because then we wouldn't be able to parse inputs such as b; let a = b in c. In essence, we want to have let be part of a set of high precedence keywords, but also let the trailing expression have low precedence when reducing.
The solution (using conditional macros/explicitly handling no-short-if case) in #386 does not work as both solutions (the linked example code) nor the linked java grammar has the issue where we have a keyword "let" with a high priority yet have the trailing expression as low priority (i.e. a mixed context-dependent precedence) (note ternary in java tactfully does not have an "if" to denote the beginning of a ternary expression, so it can just be placed as a low priority operator).
A solution in yacc has been to mark the let keyword as high precedence, but mark the whole production as a low precedence, ex:
%token LET IN
%token<str> VAR
%nonassoc P_LET
%left ';'
%nonassoc LET
%%
expr: VAR { }
| LET VAR '=' expr IN expr %prec P_LET { }
| expr ';' expr { }
;
In essence, we are saying to prefer shift over reduce if we are in the let ... in ... production. This seems to be similar to issue #620 but more generalized.
Note this was also briefly mentioned in #67, though was never actually addressed.
The text was updated successfully, but these errors were encountered:
Hi I'm having trouble trying to disambiguate this fairly simple grammar (note that this is only a small chunk of a larger language):
This would result as the following shift-reduce conflict:
However we also can't place the
let ... in ...
production rule as a lower precedence to everything else because then we wouldn't be able to parse inputs such asb; let a = b in c
. In essence, we want to havelet
be part of a set of high precedence keywords, but also let the trailing expression have low precedence when reducing.The solution (using conditional macros/explicitly handling no-short-if case) in #386 does not work as both solutions (the linked example code) nor the linked java grammar has the issue where we have a keyword "let" with a high priority yet have the trailing expression as low priority (i.e. a mixed context-dependent precedence) (note ternary in java tactfully does not have an "if" to denote the beginning of a ternary expression, so it can just be placed as a low priority operator).
A solution in yacc has been to mark the
let
keyword as high precedence, but mark the whole production as a low precedence, ex:In essence, we are saying to prefer shift over reduce if we are in the
let ... in ...
production. This seems to be similar to issue #620 but more generalized.Note this was also briefly mentioned in #67, though was never actually addressed.
The text was updated successfully, but these errors were encountered: