[antlr-interest] Syntactic predicates cause unexplainable compilation errors in different partsof the code

Peter Robinson Peter.Robinson at t-online.de
Wed Jan 26 12:34:06 PST 2005



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 at t-online.de
peter.robinson at charite.de
http://www.charite.de/ch/medgen/robinson/



More information about the antlr-interest mailing list