[antlr-interest] Re: second lexical pass - yeah

FranklinChen at cmu.edu FranklinChen at cmu.edu
Mon Apr 12 11:50:00 PDT 2004


"idontwantanidwith2000init" <idontwantanidwith2000init at yahoo.com>
writes:

> It recognized DATE in the parser :)
> Now, could you review it:
> protected
> DATE
> 	: YEAR
> 	  '-' MONTH
> 	  '-' DAY
> 	  ' ' HOUR
> 	  ':' MINUTES
> 	  ':' SECONDS
> 	;
> // string literals
> STRING_LITERAL
> 	: 	'"'! (~('"'|'\n'|'\r'|'\\')|'\\' .)*'"'!
> 		{
> 			try
> 			{
> 				ScriptLexer scriptLexer = new 
> ScriptLexer(new StringReader($getText));
> 				scriptLexer.mDATE(false);
> 				$setType(DATE);
> 			}catch(ANTLRException exp){
> 				$setType(STRING);
> 			}
> 		}
> 	;
> 
> I've done all the neccesary imports.
> If you like it, Terr, maybe it deserve a place in the FAQ...
> 
> This is just great.
> 
> Tal.

Is there a reason not to just do this:

protected DATE: ...
protected STRING_LITERAL: ...

DATE_OR_STRING_LITERAL
    : (DATE) => DATE { $setType(DATE); }
    | STRING_LITERAL { $setType(STRING_LITERAL); }
    ;

By the way, has anyone been seeing my messages to this list?  I've
posted three or four separate messages on different questions I've had
(one related to lexer issues).

-- 
Franklin


 
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