Solved

AST tree 2-dimensional using ANTLr grammar

Posted on 2011-03-12
1
444 Views
Last Modified: 2012-06-22
Hello experts,
I have attached the java antlr grammar that I found on the web. I am trying to use this grammar to create an AST tree. My problem is how I will modify this grammar so that I get a 2D AST tree instead of getting only one root and all other nodes as children of that particular root. In other words I want a multilevel tree
I tried to write the rewrite rules but I got more confused. Isnt there a ready grammar which does what I am asking?
javagrammar.txt
0
Comment
Question by:puffyy_beginner
1 Comment
 
LVL 2

Accepted Solution

by:
BarryMcGillin earned 500 total points
ID: 35332698
You need to decorate your parse rules with tree identifers

so for example, you need to do something like this:  Assume the grammar is:

start
       : MY GRAMMAR FILE
       ;

Decorate it to have root nodes

start
       : MY GRAMMAR^ FILE
       ;

and you can remove items you do not want as well.

start
       : MY! GRAMMAR^ FILE
       ;

or use a rewrite rule

start
       : MY GRAMMAR FILE -> ^(GRAMMAR FILE)
       ;

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question