Class: Depager::LALR::Basis
Direct Known Subclasses
ASTBuilderExtension::PostRhs1::Parser, ASTBuilderExtension::PreRuleList0::Parser, CSTBuilderExtension::PostLhs1::Parser, CSTBuilderExtension::PreRuleList0::Parser, Depager::LexerExtension::PreRuleList0::Parser, RieExtension::PostLhs0::Parser, RieExtension::PostRhs1::Parser, StatefulLexerExtension::PreRhsPostSymbol1::Parser, StatefulLexerExtension::PreRuleList0::Parser
Constant Summary
Constants inherited from Parser
Instance Attribute Summary collapse
-
#action_value ⇒ Object
Returns the value of attribute action_value.
-
#basis ⇒ Object
readonly
Returns the value of attribute basis.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#lookahead ⇒ Object
Returns the value of attribute lookahead.
-
#parser_size ⇒ Object
readonly
Returns the value of attribute parser_size.
-
#stack ⇒ Object
Returns the value of attribute stack.
Instance Method Summary collapse
- #abort_driver ⇒ Object
- #accept ⇒ Object
- #banner ⇒ Object
- #do_abort_driver ⇒ Object
- #error ⇒ Object
-
#initialize ⇒ Basis
constructor
A new instance of Basis.
- #next_decorator_index ⇒ Object
- #reduce ⇒ Object
- #shift ⇒ Object
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
#initialize ⇒ Basis
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_value ⇒ Object
Returns the value of attribute action_value.
120 121 122 |
# File 'lib/depager/parser.rb', line 120 def action_value @action_value end |
#basis ⇒ Object (readonly)
Returns the value of attribute basis.
119 120 121 |
# File 'lib/depager/parser.rb', line 119 def basis @basis end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
119 120 121 |
# File 'lib/depager/parser.rb', line 119 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
119 120 121 |
# File 'lib/depager/parser.rb', line 119 def line @line end |
#lookahead ⇒ Object
Returns the value of attribute lookahead.
120 121 122 |
# File 'lib/depager/parser.rb', line 120 def lookahead @lookahead end |
#parser_size ⇒ Object (readonly)
Returns the value of attribute parser_size.
119 120 121 |
# File 'lib/depager/parser.rb', line 119 def parser_size @parser_size end |
#stack ⇒ Object
Returns the value of attribute stack.
120 121 122 |
# File 'lib/depager/parser.rb', line 120 def stack @stack end |
Instance Method Details
#abort_driver ⇒ Object
171 172 173 |
# File 'lib/depager/parser.rb', line 171 def abort_driver exit 1 end |
#accept ⇒ Object
137 |
# File 'lib/depager/parser.rb', line 137 def accept; end |
#banner ⇒ Object
129 130 131 |
# File 'lib/depager/parser.rb', line 129 def self.class.name end |
#do_abort_driver ⇒ Object
167 168 169 |
# File 'lib/depager/parser.rb', line 167 def do_abort_driver abort_driver end |
#error ⇒ Object
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(#{}), unexpected #{la}, expecting #{exp}." warn @stack.pretty_inspect if Depager.respond_to?(:debug_mode?) && Depager.debug_mode? end |
#next_decorator_index ⇒ Object
133 134 135 |
# File 'lib/depager/parser.rb', line 133 def next_decorator_index @parser_size += 1 end |
#reduce ⇒ Object
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 |
#shift ⇒ Object
156 157 158 |
# File 'lib/depager/parser.rb', line 156 def shift stack << lookahead << action_value end |