Class: LL::Rule
- Inherits:
-
Object
- Object
- LL::Rule
- Defined in:
- lib/ll/rule.rb
Overview
Class containing details of a single rule in a grammar.
Instance Attribute Summary (collapse)
-
- (Object) branches
readonly
Returns the value of attribute branches.
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) references
readonly
Returns the value of attribute references.
-
- (Object) source_line
readonly
Returns the value of attribute source_line.
Instance Method Summary (collapse)
-
- (Object) add_branch(steps, source_line, ruby_code = nil)
-
- (Array<LL::Terminal>) first_set
Returns an Array containing the terminals that make up the FIRST() set of this rule.
-
- (Object) increment_references
-
- (Rule) initialize(name, source_line)
constructor
A new instance of Rule.
-
- (String) inspect
Constructor Details
- (Rule) initialize(name, source_line)
Returns a new instance of 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
- (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)
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.
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
49 50 51 |
# File 'lib/ll/rule.rb', line 49 def inspect return "Rule(name: #{name.inspect}, branches: #{branches.inspect})" end |