[antlr-interest] Parse simle list
Tomasz Bluszcz
moviem at web.de
Sat Jan 22 03:57:09 PST 2005
hi all,
sorry for my bad english first..
I'm a beginner in antlr and don't want do build a compiler...
I'm trying to parse a simle file and tranfere this to my own structures.
Programming language is C++.
Example file content:
"ELEMENT Name1
'{'
"BOOL" bool1;
"BOOL" bool11;
...
'}'
"ELEMENT" Name2
'{'
"BOOL" bool2;
"BOOL" bool22;
...
'}'
...
Because i get an stack overflow with the automatic generated flat ast on
leaving a method where the ast is used ("Refast t = parser.getAst();")
(filesize 15K, 1000 lines) I would like to generate a simple tree like:
ELEMENT - Name1 - BOOL - bool1 - bool11 - ...
|
ELEMENT - Name2 - BOOL - bool2 - bool22 - ...
|
ELEMENT - ...
|
..... - ...
When i made the "ELEMENT"^ token to a root Token then i works fine (no stack
overflow) but my list is then a tree and i cannot walk the list down to
initialise my structures.
Here is the very simple parser grammar:
parse : (KW_ELEMENT LEGALNAME attribs)* ;
attribs : '{'! (CCBOOL LEGALNAME)* '}'!;
Can anybody point my an example or give my some hints?
What modification i have to do to get the tree structure described above?
Exist a c++ class to view the ast like the java class ASTviewer?
Have anyone a similar exsamle for me?
Many Thx, Tom.
More information about the antlr-interest
mailing list