27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/opal/racc/parser.rb', line 27
def _racc_do_parse_rb(arg, in_debug)
action_table = arg[0]
action_check = arg[1]
action_default = arg[2]
action_pointer = arg[3]
goto_table = arg[4]
goto_check = arg[5]
goto_default = arg[6]
goto_pointer = arg[7]
nt_base = arg[8]
reduce_table = arg[9]
token_table = arg[10]
shift_n = arg[11]
reduce_n = arg[12]
use_result = arg[13]
racc_state = [0]
racc_tstack = []
racc_vstack = []
racc_t = nil
racc_tok = nil
racc_val = nil
racc_read_next = true
racc_user_yyerror = false
racc_error_status = 0
token = nil; act = nil; i = nil; nerr = nil; custate = nil
while true
i = action_pointer[racc_state[-1]]
if i
if racc_read_next
if racc_t != 0 token = next_token
racc_tok = token[0]
racc_val = token[1]
if racc_tok == false racc_t = 0
else
racc_t = token_table[racc_tok]
racc_t = 1 unless racc_t
end
racc_read_next = false
end
end
i += racc_t
if (i < 0) || (act = action_table[i]).nil? || (action_check[i] != racc_state[-1])
act = action_default[racc_state[-1]]
end
else
act = action_default[racc_state[-1]]
end
if act > 0 && act < shift_n
if racc_error_status > 0
if racc_t != 1
racc_error_status -= 1
end
end
racc_vstack.push racc_val
curstate = act
racc_state << act
racc_read_next = true
elsif act < 0 && act > -reduce_n
reduce_i = act * -3
reduce_len = reduce_table[reduce_i]
reduce_to = reduce_table[reduce_i + 1]
method_id = reduce_table[reduce_i + 2]
tmp_v = racc_vstack.last reduce_len
racc_state.pop reduce_len
racc_vstack.pop reduce_len
racc_tstack.pop reduce_len
if use_result
reduce_call_result = self.__send__ method_id, tmp_v, nil, tmp_v[0]
racc_vstack.push reduce_call_result
else
raise "not using result??"
end
racc_tstack.push reduce_to
k1 = reduce_to - nt_base
if (reduce_i = goto_pointer[k1]) != nil
reduce_i += racc_state[-1]
if (reduce_i >= 0) && ((curstate = goto_table[reduce_i]) != nil) && (goto_check[reduce_i] == k1)
racc_state.push curstate
else
racc_state.push goto_default[k1]
end
else
racc_state.push goto_default[k1]
end
elsif act == shift_n
return racc_vstack[0]
elsif act == -reduce_n
raise "Opal Syntax Error: unexpected '#{racc_tok.inspect}'"
else
raise "Rac: unknown action: #{act}"
end
end
end
|