Class: Rley::PTree::ParseTree

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(theRootNode) ⇒ ParseTree

Returns a new instance of ParseTree.

Parameters:

  • theRootNode (ParseTreeNode)

    The root node of the parse tree.



21
22
23
# File 'lib/rley/ptree/parse_tree.rb', line 21

def initialize(theRootNode)
  @root = theRootNode
end

Instance Attribute Details

#rootParseTreeNode

Returns The root node of the tree.

Returns:



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

Parameters:



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