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
- LVParseTree::Iterator Begin()
- LVParseTree::Iterator End()
Example
The following code prints out every node in a parse tree.
LVParseTree::Iterator Itr = Tree.Begin();
LVParseTree::Iterator End = Tree.End();
for (; Itr != End; Itr++)
{
for (int i = 0; i < Itr->Level(); ++i) cout << "\t";
if (Itr->IsRule())
cout << "$" << Itr->RuleName() << ":" << endl;
if (Itr->IsTag())
cout << "{" << Itr->Text() << "}" << endl;
if (Itr->IsTerminal())
cout << "\"" << Itr->Text() << "\"" << endl;
}
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
- LVParseTree_GetIteratorBegin and LVParseTree_GetIteratorEnd (C API)