Class: Rley::PTree::ParseTree
- Inherits:
-
Object
- Object
- Rley::PTree::ParseTree
- Defined in:
- lib/rley/ptree/parse_tree.rb
Overview
A parse tree (a.k.a. concrete syntax tree) is a tree-based representation for the parse that corresponds to the input text. In a parse tree, a node corresponds to a grammar symbol used during the parsing:
- a leaf node maps to a terminal symbol occurring in the input, and
- a intermediate node maps to a non-terminal node reduced during the parse. The root node corresponds to the main/start symbol of the grammar.
Instance Attribute Summary collapse
-
#root ⇒ ParseTreeNode
The root node of the tree.
Instance Method Summary collapse
-
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in the Visitor design pattern.
-
#done! ⇒ Object
Notification from the builder telling that the parse tree construction is over.
-
#initialize(theRootNode) ⇒ ParseTree
constructor
A new instance of ParseTree.
Constructor Details
#initialize(theRootNode) ⇒ ParseTree
Returns a new instance of ParseTree.
21 22 23 |
# File 'lib/rley/ptree/parse_tree.rb', line 21 def initialize(theRootNode) @root = theRootNode end |
Instance Attribute Details
#root ⇒ ParseTreeNode
Returns The root node of the tree.
18 19 20 |
# File 'lib/rley/ptree/parse_tree.rb', line 18 def root @root end |
Instance Method Details
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in the Visitor design pattern. A visitee is expected to accept the visit from a visitor object
34 35 36 37 38 39 40 41 |
# File 'lib/rley/ptree/parse_tree.rb', line 34 def accept(aVisitor) aVisitor.start_visit_ptree(self) # Let's proceed with the visit of nodes root&.accept(aVisitor) aVisitor.end_visit_ptree(self) end |
#done! ⇒ Object
Notification from the builder telling that the parse tree construction is over. This method can be overriden.
27 28 29 |
# File 'lib/rley/ptree/parse_tree.rb', line 27 def done! @root.done! end |