Sha256: b342f398492a36ba62a51dfe235c74b281cf3a6c3293a2c997e527bbb28df2ba
Contents?: true
Size: 1.94 KB
Versions: 3
Compression:
Stored size: 1.94 KB
Contents
require_relative 'token_node' require_relative 'non_terminal_node' require_relative 'alternative_node' module Rley # This module is used as a namespace module SPPF # This module is used as a namespace # TODO change comment # 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. class ParseForest # The root node of the forest attr_reader(:root) # A Hash with pairs of the kind node key => node attr_reader(:key2node) # A setter that tells that the parse is ambiguous. attr_writer(:is_ambiguous) # @param theRootNode [ParseForestNode] The root node of the parse tree. def initialize(theRootNode) @root = theRootNode @key2node = {} @is_ambiguous = false end # Returns true if the given node is present in the forest. def include?(aNode) return key2node.include?(aNode) end # Returns true if the parse encountered a structural ambiguity # (i.e. more than one parse tree for the given input) def ambiguous?() return @is_ambiguous 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 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 end # class end # module end # module # End of file
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rley-0.3.12 | lib/rley/sppf/parse_forest.rb |
rley-0.3.11 | lib/rley/sppf/parse_forest.rb |
rley-0.3.10 | lib/rley/sppf/parse_forest.rb |