[antlr-interest] Problem to build AST (kind of reverse AST)

Андрей Асеев andron-eiu at mail.ru
Fri Aug 24 04:30:40 PDT 2012


Hi, Aurelien.

Do you want grammar to build AST or to perform AST reverse transformaion?

24.08.2012 13:41, Aurelien Thiriet пишет:
> Hi,
>
> I'm new to ANTLR (I've read the books by the way ;)).
>
>
> I'd like to parse and build AST for this kind of file :
>
> "
> package1 data11;
> package1 data12;
>
> package2 data21;
> package2 data22;
> "
>
> Which means  data11 and data12 belongs to package1, data21 and data22
> belongs to package2.
>
>
> Its very easy to build this kind of AST :
>
> (DOCUMENT (DATA ( PACKAGE(package1) data11) DATA ( PACKAGE(package1)
> data12) DATA ( PACKAGE(package2) data21) DATA ( PACKAGE(package1) data22)))
>
>
> But my point is to reverse it like this :
> (DOCUMENT ( PACKAGE (package1 DATA(data11) DATA(data12)))    ( PACKAGE
> (package2 DATA(data21) DATA(data22)))   )
>
>
> How would you write the grammar to perform this AST ?
>
> I've almost succed using many  java code into grammar file, but I'd like to
> use grammar only if possible.
>
>
> Thanks a lot
>
> Aurélien
>
> 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