[antlr-interest] Re: Help with Java grammar

Terence Parr parrt at cs.usfca.edu
Tue Mar 9 10:01:31 PST 2004


Just to make sure everybody's aware, this EOF issue is already on my  
"stuff I don't like about ANTLR 2 list" ;)

Ter

On Mar 9, 2004, at 6:26 AM, Ric Klaren wrote:

> On Tue, Mar 09, 2004 at 02:08:09PM -0000, cliftonccraig wrote:
>> I just tried this:
>> SL_COMMENT
>> 	:	"//"
>> 		(~('\n'|'\r'))* ('\n'|'\r'('\n')?)
>> 		{
>> //*CCC- Allow comments to flow through to the rewrite engine
>> //		    $setType(Token.SKIP);
>> 		    newline();
>> 		}
>> 		|
>> 		"//" (~('\n'|'\r'))*
>> 	;
>
> How about this?
>
> SL_COMMENT
>    :  "//"
>       ( ~('\n'|'\r') )*                         // not a newline  
> part...
>       ( ('\n'|'\r'('\n')? { newline(); } ) )?   // optional newline
>    ;
>
> If this gives trouble generate the lexer with -traceLexer and see  
> where it
> gets stuck. (or check with debugger)
>
> There's a few dirty tricks you can do with EOF checks that work by  
> checking
> LA(i) for EOF in the init action of a closure rule, but I don't think  
> these
> should be necessary for this. (unless I'm missing the point somewhere)
>
>> And I got an warning saying:
>> D:\scm\tools\parsers\grammar\ANTLR\java.g:1235: warning:lexical
>> nondeterminism between alts 1 and 2 of block upon
>> D:\scm\tools\parsers\grammar\ANTLR\java.g:1235:     k==1:'/'
>> D:\scm\tools\parsers\grammar\ANTLR\java.g:1235:     k==2:'/'
>> D:\scm\tools\parsers\grammar\ANTLR\java.g:1235:
>> k==3:'\u0003'..'\t','\u000b','\u000c','\u000e'..'\uffff'
>> D:\scm\tools\parsers\grammar\ANTLR\java.g:1235:
>> k==4:<end-of- 
>> token>,'\u0003'..'\t','\u000b','\u000c','\u000e'..'\uffff'
>
> Don't worry too much about warnings like these ;) Read the source for  
> what
> antlr generated for the rule and it often becomes obvious if the
> parser/lexer will do the right thing. (and it helps in getting a feel  
> for
> things)
>
> Cheers,
>
> Ric
> -- 
> ----- 
> +++++*****************************************************+++++++++---- 
> ---
>     ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722   
> ----
> ----- 
> +++++*****************************************************+++++++++---- 
> ---
>  Time what is time - I wish I knew how to tell You why - It hurts to  
> know -
>           Aren't we machines - Time what is time - Unlock the door
>                - And see the truth - Then time is time again
>                 From: 'Time what is Time' by Blind Guardian
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
--
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