[antlr-interest] different behavior java vs c?

Jim Idle jimi at temporal-wave.com
Fri Aug 3 14:12:10 PDT 2007


I'll take a look, though the only thing I have seen similar is that it
seems a recognition error is not printed at a tope rule on the last
reference. This is because the java model throws an exception and the C
just sets up a flag to say it has seen an exception, which the next rule
up the chain will display. Until I have though through what to do about
that, I recommend an extra top rule to ensure that you see all errors.

You can end up failing silently basically, which I will fix. Also, there
are a lot of tiny bug fixes accrued for the next release.

Try this, just to see if you get a difference:

start : test ;

test : testentry secondentry EOF;

...

> -----Original Message-----
> From: Martin Kortmann [mailto:email at kortmann.de]
> Sent: Friday, August 03, 2007 1:27 PM
> To: antlr-interest at antlr.org
> Cc: Jim Idle
> Subject: different behavior java vs c?
> 
> Hi,
> 
> I think that i have found and error in the C-target.
> It is possible that this is really my fault (i am
> absolutely new to ANTLR) but please check this:
> 
> 
> The following grammar works fine with the java target:
> 
> grammar java_vs_c;
> 
> options{
> output=AST;
> filter=true;
> // language=C;
> ASTLabelType=CommonTree;
> }
> 
> // Start Rule
> test	:	testentry secondentry
> 	;
> 
> testentry
> 	:	'TEST' num1=INT num2=INT
> 	;
> 
> secondentry
> 	:	'SECOND' num1=INT
> 	;
> 
> INT	:	('0' | '1'..'9') '0'..'9'*
> 	;
> 
> WS	:	(' '|'\t'|'\r'|'\n')+ {$channel=HIDDEN;}
> 	;
> 
> ANYOTHER:	. ;
> 
> 
> Input text:
> 
> TEST 1 2
> SECOND 3
> 
> but it fails with language=C.
> 
> The C-Lexer recgnized die tokens, but fillBuffer
> (in antlrtokenstream.c) adds only the first
> three tokens to the tokenStream ('TEST', ' ' and INT)
> and then ignores everything that follows.
> 
> I have testet this with GCC and MSVC .Net 2003.
> 
> Martin


More information about the antlr-interest mailing list