c++ - Pretty printing a parse tree to std out? -


i have written simple recursive descent parser in c++.

i need way print std out cannot figure out how this.

i have class node , has function printsymbol() print symbol.

it has std::list <node*> m_children children.

given this, how can pretty print parse tree std out?

thanks

add overload printsymbol takes indent-level, or default value, either works:

void printsymbol(unsigned indent = 0) const {     std::cout << std::string(indent,' ') << m_symbol << '\n';     (auto child : m_children)         child->printsymbol(indent+2); } 

given single node direct call printsymbol() should output symbol, newline, , children if has any, indented. given root pointer should dump entire parse hierarchy stdout. can extraordinarily creative regarding ascii art, console-dependent line chars if you're set on it, can tedious quickly, warn you.

regardless, should @ least give picture can print. either or utterly misunderstood question.

best of luck


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -