-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are %shift modifiers still supported to resolve ambiguities? #26
Comments
The specific ambiguity I'm trying to figure out how to deal with is described in llir/llvm#40. I've tried quite a few different approaches to resolve the ambiguity by making changes to the grammar, but so far, I've been unsuccessful to find a working approach. Any feedback would be much appreciated, as my "usual" approaches don't seem to work this time. The core issue boils down to the fact that LLVM IR has a lost of optional fields and attributes, as already discussed in other issues. In particular, what I would like to do, is to enable # NOTE: FuncAttribute should contain Align. However, using LALR(1) this
# produces a reduce/reduce conflict as the global attributes of
# GlobalDecl and GlobalDef also contains Align.
%interface FuncAttribute;
# TODO: Figure out how to enable Align in FuncAttribute again.
FuncAttribute -> FuncAttribute
: AttrString
| AttrPair
# not used in attribute groups.
| AttrGroupID
# used in functions.
#| Align # NOTE: removed to resolve reduce/reduce conflict, see above.
# used in attribute groups.
| AlignPair
| AlignStack
| AlignStackPair
| AllocSize
| FuncAttr
;
ReturnAttribute -> ReturnAttribute
# TODO: Figure out how to re-enable without getting these errors in FuncHeader:
# - two unnamed fields share the same type `AttrPair`: ReturnAttribute -vs- FuncAttribute
# - `AttrPair` occurs in both named and unnamed fields
# - `ReturnAttrs` cannot be nullable, since it precedes FuncAttrs
#: AttrString
#| AttrPair
#| Align
: Dereferenceable
| ReturnAttr
; The
And,
Initially when I try to update the grammar I get At this point, I get the error Now, this is usually where I try to break up use of optional non-terminals in production rules into While not pretty, the following approach was used successfully with Gocc: From ll.bnf:
I've tried to apply similar techniques using Textmapper, but so far to no vail. This is what I tried:
Which results in the following error:
Any thoughts? Is there something obvious I'm missing, or is this grammar especially tricky since it contains so many optional attributes? Kindly, |
From my understanding of http://textmapper.org/documentation.html#grammar-ambiguities,
%shift
modifiers may be used to resolve shift/reduce ambiguities in grammars.From the example, I tried to derive a minimal working grammar. However, when I tried to generate the parser using Textmapper, I got the following error:
From https://github.com/mewspring/foo/blob/427ecc6ddb2a95906cea7570c5b28c33abc26544/shiftreduce/shiftreduce.tm#L33:
Is that the correct syntax for using
%shift
modifiers, and if so, why is there a shift/reduce error being reported?If I remove
'if' '(' Expr ')' Stmt %shift 'else'
from the grammar, Textmapper is able to successfully produce both lexers and parsers.Edit: this is on version v0.9.22 of Textmapper.
The text was updated successfully, but these errors were encountered: