Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 450
  • Last Modified:

AST tree 2-dimensional using ANTLr grammar

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
puffyy_beginner
Asked:
puffyy_beginner
1 Solution
 
BarryMcGillinCommented:
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

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now