Solved

AST tree 2-dimensional using ANTLr grammar

Posted on 2011-03-12
1
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

628 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