[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: parse tree
From: |
Aurelian Melinte |
Subject: |
Re: parse tree |
Date: |
Thu, 18 Apr 2002 17:33:16 -0400 |
At 10:29 PM 4/18/2002 +0200, Hans Aberg wrote:
At 15:52 -0400 2002/04/18, Aurelian Melinte wrote:
>I will soon need to modify a grammar to build a parse tree. As bison does
>not offer such a functionality , I thought it would be nice to put it
>straight into it. At least, I could not find it and I am surprised to be
>the first one to have thought to.
I am not sure what property you are asking for; what are you going to use
it for?
Hello,
I have been reading some reeingineering papers those days and all the
techniques explained had as a starting point the parse tree of the sources.
So, I looked around and found that bison does not offer the parse tree (or,
alternatively, the abstract tree syntax).
One way to have it, would be to decorate the grammar with tree building
actions, as you suggest.
The other way I thought of, let bison do it and this way it will be there
for every grammar. Ideally, after the call to yyparse(), I would have a
tree I can walk on, with a simple call, like:
yytreewalk( action_function );
where
void action_function( node* node );
is a function I would supply. I will use it as a start point to build
dataflows and control flow graphs.
As an example of tool having offering the parse tree, see JavaCC. They also
are offering some polymorphic classes to walk the tree. A nice tool, but in
Java and with a non-GPL license.
Regards,
a.
-- Then Bison generated parser build the parser tree via the actions in
given in the .y file. Thus, if all the rules have the form
x: x_1 ... x_n { $$ = node(root: name_of(x), leaves: x_1, ..., x_n }
then you get your tree at runtime. This could easily be implemented under
C++ using a polymorphic hierarchy.
Do you want that to be automated as a debugging feature?
Hans Aberg
_______________________________________________
address@hidden http://mail.gnu.org/mailman/listinfo/help-bison