[antlr-interest] Error compiling C code generated by antlr3c.
Renji Panicker
renjipanicker+antlr at gmail.com
Wed Sep 22 18:36:42 PDT 2010
Thanks Jim! I found this:
http://www.mail-archive.com/il-antlr-interest@googlegroups.com/msg03823.html
-/renji
On Wed, Sep 22, 2010 at 11:05 PM, Jim Idle <jimi at temporal-wave.com> wrote:
> Please look for "hoisted predicates generating local references" (or
> similar) on antlr.markmail.org and see that you need to use a scope variable
> for this.
>
> Cheers,
>
> Jim
>
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Renji Panicker
> Sent: Wednesday, September 22, 2010 5:46 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Error compiling C code generated by antlr3c.
>
> 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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
More information about the antlr-interest
mailing list