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

- (Rule) initialize(name, source_line)

Returns a new instance of Rule

Parameters:



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

- (Object) branches (readonly)

Returns the value of attribute branches



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

def branches
  @branches
end

- (Object) name (readonly)

Returns the value of attribute name



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

def name
  @name
end

- (Object) references (readonly)

Returns the value of attribute references



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

def references
  @references
end

- (Object) source_line (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

- (Object) add_branch(steps, source_line, ruby_code = nil)

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

- (Array<LL::Terminal>) first_set

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

Returns:



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

- (Object) increment_references



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

def increment_references
  @references += 1
end

- (String) inspect

Returns:

  • (String)


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

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