LVParseTree::Begin and LVParseTree::End

Begin and End provide iterators for visiting every node in the tree in a top-to-bottom, left-to-right descent. It is the basis for the Tag and Terminal iterators.

Functions

Example

The following code prints out every node in a parse tree.

  1. LVParseTree::Iterator Itr = Tree.Begin();
  2. LVParseTree::Iterator End = Tree.End();
  3.  
  4. for (; Itr != End; Itr++)
  5. {
  6. for (int i = 0; i < Itr->Level(); ++i) cout << "\t";
  7. if (Itr->IsRule())
  8. cout << "$" << Itr->RuleName()  << ":"  << endl;
  9. if (Itr->IsTag())
  10. cout << "{"  << Itr->Text()  << "}"  << endl;
  11. if (Itr->IsTerminal())
  12. cout << "\"" << Itr->Text()  << "\"" << endl;
  13. }

If the grammar was the top level navigation example grammar, and the engine recognized "go back", the above code would print out:

See Also

© 2012 LumenVox LLC. All rights reserved.