Class: Rley::SPPF::ParseForest
- Inherits:
-
Object
- Object
- Rley::SPPF::ParseForest
- Defined in:
- lib/rley/sppf/parse_forest.rb
Overview
In an ambiguous grammar there are valid inputs that can result in multiple parse trees. A set of parse trees is commonly referred to as a parse forest. More specifically a parse forest is a graph data structure designed to represent a set of equally syntactically correct parse trees. Parse forests generated by Rley are so-called Shared Packed Parse Forests (SPPF). SPPFs allow very compact representation of parse trees by sharing common sub-tree amongst the parse trees.
Instance Attribute Summary collapse
-
#is_ambiguous ⇒ Object
writeonly
A setter that tells that the parse is ambiguous.
-
#key2node ⇒ Object
readonly
A Hash with pairs of the kind node key => node.
-
#root ⇒ Object
readonly
The root node of the forest.
Instance Method Summary collapse
-
#accept(aVisitor) ⇒ Object
Part of the 'visitee' role in the Visitor design pattern.
-
#ambiguous? ⇒ Boolean
Returns true if the parse encountered a structural ambiguity (i.e. more than one parse tree for the given input).
-
#include?(aNode) ⇒ Boolean
Returns true if the given node is present in the forest.
-
#initialize(theRootNode) ⇒ ParseForest
constructor
A new instance of ParseForest.
Constructor Details
#initialize(theRootNode) ⇒ ParseForest
Returns a new instance of ParseForest.
26 27 28 29 30 |
# File 'lib/rley/sppf/parse_forest.rb', line 26 def initialize(theRootNode) @root = theRootNode @key2node = {} @is_ambiguous = false end |
Instance Attribute Details
#is_ambiguous=(value) ⇒ Object (writeonly)
A setter that tells that the parse is ambiguous.
22 23 24 |
# File 'lib/rley/sppf/parse_forest.rb', line 22 def is_ambiguous=(value) @is_ambiguous = value end |
#key2node ⇒ Object (readonly)
A Hash with pairs of the kind node key => node
19 20 21 |
# File 'lib/rley/sppf/parse_forest.rb', line 19 def key2node @key2node end |
#root ⇒ Object (readonly)
The root node of the forest
16 17 18 |
# File 'lib/rley/sppf/parse_forest.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
47 48 49 50 51 52 53 54 |
# File 'lib/rley/sppf/parse_forest.rb', line 47 def accept(aVisitor) aVisitor.start_visit_pforest(self) # Let's proceed with the visit of nodes root.accept(aVisitor) if root aVisitor.end_visit_pforest(self) end |
#ambiguous? ⇒ Boolean
Returns true if the parse encountered a structural ambiguity (i.e. more than one parse tree for the given input)
39 40 41 |
# File 'lib/rley/sppf/parse_forest.rb', line 39 def ambiguous?() return @is_ambiguous end |
#include?(aNode) ⇒ Boolean
Returns true if the given node is present in the forest.
33 34 35 |
# File 'lib/rley/sppf/parse_forest.rb', line 33 def include?(aNode) return key2node.include?(aNode) end |