Hey everyone!
I'm trying to generate an AST tree as stated in the PLY tutorial using
the general Node class, with fields Type,Children and Leaf for "easy"
tree traversal. This seems easy enough with the "binop" example where:
'expression : expression PLUS expression' becomes p[0] = Node("binop",
[p[1],p[3]],p[2]). The two expressions are Children and PLUS is Leaf.
But what about a more complex function example like this? :
FUNCTION ID LPAREN args RPAREN LBRACE statements RBRACE
where FUNCTION, ID,LPAREN,RPAREN,LBRACE,RBRACE are tokens/terminals,
args, statements are non-terminals. These non-terminals must be
Children, but how is the Leaf defined?
Another example with only non-terminals:
foo -> bar1
bar1 -> bar2
How would the AST tree be defined for the above two rules?
And finally - Can anyone give me an example of tree traversing the
final AST?
Any help is much appretiated!!!
HD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---