[prev in list] [next in list] [prev in thread] [next in thread]
List: antlr-interest
Subject: [antlr-interest] Syntactic predicates cause unexplainable
From: Peter.Robinson () t-online ! de (Peter Robinson)
Date: 2005-01-26 12:33:25
Message-ID: 1106771646.3230.12.camel () localhost ! localdomain
[Download RAW message or body]
Gene-ref ::= SEQUENCE {
A VisibleString OPTIONAL ,
B VisibleString OPTIONAL ,
C VisibleString OPTIONAL ,
D VisibleString OPTIONAL ,
E BOOLEAN DEFAULT FALSE ,
F SET OF Dbtag OPTIONAL ,
G SET OF VisibleString OPTIONAL ,
H VisibleString OPTIONAL }
END
Dear ANTLR list,
First of all thanks to you all for being a helpful and informative list.
I recently have been trying to learn antlr and cannot now imagine using
things like lex/yacc with which I previously occasionally did things.
I am now trying to parse a file structure from NCBI in ASN.1 format. The
specification of a small part of the entire thing is as follows ( I
have replaced some keywords with the letters A-H for clarity). Any one
of the entries is optional and is followed by a comma if there is going
to be another line. There are Gene-ref entries with only one entry (and
no comma).
Gene-ref ::= SEQUENCE {
A VisibleString OPTIONAL ,
B VisibleString OPTIONAL ,
C VisibleString OPTIONAL ,
D VisibleString OPTIONAL ,
E BOOLEAN DEFAULT FALSE ,
F SET OF Dbtag OPTIONAL ,
G SET OF VisibleString OPTIONAL ,
H VisibleString OPTIONAL }
END
After trying constructs such as (",")? and getting nondeterminateness
warnings, I tried my hand at a syntactic predicate as follows:
generef_line returns [myJavaObject ... ]
{
String s;
Dbtag d;
}: GENE_KW "{"
( ( A STRING ",")=>
A s1:STRING { System.out.println(s1.getText()); } ","
| A s2:STRING { System.out.println(s2.getText()); }
)?
( (B STRING ",")=>
B s3:STRING { System.out.println(s3.getText()); } ","
| B s4:STRING { System.out.println(s4.getText()); }
)?
AND SO ON...
"}"
;
However, this now causes unexplainable compilation errors in other parts
of the code (about 400 lines of grammar etc) to appear, in code that
**worked perfectly fine** before. What is going on?? and is there a
better way to parse the above construct? Thanks, Peter
--
Peter N. Robinson
peter.robinson@t-online.de
peter.robinson@charite.de
http://www.charite.de/ch/medgen/robinson/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic