[antlr-interest] Please help with arbitrary arrangements and
oldBNF syntax
Geir Ove Skjaervik
geiroves at online.no
Fri Dec 16 12:33:03 PST 2005
Hello,
I haven't tried this, but I am pretty sure the following would do the
trick:
I use a semtic predicates to rule out choices already chosen. Maybe
there are other ways to do this.
I put the code together real fast, so exuse me if there are logical
errors:
written
: w1 w2 w3
;
w1
: a:author | p:program | d:dataOrigin w2[a, p, d]
;
w2[AST a, AST p, AST d]
: {a != null}? p1:program | d1:dataOrigin w3[p1, d1]
| {p != null}? a2:author | d2:dataOrigin w4[a2, d2]
| {d != null}? a3:author | p3:program w5[a3, p2]
;
w3[AST p, AST d]
: {p != null}? dataOrigin
| {d != null}? program
;
w4[AST a, AST d]
: {a != null}? dataOrigin
| {d != null}? program
;
w5[AST a, AST p]
: {a != null}? program
| {p != null}? author
;
Geir Ove
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Brannon King
Sent: 16. desember 2005 20:46
To: antlr-interest at antlr.org
Subject: [antlr-interest] Please help with arbitrary arrangements and
oldBNF syntax
Suppose I have the following parser rule snipped from edif.org:
written :
LP! "written"
timeStamp
( < author > | < program > | < dataOrigin > |
property | comment | userData )*
RP!;
Where the angle brackets mean that those can only appear once (in an
arbitrary order). How do I enforce this in an ANTLR grammar?
In a similar vein, is this the right way to limit an identifier length?
IDENTIFIER
options {testLiterals=true;} //make sure it's not a built in
function
: (ALPHA|'&') a:('_'|ALPHA|DIGIT)*
{a.getText().length() < 256}? ; //less than 256 chars total
Thanks for your time
More information about the antlr-interest
mailing list