[antlr-interest] To print the AST as seperate lines and not in a list (LISP notation)

nisha nagendran nisha.nagendran at gmail.com
Fri Apr 6 12:48:51 PDT 2007


Hi,

   I am new to ANTLR and i am getting used to it. I need to parse java
source code and produce a parse tree for each line in the source file along
with the line number. I was able to produce the AST with the use of the Java
grammar and tree grammar present in the examples. But the produced output is
in LISP notation as :

 ( CLASS_DEF ( MODIFIERS public ) [Sample,<IDENT>] EXTENDS_CLAUSE
IMPLEMENTS_CLA
USE ( OBJBLOCK ( METHOD_DEF ( MODIFIERS public static ) ( TYPE void )
[main,<IDE
NT>] ( PARAMETERS ( PARAMETER_DEF MODIFIERS ( TYPE ( [[,<ARRAY_DECLARATOR>]
[Str
ing,<IDENT>] ) ) [args,<IDENT>] ) ) ( [{,<SLIST>] ( VARIABLE_DEF MODIFIERS (
TYP
E int ) [i,<IDENT>] ( [=,<ASSIGN>] ( EXPR [0,<NUM_INT>] ) ) ) ( VARIABLE_DEF
MOD
IFIERS ( TYPE int ) [j,<IDENT>] ( [=,<ASSIGN>] ( EXPR [1,<NUM_INT>] ) ) ) (
VARI
ABLE_DEF MODIFIERS ( TYPE int ) [k,<IDENT>] ( [=,<ASSIGN>] ( EXPR (
[+,<PLUS>] [
i,<IDENT>] [j,<IDENT>] ) ) ) ) ( EXPR ( [(,<METHOD_CALL>] ( [.,<DOT>] (
[.,<DOT>
] [System,<IDENT>] [out,<IDENT>] ) [println,<IDENT>] ) ( ELIST ( EXPR (
[+,<PLUS
>] ["the number is ",<STRING_LITERAL>] [k,<IDENT>] ) ) ) ) ) ) ) ) )


But i want it to be produced seperately for every line in the source program
on different lines along with the line numbers as

1. CLASS_DEF ( MODIFIERS public ) [Sample,<IDENT>] EXTENDS_CLAUSE
IMPLEMENTS_CLAUSE
2.( OBJBLOCK ( METHOD_DEF ( MODIFIERS public static ) ( TYPE void )
[main,<IDENT>] ( PARAMETERS ( PARAMETER_DEF MODIFIERS ( TYPE
([[,<ARRAY_DECLARATOR>] [String,<IDENT>] ) ) [args,<IDENT>] ) )
3.....
4....

and so on.
Can anyone suggest what i could do in order to get the same. I am sorry if
such questions were discussed earlier in the discussion group. I am new to
this group.

Thanks,
Nisha.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070406/b005a14a/attachment.html 


More information about the antlr-interest mailing list