Class: LL::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/ll/rule.rb

Overview

Class containing details of a single rule in a grammar.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, source_line) ⇒ Rule



12
13
14
15
16
17
# File 'lib/ll/rule.rb', line 12

def initialize(name, source_line)
  @name        = name
  @branches    = []
  @source_line = source_line
  @references  = 0
end

Instance Attribute Details

#branchesObject (readonly)

Returns the value of attribute branches.



6
7
8
# File 'lib/ll/rule.rb', line 6

def branches
  @branches
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/ll/rule.rb', line 6

def name
  @name
end

#referencesObject (readonly)

Returns the value of attribute references.



6
7
8
# File 'lib/ll/rule.rb', line 6

def references
  @references
end

#source_lineObject (readonly)

Returns the value of attribute source_line.



6
7
8
# File 'lib/ll/rule.rb', line 6

def source_line
  @source_line
end

Instance Method Details

#add_branch(steps, source_line, ruby_code = nil) ⇒ Object

See Also:

  • LL::Rule.[LL[LL::Branch[LL::Branch#initialize]


22
23
24
# File 'lib/ll/rule.rb', line 22

def add_branch(steps, source_line, ruby_code = nil)
  branches << Branch.new(steps, source_line, ruby_code)
end

#first_setArray<LL::Terminal>

Returns an Array containing the terminals that make up the FIRST() set of this rule.



36
37
38
39
40
41
42
43
44
# File 'lib/ll/rule.rb', line 36

def first_set
  terminals = []

  branches.each do |branch|
    terminals += branch.first_set
  end

  return terminals
end

#increment_referencesObject



26
27
28
# File 'lib/ll/rule.rb', line 26

def increment_references
  @references += 1
end

#inspectString



49
50
51
# File 'lib/ll/rule.rb', line 49

def inspect
  return "Rule(name: #{name.inspect}, branches: #{branches.inspect})"
end