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 ⇒ Object
readonly
The root node of the tree.
Instance Method Summary collapse
-
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in the Visitor design pattern.
-
#initialize(theRootNode) ⇒ ParseTree
constructor
A new instance of ParseTree.
Constructor Details
#initialize(theRootNode) ⇒ ParseTree
Returns a new instance of ParseTree.
19 20 21 |
# File 'lib/rley/ptree/parse_tree.rb', line 19 def initialize(theRootNode) @root = theRootNode end |
Instance Attribute Details
#root ⇒ Object (readonly)
The root node of the tree
16 17 18 |
# File 'lib/rley/ptree/parse_tree.rb', line 16 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
27 28 29 30 31 32 33 34 |
# File 'lib/rley/ptree/parse_tree.rb', line 27 def accept(aVisitor) aVisitor.start_visit_ptree(self) # Let's proceed with the visit of nodes root.accept(aVisitor) if root aVisitor.end_visit_ptree(self) end |