[antlr-interest] StringTemplate: Infinite Recursion in anonymous conditional template.

Swapnil Kashikar swapnil.kashikar at gmail.com
Fri Apr 21 15:18:28 PDT 2006


Hi,

I am parsing PL/SQL code using antlr and transforming it using
 StringTemplate 2.3b6 .
 Could someone please help me with fixing the error below (Obtained with the
*setLintMode* output from stringtemplate):
------------
exception: java.lang.IllegalStateException: infinite recursion to
<anonymous([s])@9> referenced in <plsql_block([type_declaration, functions,
procedures, code, exception_handlers, into_clause, pb])@104>; stack trace:
<anonymous([s])@9>, references=[s, s, LPAREN]>
<plsql_block([type_declaration, functions, procedures, code,
exception_handlers, into_clause, pb])@104>,
attributes=[code=<statement()@105>, pb], references=[LPAREN,
type_declaration, functions, procedures, code]>
<else_subtemplate([])@138>, references=[s, LPAREN]>
<anonymous([s])@9> (start of recursive cycle)
...
------------

 The problem occurs while generating code using toString() when the input
code has nested plsql blocks like these:
---------
declare
v1 integer;
begin
   declare
      v2 char;
    begin
       select * from names;
    end;
end;
---------

Note : Without nested plsql blocks, it works fine. For ex this is OK:
 ---------
declare
v1 integer;
begin
       select * from names;
end;
---------


The *statement* production rule I am using is:
statement [StringTemplate parentST] returns [StringTemplate
code=template("statement")]
{
    StringTemplate s=null;


}


:
( ("SELECT") =>s=select_statement[code]
  | s=expression [code]
  |("DECLARE" || "BEGIN") => s=*plsql_block*[code]
  | SEMI
  | DIVIDE
  ) (SEMI)?
{
    code.setAttribute("code",s);
}


;

The templates  I use for output generation are *start, statement* and *
'plsql_block'* :
start(statements) ::= <<
 *<statements:{s|<if (s.sql)> This is a SQL statement: <s.code> <else>
This is a PLSQLBlock: <s.code>
<endif> }; separator="\n\n">*
>>
statement(code,sql) ::= <<
<code>
>>

plsql_block(type_declaration, functions, procedures, code,
exception_handlers) ::=
<<
{
<type_declaration;separator="\n">
<functions>
<procedures>

*<code:{s|<if (s.sql)> This is a SQL statement: <s.code> <else>
This is a PLSQLBlock: <s.code>
<endif> }; separator="\n\n">*

<exception_handlers>


}
>>

Thanks,
Swapnil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060421/5b055dcf/attachment.html


More information about the antlr-interest mailing list