I am learning Go and looking for a way to print my AST (For reference, I'm following along with Ruslan's excellent Let's Build a Simple Interpreter).
I am printing the root with the following:
tree := par.Parse()
fmt.Printf("
Parse Tree:
%#v
", tree)
Which prints:
Parse Tree:
&Node.Program{name:"PART10AST", block:(*Node.Block)(0x11b32160)}
Is there a way to recursively print a node, and all child nodes? Something to the effect of:
&Node.Program{name:"PART10AST", block:(*Node.Block{decl: *Node.declarations{...}, comp: *Node.Compound{...}})}
Is this functionality built in to Go in any way? Node
is an interface for several different types of struct
s which store data and/or more Node
s.