Browse
 
Tools
Rss Categories

LVParseTree::Begin and LVParseTree::End

Reference Number: AA-00968 Views: 1591 0 Rating/ Voters
 

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

  • LVParseTree::Iterator Begin()

    LVParseTree::Iterator End()
 

Example

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

C++ code

  1. LVParseTree::Iterator Itr = Tree.Begin();
  2. LVParseTree::Iterator End = Tree.End();

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

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

  • $directive:
    • "go"
    • "back"
    • {$ = "APPLICATION_BACK"}

See Also