[antlr-interest] 3 curly brackets commet

Terence Parr parrt at cs.usfca.edu
Mon Apr 12 11:12:02 PDT 2004


On Apr 12, 2004, at 8:48 AM, mailinglist at august.de wrote:

>  How would you detect a comment block that is enclosed in 3 curly 
> brackets?
> e.g.:
> 1. {{{}}} or
> 2. {{{ comment }}} or
> 3. {{{} }}} or
> 4. {{{}} }}} ...
>
> My solution leads to "lexical nondeterminism" though it functions ...
>
> options { k=3; charVocabulary = '\u0020' .. '\u007e';}
> CMT: "{{{"
>         (
>             {LA(3)!='}'}?   "}}"
>         |   {LA(2)!='}'}?   '}'
>         |                           ~'}'
>         )*
>         "}}}";
>
> ... but as I'm new to antlr I'm not quite sure what I'm doing here.
> Avoiding "lexical nondeterminism" as a general advice seems to be 
> helpful.
> Would like to keep the goal, not to see this warning.
>
> Any idea better than adding warnWhenFollowAmbig option?

Hi Rolf,

I suggest using greedy=false option:

CMT : "{{{" (options {greedy=false;} : . )* "}}}" ;

with k=3, this should function as you would like :)  Clean too :)

Ter
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!
Cofounder, http://www.peerscope.com pure link sharing





 
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