[antlr-interest] weird internal false problem

Werner Punz werner.punz at gmail.com
Wed Sep 24 14:12:24 PDT 2008


Hello

First of all I am new to ANTLR and it has been quite a few
years since I did my last parser so a lot of knowledge is lost on my side.
That much for an excuse now to my problem.
I have a weird problem I try to define
a grammar which has two character streams which are both delimited by a 
token.

grammar testtrue;

options{backtrack=true;}

tokens {
	END	=	'TPL*/';
	BEGIN	= 	'/*TPL';
	TTRUE	=	'true';
	TFALSE	=	'false';
}


r	:	stream (BEGIN codestream END stream)*;
codestream :	~BEGIN+;
stream	:	~END+;



ALPHA	:	('A'..'Z'|'a'..'z'|'_'|'-');


NUMBER	:	'0'..'9';



QUOTE	:	'"';
VARIDENT:	'$';
CMDIDENT:	'#';
CURLL	:	'{';
CURLR	:	'}';

BRACEL	:	'(';
BRACER	:	')';

LBRACK  :	 '[';
RBRACK  :	 ']';

POINT	:	'.';
COMMA	:	',';

SMALLER	:	'<';
BIGGER	:	'>';
JAVADELIM
	:	';';	
SLASH	:	'/';
MULT	:	'*';


WS  : (' '|'\r'|'\t'|'\u000C'|'\n');
     	

So far so good but if I feed it with following input

public class xxx {
   public void hello() {
	int myvar "hello world"
dfadf
adf
/*TPL
dddd
TPL*/
DDD

It resolves everything properly as exected but I get following output on 
the console:

line 4:3 mismatched character 'd' expecting 'l'

I tried with several combinations and it seems that in the stream part 
on dfadf it tries to find a false and does not get one.
It seems to apply the token TTFALSE here, instead of just adding the
characters to the stream until the BEGIN token is reached.

What do I have to do to get this right?

Thanks in advance

Werner Punz




More information about the antlr-interest mailing list