[parser] allow to type binders in lambda abstractions + tests #304
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation of the shift-reduce error with typed binders
Informal description of the problem
The extension of the grammar such that it is possible to give types to binders
in lambda abstractions causes a shift/reduce conflict since the sentence:
(x : ty \ t as y) ...
is ambiguous.
It can be shifted by:
and reduced by:
The ambiguity may occur if we had the derivation (meaningless in our grammar):
type_term: type_term BIND term AS term { ... }
Allowing the sentence:
(x : ty \ t as y) ...
to be derived in two distinctways.
Solution of the problem:
The derivation we want is the shifted one:
To solve the issue,the
constant
production of thehead_term
rule musthave lower priority than the
COLON
token. Therefore, we add to the grammar:such that
colon_minus1
has lower priority than the tokenCOLON
. Finally weattach the tag
colon_minus1
to theconstant
production of thehead_term
rule.
This way, the reduction
head_term nonempty_list(closed...
is neglected infavour of the the wanted derivation.
Note that the production rule:
has to be added, otherwise
(x : int)
could not be parsed, this is because ofthe impossibility of parsing the
CONSTANT
before aCOLON
in the rulehead_term
.BELOW THE TRACE OF THE SHIFT/REDUCE CONFLICT