[antlr-interest] Multiple optional fields question

Alexey Demakov demakov at ispras.ru
Tue Dec 14 01:04:03 PST 2004


Hi alecs,

The problem is in lookahead k=4.
Your grammar is simple enough for k=1.
Of course, ( DELIM( field3:DIGIT )? )? will conflict with the next
( DELIM ( field4:TEXT )? )? but it can be managed
with 
( options { warnWhenFollowAmbig = false; } :
  DELIM (field3:DIGIT)?
)?
because default ANTLR behaviour is to consume DELIM (field3:DIGIT)?
if DELIM is found.

I use k=1 almost always, local conflicts can be resolved
using predicates.

Regards,
Alexey

-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com

----- Original Message ----- 
From: "mynetadm" <alecsandru.chirosca at comtec.ro>
To: <antlr-interest at yahoogroups.com>
Sent: Tuesday, December 14, 2004 10:52 AM
Subject: [antlr-interest] Multiple optional fields question

> Hi list
> 
> I'm doing an parser to test de ANTLR capabilities and I have one
> problem,,,, 
> 
> we have something like :
> 
> test+1200+234EM123+1+TEST;
> 
> where fields : test, 1200 , 234EM123 are mandatory and 1 and TEST are
> optional. I have to support options like :
> 
> test+1200+234EM123++TEST; or test+1200+234EM123+1 or test+1200+234EM123;
> 
> so I made :
> 
> class myParser extends Parser;
> options  { k=4; }
> test:    ( field1:TEXT DELIM field2:NUMBER DELIM compositeField 
>           (DELIM (field3:DIGIT)?)?
>            (DELIM (field4:TEXT)?)?
>            ENDLINE
>           );
> compositeField: (
>                    na:NUMBER t:TEXT nb:NUMBER
>                 );
> class myLexer extends Lexer;
> DIGIT:  ('0'..'9');
> NUMBER: (DIGIT)(DIGIT)+;
> CHAR: ('a'..'z' | 'A'..'Z');
> TEXT: (CHAR)(CHAR)+;
> ENDLINE:         ";";
> 
> 
> the problem is that :
> 
> test+1200+234EM123+1+TEST; interprets corectly
> test+1200+234EM123+1;      interprets corectly
> test+1200+234EM123++TEST;  interprets corectly
> test+1200+234EM123;        gives me an unexpected end of line
> 
> Can anyone help me please?
> 
> 
> BR,
> alecs




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list