I am working on creating a compiler, and in this I will generate a tree representing the source program that is being passed. I want to show that this tree is like a mod, so I can display the structure of the program to everyone who is interested,
Now I just print the tree on one line:
ProgramNode -> 'Math' BlockNode -> DeclarationNode -> ConstantDeclarationNode -> const ConstantListNode -> [m := 7, ConstantANode -> [n := StringLiteralNode -> ""TEST"" ]] ;
What I would like is something like this:
ProgramNode / \ 'Math' BlockNode | DeclarationNode | ConstantDeclarationNode ------------------------------ / \ | const ConstantListNode | / | \ \ | m := 7 ConstantANode | / | \ | n := StringLiteralNode | / | \ | " TEST " ;
I really didn't work with trees in Ruby, how are they usually represented?
Any help would be appreciated.
Hunter mcmillen
source share