Friday, 15 August 2014

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


I wrote a simple recursive original parser in C ++.

I want a way to print it out of the studs but how can I understand how to do it.

I have a class node and its function is printSymbol () to print its symbol.

Include a std :: list & lt; Node *>

thanks

Add a surcharge to printSymbol , which takes an indent-level or default value, either works:

 < Code> zero print symbol (unsigned indent = 0) const {std :: cout & lt; & Lt; Std :: string (Indent, '') & lt; & Lt; M_symbol & lt; & Lt; '\ N'; (Auto child: m_children) child-> Print symbol (indent + 2); }  

Looking at a single node, printSymbol () should output a direct call to only one symbol, a new line and all its children, if Nobody is properly jagged. Looking at the root pointer, it should dump its entire pars hierarchy into the studio. If you can actually get exceptionally creative about the characters of the eighty-art, console-dependent line, but actually set it as soon as possible, then I warn you.

However, this should give you at least one picture that you can print. Either I or your question absolutely misunderstood.

Good luck


No comments:

Post a Comment