Class: MultElement
- Inherits:
-
OperatorElement
- Object
- Element
- OperatorElement
- MultElement
- Defined in:
- lib/rpdf2txt-rockit/grammar.rb
Instance Attribute Summary
Attributes inherited from OperatorElement
Attributes inherited from Element
#sub_elements, #tree_specification
Instance Method Summary collapse
- #inspect ⇒ Object
-
#normalize(productions) ⇒ Object
NT -> a b (se1 … sen)* c d.
Methods inherited from OperatorElement
#==, #initialize, #name, #to_src
Methods inherited from Element
Methods included from SourceCodeDumpable
as_code, as_method_named, as_module_method_named, #create_new, indent_lines, name_hash, #new_of_my_type, #parameter_named, #to_compact_src, #to_src_in_module, #type_to_src
Constructor Details
This class inherits a constructor from OperatorElement
Instance Method Details
#inspect ⇒ Object
155 156 157 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 155 def inspect "#{inspect_sub_elements}*" end |
#normalize(productions) ⇒ Object
NT -> a b (se1 … sen)* c d
is normalized to
NT -> a b NT-Mult-X c d
| a b c d
NT-Mult-X -> NT-Mult-X se1 … sen
| se1 ... sen
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 167 def normalize(productions) temp_nonterm = temp_nonterminal("Mult", productions.first) num_sub_elements = @sub_elements.length temp_production1 = Production.new(temp_nonterm, [temp_nonterm].concat(@sub_elements), ArrayNodeBuilder.new((1..num_sub_elements).to_a, 0)) temp_production2 = Production.new(temp_nonterm, @sub_elements, ArrayNodeBuilder.new((0...num_sub_elements).to_a)) ps2 = clone_and_substitute_productions(productions, []) do |prod, i| # Will insert empty ArrayNode prod.tree_builder = ArrayNodeBuilder.new([], nil, prod.tree_builder, i) prod.tree_builder.shifting_insert = true prod end [clone_and_substitute_productions(productions, [temp_nonterm]) + ps2, temp_production1.normalize + temp_production2.normalize] end |