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

Jim Idle jimi at temporal-wave.com
Fri Aug 24 11:36:50 PDT 2012


I can't see why you would want to do this. Perhaps you are asking the
wrong question - can you explain what you are trying to achieve, as there
may be better ways to achieve what you are trying to do.

Your question as it stands cannot really be answered as you don't say
anything about the bounds/cardinality. If your input is always four lines
like this, then there is no need for a grammar, as a few lines of C would
do it. If there is an unlimited set, then how do you determine what swaps
with what?

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Aurelien Thiriet
> Sent: Friday, August 24, 2012 2:42 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Problem to build AST (kind of reverse AST)
>
> 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