Solved

AST tree 2-dimensional using ANTLr grammar

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now