lrama 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codespellignore +0 -0
- data/.github/workflows/codespell.yaml +16 -0
- data/.github/workflows/test.yaml +18 -2
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/README.md +69 -3
- data/Rakefile +12 -0
- data/Steepfile +3 -0
- data/lib/lrama/command.rb +2 -1
- data/lib/lrama/context.rb +4 -4
- data/lib/lrama/digraph.rb +1 -2
- data/lib/lrama/grammar/union.rb +2 -2
- data/lib/lrama/grammar.rb +110 -1
- data/lib/lrama/lexer.rb +131 -303
- data/lib/lrama/option_parser.rb +5 -2
- data/lib/lrama/output.rb +27 -15
- data/lib/lrama/parser.rb +1764 -255
- data/lib/lrama/version.rb +1 -1
- data/parser.y +422 -0
- data/rbs_collection.lock.yaml +1 -1
- data/sample/calc.y +0 -2
- data/sample/parse.y +0 -3
- data/sig/lrama/digraph.rbs +23 -0
- data/sig/lrama/lexer/token/type.rbs +17 -0
- data/template/bison/_yacc.h +71 -0
- data/template/bison/yacc.c +6 -71
- data/template/bison/yacc.h +1 -73
- metadata +8 -3
- data/lib/lrama/parser/token_scanner.rb +0 -56
data/lib/lrama/parser.rb
CHANGED
@@ -1,293 +1,1802 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.7.1
|
4
|
+
# from Racc grammar file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
###### racc/parser.rb begin
|
8
|
+
unless $".find {|p| p.end_with?('/racc/parser.rb')}
|
9
|
+
$".push "#{__dir__}/racc/parser.rb"
|
10
|
+
self.class.module_eval(<<'...end racc/parser.rb/module_eval...', 'racc/parser.rb', 1)
|
11
|
+
# frozen_string_literal: false
|
12
|
+
#--
|
13
|
+
# Copyright (c) 1999-2006 Minero Aoki
|
14
|
+
#
|
15
|
+
# This program is free software.
|
16
|
+
# You can distribute/modify this program under the same terms of ruby.
|
17
|
+
#
|
18
|
+
# As a special exception, when this code is copied by Racc
|
19
|
+
# into a Racc output file, you may use that output file
|
20
|
+
# without restriction.
|
21
|
+
#++
|
22
|
+
|
23
|
+
unless $".find {|p| p.end_with?('/racc/info.rb')}
|
24
|
+
$".push "#{__dir__}/racc/info.rb"
|
25
|
+
#--
|
26
|
+
#
|
27
|
+
#
|
28
|
+
#
|
29
|
+
# Copyright (c) 1999-2006 Minero Aoki
|
30
|
+
#
|
31
|
+
# This program is free software.
|
32
|
+
# You can distribute/modify this program under the same terms of ruby.
|
33
|
+
# see the file "COPYING".
|
34
|
+
#
|
35
|
+
#++
|
36
|
+
|
37
|
+
module Racc
|
38
|
+
VERSION = '1.7.1'
|
39
|
+
Version = VERSION
|
40
|
+
Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
unless defined?(NotImplementedError)
|
47
|
+
NotImplementedError = NotImplementError # :nodoc:
|
48
|
+
end
|
49
|
+
|
50
|
+
module Racc
|
51
|
+
class ParseError < StandardError; end
|
52
|
+
end
|
53
|
+
unless defined?(::ParseError)
|
54
|
+
ParseError = Racc::ParseError # :nodoc:
|
55
|
+
end
|
56
|
+
|
57
|
+
# Racc is a LALR(1) parser generator.
|
58
|
+
# It is written in Ruby itself, and generates Ruby programs.
|
59
|
+
#
|
60
|
+
# == Command-line Reference
|
61
|
+
#
|
62
|
+
# racc [-o<var>filename</var>] [--output-file=<var>filename</var>]
|
63
|
+
# [-e<var>rubypath</var>] [--executable=<var>rubypath</var>]
|
64
|
+
# [-v] [--verbose]
|
65
|
+
# [-O<var>filename</var>] [--log-file=<var>filename</var>]
|
66
|
+
# [-g] [--debug]
|
67
|
+
# [-E] [--embedded]
|
68
|
+
# [-l] [--no-line-convert]
|
69
|
+
# [-c] [--line-convert-all]
|
70
|
+
# [-a] [--no-omit-actions]
|
71
|
+
# [-C] [--check-only]
|
72
|
+
# [-S] [--output-status]
|
73
|
+
# [--version] [--copyright] [--help] <var>grammarfile</var>
|
74
|
+
#
|
75
|
+
# [+grammarfile+]
|
76
|
+
# Racc grammar file. Any extension is permitted.
|
77
|
+
# [-o+outfile+, --output-file=+outfile+]
|
78
|
+
# A filename for output. default is <+filename+>.tab.rb
|
79
|
+
# [-O+filename+, --log-file=+filename+]
|
80
|
+
# Place logging output in file +filename+.
|
81
|
+
# Default log file name is <+filename+>.output.
|
82
|
+
# [-e+rubypath+, --executable=+rubypath+]
|
83
|
+
# output executable file(mode 755). where +path+ is the Ruby interpreter.
|
84
|
+
# [-v, --verbose]
|
85
|
+
# verbose mode. create +filename+.output file, like yacc's y.output file.
|
86
|
+
# [-g, --debug]
|
87
|
+
# add debug code to parser class. To display debuggin information,
|
88
|
+
# use this '-g' option and set @yydebug true in parser class.
|
89
|
+
# [-E, --embedded]
|
90
|
+
# Output parser which doesn't need runtime files (racc/parser.rb).
|
91
|
+
# [-C, --check-only]
|
92
|
+
# Check syntax of racc grammar file and quit.
|
93
|
+
# [-S, --output-status]
|
94
|
+
# Print messages time to time while compiling.
|
95
|
+
# [-l, --no-line-convert]
|
96
|
+
# turns off line number converting.
|
97
|
+
# [-c, --line-convert-all]
|
98
|
+
# Convert line number of actions, inner, header and footer.
|
99
|
+
# [-a, --no-omit-actions]
|
100
|
+
# Call all actions, even if an action is empty.
|
101
|
+
# [--version]
|
102
|
+
# print Racc version and quit.
|
103
|
+
# [--copyright]
|
104
|
+
# Print copyright and quit.
|
105
|
+
# [--help]
|
106
|
+
# Print usage and quit.
|
107
|
+
#
|
108
|
+
# == Generating Parser Using Racc
|
109
|
+
#
|
110
|
+
# To compile Racc grammar file, simply type:
|
111
|
+
#
|
112
|
+
# $ racc parse.y
|
113
|
+
#
|
114
|
+
# This creates Ruby script file "parse.tab.y". The -o option can change the output filename.
|
115
|
+
#
|
116
|
+
# == Writing A Racc Grammar File
|
117
|
+
#
|
118
|
+
# If you want your own parser, you have to write a grammar file.
|
119
|
+
# A grammar file contains the name of your parser class, grammar for the parser,
|
120
|
+
# user code, and anything else.
|
121
|
+
# When writing a grammar file, yacc's knowledge is helpful.
|
122
|
+
# If you have not used yacc before, Racc is not too difficult.
|
123
|
+
#
|
124
|
+
# Here's an example Racc grammar file.
|
125
|
+
#
|
126
|
+
# class Calcparser
|
127
|
+
# rule
|
128
|
+
# target: exp { print val[0] }
|
129
|
+
#
|
130
|
+
# exp: exp '+' exp
|
131
|
+
# | exp '*' exp
|
132
|
+
# | '(' exp ')'
|
133
|
+
# | NUMBER
|
134
|
+
# end
|
135
|
+
#
|
136
|
+
# Racc grammar files resemble yacc files.
|
137
|
+
# But (of course), this is Ruby code.
|
138
|
+
# yacc's $$ is the 'result', $0, $1... is
|
139
|
+
# an array called 'val', and $-1, $-2... is an array called '_values'.
|
140
|
+
#
|
141
|
+
# See the {Grammar File Reference}[rdoc-ref:lib/racc/rdoc/grammar.en.rdoc] for
|
142
|
+
# more information on grammar files.
|
143
|
+
#
|
144
|
+
# == Parser
|
145
|
+
#
|
146
|
+
# Then you must prepare the parse entry method. There are two types of
|
147
|
+
# parse methods in Racc, Racc::Parser#do_parse and Racc::Parser#yyparse
|
148
|
+
#
|
149
|
+
# Racc::Parser#do_parse is simple.
|
150
|
+
#
|
151
|
+
# It's yyparse() of yacc, and Racc::Parser#next_token is yylex().
|
152
|
+
# This method must returns an array like [TOKENSYMBOL, ITS_VALUE].
|
153
|
+
# EOF is [false, false].
|
154
|
+
# (TOKENSYMBOL is a Ruby symbol (taken from String#intern) by default.
|
155
|
+
# If you want to change this, see the grammar reference.
|
156
|
+
#
|
157
|
+
# Racc::Parser#yyparse is little complicated, but useful.
|
158
|
+
# It does not use Racc::Parser#next_token, instead it gets tokens from any iterator.
|
159
|
+
#
|
160
|
+
# For example, <code>yyparse(obj, :scan)</code> causes
|
161
|
+
# calling +obj#scan+, and you can return tokens by yielding them from +obj#scan+.
|
162
|
+
#
|
163
|
+
# == Debugging
|
164
|
+
#
|
165
|
+
# When debugging, "-v" or/and the "-g" option is helpful.
|
166
|
+
#
|
167
|
+
# "-v" creates verbose log file (.output).
|
168
|
+
# "-g" creates a "Verbose Parser".
|
169
|
+
# Verbose Parser prints the internal status when parsing.
|
170
|
+
# But it's _not_ automatic.
|
171
|
+
# You must use -g option and set +@yydebug+ to +true+ in order to get output.
|
172
|
+
# -g option only creates the verbose parser.
|
173
|
+
#
|
174
|
+
# === Racc reported syntax error.
|
175
|
+
#
|
176
|
+
# Isn't there too many "end"?
|
177
|
+
# grammar of racc file is changed in v0.10.
|
178
|
+
#
|
179
|
+
# Racc does not use '%' mark, while yacc uses huge number of '%' marks..
|
180
|
+
#
|
181
|
+
# === Racc reported "XXXX conflicts".
|
182
|
+
#
|
183
|
+
# Try "racc -v xxxx.y".
|
184
|
+
# It causes producing racc's internal log file, xxxx.output.
|
185
|
+
#
|
186
|
+
# === Generated parsers does not work correctly
|
187
|
+
#
|
188
|
+
# Try "racc -g xxxx.y".
|
189
|
+
# This command let racc generate "debugging parser".
|
190
|
+
# Then set @yydebug=true in your parser.
|
191
|
+
# It produces a working log of your parser.
|
192
|
+
#
|
193
|
+
# == Re-distributing Racc runtime
|
194
|
+
#
|
195
|
+
# A parser, which is created by Racc, requires the Racc runtime module;
|
196
|
+
# racc/parser.rb.
|
197
|
+
#
|
198
|
+
# Ruby 1.8.x comes with Racc runtime module,
|
199
|
+
# you need NOT distribute Racc runtime files.
|
200
|
+
#
|
201
|
+
# If you want to include the Racc runtime module with your parser.
|
202
|
+
# This can be done by using '-E' option:
|
203
|
+
#
|
204
|
+
# $ racc -E -omyparser.rb myparser.y
|
205
|
+
#
|
206
|
+
# This command creates myparser.rb which `includes' Racc runtime.
|
207
|
+
# Only you must do is to distribute your parser file (myparser.rb).
|
208
|
+
#
|
209
|
+
# Note: parser.rb is ruby license, but your parser is not.
|
210
|
+
# Your own parser is completely yours.
|
211
|
+
module Racc
|
212
|
+
|
213
|
+
unless defined?(Racc_No_Extensions)
|
214
|
+
Racc_No_Extensions = false # :nodoc:
|
215
|
+
end
|
3
216
|
|
4
|
-
module Lrama
|
5
|
-
# Parser for parse.y, generates a grammar
|
6
217
|
class Parser
|
7
|
-
include Lrama::Report::Duration
|
8
218
|
|
9
|
-
|
219
|
+
Racc_Runtime_Version = ::Racc::VERSION
|
220
|
+
Racc_Runtime_Core_Version_R = ::Racc::VERSION
|
221
|
+
|
222
|
+
begin
|
223
|
+
if Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
|
224
|
+
require 'jruby'
|
225
|
+
require 'racc/cparse-jruby.jar'
|
226
|
+
com.headius.racc.Cparse.new.load(JRuby.runtime, false)
|
227
|
+
else
|
228
|
+
require 'racc/cparse'
|
229
|
+
end
|
230
|
+
|
231
|
+
unless new.respond_to?(:_racc_do_parse_c, true)
|
232
|
+
raise LoadError, 'old cparse.so'
|
233
|
+
end
|
234
|
+
if Racc_No_Extensions
|
235
|
+
raise LoadError, 'selecting ruby version of racc runtime core'
|
236
|
+
end
|
237
|
+
|
238
|
+
Racc_Main_Parsing_Routine = :_racc_do_parse_c # :nodoc:
|
239
|
+
Racc_YY_Parse_Method = :_racc_yyparse_c # :nodoc:
|
240
|
+
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C # :nodoc:
|
241
|
+
Racc_Runtime_Type = 'c' # :nodoc:
|
242
|
+
rescue LoadError
|
243
|
+
Racc_Main_Parsing_Routine = :_racc_do_parse_rb
|
244
|
+
Racc_YY_Parse_Method = :_racc_yyparse_rb
|
245
|
+
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
|
246
|
+
Racc_Runtime_Type = 'ruby'
|
247
|
+
end
|
10
248
|
|
11
|
-
def
|
12
|
-
|
249
|
+
def Parser.racc_runtime_type # :nodoc:
|
250
|
+
Racc_Runtime_Type
|
13
251
|
end
|
14
252
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
parse_grammar_rules(TokenScanner.new(lexer.grammar_rules_tokens), grammar)
|
22
|
-
process_epilogue(grammar, lexer)
|
23
|
-
grammar.prepare
|
24
|
-
grammar.compute_nullable
|
25
|
-
grammar.compute_first_set
|
26
|
-
grammar.validate!
|
27
|
-
|
28
|
-
grammar
|
253
|
+
def _racc_setup
|
254
|
+
@yydebug = false unless self.class::Racc_debug_parser
|
255
|
+
@yydebug = false unless defined?(@yydebug)
|
256
|
+
if @yydebug
|
257
|
+
@racc_debug_out = $stderr unless defined?(@racc_debug_out)
|
258
|
+
@racc_debug_out ||= $stderr
|
29
259
|
end
|
260
|
+
arg = self.class::Racc_arg
|
261
|
+
arg[13] = true if arg.size < 14
|
262
|
+
arg
|
30
263
|
end
|
31
264
|
|
32
|
-
|
265
|
+
def _racc_init_sysvars
|
266
|
+
@racc_state = [0]
|
267
|
+
@racc_tstack = []
|
268
|
+
@racc_vstack = []
|
33
269
|
|
34
|
-
|
35
|
-
|
36
|
-
|
270
|
+
@racc_t = nil
|
271
|
+
@racc_val = nil
|
272
|
+
|
273
|
+
@racc_read_next = true
|
274
|
+
|
275
|
+
@racc_user_yyerror = false
|
276
|
+
@racc_error_status = 0
|
277
|
+
end
|
278
|
+
|
279
|
+
# The entry point of the parser. This method is used with #next_token.
|
280
|
+
# If Racc wants to get token (and its value), calls next_token.
|
281
|
+
#
|
282
|
+
# Example:
|
283
|
+
# def parse
|
284
|
+
# @q = [[1,1],
|
285
|
+
# [2,2],
|
286
|
+
# [3,3],
|
287
|
+
# [false, '$']]
|
288
|
+
# do_parse
|
289
|
+
# end
|
290
|
+
#
|
291
|
+
# def next_token
|
292
|
+
# @q.shift
|
293
|
+
# end
|
294
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
295
|
+
def do_parse
|
296
|
+
#{Racc_Main_Parsing_Routine}(_racc_setup(), false)
|
37
297
|
end
|
298
|
+
RUBY
|
38
299
|
|
39
|
-
|
40
|
-
|
41
|
-
|
300
|
+
# The method to fetch next token.
|
301
|
+
# If you use #do_parse method, you must implement #next_token.
|
302
|
+
#
|
303
|
+
# The format of return value is [TOKEN_SYMBOL, VALUE].
|
304
|
+
# +token-symbol+ is represented by Ruby's symbol by default, e.g. :IDENT
|
305
|
+
# for 'IDENT'. ";" (String) for ';'.
|
306
|
+
#
|
307
|
+
# The final symbol (End of file) must be false.
|
308
|
+
def next_token
|
309
|
+
raise NotImplementedError, "#{self.class}\#next_token is not defined"
|
42
310
|
end
|
43
311
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
when T::P_parse_param
|
76
|
-
ts.next
|
77
|
-
code = ts.consume!(T::User_code)
|
78
|
-
code = grammar.build_code(:parse_param, code)
|
79
|
-
grammar.parse_param = code.token_code.s_value
|
80
|
-
when T::P_initial_action
|
81
|
-
ts.next
|
82
|
-
code = ts.consume!(T::User_code)
|
83
|
-
code = grammar.build_code(:initial_action, code)
|
84
|
-
ts.consume(T::Semicolon)
|
85
|
-
grammar.initial_action = code
|
86
|
-
when T::P_union
|
87
|
-
lineno = ts.current_token.line
|
88
|
-
ts.next
|
89
|
-
code = ts.consume!(T::User_code)
|
90
|
-
code = grammar.build_code(:union, code)
|
91
|
-
ts.consume(T::Semicolon)
|
92
|
-
grammar.set_union(code, lineno)
|
93
|
-
when T::P_token
|
94
|
-
# %token tag? (ident number? string?)+
|
95
|
-
#
|
96
|
-
# * ident can be char, e.g. '\\', '\t', '\13'
|
97
|
-
# * number is a token_id for term
|
98
|
-
#
|
99
|
-
# These are valid token declaration (from CRuby parse.y)
|
100
|
-
#
|
101
|
-
# %token END_OF_INPUT 0 "end-of-input"
|
102
|
-
# %token <id> '\\' "backslash"
|
103
|
-
# %token tSP "escaped space"
|
104
|
-
# %token tUPLUS 132 "unary+"
|
105
|
-
# %token tCOLON3 ":: at EXPR_BEG"
|
106
|
-
# %token tSTRING_DBEG tSTRING_DVAR tLAMBEG tLABEL_END
|
107
|
-
#
|
108
|
-
#
|
109
|
-
# See: https://www.gnu.org/software/bison/manual/html_node/Symbol-Decls.html
|
110
|
-
ts.next
|
111
|
-
opt_tag = ts.consume(T::Tag)
|
112
|
-
|
113
|
-
while (id = ts.consume(T::Ident, T::Char)) do
|
114
|
-
opt_number = ts.consume(T::Number)
|
115
|
-
opt_string = ts.consume(T::String)
|
116
|
-
# Can replace 0 (EOF)
|
117
|
-
grammar.add_term(
|
118
|
-
id: id,
|
119
|
-
alias_name: opt_string && opt_string.s_value,
|
120
|
-
token_id: opt_number && opt_number.s_value,
|
121
|
-
tag: opt_tag,
|
122
|
-
replace: true,
|
123
|
-
)
|
312
|
+
def _racc_do_parse_rb(arg, in_debug)
|
313
|
+
action_table, action_check, action_default, action_pointer,
|
314
|
+
_, _, _, _,
|
315
|
+
_, _, token_table, * = arg
|
316
|
+
|
317
|
+
_racc_init_sysvars
|
318
|
+
tok = act = i = nil
|
319
|
+
|
320
|
+
catch(:racc_end_parse) {
|
321
|
+
while true
|
322
|
+
if i = action_pointer[@racc_state[-1]]
|
323
|
+
if @racc_read_next
|
324
|
+
if @racc_t != 0 # not EOF
|
325
|
+
tok, @racc_val = next_token()
|
326
|
+
unless tok # EOF
|
327
|
+
@racc_t = 0
|
328
|
+
else
|
329
|
+
@racc_t = (token_table[tok] or 1) # error token
|
330
|
+
end
|
331
|
+
racc_read_token(@racc_t, tok, @racc_val) if @yydebug
|
332
|
+
@racc_read_next = false
|
333
|
+
end
|
334
|
+
end
|
335
|
+
i += @racc_t
|
336
|
+
unless i >= 0 and
|
337
|
+
act = action_table[i] and
|
338
|
+
action_check[i] == @racc_state[-1]
|
339
|
+
act = action_default[@racc_state[-1]]
|
340
|
+
end
|
341
|
+
else
|
342
|
+
act = action_default[@racc_state[-1]]
|
124
343
|
end
|
125
|
-
|
126
|
-
|
127
|
-
#
|
128
|
-
# See: https://www.gnu.org/software/bison/manual/html_node/Symbol-Decls.html
|
129
|
-
ts.next
|
130
|
-
opt_tag = ts.consume(T::Tag)
|
131
|
-
|
132
|
-
while (id = ts.consume(T::Ident, T::Char, T::String)) do
|
133
|
-
grammar.add_type(
|
134
|
-
id: id,
|
135
|
-
tag: opt_tag
|
136
|
-
)
|
344
|
+
while act = _racc_evalact(act, arg)
|
345
|
+
;
|
137
346
|
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
347
|
+
end
|
348
|
+
}
|
349
|
+
end
|
350
|
+
|
351
|
+
# Another entry point for the parser.
|
352
|
+
# If you use this method, you must implement RECEIVER#METHOD_ID method.
|
353
|
+
#
|
354
|
+
# RECEIVER#METHOD_ID is a method to get next token.
|
355
|
+
# It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
|
356
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
357
|
+
def yyparse(recv, mid)
|
358
|
+
#{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), false)
|
359
|
+
end
|
360
|
+
RUBY
|
361
|
+
|
362
|
+
def _racc_yyparse_rb(recv, mid, arg, c_debug)
|
363
|
+
action_table, action_check, action_default, action_pointer,
|
364
|
+
_, _, _, _,
|
365
|
+
_, _, token_table, * = arg
|
366
|
+
|
367
|
+
_racc_init_sysvars
|
368
|
+
|
369
|
+
catch(:racc_end_parse) {
|
370
|
+
until i = action_pointer[@racc_state[-1]]
|
371
|
+
while act = _racc_evalact(action_default[@racc_state[-1]], arg)
|
372
|
+
;
|
144
373
|
end
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
grammar.add_left(sym, precedence_number)
|
374
|
+
end
|
375
|
+
recv.__send__(mid) do |tok, val|
|
376
|
+
unless tok
|
377
|
+
@racc_t = 0
|
378
|
+
else
|
379
|
+
@racc_t = (token_table[tok] or 1) # error token
|
152
380
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
381
|
+
@racc_val = val
|
382
|
+
@racc_read_next = false
|
383
|
+
|
384
|
+
i += @racc_t
|
385
|
+
unless i >= 0 and
|
386
|
+
act = action_table[i] and
|
387
|
+
action_check[i] == @racc_state[-1]
|
388
|
+
act = action_default[@racc_state[-1]]
|
160
389
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
while (
|
166
|
-
|
167
|
-
|
390
|
+
while act = _racc_evalact(act, arg)
|
391
|
+
;
|
392
|
+
end
|
393
|
+
|
394
|
+
while !(i = action_pointer[@racc_state[-1]]) ||
|
395
|
+
! @racc_read_next ||
|
396
|
+
@racc_t == 0 # $
|
397
|
+
unless i and i += @racc_t and
|
398
|
+
i >= 0 and
|
399
|
+
act = action_table[i] and
|
400
|
+
action_check[i] == @racc_state[-1]
|
401
|
+
act = action_default[@racc_state[-1]]
|
402
|
+
end
|
403
|
+
while act = _racc_evalact(act, arg)
|
404
|
+
;
|
405
|
+
end
|
168
406
|
end
|
169
|
-
precedence_number += 1
|
170
|
-
when nil
|
171
|
-
# end of input
|
172
|
-
raise "Reach to end of input within declarations"
|
173
|
-
else
|
174
|
-
raise "Unexpected token: #{ts.current_token}"
|
175
407
|
end
|
176
|
-
|
408
|
+
}
|
177
409
|
end
|
178
410
|
|
179
|
-
|
180
|
-
|
181
|
-
|
411
|
+
###
|
412
|
+
### common
|
413
|
+
###
|
414
|
+
|
415
|
+
def _racc_evalact(act, arg)
|
416
|
+
action_table, action_check, _, action_pointer,
|
417
|
+
_, _, _, _,
|
418
|
+
_, _, _, shift_n,
|
419
|
+
reduce_n, * = arg
|
420
|
+
nerr = 0 # tmp
|
421
|
+
|
422
|
+
if act > 0 and act < shift_n
|
423
|
+
#
|
424
|
+
# shift
|
425
|
+
#
|
426
|
+
if @racc_error_status > 0
|
427
|
+
@racc_error_status -= 1 unless @racc_t <= 1 # error token or EOF
|
428
|
+
end
|
429
|
+
@racc_vstack.push @racc_val
|
430
|
+
@racc_state.push act
|
431
|
+
@racc_read_next = true
|
432
|
+
if @yydebug
|
433
|
+
@racc_tstack.push @racc_t
|
434
|
+
racc_shift @racc_t, @racc_tstack, @racc_vstack
|
435
|
+
end
|
436
|
+
|
437
|
+
elsif act < 0 and act > -reduce_n
|
438
|
+
#
|
439
|
+
# reduce
|
440
|
+
#
|
441
|
+
code = catch(:racc_jump) {
|
442
|
+
@racc_state.push _racc_do_reduce(arg, act)
|
443
|
+
false
|
444
|
+
}
|
445
|
+
if code
|
446
|
+
case code
|
447
|
+
when 1 # yyerror
|
448
|
+
@racc_user_yyerror = true # user_yyerror
|
449
|
+
return -reduce_n
|
450
|
+
when 2 # yyaccept
|
451
|
+
return shift_n
|
452
|
+
else
|
453
|
+
raise '[Racc Bug] unknown jump code'
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
elsif act == shift_n
|
458
|
+
#
|
459
|
+
# accept
|
460
|
+
#
|
461
|
+
racc_accept if @yydebug
|
462
|
+
throw :racc_end_parse, @racc_vstack[0]
|
463
|
+
|
464
|
+
elsif act == -reduce_n
|
465
|
+
#
|
466
|
+
# error
|
467
|
+
#
|
468
|
+
case @racc_error_status
|
469
|
+
when 0
|
470
|
+
unless arg[21] # user_yyerror
|
471
|
+
nerr += 1
|
472
|
+
on_error @racc_t, @racc_val, @racc_vstack
|
473
|
+
end
|
474
|
+
when 3
|
475
|
+
if @racc_t == 0 # is $
|
476
|
+
# We're at EOF, and another error occurred immediately after
|
477
|
+
# attempting auto-recovery
|
478
|
+
throw :racc_end_parse, nil
|
479
|
+
end
|
480
|
+
@racc_read_next = true
|
481
|
+
end
|
482
|
+
@racc_user_yyerror = false
|
483
|
+
@racc_error_status = 3
|
484
|
+
while true
|
485
|
+
if i = action_pointer[@racc_state[-1]]
|
486
|
+
i += 1 # error token
|
487
|
+
if i >= 0 and
|
488
|
+
(act = action_table[i]) and
|
489
|
+
action_check[i] == @racc_state[-1]
|
490
|
+
break
|
491
|
+
end
|
492
|
+
end
|
493
|
+
throw :racc_end_parse, nil if @racc_state.size <= 1
|
494
|
+
@racc_state.pop
|
495
|
+
@racc_vstack.pop
|
496
|
+
if @yydebug
|
497
|
+
@racc_tstack.pop
|
498
|
+
racc_e_pop @racc_state, @racc_tstack, @racc_vstack
|
499
|
+
end
|
500
|
+
end
|
501
|
+
return act
|
502
|
+
|
503
|
+
else
|
504
|
+
raise "[Racc Bug] unknown action #{act.inspect}"
|
182
505
|
end
|
506
|
+
|
507
|
+
racc_next_state(@racc_state[-1], @racc_state) if @yydebug
|
508
|
+
|
509
|
+
nil
|
183
510
|
end
|
184
511
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
512
|
+
def _racc_do_reduce(arg, act)
|
513
|
+
_, _, _, _,
|
514
|
+
goto_table, goto_check, goto_default, goto_pointer,
|
515
|
+
nt_base, reduce_table, _, _,
|
516
|
+
_, use_result, * = arg
|
517
|
+
|
518
|
+
state = @racc_state
|
519
|
+
vstack = @racc_vstack
|
520
|
+
tstack = @racc_tstack
|
521
|
+
|
522
|
+
i = act * -3
|
523
|
+
len = reduce_table[i]
|
524
|
+
reduce_to = reduce_table[i+1]
|
525
|
+
method_id = reduce_table[i+2]
|
526
|
+
void_array = []
|
527
|
+
|
528
|
+
tmp_t = tstack[-len, len] if @yydebug
|
529
|
+
tmp_v = vstack[-len, len]
|
530
|
+
tstack[-len, len] = void_array if @yydebug
|
531
|
+
vstack[-len, len] = void_array
|
532
|
+
state[-len, len] = void_array
|
533
|
+
|
534
|
+
# tstack must be updated AFTER method call
|
535
|
+
if use_result
|
536
|
+
vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0])
|
537
|
+
else
|
538
|
+
vstack.push __send__(method_id, tmp_v, vstack)
|
196
539
|
end
|
540
|
+
tstack.push reduce_to
|
197
541
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
# |
|
206
|
-
bar_lineno = ts.current_token.line
|
207
|
-
ts.next
|
208
|
-
rhs = parse_grammar_rule_rhs(ts, grammar, lhs)
|
209
|
-
grammar.add_rule(lhs: lhs, rhs: rhs, lineno: rhs.first ? rhs.first.line : bar_lineno)
|
210
|
-
when T::Semicolon
|
211
|
-
# ;
|
212
|
-
ts.next
|
213
|
-
break
|
214
|
-
when T::Ident_Colon
|
215
|
-
# Next lhs can be here because ";" is optional.
|
216
|
-
# Do not consume next token.
|
217
|
-
break
|
218
|
-
when nil
|
219
|
-
# end of input can be here when ";" is omitted
|
220
|
-
break
|
221
|
-
else
|
222
|
-
raise "Unexpected token: #{ts.current_token}"
|
542
|
+
racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug
|
543
|
+
|
544
|
+
k1 = reduce_to - nt_base
|
545
|
+
if i = goto_pointer[k1]
|
546
|
+
i += state[-1]
|
547
|
+
if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1
|
548
|
+
return curstate
|
223
549
|
end
|
224
550
|
end
|
551
|
+
goto_default[k1]
|
225
552
|
end
|
226
553
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
a << ts.current_token
|
246
|
-
ts.next
|
247
|
-
when T::P_prec
|
248
|
-
# %prec tPLUS
|
249
|
-
#
|
250
|
-
# See: https://www.gnu.org/software/bison/manual/html_node/Contextual-Precedence.html
|
251
|
-
|
252
|
-
ts.next
|
253
|
-
prec_seen = true
|
254
|
-
precedence_id = ts.consume!(T::Ident, T::String, T::Char)
|
255
|
-
precedence_sym = grammar.find_symbol_by_id!(precedence_id)
|
256
|
-
a << precedence_sym
|
257
|
-
when T::User_code
|
258
|
-
# { code } in the middle of rhs
|
259
|
-
|
260
|
-
if prec_seen
|
261
|
-
raise "Multiple User_code after %prec" if code_after_prec
|
262
|
-
code_after_prec = true
|
263
|
-
end
|
554
|
+
# This method is called when a parse error is found.
|
555
|
+
#
|
556
|
+
# ERROR_TOKEN_ID is an internal ID of token which caused error.
|
557
|
+
# You can get string representation of this ID by calling
|
558
|
+
# #token_to_str.
|
559
|
+
#
|
560
|
+
# ERROR_VALUE is a value of error token.
|
561
|
+
#
|
562
|
+
# value_stack is a stack of symbol values.
|
563
|
+
# DO NOT MODIFY this object.
|
564
|
+
#
|
565
|
+
# This method raises ParseError by default.
|
566
|
+
#
|
567
|
+
# If this method returns, parsers enter "error recovering mode".
|
568
|
+
def on_error(t, val, vstack)
|
569
|
+
raise ParseError, sprintf("\nparse error on value %s (%s)",
|
570
|
+
val.inspect, token_to_str(t) || '?')
|
571
|
+
end
|
264
572
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
573
|
+
# Enter error recovering mode.
|
574
|
+
# This method does not call #on_error.
|
575
|
+
def yyerror
|
576
|
+
throw :racc_jump, 1
|
577
|
+
end
|
578
|
+
|
579
|
+
# Exit parser.
|
580
|
+
# Return value is +Symbol_Value_Stack[0]+.
|
581
|
+
def yyaccept
|
582
|
+
throw :racc_jump, 2
|
583
|
+
end
|
584
|
+
|
585
|
+
# Leave error recovering mode.
|
586
|
+
def yyerrok
|
587
|
+
@racc_error_status = 0
|
588
|
+
end
|
589
|
+
|
590
|
+
# For debugging output
|
591
|
+
def racc_read_token(t, tok, val)
|
592
|
+
@racc_debug_out.print 'read '
|
593
|
+
@racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
|
594
|
+
@racc_debug_out.puts val.inspect
|
595
|
+
@racc_debug_out.puts
|
596
|
+
end
|
597
|
+
|
598
|
+
def racc_shift(tok, tstack, vstack)
|
599
|
+
@racc_debug_out.puts "shift #{racc_token2str tok}"
|
600
|
+
racc_print_stacks tstack, vstack
|
601
|
+
@racc_debug_out.puts
|
602
|
+
end
|
603
|
+
|
604
|
+
def racc_reduce(toks, sim, tstack, vstack)
|
605
|
+
out = @racc_debug_out
|
606
|
+
out.print 'reduce '
|
607
|
+
if toks.empty?
|
608
|
+
out.print ' <none>'
|
609
|
+
else
|
610
|
+
toks.each {|t| out.print ' ', racc_token2str(t) }
|
611
|
+
end
|
612
|
+
out.puts " --> #{racc_token2str(sim)}"
|
613
|
+
racc_print_stacks tstack, vstack
|
614
|
+
@racc_debug_out.puts
|
615
|
+
end
|
616
|
+
|
617
|
+
def racc_accept
|
618
|
+
@racc_debug_out.puts 'accept'
|
619
|
+
@racc_debug_out.puts
|
620
|
+
end
|
621
|
+
|
622
|
+
def racc_e_pop(state, tstack, vstack)
|
623
|
+
@racc_debug_out.puts 'error recovering mode: pop token'
|
624
|
+
racc_print_states state
|
625
|
+
racc_print_stacks tstack, vstack
|
626
|
+
@racc_debug_out.puts
|
627
|
+
end
|
628
|
+
|
629
|
+
def racc_next_state(curstate, state)
|
630
|
+
@racc_debug_out.puts "goto #{curstate}"
|
631
|
+
racc_print_states state
|
632
|
+
@racc_debug_out.puts
|
633
|
+
end
|
634
|
+
|
635
|
+
def racc_print_stacks(t, v)
|
636
|
+
out = @racc_debug_out
|
637
|
+
out.print ' ['
|
638
|
+
t.each_index do |i|
|
639
|
+
out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
|
288
640
|
end
|
641
|
+
out.puts ' ]'
|
642
|
+
end
|
643
|
+
|
644
|
+
def racc_print_states(s)
|
645
|
+
out = @racc_debug_out
|
646
|
+
out.print ' ['
|
647
|
+
s.each {|st| out.print ' ', st }
|
648
|
+
out.puts ' ]'
|
649
|
+
end
|
289
650
|
|
290
|
-
|
651
|
+
def racc_token2str(tok)
|
652
|
+
self.class::Racc_token_to_s_table[tok] or
|
653
|
+
raise "[Racc Bug] can't convert token #{tok} to string"
|
291
654
|
end
|
655
|
+
|
656
|
+
# Convert internal ID of token symbol to the string.
|
657
|
+
def token_to_str(t)
|
658
|
+
self.class::Racc_token_to_s_table[t]
|
659
|
+
end
|
660
|
+
|
661
|
+
end
|
662
|
+
|
663
|
+
end
|
664
|
+
|
665
|
+
...end racc/parser.rb/module_eval...
|
666
|
+
end
|
667
|
+
###### racc/parser.rb end
|
668
|
+
module Lrama
|
669
|
+
class Parser < Racc::Parser
|
670
|
+
|
671
|
+
module_eval(<<'...end parser.y/module_eval...', 'parser.y', 388)
|
672
|
+
|
673
|
+
include Lrama::Report::Duration
|
674
|
+
|
675
|
+
def initialize(text, path)
|
676
|
+
@text = text
|
677
|
+
@path = path
|
678
|
+
end
|
679
|
+
|
680
|
+
def parse
|
681
|
+
report_duration(:parse) do
|
682
|
+
@lexer = Lrama::Lexer.new(@text)
|
683
|
+
@grammar = Lrama::Grammar.new
|
684
|
+
@precedence_number = 0
|
685
|
+
do_parse
|
686
|
+
@grammar.extract_references
|
687
|
+
@grammar.prepare
|
688
|
+
@grammar.compute_nullable
|
689
|
+
@grammar.compute_first_set
|
690
|
+
@grammar.validate!
|
691
|
+
@grammar
|
692
|
+
end
|
693
|
+
end
|
694
|
+
|
695
|
+
def next_token
|
696
|
+
@lexer.next_token
|
697
|
+
end
|
698
|
+
|
699
|
+
def on_error(error_token_id, error_value, value_stack)
|
700
|
+
source = @text.split("\n")[error_value.line - 1]
|
701
|
+
raise ParseError, <<~ERROR
|
702
|
+
#{@path}:#{@lexer.line}:#{@lexer.column}: parse error on value #{error_value.inspect} (#{token_to_str(error_token_id) || '?'})
|
703
|
+
#{source}
|
704
|
+
#{' ' * @lexer.column}^
|
705
|
+
ERROR
|
706
|
+
end
|
707
|
+
...end parser.y/module_eval...
|
708
|
+
##### State transition tables begin ###
|
709
|
+
|
710
|
+
racc_action_table = [
|
711
|
+
82, 132, 83, 42, 42, 41, 41, 65, 65, 42,
|
712
|
+
42, 41, 41, 131, 56, 68, 3, 8, 38, 134,
|
713
|
+
134, 42, 42, 41, 41, 65, 61, 68, 38, 6,
|
714
|
+
32, 7, 84, 77, 135, 135, 20, 22, 23, 24,
|
715
|
+
25, 26, 27, 28, 29, 30, 20, 22, 23, 24,
|
716
|
+
25, 26, 27, 28, 29, 30, 9, 39, 44, 14,
|
717
|
+
12, 13, 15, 16, 17, 18, 46, 46, 19, 20,
|
718
|
+
22, 23, 24, 25, 26, 27, 28, 29, 30, 42,
|
719
|
+
42, 41, 41, 46, 68, 68, 42, 42, 41, 41,
|
720
|
+
65, 153, 42, 42, 41, 41, 65, 153, 42, 42,
|
721
|
+
41, 41, 65, 153, 42, 42, 41, 41, 65, 153,
|
722
|
+
42, 42, 41, 41, 65, 153, 42, 42, 41, 41,
|
723
|
+
65, 153, 42, 42, 41, 41, 65, 65, 42, 42,
|
724
|
+
41, 41, 65, 65, 42, 42, 41, 41, 65, 65,
|
725
|
+
42, 42, 41, 41, 42, 42, 41, 41, 42, 42,
|
726
|
+
41, 41, 42, 42, 41, 41, 49, 50, 51, 52,
|
727
|
+
53, 74, 78, 80, 85, 85, 85, 92, 96, 97,
|
728
|
+
105, 106, 108, 109, 110, 111, 112, 113, 116, 118,
|
729
|
+
119, 122, 123, 124, 138, 139, 140, 141, 142, 143,
|
730
|
+
122, 80, 148, 149, 156, 160, 161, 80, 80 ]
|
731
|
+
|
732
|
+
racc_action_check = [
|
733
|
+
40, 120, 40, 121, 144, 121, 144, 121, 144, 25,
|
734
|
+
27, 25, 27, 120, 25, 27, 1, 3, 9, 121,
|
735
|
+
144, 26, 28, 26, 28, 26, 26, 28, 33, 2,
|
736
|
+
7, 2, 40, 33, 121, 144, 9, 9, 9, 9,
|
737
|
+
9, 9, 9, 9, 9, 9, 33, 33, 33, 33,
|
738
|
+
33, 33, 33, 33, 33, 33, 4, 12, 14, 4,
|
739
|
+
4, 4, 4, 4, 4, 4, 15, 16, 4, 4,
|
740
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 29,
|
741
|
+
30, 29, 30, 17, 29, 30, 141, 13, 141, 13,
|
742
|
+
141, 141, 142, 55, 142, 55, 142, 142, 143, 56,
|
743
|
+
143, 56, 143, 143, 150, 66, 150, 66, 150, 150,
|
744
|
+
154, 67, 154, 67, 154, 154, 155, 68, 155, 68,
|
745
|
+
155, 155, 60, 61, 60, 61, 60, 61, 97, 99,
|
746
|
+
97, 99, 97, 99, 117, 135, 117, 135, 117, 135,
|
747
|
+
71, 72, 71, 72, 73, 92, 73, 92, 94, 100,
|
748
|
+
94, 100, 102, 114, 102, 114, 18, 20, 22, 23,
|
749
|
+
24, 31, 36, 37, 45, 47, 48, 54, 58, 59,
|
750
|
+
79, 80, 86, 87, 88, 89, 90, 91, 95, 103,
|
751
|
+
104, 105, 106, 107, 125, 126, 127, 128, 129, 130,
|
752
|
+
131, 133, 136, 137, 146, 157, 159, 160, 161 ]
|
753
|
+
|
754
|
+
racc_action_pointer = [
|
755
|
+
nil, 16, 19, 17, 47, nil, nil, 23, nil, 14,
|
756
|
+
nil, nil, 51, 84, 51, 47, 48, 64, 137, nil,
|
757
|
+
138, nil, 139, 140, 141, 6, 18, 7, 19, 76,
|
758
|
+
77, 159, nil, 24, nil, nil, 141, 128, nil, nil,
|
759
|
+
-5, nil, nil, nil, nil, 145, nil, 146, 147, nil,
|
760
|
+
nil, nil, nil, nil, 159, 90, 96, nil, 162, 161,
|
761
|
+
119, 120, nil, nil, nil, nil, 102, 108, 114, nil,
|
762
|
+
nil, 137, 138, 141, nil, nil, nil, nil, nil, 138,
|
763
|
+
166, nil, nil, nil, nil, nil, 170, 171, 172, 173,
|
764
|
+
174, 175, 142, nil, 145, 171, nil, 125, nil, 126,
|
765
|
+
146, nil, 149, 168, 178, 162, 146, 181, nil, nil,
|
766
|
+
nil, nil, nil, nil, 150, nil, nil, 131, nil, nil,
|
767
|
+
-20, 0, nil, nil, nil, 164, 165, 166, 167, 168,
|
768
|
+
169, 171, nil, 156, nil, 132, 190, 173, nil, nil,
|
769
|
+
nil, 83, 89, 95, 1, nil, 192, nil, nil, nil,
|
770
|
+
101, nil, nil, nil, 107, 113, nil, 175, nil, 176,
|
771
|
+
162, 163, nil, nil ]
|
772
|
+
|
773
|
+
racc_action_default = [
|
774
|
+
-2, -104, -8, -104, -104, -3, -4, -104, 164, -104,
|
775
|
+
-9, -10, -104, -104, -104, -104, -104, -104, -104, -20,
|
776
|
+
-104, -24, -104, -104, -104, -104, -104, -104, -104, -104,
|
777
|
+
-104, -104, -7, -91, -71, -73, -104, -88, -90, -11,
|
778
|
+
-95, -69, -70, -94, -13, -14, -60, -15, -16, -17,
|
779
|
+
-21, -25, -28, -31, -34, -40, -104, -43, -46, -35,
|
780
|
+
-50, -104, -53, -55, -56, -103, -36, -63, -104, -66,
|
781
|
+
-68, -37, -38, -39, -5, -1, -72, -92, -74, -104,
|
782
|
+
-104, -12, -96, -97, -98, -57, -104, -104, -104, -104,
|
783
|
+
-104, -104, -104, -44, -41, -48, -47, -104, -54, -51,
|
784
|
+
-65, -67, -64, -104, -104, -79, -104, -104, -61, -18,
|
785
|
+
-22, -26, -29, -32, -42, -45, -49, -52, -6, -93,
|
786
|
+
-75, -76, -84, -89, -58, -104, -104, -104, -104, -104,
|
787
|
+
-104, -79, -78, -88, -81, -104, -104, -104, -62, -19,
|
788
|
+
-23, -104, -104, -104, -77, -80, -104, -87, -85, -59,
|
789
|
+
-27, -99, -101, -102, -30, -33, -82, -104, -100, -104,
|
790
|
+
-88, -88, -86, -83 ]
|
791
|
+
|
792
|
+
racc_goto_table = [
|
793
|
+
79, 43, 62, 60, 55, 121, 93, 101, 34, 66,
|
794
|
+
71, 72, 73, 58, 1, 70, 70, 70, 70, 100,
|
795
|
+
2, 102, 4, 158, 100, 100, 100, 158, 158, 33,
|
796
|
+
75, 144, 76, 5, 31, 94, 98, 62, 99, 103,
|
797
|
+
101, 10, 101, 58, 58, 93, 45, 47, 48, 150,
|
798
|
+
154, 155, 11, 40, 70, 70, 70, 81, 87, 70,
|
799
|
+
70, 70, 126, 88, 127, 93, 89, 128, 90, 129,
|
800
|
+
91, 114, 130, 62, 117, 98, 54, 59, 95, 115,
|
801
|
+
58, 107, 58, 137, 86, 125, 120, 146, 70, 159,
|
802
|
+
70, 136, 157, 98, 104, nil, 145, 133, nil, nil,
|
803
|
+
nil, nil, 58, nil, nil, nil, nil, nil, nil, nil,
|
804
|
+
nil, 147, nil, nil, nil, nil, nil, nil, nil, nil,
|
805
|
+
133, nil, nil, 162, 163 ]
|
806
|
+
|
807
|
+
racc_goto_check = [
|
808
|
+
46, 31, 35, 34, 29, 48, 30, 42, 43, 28,
|
809
|
+
28, 28, 28, 31, 1, 31, 31, 31, 31, 41,
|
810
|
+
2, 41, 3, 54, 41, 41, 41, 54, 54, 4,
|
811
|
+
5, 48, 43, 6, 7, 29, 35, 35, 34, 8,
|
812
|
+
42, 9, 42, 31, 31, 30, 13, 13, 13, 17,
|
813
|
+
17, 17, 10, 11, 31, 31, 31, 12, 14, 31,
|
814
|
+
31, 31, 15, 18, 19, 30, 20, 21, 22, 23,
|
815
|
+
24, 29, 25, 35, 34, 35, 26, 27, 32, 33,
|
816
|
+
31, 37, 31, 38, 39, 40, 47, 49, 31, 50,
|
817
|
+
31, 51, 52, 35, 53, nil, 46, 35, nil, nil,
|
818
|
+
nil, nil, 31, nil, nil, nil, nil, nil, nil, nil,
|
819
|
+
nil, 35, nil, nil, nil, nil, nil, nil, nil, nil,
|
820
|
+
35, nil, nil, 46, 46 ]
|
821
|
+
|
822
|
+
racc_goto_pointer = [
|
823
|
+
nil, 14, 20, 20, 20, -3, 31, 28, -35, 37,
|
824
|
+
48, 40, 17, 31, 9, -47, nil, -92, 13, -46,
|
825
|
+
15, -44, 16, -43, 17, -41, 51, 51, -18, -21,
|
826
|
+
-49, -12, 20, -16, -23, -24, nil, -4, -41, 38,
|
827
|
+
-23, -47, -60, -1, nil, nil, -37, -19, -100, -47,
|
828
|
+
-67, -31, -56, 17, -127 ]
|
829
|
+
|
830
|
+
racc_goto_default = [
|
831
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
832
|
+
36, nil, nil, nil, nil, nil, 21, nil, nil, nil,
|
833
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
834
|
+
57, 63, nil, nil, nil, 152, 64, nil, nil, nil,
|
835
|
+
nil, 67, 69, nil, 35, 37, nil, nil, nil, nil,
|
836
|
+
nil, nil, nil, nil, 151 ]
|
837
|
+
|
838
|
+
racc_reduce_table = [
|
839
|
+
0, 0, :racc_error,
|
840
|
+
5, 39, :_reduce_none,
|
841
|
+
0, 40, :_reduce_none,
|
842
|
+
2, 40, :_reduce_none,
|
843
|
+
0, 45, :_reduce_4,
|
844
|
+
0, 46, :_reduce_5,
|
845
|
+
5, 44, :_reduce_6,
|
846
|
+
2, 44, :_reduce_none,
|
847
|
+
0, 41, :_reduce_8,
|
848
|
+
2, 41, :_reduce_none,
|
849
|
+
1, 47, :_reduce_none,
|
850
|
+
2, 47, :_reduce_11,
|
851
|
+
3, 47, :_reduce_none,
|
852
|
+
2, 47, :_reduce_none,
|
853
|
+
2, 47, :_reduce_none,
|
854
|
+
2, 47, :_reduce_15,
|
855
|
+
2, 47, :_reduce_16,
|
856
|
+
0, 52, :_reduce_17,
|
857
|
+
0, 53, :_reduce_18,
|
858
|
+
6, 47, :_reduce_19,
|
859
|
+
1, 47, :_reduce_none,
|
860
|
+
0, 56, :_reduce_21,
|
861
|
+
0, 57, :_reduce_22,
|
862
|
+
6, 48, :_reduce_23,
|
863
|
+
1, 48, :_reduce_none,
|
864
|
+
0, 58, :_reduce_25,
|
865
|
+
0, 59, :_reduce_26,
|
866
|
+
7, 48, :_reduce_none,
|
867
|
+
0, 60, :_reduce_28,
|
868
|
+
0, 61, :_reduce_29,
|
869
|
+
7, 48, :_reduce_30,
|
870
|
+
0, 62, :_reduce_31,
|
871
|
+
0, 63, :_reduce_32,
|
872
|
+
7, 48, :_reduce_33,
|
873
|
+
2, 54, :_reduce_none,
|
874
|
+
2, 54, :_reduce_35,
|
875
|
+
2, 54, :_reduce_36,
|
876
|
+
2, 54, :_reduce_37,
|
877
|
+
2, 54, :_reduce_38,
|
878
|
+
2, 54, :_reduce_39,
|
879
|
+
1, 64, :_reduce_40,
|
880
|
+
2, 64, :_reduce_41,
|
881
|
+
3, 64, :_reduce_42,
|
882
|
+
1, 67, :_reduce_43,
|
883
|
+
2, 67, :_reduce_44,
|
884
|
+
3, 68, :_reduce_45,
|
885
|
+
0, 70, :_reduce_none,
|
886
|
+
1, 70, :_reduce_none,
|
887
|
+
0, 71, :_reduce_none,
|
888
|
+
1, 71, :_reduce_none,
|
889
|
+
1, 65, :_reduce_50,
|
890
|
+
2, 65, :_reduce_51,
|
891
|
+
3, 65, :_reduce_52,
|
892
|
+
1, 72, :_reduce_53,
|
893
|
+
2, 72, :_reduce_54,
|
894
|
+
1, 73, :_reduce_none,
|
895
|
+
1, 73, :_reduce_none,
|
896
|
+
0, 75, :_reduce_57,
|
897
|
+
0, 76, :_reduce_58,
|
898
|
+
6, 51, :_reduce_59,
|
899
|
+
0, 77, :_reduce_60,
|
900
|
+
0, 78, :_reduce_61,
|
901
|
+
5, 51, :_reduce_62,
|
902
|
+
1, 66, :_reduce_63,
|
903
|
+
2, 66, :_reduce_64,
|
904
|
+
2, 66, :_reduce_65,
|
905
|
+
1, 79, :_reduce_66,
|
906
|
+
2, 79, :_reduce_67,
|
907
|
+
1, 80, :_reduce_none,
|
908
|
+
1, 69, :_reduce_69,
|
909
|
+
1, 69, :_reduce_70,
|
910
|
+
1, 42, :_reduce_none,
|
911
|
+
2, 42, :_reduce_none,
|
912
|
+
1, 81, :_reduce_none,
|
913
|
+
2, 81, :_reduce_none,
|
914
|
+
4, 82, :_reduce_75,
|
915
|
+
1, 85, :_reduce_76,
|
916
|
+
3, 85, :_reduce_77,
|
917
|
+
2, 85, :_reduce_none,
|
918
|
+
0, 86, :_reduce_79,
|
919
|
+
3, 86, :_reduce_80,
|
920
|
+
0, 87, :_reduce_81,
|
921
|
+
0, 88, :_reduce_82,
|
922
|
+
7, 86, :_reduce_83,
|
923
|
+
0, 89, :_reduce_84,
|
924
|
+
0, 90, :_reduce_85,
|
925
|
+
6, 86, :_reduce_86,
|
926
|
+
3, 86, :_reduce_87,
|
927
|
+
0, 84, :_reduce_none,
|
928
|
+
3, 84, :_reduce_89,
|
929
|
+
1, 83, :_reduce_none,
|
930
|
+
0, 43, :_reduce_none,
|
931
|
+
0, 91, :_reduce_92,
|
932
|
+
3, 43, :_reduce_93,
|
933
|
+
1, 49, :_reduce_none,
|
934
|
+
0, 50, :_reduce_none,
|
935
|
+
1, 50, :_reduce_none,
|
936
|
+
1, 50, :_reduce_none,
|
937
|
+
1, 50, :_reduce_none,
|
938
|
+
1, 55, :_reduce_99,
|
939
|
+
2, 55, :_reduce_100,
|
940
|
+
1, 92, :_reduce_none,
|
941
|
+
1, 92, :_reduce_none,
|
942
|
+
1, 74, :_reduce_103 ]
|
943
|
+
|
944
|
+
racc_reduce_n = 104
|
945
|
+
|
946
|
+
racc_shift_n = 164
|
947
|
+
|
948
|
+
racc_token_table = {
|
949
|
+
false => 0,
|
950
|
+
:error => 1,
|
951
|
+
:C_DECLARATION => 2,
|
952
|
+
:CHARACTER => 3,
|
953
|
+
:IDENT_COLON => 4,
|
954
|
+
:IDENTIFIER => 5,
|
955
|
+
:INTEGER => 6,
|
956
|
+
:STRING => 7,
|
957
|
+
:TAG => 8,
|
958
|
+
"%%" => 9,
|
959
|
+
"%{" => 10,
|
960
|
+
"%}" => 11,
|
961
|
+
"%require" => 12,
|
962
|
+
"%expect" => 13,
|
963
|
+
"%define" => 14,
|
964
|
+
"%param" => 15,
|
965
|
+
"%lex-param" => 16,
|
966
|
+
"%parse-param" => 17,
|
967
|
+
"%initial-action" => 18,
|
968
|
+
"{" => 19,
|
969
|
+
"}" => 20,
|
970
|
+
";" => 21,
|
971
|
+
"%union" => 22,
|
972
|
+
"%destructor" => 23,
|
973
|
+
"%printer" => 24,
|
974
|
+
"%error-token" => 25,
|
975
|
+
"%token" => 26,
|
976
|
+
"%type" => 27,
|
977
|
+
"%left" => 28,
|
978
|
+
"%right" => 29,
|
979
|
+
"%precedence" => 30,
|
980
|
+
"%nonassoc" => 31,
|
981
|
+
":" => 32,
|
982
|
+
"|" => 33,
|
983
|
+
"%prec" => 34,
|
984
|
+
"[" => 35,
|
985
|
+
"]" => 36,
|
986
|
+
"{...}" => 37 }
|
987
|
+
|
988
|
+
racc_nt_base = 38
|
989
|
+
|
990
|
+
racc_use_result_var = true
|
991
|
+
|
992
|
+
Racc_arg = [
|
993
|
+
racc_action_table,
|
994
|
+
racc_action_check,
|
995
|
+
racc_action_default,
|
996
|
+
racc_action_pointer,
|
997
|
+
racc_goto_table,
|
998
|
+
racc_goto_check,
|
999
|
+
racc_goto_default,
|
1000
|
+
racc_goto_pointer,
|
1001
|
+
racc_nt_base,
|
1002
|
+
racc_reduce_table,
|
1003
|
+
racc_token_table,
|
1004
|
+
racc_shift_n,
|
1005
|
+
racc_reduce_n,
|
1006
|
+
racc_use_result_var ]
|
1007
|
+
Ractor.make_shareable(Racc_arg) if defined?(Ractor)
|
1008
|
+
|
1009
|
+
Racc_token_to_s_table = [
|
1010
|
+
"$end",
|
1011
|
+
"error",
|
1012
|
+
"C_DECLARATION",
|
1013
|
+
"CHARACTER",
|
1014
|
+
"IDENT_COLON",
|
1015
|
+
"IDENTIFIER",
|
1016
|
+
"INTEGER",
|
1017
|
+
"STRING",
|
1018
|
+
"TAG",
|
1019
|
+
"\"%%\"",
|
1020
|
+
"\"%{\"",
|
1021
|
+
"\"%}\"",
|
1022
|
+
"\"%require\"",
|
1023
|
+
"\"%expect\"",
|
1024
|
+
"\"%define\"",
|
1025
|
+
"\"%param\"",
|
1026
|
+
"\"%lex-param\"",
|
1027
|
+
"\"%parse-param\"",
|
1028
|
+
"\"%initial-action\"",
|
1029
|
+
"\"{\"",
|
1030
|
+
"\"}\"",
|
1031
|
+
"\";\"",
|
1032
|
+
"\"%union\"",
|
1033
|
+
"\"%destructor\"",
|
1034
|
+
"\"%printer\"",
|
1035
|
+
"\"%error-token\"",
|
1036
|
+
"\"%token\"",
|
1037
|
+
"\"%type\"",
|
1038
|
+
"\"%left\"",
|
1039
|
+
"\"%right\"",
|
1040
|
+
"\"%precedence\"",
|
1041
|
+
"\"%nonassoc\"",
|
1042
|
+
"\":\"",
|
1043
|
+
"\"|\"",
|
1044
|
+
"\"%prec\"",
|
1045
|
+
"\"[\"",
|
1046
|
+
"\"]\"",
|
1047
|
+
"\"{...}\"",
|
1048
|
+
"$start",
|
1049
|
+
"input",
|
1050
|
+
"prologue_declarations",
|
1051
|
+
"bison_declarations",
|
1052
|
+
"grammar",
|
1053
|
+
"epilogue_opt",
|
1054
|
+
"prologue_declaration",
|
1055
|
+
"@1",
|
1056
|
+
"@2",
|
1057
|
+
"bison_declaration",
|
1058
|
+
"grammar_declaration",
|
1059
|
+
"variable",
|
1060
|
+
"value",
|
1061
|
+
"params",
|
1062
|
+
"@3",
|
1063
|
+
"@4",
|
1064
|
+
"symbol_declaration",
|
1065
|
+
"generic_symlist",
|
1066
|
+
"@5",
|
1067
|
+
"@6",
|
1068
|
+
"@7",
|
1069
|
+
"@8",
|
1070
|
+
"@9",
|
1071
|
+
"@10",
|
1072
|
+
"@11",
|
1073
|
+
"@12",
|
1074
|
+
"token_declarations",
|
1075
|
+
"symbol_declarations",
|
1076
|
+
"token_declarations_for_precedence",
|
1077
|
+
"token_declaration_list",
|
1078
|
+
"token_declaration",
|
1079
|
+
"id",
|
1080
|
+
"int_opt",
|
1081
|
+
"alias",
|
1082
|
+
"symbol_declaration_list",
|
1083
|
+
"symbol",
|
1084
|
+
"string_as_id",
|
1085
|
+
"@13",
|
1086
|
+
"@14",
|
1087
|
+
"@15",
|
1088
|
+
"@16",
|
1089
|
+
"token_declaration_list_for_precedence",
|
1090
|
+
"token_declaration_for_precedence",
|
1091
|
+
"rules_or_grammar_declaration",
|
1092
|
+
"rules",
|
1093
|
+
"id_colon",
|
1094
|
+
"named_ref_opt",
|
1095
|
+
"rhs_list",
|
1096
|
+
"rhs",
|
1097
|
+
"@17",
|
1098
|
+
"@18",
|
1099
|
+
"@19",
|
1100
|
+
"@20",
|
1101
|
+
"@21",
|
1102
|
+
"generic_symlist_item" ]
|
1103
|
+
Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)
|
1104
|
+
|
1105
|
+
Racc_debug_parser = false
|
1106
|
+
|
1107
|
+
##### State transition tables end #####
|
1108
|
+
|
1109
|
+
# reduce 0 omitted
|
1110
|
+
|
1111
|
+
# reduce 1 omitted
|
1112
|
+
|
1113
|
+
# reduce 2 omitted
|
1114
|
+
|
1115
|
+
# reduce 3 omitted
|
1116
|
+
|
1117
|
+
module_eval(<<'.,.,', 'parser.y', 10)
|
1118
|
+
def _reduce_4(val, _values, result)
|
1119
|
+
@lexer.status = :c_declaration
|
1120
|
+
@lexer.end_symbol = '%}'
|
1121
|
+
@grammar.prologue_first_lineno = @lexer.line
|
1122
|
+
|
1123
|
+
result
|
1124
|
+
end
|
1125
|
+
.,.,
|
1126
|
+
|
1127
|
+
module_eval(<<'.,.,', 'parser.y', 16)
|
1128
|
+
def _reduce_5(val, _values, result)
|
1129
|
+
@lexer.status = :initial
|
1130
|
+
@lexer.end_symbol = nil
|
1131
|
+
|
1132
|
+
result
|
1133
|
+
end
|
1134
|
+
.,.,
|
1135
|
+
|
1136
|
+
module_eval(<<'.,.,', 'parser.y', 21)
|
1137
|
+
def _reduce_6(val, _values, result)
|
1138
|
+
@grammar.prologue = val[2].s_value
|
1139
|
+
|
1140
|
+
result
|
1141
|
+
end
|
1142
|
+
.,.,
|
1143
|
+
|
1144
|
+
# reduce 7 omitted
|
1145
|
+
|
1146
|
+
module_eval(<<'.,.,', 'parser.y', 25)
|
1147
|
+
def _reduce_8(val, _values, result)
|
1148
|
+
result = ""
|
1149
|
+
result
|
1150
|
+
end
|
1151
|
+
.,.,
|
1152
|
+
|
1153
|
+
# reduce 9 omitted
|
1154
|
+
|
1155
|
+
# reduce 10 omitted
|
1156
|
+
|
1157
|
+
module_eval(<<'.,.,', 'parser.y', 29)
|
1158
|
+
def _reduce_11(val, _values, result)
|
1159
|
+
@grammar.expect = val[1]
|
1160
|
+
result
|
1161
|
+
end
|
1162
|
+
.,.,
|
1163
|
+
|
1164
|
+
# reduce 12 omitted
|
1165
|
+
|
1166
|
+
# reduce 13 omitted
|
1167
|
+
|
1168
|
+
# reduce 14 omitted
|
1169
|
+
|
1170
|
+
module_eval(<<'.,.,', 'parser.y', 35)
|
1171
|
+
def _reduce_15(val, _values, result)
|
1172
|
+
val[1].each {|token|
|
1173
|
+
token.references = []
|
1174
|
+
@grammar.lex_param = @grammar.build_code(:lex_param, token).token_code.s_value
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
result
|
1178
|
+
end
|
1179
|
+
.,.,
|
1180
|
+
|
1181
|
+
module_eval(<<'.,.,', 'parser.y', 42)
|
1182
|
+
def _reduce_16(val, _values, result)
|
1183
|
+
val[1].each {|token|
|
1184
|
+
token.references = []
|
1185
|
+
@grammar.parse_param = @grammar.build_code(:parse_param, token).token_code.s_value
|
1186
|
+
}
|
1187
|
+
|
1188
|
+
result
|
1189
|
+
end
|
1190
|
+
.,.,
|
1191
|
+
|
1192
|
+
module_eval(<<'.,.,', 'parser.y', 49)
|
1193
|
+
def _reduce_17(val, _values, result)
|
1194
|
+
@lexer.status = :c_declaration
|
1195
|
+
@lexer.end_symbol = '}'
|
1196
|
+
|
1197
|
+
result
|
1198
|
+
end
|
1199
|
+
.,.,
|
1200
|
+
|
1201
|
+
module_eval(<<'.,.,', 'parser.y', 54)
|
1202
|
+
def _reduce_18(val, _values, result)
|
1203
|
+
@lexer.status = :initial
|
1204
|
+
@lexer.end_symbol = nil
|
1205
|
+
|
1206
|
+
result
|
1207
|
+
end
|
1208
|
+
.,.,
|
1209
|
+
|
1210
|
+
module_eval(<<'.,.,', 'parser.y', 59)
|
1211
|
+
def _reduce_19(val, _values, result)
|
1212
|
+
@grammar.initial_action = @grammar.build_code(:initial_action, val[3])
|
1213
|
+
|
1214
|
+
result
|
1215
|
+
end
|
1216
|
+
.,.,
|
1217
|
+
|
1218
|
+
# reduce 20 omitted
|
1219
|
+
|
1220
|
+
module_eval(<<'.,.,', 'parser.y', 65)
|
1221
|
+
def _reduce_21(val, _values, result)
|
1222
|
+
@lexer.status = :c_declaration
|
1223
|
+
@lexer.end_symbol = '}'
|
1224
|
+
|
1225
|
+
result
|
1226
|
+
end
|
1227
|
+
.,.,
|
1228
|
+
|
1229
|
+
module_eval(<<'.,.,', 'parser.y', 70)
|
1230
|
+
def _reduce_22(val, _values, result)
|
1231
|
+
@lexer.status = :initial
|
1232
|
+
@lexer.end_symbol = nil
|
1233
|
+
|
1234
|
+
result
|
292
1235
|
end
|
1236
|
+
.,.,
|
1237
|
+
|
1238
|
+
module_eval(<<'.,.,', 'parser.y', 75)
|
1239
|
+
def _reduce_23(val, _values, result)
|
1240
|
+
@grammar.set_union(@grammar.build_code(:union, val[3]), val[3].line)
|
1241
|
+
|
1242
|
+
result
|
1243
|
+
end
|
1244
|
+
.,.,
|
1245
|
+
|
1246
|
+
# reduce 24 omitted
|
1247
|
+
|
1248
|
+
module_eval(<<'.,.,', 'parser.y', 80)
|
1249
|
+
def _reduce_25(val, _values, result)
|
1250
|
+
@lexer.status = :c_declaration
|
1251
|
+
@lexer.end_symbol = '}'
|
1252
|
+
|
1253
|
+
result
|
1254
|
+
end
|
1255
|
+
.,.,
|
1256
|
+
|
1257
|
+
module_eval(<<'.,.,', 'parser.y', 85)
|
1258
|
+
def _reduce_26(val, _values, result)
|
1259
|
+
@lexer.status = :initial
|
1260
|
+
@lexer.end_symbol = nil
|
1261
|
+
|
1262
|
+
result
|
1263
|
+
end
|
1264
|
+
.,.,
|
1265
|
+
|
1266
|
+
# reduce 27 omitted
|
1267
|
+
|
1268
|
+
module_eval(<<'.,.,', 'parser.y', 91)
|
1269
|
+
def _reduce_28(val, _values, result)
|
1270
|
+
@lexer.status = :c_declaration
|
1271
|
+
@lexer.end_symbol = '}'
|
1272
|
+
|
1273
|
+
result
|
1274
|
+
end
|
1275
|
+
.,.,
|
1276
|
+
|
1277
|
+
module_eval(<<'.,.,', 'parser.y', 96)
|
1278
|
+
def _reduce_29(val, _values, result)
|
1279
|
+
@lexer.status = :initial
|
1280
|
+
@lexer.end_symbol = nil
|
1281
|
+
|
1282
|
+
result
|
1283
|
+
end
|
1284
|
+
.,.,
|
1285
|
+
|
1286
|
+
module_eval(<<'.,.,', 'parser.y', 101)
|
1287
|
+
def _reduce_30(val, _values, result)
|
1288
|
+
@grammar.add_printer(ident_or_tags: val[6], code: @grammar.build_code(:printer, val[3]), lineno: val[3].line)
|
1289
|
+
|
1290
|
+
result
|
1291
|
+
end
|
1292
|
+
.,.,
|
1293
|
+
|
1294
|
+
module_eval(<<'.,.,', 'parser.y', 105)
|
1295
|
+
def _reduce_31(val, _values, result)
|
1296
|
+
@lexer.status = :c_declaration
|
1297
|
+
@lexer.end_symbol = '}'
|
1298
|
+
|
1299
|
+
result
|
1300
|
+
end
|
1301
|
+
.,.,
|
1302
|
+
|
1303
|
+
module_eval(<<'.,.,', 'parser.y', 110)
|
1304
|
+
def _reduce_32(val, _values, result)
|
1305
|
+
@lexer.status = :initial
|
1306
|
+
@lexer.end_symbol = nil
|
1307
|
+
|
1308
|
+
result
|
1309
|
+
end
|
1310
|
+
.,.,
|
1311
|
+
|
1312
|
+
module_eval(<<'.,.,', 'parser.y', 115)
|
1313
|
+
def _reduce_33(val, _values, result)
|
1314
|
+
@grammar.add_error_token(ident_or_tags: val[6], code: @grammar.build_code(:error_token, val[3]), lineno: val[3].line)
|
1315
|
+
|
1316
|
+
result
|
1317
|
+
end
|
1318
|
+
.,.,
|
1319
|
+
|
1320
|
+
# reduce 34 omitted
|
1321
|
+
|
1322
|
+
module_eval(<<'.,.,', 'parser.y', 121)
|
1323
|
+
def _reduce_35(val, _values, result)
|
1324
|
+
val[1].each {|hash|
|
1325
|
+
hash[:tokens].each {|id|
|
1326
|
+
@grammar.add_type(id: id, tag: hash[:tag])
|
1327
|
+
}
|
1328
|
+
}
|
1329
|
+
|
1330
|
+
result
|
1331
|
+
end
|
1332
|
+
.,.,
|
1333
|
+
|
1334
|
+
module_eval(<<'.,.,', 'parser.y', 129)
|
1335
|
+
def _reduce_36(val, _values, result)
|
1336
|
+
val[1].each {|hash|
|
1337
|
+
hash[:tokens].each {|id|
|
1338
|
+
sym = @grammar.add_term(id: id)
|
1339
|
+
@grammar.add_left(sym, @precedence_number)
|
1340
|
+
}
|
1341
|
+
}
|
1342
|
+
@precedence_number += 1
|
1343
|
+
|
1344
|
+
result
|
1345
|
+
end
|
1346
|
+
.,.,
|
1347
|
+
|
1348
|
+
module_eval(<<'.,.,', 'parser.y', 139)
|
1349
|
+
def _reduce_37(val, _values, result)
|
1350
|
+
val[1].each {|hash|
|
1351
|
+
hash[:tokens].each {|id|
|
1352
|
+
sym = @grammar.add_term(id: id)
|
1353
|
+
@grammar.add_right(sym, @precedence_number)
|
1354
|
+
}
|
1355
|
+
}
|
1356
|
+
@precedence_number += 1
|
1357
|
+
|
1358
|
+
result
|
1359
|
+
end
|
1360
|
+
.,.,
|
1361
|
+
|
1362
|
+
module_eval(<<'.,.,', 'parser.y', 149)
|
1363
|
+
def _reduce_38(val, _values, result)
|
1364
|
+
val[1].each {|hash|
|
1365
|
+
hash[:tokens].each {|id|
|
1366
|
+
sym = @grammar.add_term(id: id)
|
1367
|
+
@grammar.add_precedence(sym, @precedence_number)
|
1368
|
+
}
|
1369
|
+
}
|
1370
|
+
@precedence_number += 1
|
1371
|
+
|
1372
|
+
result
|
1373
|
+
end
|
1374
|
+
.,.,
|
1375
|
+
|
1376
|
+
module_eval(<<'.,.,', 'parser.y', 159)
|
1377
|
+
def _reduce_39(val, _values, result)
|
1378
|
+
val[1].each {|hash|
|
1379
|
+
hash[:tokens].each {|id|
|
1380
|
+
sym = @grammar.add_term(id: id)
|
1381
|
+
@grammar.add_nonassoc(sym, @precedence_number)
|
1382
|
+
}
|
1383
|
+
}
|
1384
|
+
@precedence_number += 1
|
1385
|
+
|
1386
|
+
result
|
1387
|
+
end
|
1388
|
+
.,.,
|
1389
|
+
|
1390
|
+
module_eval(<<'.,.,', 'parser.y', 170)
|
1391
|
+
def _reduce_40(val, _values, result)
|
1392
|
+
val[0].each {|token_declaration|
|
1393
|
+
@grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: nil, replace: true)
|
1394
|
+
}
|
1395
|
+
|
1396
|
+
result
|
1397
|
+
end
|
1398
|
+
.,.,
|
1399
|
+
|
1400
|
+
module_eval(<<'.,.,', 'parser.y', 176)
|
1401
|
+
def _reduce_41(val, _values, result)
|
1402
|
+
val[1].each {|token_declaration|
|
1403
|
+
@grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[0], replace: true)
|
1404
|
+
}
|
1405
|
+
|
1406
|
+
result
|
1407
|
+
end
|
1408
|
+
.,.,
|
1409
|
+
|
1410
|
+
module_eval(<<'.,.,', 'parser.y', 182)
|
1411
|
+
def _reduce_42(val, _values, result)
|
1412
|
+
val[2].each {|token_declaration|
|
1413
|
+
@grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[1], replace: true)
|
1414
|
+
}
|
1415
|
+
|
1416
|
+
result
|
1417
|
+
end
|
1418
|
+
.,.,
|
1419
|
+
|
1420
|
+
module_eval(<<'.,.,', 'parser.y', 187)
|
1421
|
+
def _reduce_43(val, _values, result)
|
1422
|
+
result = [val[0]]
|
1423
|
+
result
|
1424
|
+
end
|
1425
|
+
.,.,
|
1426
|
+
|
1427
|
+
module_eval(<<'.,.,', 'parser.y', 188)
|
1428
|
+
def _reduce_44(val, _values, result)
|
1429
|
+
result = val[0].append(val[1])
|
1430
|
+
result
|
1431
|
+
end
|
1432
|
+
.,.,
|
1433
|
+
|
1434
|
+
module_eval(<<'.,.,', 'parser.y', 190)
|
1435
|
+
def _reduce_45(val, _values, result)
|
1436
|
+
result = val
|
1437
|
+
result
|
1438
|
+
end
|
1439
|
+
.,.,
|
1440
|
+
|
1441
|
+
# reduce 46 omitted
|
1442
|
+
|
1443
|
+
# reduce 47 omitted
|
1444
|
+
|
1445
|
+
# reduce 48 omitted
|
1446
|
+
|
1447
|
+
# reduce 49 omitted
|
1448
|
+
|
1449
|
+
module_eval(<<'.,.,', 'parser.y', 200)
|
1450
|
+
def _reduce_50(val, _values, result)
|
1451
|
+
result = [{tag: nil, tokens: val[0]}]
|
1452
|
+
|
1453
|
+
result
|
1454
|
+
end
|
1455
|
+
.,.,
|
1456
|
+
|
1457
|
+
module_eval(<<'.,.,', 'parser.y', 204)
|
1458
|
+
def _reduce_51(val, _values, result)
|
1459
|
+
result = [{tag: val[0], tokens: val[1]}]
|
1460
|
+
|
1461
|
+
result
|
1462
|
+
end
|
1463
|
+
.,.,
|
1464
|
+
|
1465
|
+
module_eval(<<'.,.,', 'parser.y', 208)
|
1466
|
+
def _reduce_52(val, _values, result)
|
1467
|
+
result = val[0].append({tag: val[1], tokens: val[2]})
|
1468
|
+
|
1469
|
+
result
|
1470
|
+
end
|
1471
|
+
.,.,
|
1472
|
+
|
1473
|
+
module_eval(<<'.,.,', 'parser.y', 211)
|
1474
|
+
def _reduce_53(val, _values, result)
|
1475
|
+
result = [val[0]]
|
1476
|
+
result
|
1477
|
+
end
|
1478
|
+
.,.,
|
1479
|
+
|
1480
|
+
module_eval(<<'.,.,', 'parser.y', 212)
|
1481
|
+
def _reduce_54(val, _values, result)
|
1482
|
+
result = val[0].append(val[1])
|
1483
|
+
result
|
1484
|
+
end
|
1485
|
+
.,.,
|
1486
|
+
|
1487
|
+
# reduce 55 omitted
|
1488
|
+
|
1489
|
+
# reduce 56 omitted
|
1490
|
+
|
1491
|
+
module_eval(<<'.,.,', 'parser.y', 219)
|
1492
|
+
def _reduce_57(val, _values, result)
|
1493
|
+
@lexer.status = :c_declaration
|
1494
|
+
@lexer.end_symbol = '}'
|
1495
|
+
|
1496
|
+
result
|
1497
|
+
end
|
1498
|
+
.,.,
|
1499
|
+
|
1500
|
+
module_eval(<<'.,.,', 'parser.y', 224)
|
1501
|
+
def _reduce_58(val, _values, result)
|
1502
|
+
@lexer.status = :initial
|
1503
|
+
@lexer.end_symbol = nil
|
1504
|
+
|
1505
|
+
result
|
1506
|
+
end
|
1507
|
+
.,.,
|
1508
|
+
|
1509
|
+
module_eval(<<'.,.,', 'parser.y', 229)
|
1510
|
+
def _reduce_59(val, _values, result)
|
1511
|
+
result = val[0].append(val[3])
|
1512
|
+
|
1513
|
+
result
|
1514
|
+
end
|
1515
|
+
.,.,
|
1516
|
+
|
1517
|
+
module_eval(<<'.,.,', 'parser.y', 233)
|
1518
|
+
def _reduce_60(val, _values, result)
|
1519
|
+
@lexer.status = :c_declaration
|
1520
|
+
@lexer.end_symbol = '}'
|
1521
|
+
|
1522
|
+
result
|
1523
|
+
end
|
1524
|
+
.,.,
|
1525
|
+
|
1526
|
+
module_eval(<<'.,.,', 'parser.y', 238)
|
1527
|
+
def _reduce_61(val, _values, result)
|
1528
|
+
@lexer.status = :initial
|
1529
|
+
@lexer.end_symbol = nil
|
1530
|
+
|
1531
|
+
result
|
1532
|
+
end
|
1533
|
+
.,.,
|
1534
|
+
|
1535
|
+
module_eval(<<'.,.,', 'parser.y', 243)
|
1536
|
+
def _reduce_62(val, _values, result)
|
1537
|
+
result = [val[2]]
|
1538
|
+
|
1539
|
+
result
|
1540
|
+
end
|
1541
|
+
.,.,
|
1542
|
+
|
1543
|
+
module_eval(<<'.,.,', 'parser.y', 248)
|
1544
|
+
def _reduce_63(val, _values, result)
|
1545
|
+
result = [{tag: nil, tokens: val[0]}]
|
1546
|
+
|
1547
|
+
result
|
1548
|
+
end
|
1549
|
+
.,.,
|
1550
|
+
|
1551
|
+
module_eval(<<'.,.,', 'parser.y', 252)
|
1552
|
+
def _reduce_64(val, _values, result)
|
1553
|
+
result = [{tag: val[0], tokens: val[1]}]
|
1554
|
+
|
1555
|
+
result
|
1556
|
+
end
|
1557
|
+
.,.,
|
1558
|
+
|
1559
|
+
module_eval(<<'.,.,', 'parser.y', 256)
|
1560
|
+
def _reduce_65(val, _values, result)
|
1561
|
+
result = val[0].append({tag: nil, tokens: val[1]})
|
1562
|
+
|
1563
|
+
result
|
1564
|
+
end
|
1565
|
+
.,.,
|
1566
|
+
|
1567
|
+
module_eval(<<'.,.,', 'parser.y', 259)
|
1568
|
+
def _reduce_66(val, _values, result)
|
1569
|
+
result = [val[0]]
|
1570
|
+
result
|
1571
|
+
end
|
1572
|
+
.,.,
|
1573
|
+
|
1574
|
+
module_eval(<<'.,.,', 'parser.y', 260)
|
1575
|
+
def _reduce_67(val, _values, result)
|
1576
|
+
result = val[0].append(val[1])
|
1577
|
+
result
|
1578
|
+
end
|
1579
|
+
.,.,
|
1580
|
+
|
1581
|
+
# reduce 68 omitted
|
1582
|
+
|
1583
|
+
module_eval(<<'.,.,', 'parser.y', 264)
|
1584
|
+
def _reduce_69(val, _values, result)
|
1585
|
+
raise "Ident after %prec" if @prec_seen
|
1586
|
+
result
|
1587
|
+
end
|
1588
|
+
.,.,
|
1589
|
+
|
1590
|
+
module_eval(<<'.,.,', 'parser.y', 265)
|
1591
|
+
def _reduce_70(val, _values, result)
|
1592
|
+
raise "Char after %prec" if @prec_seen
|
1593
|
+
result
|
1594
|
+
end
|
1595
|
+
.,.,
|
1596
|
+
|
1597
|
+
# reduce 71 omitted
|
1598
|
+
|
1599
|
+
# reduce 72 omitted
|
1600
|
+
|
1601
|
+
# reduce 73 omitted
|
1602
|
+
|
1603
|
+
# reduce 74 omitted
|
1604
|
+
|
1605
|
+
module_eval(<<'.,.,', 'parser.y', 275)
|
1606
|
+
def _reduce_75(val, _values, result)
|
1607
|
+
lhs = val[0]
|
1608
|
+
lhs.alias = val[1]
|
1609
|
+
val[3].each {|hash|
|
1610
|
+
@grammar.add_rule(lhs: lhs, rhs: hash[:rhs], lineno: hash[:lineno])
|
1611
|
+
}
|
1612
|
+
|
1613
|
+
result
|
1614
|
+
end
|
1615
|
+
.,.,
|
1616
|
+
|
1617
|
+
module_eval(<<'.,.,', 'parser.y', 284)
|
1618
|
+
def _reduce_76(val, _values, result)
|
1619
|
+
result = [{rhs: val[0], lineno: val[0].first&.line || @lexer.line - 1}]
|
1620
|
+
|
1621
|
+
result
|
1622
|
+
end
|
1623
|
+
.,.,
|
1624
|
+
|
1625
|
+
module_eval(<<'.,.,', 'parser.y', 288)
|
1626
|
+
def _reduce_77(val, _values, result)
|
1627
|
+
result = val[0].append({rhs: val[2], lineno: val[2].first&.line || @lexer.line - 1})
|
1628
|
+
|
1629
|
+
result
|
1630
|
+
end
|
1631
|
+
.,.,
|
1632
|
+
|
1633
|
+
# reduce 78 omitted
|
1634
|
+
|
1635
|
+
module_eval(<<'.,.,', 'parser.y', 294)
|
1636
|
+
def _reduce_79(val, _values, result)
|
1637
|
+
result = []
|
1638
|
+
@prec_seen = false
|
1639
|
+
@code_after_prec = false
|
1640
|
+
|
1641
|
+
result
|
1642
|
+
end
|
1643
|
+
.,.,
|
1644
|
+
|
1645
|
+
module_eval(<<'.,.,', 'parser.y', 300)
|
1646
|
+
def _reduce_80(val, _values, result)
|
1647
|
+
token = val[1]
|
1648
|
+
token.alias = val[2]
|
1649
|
+
result = val[0].append(token)
|
1650
|
+
|
1651
|
+
result
|
1652
|
+
end
|
1653
|
+
.,.,
|
1654
|
+
|
1655
|
+
module_eval(<<'.,.,', 'parser.y', 306)
|
1656
|
+
def _reduce_81(val, _values, result)
|
1657
|
+
if @prec_seen
|
1658
|
+
raise "Multiple User_code after %prec" if @code_after_prec
|
1659
|
+
@code_after_prec = true
|
1660
|
+
end
|
1661
|
+
@lexer.status = :c_declaration
|
1662
|
+
@lexer.end_symbol = '}'
|
1663
|
+
|
1664
|
+
result
|
1665
|
+
end
|
1666
|
+
.,.,
|
1667
|
+
|
1668
|
+
module_eval(<<'.,.,', 'parser.y', 315)
|
1669
|
+
def _reduce_82(val, _values, result)
|
1670
|
+
@lexer.status = :initial
|
1671
|
+
@lexer.end_symbol = nil
|
1672
|
+
|
1673
|
+
result
|
1674
|
+
end
|
1675
|
+
.,.,
|
1676
|
+
|
1677
|
+
module_eval(<<'.,.,', 'parser.y', 320)
|
1678
|
+
def _reduce_83(val, _values, result)
|
1679
|
+
token = val[3]
|
1680
|
+
token.alias = val[6]
|
1681
|
+
result = val[0].append(token)
|
1682
|
+
|
1683
|
+
result
|
1684
|
+
end
|
1685
|
+
.,.,
|
1686
|
+
|
1687
|
+
module_eval(<<'.,.,', 'parser.y', 326)
|
1688
|
+
def _reduce_84(val, _values, result)
|
1689
|
+
if @prec_seen
|
1690
|
+
raise "Multiple User_code after %prec" if @code_after_prec
|
1691
|
+
@code_after_prec = true
|
1692
|
+
end
|
1693
|
+
@lexer.status = :c_declaration
|
1694
|
+
@lexer.end_symbol = '}'
|
1695
|
+
|
1696
|
+
result
|
1697
|
+
end
|
1698
|
+
.,.,
|
1699
|
+
|
1700
|
+
module_eval(<<'.,.,', 'parser.y', 335)
|
1701
|
+
def _reduce_85(val, _values, result)
|
1702
|
+
@lexer.status = :initial
|
1703
|
+
@lexer.end_symbol = nil
|
1704
|
+
|
1705
|
+
result
|
1706
|
+
end
|
1707
|
+
.,.,
|
1708
|
+
|
1709
|
+
module_eval(<<'.,.,', 'parser.y', 340)
|
1710
|
+
def _reduce_86(val, _values, result)
|
1711
|
+
token = val[2]
|
1712
|
+
token.alias = val[5]
|
1713
|
+
result = [token]
|
1714
|
+
|
1715
|
+
result
|
1716
|
+
end
|
1717
|
+
.,.,
|
1718
|
+
|
1719
|
+
module_eval(<<'.,.,', 'parser.y', 346)
|
1720
|
+
def _reduce_87(val, _values, result)
|
1721
|
+
sym = @grammar.find_symbol_by_id!(val[2])
|
1722
|
+
result = val[0].append(sym)
|
1723
|
+
@prec_seen = true
|
1724
|
+
|
1725
|
+
result
|
1726
|
+
end
|
1727
|
+
.,.,
|
1728
|
+
|
1729
|
+
# reduce 88 omitted
|
1730
|
+
|
1731
|
+
module_eval(<<'.,.,', 'parser.y', 352)
|
1732
|
+
def _reduce_89(val, _values, result)
|
1733
|
+
result = val[1].s_value
|
1734
|
+
result
|
1735
|
+
end
|
1736
|
+
.,.,
|
1737
|
+
|
1738
|
+
# reduce 90 omitted
|
1739
|
+
|
1740
|
+
# reduce 91 omitted
|
1741
|
+
|
1742
|
+
module_eval(<<'.,.,', 'parser.y', 359)
|
1743
|
+
def _reduce_92(val, _values, result)
|
1744
|
+
@lexer.status = :c_declaration
|
1745
|
+
@lexer.end_symbol = '\Z'
|
1746
|
+
@grammar.epilogue_first_lineno = @lexer.line + 1
|
1747
|
+
|
1748
|
+
result
|
1749
|
+
end
|
1750
|
+
.,.,
|
1751
|
+
|
1752
|
+
module_eval(<<'.,.,', 'parser.y', 365)
|
1753
|
+
def _reduce_93(val, _values, result)
|
1754
|
+
@lexer.status = :initial
|
1755
|
+
@lexer.end_symbol = nil
|
1756
|
+
@grammar.epilogue = val[2].s_value
|
1757
|
+
|
1758
|
+
result
|
1759
|
+
end
|
1760
|
+
.,.,
|
1761
|
+
|
1762
|
+
# reduce 94 omitted
|
1763
|
+
|
1764
|
+
# reduce 95 omitted
|
1765
|
+
|
1766
|
+
# reduce 96 omitted
|
1767
|
+
|
1768
|
+
# reduce 97 omitted
|
1769
|
+
|
1770
|
+
# reduce 98 omitted
|
1771
|
+
|
1772
|
+
module_eval(<<'.,.,', 'parser.y', 377)
|
1773
|
+
def _reduce_99(val, _values, result)
|
1774
|
+
result = [val[0]]
|
1775
|
+
result
|
1776
|
+
end
|
1777
|
+
.,.,
|
1778
|
+
|
1779
|
+
module_eval(<<'.,.,', 'parser.y', 378)
|
1780
|
+
def _reduce_100(val, _values, result)
|
1781
|
+
result = val[0].append(val[1])
|
1782
|
+
result
|
1783
|
+
end
|
1784
|
+
.,.,
|
1785
|
+
|
1786
|
+
# reduce 101 omitted
|
1787
|
+
|
1788
|
+
# reduce 102 omitted
|
1789
|
+
|
1790
|
+
module_eval(<<'.,.,', 'parser.y', 383)
|
1791
|
+
def _reduce_103(val, _values, result)
|
1792
|
+
result = Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Ident, s_value: val[0])
|
1793
|
+
result
|
1794
|
+
end
|
1795
|
+
.,.,
|
1796
|
+
|
1797
|
+
def _reduce_none(val, _values, result)
|
1798
|
+
val[0]
|
293
1799
|
end
|
1800
|
+
|
1801
|
+
end # class Parser
|
1802
|
+
end # module Lrama
|