Java Grammar To AST

196 views Asked by At

In java grammar I have a parser rule,

name : Identifier ('.' Identifier)* ';' ;

How to get all the identifiers under a single AST tree node?

1

There are 1 answers

0
Juan Aguilar Guisado On

It seems impossible to me only with your lexer-parser.

For this, you will need the called: tree-walker.This third part of the parsing process will make you able to go through the generated AST and, with a counter, print the number of occurrences.

I let you a reference here in case you decide to implement it.

https://theantlrguy.atlassian.net/wiki/display/ANTLR3/Tree+construction

I hope this would help you!