[antlr-interest] simple return value problem

Michael micha-1 at fantasymail.de
Tue May 12 01:24:55 PDT 2009


Am Tuesday 12 May 2009 09:42:25 schrieb Tobias Wunner:
> Hello,
>
> still new ANTLR I ran into a simple return value problem. I would like
> to parse a token sequence and return the matched string.

often it's simpler to let the lexer do the token foo and the parser do the 
checking of the syntax of the tokens.
You can also skip whitespace in the lexer.

That's my idea (not tested):

fragment
CHAR	:	'a'..'z';
fragment
DIGIT	:	'0'..'9';
fragment
DELIM		(' '|'\t'|'\n')+;

TOKEN: (CHAR|DIGIT)+ ;


in: typeExpression EOF { print(...) };

typeExpression: '@' v=TOKEN ':' DELIM? param (',' DELIM? param)*  { type = 
$v.text; };

param: TOKEN DELIM? { list.add($TOKEN.text); } ;


 Michael



More information about the antlr-interest mailing list