[antlr-interest] Aliases in AST rewrite generate wrong C code in ver 3.4
Ivan Brezina
ibre5041 at ibrezina.net
Thu Oct 13 05:27:19 PDT 2011
Hi
when I tried to migrate my grammar from version 3.3 into 3.4 I noticed this:
Grammar excerpt:
--- snap ---
subquery
:
(
//LPAREN select_statement RPAREN
// ( group_by_clause )?
// ( (k_model (k_main|k_partition|k_dimension) ) => model_clause )?
// ( union_clause )*
( fu1=for_update_clause )?
// ( order_by_clause )?
( fu2=for_update_clause )?
) -> ^(T_SUBQUERY $fu1 $fu2)
| (
LPAREN subquery RPAREN
// ( group_by_clause )?
// ( (k_model (k_main|k_partition|k_dimension) ) => model_clause )?
// ( union_clause )*
( fu1=for_update_clause )?
// ( order_by_clause )?
( fu2=for_update_clause )?
) -> ^(T_SUBQUERY subquery $fu1 $fu2)
;
/*
================================================================================
FOR UPDATE CLAUSE
================================================================================
*/
for_update_clause
: r_for r_update ( r_of for_update_clause_part_first
for_update_clause_part_next* )? (r_nowait | k_wait NUMBER | k_skip
k_locked)?
-> ^(T_FOR_UPDATE_CLAUSE r_for r_update r_of?
for_update_clause_part_first? for_update_clause_part_next* r_nowait?
k_wait? NUMBER? k_skip? k_locked?)
;
for_update_clause_part_first
: (schema_name DOT)? (table_name DOT)? column_name
;
for_update_clause_part_next
: COMMA (schema_name DOT)? (table_name DOT)? column_name
;
--- end snap ---
This is a minimalistic subset of my grammar that reproduces the problem.
ANTLR ver 3.4 produces C code which contains this:
--- snap ---
// $ANTLR start synpred2_OracleSQL
static void synpred2_OracleSQL_fragment(pOracleSQLParser ctx )
{
void ; // <== !! HERE !!!
#undef RETURN_TYPE_
#define RETURN_TYPE_ void
// OracleSQL.g:30:11: (fu1= for_update_clause )
// OracleSQL.g:30:11: fu1= for_update_clause
{
FOLLOWPUSH(FOLLOW_for_update_clause_in_synpred2_OracleSQL172);
fu1=for_update_clause(ctx);
FOLLOWPOP();
if (HASEXCEPTION())
{
goto rulesynpred2_OracleSQLEx;
}
if (HASFAILED())
{
return ;
}
}
// This is where rules clean up and exit
//
goto rulesynpred2_OracleSQLEx; /* Prevent compiler warnings */
rulesynpred2_OracleSQLEx: ;
}
--- end snap ---
While in version 3.3 the declaration "void ;" is replaced by
" OracleSQLParser_for_update_clause_return fu1;"
Note: Generated code for Java is also incorrect.
Is it a bug or am I doing something wrong?
Ivan
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OracleSQL.g
Type: application/octet-stream
Size: 2563 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20111013/964105d0/attachment.obj
More information about the antlr-interest
mailing list