[antlr-interest] AST rewrite for pipelines to functions

Rajesh T trajesh at gmail.com
Mon Jul 16 06:06:30 PDT 2012


Hi,

    I am a newbie to ANTLR, trying to do something like unix pipes with
functions and expressions.

    Eg :

*    'abc' | concat('123') | concat ('xyz')
*
    I have the following grammar

    function :

*     ID '('
             ( a+=orExpr (',' a+=orExpr )* )?
         ')'
    ;

    pipe :
            expr ('|' function)*
    ;

*    The above rules allows the following statement as valid expressions

*    'abc' | concat('123') | concat ('xyz')
*
    While doing AST rewrite I am changing the function definition as

   * function :

     ID '('
             ( a+=orExpr (',' a+=orExpr )* )?
         ')'  -> ^(ID $a+)?
     ;
*

    I can evaluate all functions with a tree Walker and it works fine,
however I am stuck in rewriting for pipe AST below


     *pipe :
            expr ('|' function)*
    ;
    *
    I need to do something like, the above pipe expression to be rewritten
as function expression - So that my function tree walker will evaluate the
below type expressions

    Eg :
       * 'abc' | concat('123') | concat ('xyz') | toLowerCase()
*
    becomes :

     *   toLowerCase(concat( concat (abc, 123) , xyz))
*
    Any help specifically sample snippets appreciated,

 Thanks
 Rajesh


More information about the antlr-interest mailing list