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

Jesse McGrew jmcgrew at hansprestige.com
Fri Aug 24 12:46:11 PDT 2012


It sounds like he just wants to group the AST by the package name
(first token on the line). So all the "package1" data nodes go in one
tree, all the "package2" data nodes go in another, etc.

Jesse

On Fri, Aug 24, 2012 at 11:36 AM, Jim Idle <jimi at temporal-wave.com> wrote:
> 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
>
> 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