[antlr-interest] Error compiling C code generated by antlr3c.
Renji Panicker
renjipanicker+antlr at gmail.com
Wed Sep 22 05:46:27 PDT 2010
Hi everyone,
I'm trying to compile the following grammar into C code:
//------------------------------------------------------
grammar SimpleG;
options
{
language=C;
backtrack=true;
}
@header{
#include <QtCore/QStringList>
#undef emit
}
external_function_call_expression
@declarations{
QStringList tlist;
QStringList vlist;
}:
(
id0=ID
| qualified_type[tlist]
| qualified_id[vlist]
)
;
qualified_id[QStringList& list]
@init {
}:
id0=ID
(
DOT
id1=ID
)*
;
qualified_type [QStringList& list]:
id0=ID
(
SCOPE
id1=ID
)*
;
DOT : '.';
SCOPE : '::';
ID : ('A'..'Z')+ ;
//------------------------------------------------------
Its a bit contrived, because the external_function_call_expression
rule could be left factored, but I am using it to demonstrate the bug.
When this grammar is run through antlr3.2, the resultant
SimpleGParser.c file has the following function at line 781:
//------------------------------------------------------
static void synpred2_SimpleG_fragment(pSimpleGParser ctx )
{
// SimpleG.g:22:10: ( qualified_type[tlist] )
// SimpleG.g:22:10: qualified_type[tlist]
{
FOLLOWPUSH(FOLLOW_qualified_type_in_synpred2_SimpleG70);
qualified_type(ctx, tlist);
FOLLOWPOP();
if (HASEXCEPTION())
{
goto rulesynpred2_SimpleGEx;
}
if (HASFAILED())
{
return ;
}
}
// This is where rules clean up and exit
//
goto rulesynpred2_SimpleGEx; /* Prevent compiler warnings */
rulesynpred2_SimpleGEx: ;
}
//------------------------------------------------------
This does not compile because it refers to 'tlist', which is nowhere
in the current scope. I hope I haven't missed out something obvious.
Regards,
-/renji
More information about the antlr-interest
mailing list