Comments (1)
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 Align
in ReturnAttribute
and FuncAttribute
.
# 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 GlobalDecl
production rule optionally contains both Align
(as a comma separated global attribute (',' Align)?
) and FuncAttribute
and is defined as follows:
GlobalDecl -> GlobalDecl
: Name=GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Comdat)? (',' Align)? Metadata=(',' MetadataAttachment)+? FuncAttrs=(',' FuncAttribute)+?
;
And, Align
is simply defined as:
Align -> Align
: 'align' N=UintLit
;
Initially when I try to update the grammar I get ll.tm,816:
Align occurs in both named and unnamed fields
. This is easily resolved by assigning a name; i.e. Align=(',' Align)?
.
At this point, I get the error ll.tm,816:
Align cannot be nullable, since it precedes FuncAttrs
which seem to be related to #25.
Now, this is usually where I try to break up use of optional non-terminals in production rules into 2^n
alternatives, where n
is the number of optional non-terminals that are part of the conflict.
While not pretty, the following approach was used successfully with Gocc:
From ll.bnf:
GlobalDecl
: GlobalIdent "=" ExternLinkage GlobalOptions Immutable ConcreteType OptCommaAttachedMDList << astx.NewGlobalDecl($0, $3, $4, $5, $6) >>
| GlobalIdent "=" ExternLinkage GlobalOptions Immutable ConcreteType "," Align OptCommaAttachedMDList << astx.NewGlobalDecl($0, $3, $4, $5, $8) >>
| GlobalIdent "=" ExternLinkage GlobalOptions Immutable ConcreteType "," Comdat OptCommaAttachedMDList << astx.NewGlobalDecl($0, $3, $4, $5, $8) >>
| GlobalIdent "=" ExternLinkage GlobalOptions Immutable ConcreteType "," Comdat "," Align OptCommaAttachedMDList << astx.NewGlobalDecl($0, $3, $4, $5, $10) >>
| GlobalIdent "=" ExternLinkage GlobalOptions Immutable ConcreteType "," Section OptCommaAttachedMDList << astx.NewGlobalDecl($0, $3, $4, $5, $8) >>
| GlobalIdent "=" ExternLinkage GlobalOptions Immutable ConcreteType "," Section "," Align OptCommaAttachedMDList << astx.NewGlobalDecl($0, $3, $4, $5, $10) >>
| GlobalIdent "=" ExternLinkage GlobalOptions Immutable ConcreteType "," Section "," Comdat OptCommaAttachedMDList << astx.NewGlobalDecl($0, $3, $4, $5, $10) >>
| GlobalIdent "=" ExternLinkage GlobalOptions Immutable ConcreteType "," Section "," Comdat "," Align OptCommaAttachedMDList << astx.NewGlobalDecl($0, $3, $4, $5, $12) >>
;
I've tried to apply similar techniques using Textmapper, but so far to no vail.
This is what I tried:
GlobalDecl -> GlobalDecl
: Name=GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Comdat)?
| Name=GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Comdat)? FuncAttrs=(',' FuncAttribute)+
| Name=GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Comdat)? Metadata=(',' MetadataAttachment)+
| Name=GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Comdat)? Metadata=(',' MetadataAttachment)+ FuncAttrs=(',' FuncAttribute)+
| Name=GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Comdat)? Align=(',' Align)+
| Name=GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Comdat)? Align=(',' Align)+ FuncAttrs=(',' FuncAttribute)+
| Name=GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Comdat)? Align=(',' Align)+ Metadata=(',' MetadataAttachment)+
| Name=GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Comdat)? Align=(',' Align) Metadata=(',' MetadataAttachment)+ FuncAttrs=(',' FuncAttribute)+
;
Which results in the following error:
ll.tm,816: `Align` cannot be nullable, since it precedes FuncAttrs
ll.tm,829: `Align` occurs in both named and unnamed fields
ll.tm,820: input: TopLevelEntity_optlist GlobalIdent '=' ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable Type ',' Align
reduce/reduce conflict (next: eoi, global_ident_tok, local_ident_tok, comdat_name_tok, metadata_name_tok, metadata_id_tok, 'attributes', 'declare', 'define', 'module', 'source_filename', 'target', 'uselistorder_bb', 'uselistorder')
list_of_','_and_1_elements2 : ',' Align
FuncAttribute : Align
conflicts: 8 shift/reduce and 9 reduce/reduce
lalr: 0.332s, text: 0.592s, parser: 2228 states, 229KB
Any thoughts? Is there something obvious I'm missing, or is this grammar especially tricky since it contains so many optional attributes?
Kindly,
Robin
from textmapper.
Related Issues (20)
- Remove out-of-date Wiki page HOT 1
- Potential optimization for listener.go, use ... notation to use arrays instead of slices for interface types HOT 3
- bug: Incorrect parent and firstChild set for leftmost and rightmost nonterminals of zero length HOT 6
- ast: comma separated list is parsed as empty (even when present in input) HOT 3
- ast: Foos cannot be a list, since it precedes Foo HOT 7
- proposal: use boolean in multiple return value to distinguish optional fields on AST nodes HOT 6
- Proposal: return value types in To*Node() to reduce allocations HOT 4
- tm-go: avoid collision of token names for character literals; error: '|' and 'or' get the same ID in generated code HOT 2
- bug: parser and Parser return parameters in different order HOT 1
- tm-parsers/tm_test: undefined: tm.SOFT
- jar: error while generating a sublexer that matches {eoi} as invalid_token HOT 2
- report line and column of syntax error when parsing HOT 2
- tm-parsers/js/js.tm: test case failing with "The on-disk content differs from the generated one" HOT 1
- Support {eoi} in patterns
- parse to ast error
- ~ character in the package name breaks generated code
- Collaborate to develop a good parser tool HOT 1
- Problems trying to convert PostgreSQL-16 grammar HOT 5
- Go version of textmapper: 'noUnwind' and 'nounwind' get the same ID in generated code (potential workaround?)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from textmapper.