Class: Depager::LALR::Basis

Inherits:
Parser
  • Object
show all
Defined in:
lib/depager/parser.rb

Constant Summary

Constants inherited from Parser

Parser::ACC

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#action_table, #defred_after_shift_table, #defred_table, #goto_table, #int_to_nonterm, #int_to_term, #lex, #nonterm_to_int, #parse, #reduce_table, #term_to_int

Constructor Details

#initializeBasis

Returns a new instance of Basis.



122
123
124
125
126
127
# File 'lib/depager/parser.rb', line 122

def initialize
  super

  @basis = self
  @parser_size = 1
end

Instance Attribute Details

#action_valueObject

Returns the value of attribute action_value.



120
121
122
# File 'lib/depager/parser.rb', line 120

def action_value
  @action_value
end

#basisObject (readonly)

Returns the value of attribute basis.



119
120
121
# File 'lib/depager/parser.rb', line 119

def basis
  @basis
end

#fileObject (readonly)

Returns the value of attribute file.



119
120
121
# File 'lib/depager/parser.rb', line 119

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



119
120
121
# File 'lib/depager/parser.rb', line 119

def line
  @line
end

#lookaheadObject

Returns the value of attribute lookahead.



120
121
122
# File 'lib/depager/parser.rb', line 120

def lookahead
  @lookahead
end

#parser_sizeObject (readonly)

Returns the value of attribute parser_size.



119
120
121
# File 'lib/depager/parser.rb', line 119

def parser_size
  @parser_size
end

#stackObject

Returns the value of attribute stack.



120
121
122
# File 'lib/depager/parser.rb', line 120

def stack
  @stack
end

Instance Method Details

#abort_driverObject



171
172
173
# File 'lib/depager/parser.rb', line 171

def abort_driver
  exit 1
end

#acceptObject



137
# File 'lib/depager/parser.rb', line 137

def accept; end


129
130
131
# File 'lib/depager/parser.rb', line 129

def banner
  self.class.name
end

#do_abort_driverObject



167
168
169
# File 'lib/depager/parser.rb', line 167

def do_abort_driver
  abort_driver
end

#errorObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/depager/parser.rb', line 139

def error
  path = Depager.path_of(file)
  exp  = []
  action_table[stack.last].each_with_index do |i, x|
    exp << int_to_term[x] if i
  end
  la = begin
    lookahead[1].value
  rescue StandardError
    lookahead[1]
  end
  la  = (int_to_term[lookahead[0]] || la).inspect
  exp = exp.map { |i| i ? i.inspect : "$" }.join(", ")
  warn "#{path}:#{file.lineno}: syntax error(#{banner}), unexpected #{la}, expecting #{exp}."
  warn @stack.pretty_inspect if Depager.respond_to?(:debug_mode?) && Depager.debug_mode?
end

#next_decorator_indexObject



133
134
135
# File 'lib/depager/parser.rb', line 133

def next_decorator_index
  @parser_size += 1
end

#reduceObject



160
161
162
163
164
165
# File 'lib/depager/parser.rb', line 160

def reduce
  r, x = reduce_table[-action_value]
  (x * 2).times { stack.pop }
  v = goto_table[stack.last][r]
  stack << [r, :NT] << v
end

#shiftObject



156
157
158
# File 'lib/depager/parser.rb', line 156

def shift
  stack << lookahead << action_value
end