[antlr-interest] About tree duplication ?

Bryan Ewbank ewbank at gmail.com
Thu Nov 17 01:55:53 PST 2005


The easiest way I've found is to use the "dup" member functions of the
parser and treeparser classes.  Another way that is closer, perhaps,
to what you are wanting, is to write a production that duplicates a
node (works only with buildAST=true).

On 11/17/05, Mathieu Clabaut <mathieu.clabaut at gmail.com> wrote:
>  Hello,
>
>   In a tree parser, I can not reference twice the same tree when
> constructing a new tree. I have to call astFactory->create().
>   Is there a way to only use antlr notation ? Is this a feature or a bug ?
>
>  For example, the following creation rules
>             ##= #([OR_SERVICE,"||"],
>                      #([TWOWAY,"<>"],#s3,
>                         #([SOURCE,":<"], #f3),
>                         #([DESTINATION,":>"],#t3)
>                      ),
>                      #([TWOWAY,"<>"],#s3,
>                         #([SOURCE,":<"], #t3),
>                         #([DESTINATION,":>"],#f3)
>                      )
> gives the following tree :
> ||
>  <>
>   s3 :<f3 :> t3 :<t3 :>f3
>  <>
>   s3 :<f3 :> t3 :<t3 :>f3
>
> Whereas the following creation rules:
>             ##= #([OR_SERVICE,"||"],
>                      #([TWOWAY,"<>"],#s3,
>                         #([TWOCOLON,"::"] , #b3),
>                         #([SOURCE,":<"], #f3),
>                         #([DESTINATION,":>"],#t3)
>                      ),
>                      #([TWOWAY,"<>"],astFactory->create(#s3),
>                         #([TWOCOLON,"::"] , #b3),
>                         #([SOURCE,":<"], #t3),
>                         #([DESTINATION,":>"],#f3)
>                      )
> Gives the expected results :
> ||
>  <>
>   s3 :<f3 :> t3
>  <>
>   s3 :<t3 :>f3
>
> -mathieu
>
> --
> ____________http://www.gnu.org/philosophy/no-word-attachments.fr.html
> Mathieu CLABAUT                         mailto:mathieu.clabaut at gmail.com
>            F2F5 442F F2AC E1D5 9D31  3EFC 842A BC4A 123B 9A65
>


More information about the antlr-interest mailing list