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.



19
20
21
# File 'lib/rley/ptree/parse_tree.rb', line 19

def initialize(theRootNode)
  @root = theRootNode
end

Instance Attribute Details

#rootObject (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

Parameters:



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