class Rley::SPPF::ParseForest
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.
Attributes
A setter that tells that the parse is ambiguous.
A Hash with pairs of the kind node key => node
The root node of the forest
Public Class Methods
Source
# File lib/rley/sppf/parse_forest.rb, line 28 def initialize(theRootNode) @root = theRootNode @key2node = {} @is_ambiguous = false end
@param theRootNode [ParseForestNode] The root node of the parse tree.
Public Instance Methods
Source
# File lib/rley/sppf/parse_forest.rb, line 65 def accept(aVisitor) aVisitor.start_visit_pforest(self) # Let's proceed with the visit of nodes root&.accept(aVisitor) aVisitor.end_visit_pforest(self) end
Part of the ‘visitee’ role in the Visitor design pattern.
A visitee is expected to accept the visit from a visitor object
@param aVisitor [ParseForestVisitor] the visitor object
Source
# File lib/rley/sppf/parse_forest.rb, line 46 def ambiguous? @is_ambiguous end
Returns true if the parse encountered a structural ambiguity (i.e. more than one parse tree for the given input)
Source
# File lib/rley/sppf/parse_forest.rb, line 35 def done! # Do nothing end
Notification that the SPPF
construction is over
Source
# File lib/rley/sppf/parse_forest.rb, line 40 def include?(aNode) key2node.include?(aNode) end
Returns true if the given node is present in the forest.