[antlr-interest] Bug in all targets? (Was: Possible bug in C# backend)

Johannes Luber jaluber at gmx.de
Sat Dec 22 15:50:32 PST 2007


Other target developers can skip to the grammar part!

Federico Di Gregorio schrieb:
> Il giorno sab, 22/12/2007 alle 00.51 +0100, Johannes Luber ha scritto:
>> Can you attach a sample grammar exhibiting this behaviour?
> 
> Yes, but I don't knwo if this is really a bug. It happens only with an
> empty scope. My case was:
> 
> statement
> scope {
> }
> 	: ^(PREFIX PNAME URIREF) { ParserUtils.SetPrefix($PNAME.Text, $URIREF.Text); }
> 	| ^(BASE URIREF)         { ParserUtils.SetBase($URIREF.Text);               }
> 	| ^(STATEMENTS subject
> 		   (predicateObjectList[$subject.node] { Statements.AddRange($predicateObjectList.stms); })+ )
> 	;
> 

It is a bug alright. (But usually sample grammar isn't a single rule,
but directly compilable.) I will have a look at it - right now I'm
fixing the sample grammars. I had to wrangle with making the nant build
file platform independent, too. Things could have gone more smoothly
there...
> 
> I know an empty scope probably should not be used (I was debugging and I
> just left it there to avoid too much retyping) but I suppose it should
> generate right code or fail the code generation not fail during the
> compile step.

Empty scopes are only waste of resources, but not actually forbidden. I
wonder if the other targets exhibit the same behaviour. I've created a
sample grammar:

grammar EmptyScope;

options{
language=CSharp;
}

compilation_start
	:	rule1*
	;
	
rule1
scope {
}
	:	WS
	;

WS:	' ';

Testing for Java I saw the same error, so I suppose this is true for all
targets.

Johannes


More information about the antlr-interest mailing list