Solved

AST tree 2-dimensional using ANTLr grammar

Posted on 2011-03-12
1
441 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
even odd program using while loop 3 40
draw a Christmas tree by using a nested loop? 26 61
hibernate example for saving data 19 37
by zero exception 10 39
This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

785 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