1 /*1410:*/
2 #line 13551 "./marpa.w"
3 
4 /*
5  * Copyright 2012 Jeffrey Kegler
6  * This file is part of Marpa::XS.  Marpa::XS is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU Lesser
8  * General Public License as published by the Free Software Foundation,
9  * either version 3 of the License, or (at your option) any later version.
10  *
11  * Marpa::XS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser
17  * General Public License along with Marpa::XS.  If not, see
18  * http://www.gnu.org/licenses/.
19  */
20 /*
21  * DO NOT EDIT DIRECTLY
22  * This file is written by ctangle
23  * It is not intended to be modified directly
24  */
25 
26 /*:1410*//*1411:*/
27 #line 13574 "./marpa.w"
28 
29 #include "config.h"
30 #include "marpa.h"
31 /*1397:*/
32 #line 13382 "./marpa.w"
33 
34 #define MARPA_DEBUG  0
35 #define MARPA_ENABLE_ASSERT  0
36 #if MARPA_DEBUG
37 #define MARPA_DEBUG1(a)  g_debug((a));
38 #define MARPA_DEBUG2(a, b)  g_debug((a),(b));
39 #define MARPA_DEBUG3(a, b, c)  g_debug((a),(b),(c));
40 #define MARPA_DEBUG4(a, b, c, d)  g_debug((a),(b),(c),(d));
41 #define MARPA_DEBUG5(a, b, c, d, e)  g_debug((a),(b),(c),(d),(e));
42 #define MARPA_ASSERT(expr) do { if G_LIKELY (expr) ; else \
43        g_error ("%s: assertion failed %s", G_STRLOC, #expr); } while (0);
44 #else
45 #define MARPA_DEBUG1(a)
46 #define MARPA_DEBUG2(a, b)
47 #define MARPA_DEBUG3(a, b, c)
48 #define MARPA_DEBUG4(a, b, c, d)
49 #define MARPA_DEBUG5(a, b, c, d, e)
50 #define MARPA_ASSERT(exp)
51 #endif
52 
53 #if MARPA_ENABLE_ASSERT
54 #undef MARPA_ASSERT
55 #define MARPA_ASSERT(expr) do { if G_LIKELY (expr) ; else \
56        g_error ("%s: assertion failed %s", G_STRLOC, #expr); } while (0);
57 #endif
58 
59 /*:1397*/
60 #line 13577 "./marpa.w"
61 
62 #define PRIVATE_NOT_INLINE static \
63 
64 #define SYM_Count_of_G(g) ((g) ->t_symbols->len)  \
65 
66 #define SYM_by_ID(id) (g_array_index(g->t_symbols,SYM,(id) ) )  \
67 
68 #define RULE_Count_of_G(g) ((g) ->t_rules->len)
69 #define RULE_by_ID(g,id) (g_array_index((g) ->t_rules,RULE,(id) ) )  \
70 
71 #define RULEID_of_G_is_Valid(g,rule_id)  \
72 ((rule_id) >=0&&(guint) (rule_id) <(g) ->t_rules->len)  \
73 
74 #define Default_Value_of_G(g) ((g) ->t_default_value)
75 #define Size_of_G(g) ((g) ->t_size)
76 #define LV_Size_of_G(g) ((g) ->t_size)
77 #define G_is_Precomputed(g) ((g) ->t_is_precomputed)
78 #define Context_of_G(g) ((g) ->t_context)
79 #define ID_of_SYM(sym) ((sym) ->t_symbol_id)
80 #define LV_ID_of_SYM(sym) ID_of_SYM(sym)
81 #define SYMBOL_LHS_RULE_COUNT(symbol) ((symbol) ->t_lhs->len)
82 #define SYM_is_Nulling(sym) ((sym) ->t_is_nulling)
83 #define SYM_is_Terminal(symbol) ((symbol) ->t_is_terminal)
84 #define SYMID_is_Terminal(id) (SYM_is_Terminal(SYM_by_ID(id) ) )
85 #define MAX_RHS_LENGTH (G_MAXINT>>(2) )
86 #define Length_of_RULE(rule) ((rule) ->t_rhs_length)
87 #define LHS_ID_of_RULE(rule) ((rule) ->t_symbols[0])
88 #define RHS_ID_of_RULE(rule,position)  \
89 ((rule) ->t_symbols[(position) +1])  \
90 
91 #define ID_of_RULE(rule) ((rule) ->t_id)
92 #define RULE_is_Used(rule) ((rule) ->t_is_used)
93 #define RULE_is_Start(rule) ((rule) ->t_is_start)
94 #define RULE_is_Virtual_LHS(rule) ((rule) ->t_is_virtual_lhs)
95 #define RULE_is_Virtual_RHS(rule) ((rule) ->t_is_virtual_rhs)
96 #define Real_SYM_Count_of_RULE(rule) ((rule) ->t_real_symbol_count)
97 #define SYMI_Count_of_G(g) ((g) ->t_symbol_instance_count)
98 #define SYMI_of_RULE(rule) ((rule) ->t_symbol_instance_base)
99 #define Last_Proper_SYMI_of_RULE(rule) ((rule) ->t_last_proper_symi)
100 #define SYMI_of_Completed_RULE(rule)  \
101 (SYMI_of_RULE(rule) +Length_of_RULE(rule) -1)
102 #define SYMI_of_AIM(aim) (symbol_instance_of_ahfa_item_get(aim) )
103 #define Sort_Key_of_AIM(aim) ((aim) ->t_sort_key)
104 #define Next_AIM_of_AIM(aim) ((aim) +1)
105 #define AIM_by_ID(id) (g->t_AHFA_items+(id) )
106 #define AIM_Count_of_G(g) ((g) ->t_aim_count)
107 #define LV_AIM_Count_of_G(g) AIM_Count_of_G(g)
108 #define RULE_of_AIM(item) ((item) ->t_rule)
109 #define RULEID_of_AIM(item) ID_of_RULE(RULE_of_AIM(item) )
110 #define LHS_ID_of_AIM(item) (LHS_ID_of_RULE(RULE_of_AIM(item) ) )
111 #define Position_of_AIM(aim) ((aim) ->t_position)
112 #define Postdot_SYMID_of_AIM(item) ((item) ->t_postdot)
113 #define AIM_is_Completion(aim) (Postdot_SYMID_of_AIM(aim) <0)
114 #define AIM_has_Completed_Start_Rule(aim)  \
115 (AIM_is_Completion(aim) &&RULE_is_Start(RULE_of_AIM(aim) ) )
116 #define Null_Count_of_AIM(aim) ((aim) ->t_leading_nulls)
117 #define AHFA_of_G_by_ID(g,id) ((g) ->t_AHFA+(id) )
118 #define AHFA_has_Completed_Start_Rule(ahfa) ((ahfa) ->t_has_completed_start_rule)
119 #define Complete_SYMIDs_of_AHFA(state) ((state) ->t_complete_symbols)
120 #define LV_Complete_SYMIDs_of_AHFA(state) Complete_SYMIDs_of_AHFA(state)
121 #define Complete_SYM_Count_of_AHFA(state) ((state) ->t_complete_symbol_count)
122 #define LV_Complete_SYM_Count_of_AHFA(state) Complete_SYM_Count_of_AHFA(state)
123 #define AIMs_of_AHFA(ahfa) ((ahfa) ->t_items)
124 #define AIM_of_AHFA_by_AEX(ahfa,aex) (AIMs_of_AHFA(ahfa) [aex])
125 #define LV_AIMs_of_AHFA(ahfa) AIMs_of_AHFA(ahfa)
126 #define AIM_Count_of_AHFA(ahfa) ((ahfa) ->t_item_count)
127 #define LV_AIM_Count_of_AHFA(ahfa) AIM_Count_of_AHFA(ahfa)
128 #define AEX_of_AHFA_by_AIM(ahfa,aim) aex_of_ahfa_by_aim_get((ahfa) ,(aim) )
129 #define AHFA_is_Predicted(ahfa) ((ahfa) ->t_is_predict)
130 #define LV_AHFA_is_Predicted(ahfa) AHFA_is_Predicted(ahfa)
131 #define EIM_is_Predicted(eim) AHFA_is_Predicted(AHFA_of_EIM(eim) )
132 #define AHFA_Count_of_G(g) ((g) ->t_AHFA_len)
133 #define ID_of_AHFA(state) ((state) ->t_key.t_id)  \
134 
135 #define Postdot_SYM_Count_of_AHFA(state) ((state) ->t_postdot_sym_count)
136 #define LV_Postdot_SYM_Count_of_AHFA(state) Postdot_SYM_Count_of_AHFA(state)
137 #define Postdot_SYMID_Ary_of_AHFA(state) ((state) ->t_postdot_symid_ary)
138 #define LV_Postdot_SYMID_Ary_of_AHFA(state) Postdot_SYMID_Ary_of_AHFA(state)
139 #define AIMID_of_AHFA_by_AEX(g,ahfa,aex)  \
140 ((ahfa) ->t_items[aex]-(g) ->t_AHFA_items)
141 #define Leo_LHS_ID_of_AHFA(state) ((state) ->t_leo_lhs_sym)
142 #define LV_Leo_LHS_ID_of_AHFA(state) Leo_LHS_ID_of_AHFA(state)
143 #define AHFA_is_Leo_Completion(state) (Leo_LHS_ID_of_AHFA(state) >=0)
144 #define TRANS_of_AHFA_by_SYMID(from_ahfa,id)  \
145 (*(TRANSs_of_AHFA(from_ahfa) +(id) ) )
146 #define TRANS_of_EIM_by_SYMID(eim,id) TRANS_of_AHFA_by_SYMID(AHFA_of_EIM(eim) ,(id) )
147 #define To_AHFA_of_TRANS(trans) (to_ahfa_of_transition_get(trans) )
148 #define LV_To_AHFA_of_TRANS(trans) ((trans) ->t_ur.t_to_ahfa)
149 #define Completion_Count_of_TRANS(trans)  \
150 (completion_count_of_transition_get(trans) )
151 #define LV_Completion_Count_of_TRANS(trans) ((trans) ->t_ur.t_completion_count)
152 #define To_AHFA_of_AHFA_by_SYMID(from_ahfa,id)  \
153 (To_AHFA_of_TRANS(TRANS_of_AHFA_by_SYMID((from_ahfa) ,(id) ) ) )
154 #define Completion_Count_of_AHFA_by_SYMID(from_ahfa,id)  \
155 (Completion_Count_of_TRANS(TRANS_of_AHFA_by_SYMID((from ahfa) ,(id) ) ) )
156 #define To_AHFA_of_EIM_by_SYMID(eim,id) To_AHFA_of_AHFA_by_SYMID(AHFA_of_EIM(eim) ,(id) )
157 #define AEXs_of_TRANS(trans) ((trans) ->t_aex)
158 #define Leo_Base_AEX_of_TRANS(trans) ((trans) ->t_leo_base_aex)
159 #define TRANSs_of_AHFA(ahfa) ((ahfa) ->t_transitions)
160 #define LV_TRANSs_of_AHFA(ahfa) TRANSs_of_AHFA(ahfa)
161 #define Empty_Transition_of_AHFA(state) ((state) ->t_empty_transition)
162 #define G_of_R(r) ((r) ->t_grammar)
163 #define AHFA_Count_of_R(r) AHFA_Count_of_G(G_of_R(r) )
164 #define Phase_of_R(r) ((r) ->t_phase)
165 #define First_ES_of_R(r) ((r) ->t_first_earley_set)
166 #define LV_First_ES_of_R(r) First_ES_of_R(r)
167 #define Latest_ES_of_R(r) ((r) ->t_latest_earley_set)
168 #define LV_Latest_ES_of_R(r) Latest_ES_of_R(r)
169 #define Current_Earleme_of_R(r) ((r) ->t_current_earleme)
170 #define LV_Current_Earleme_of_R(r) (Current_Earleme_of_R(r) )
171 #define Current_ES_of_R(r) current_es_of_r(r)
172 #define DEFAULT_EIM_WARNING_THRESHOLD (100)
173 #define Furthest_Earleme_of_R(r) ((r) ->t_furthest_earleme)
174 #define LV_Furthest_Earleme_of_R(r) Furthest_Earleme_of_R(r)
175 #define R_is_Exhausted(r) ((r) ->t_is_exhausted)
176 #define LV_R_is_Exhausted(r) R_is_Exhausted(r)
177 #define Context_of_R(r) ((r) ->t_context)
178 #define EARLEME_THRESHOLD (G_MAXINT/4)
179 #define Next_ES_of_ES(set) ((set) ->t_next_earley_set)
180 #define LV_Next_ES_of_ES(set) Next_ES_of_ES(set)
181 #define Postdot_SYM_Count_of_ES(set) ((set) ->t_postdot_sym_count)
182 #define First_PIM_of_ES_by_SYMID(set,symid) (first_pim_of_es_by_symid((set) ,(symid) ) )
183 #define PIM_SYM_P_of_ES_by_SYMID(set,symid) (pim_sym_p_find((set) ,(symid) ) )
184 #define EIM_Count_of_ES(set) ((set) ->t_eim_count)
185 #define EIMs_of_ES(set) ((set) ->t_earley_items)
186 #define ES_Count_of_R(r) ((r) ->t_earley_set_count)
187 #define Ord_of_ES(set) ((set) ->t_ordinal)
188 #define ES_Ord_is_Valid(r,ordinal)  \
189 ((ordinal) >=0&&(ordinal) <ES_Count_of_R(r) )
190 #define Earleme_of_ES(set) ((set) ->t_key.t_earleme)  \
191 
192 #define EIM_FATAL_THRESHOLD (G_MAXINT/4)
193 #define Complete_SYMIDs_of_EIM(item)  \
194 Complete_SYMIDs_of_AHFA(AHFA_of_EIM(item) )
195 #define Complete_SYM_Count_of_EIM(item)  \
196 Complete_SYM_Count_of_AHFA(AHFA_of_EIM(item) )
197 #define Leo_LHS_ID_of_EIM(eim) Leo_LHS_ID_of_AHFA(AHFA_of_EIM(eim) )
198 #define Earley_Item_is_Completion(item)  \
199 (Complete_SYM_Count_of_EIM(item) > 0)
200 #define ES_of_EIM(item) ((item) ->t_key.t_set)
201 #define ES_Ord_of_EIM(item) (Ord_of_ES(ES_of_EIM(item) ) )
202 #define Ord_of_EIM(item) ((item) ->t_ordinal)
203 #define Earleme_of_EIM(item) Earleme_of_ES(ES_of_EIM(item) )
204 #define AHFAID_of_EIM(item) (ID_of_AHFA(AHFA_of_EIM(item) ) )
205 #define AHFA_of_EIM(item) ((item) ->t_key.t_state)
206 #define AIM_Count_of_EIM(item) (AIM_Count_of_AHFA(AHFA_of_EIM(item) ) )
207 #define Origin_Earleme_of_EIM(item) (Earleme_of_ES(Origin_of_EIM(item) ) )
208 #define Origin_Ord_of_EIM(item) (Ord_of_ES(Origin_of_EIM(item) ) )
209 #define Origin_of_EIM(item) ((item) ->t_key.t_origin)
210 #define AIM_of_EIM_by_AEX(eim,aex) AIM_of_AHFA_by_AEX(AHFA_of_EIM(eim) ,(aex) )
211 #define AEX_of_EIM_by_AIM(eim,aim) AEX_of_AHFA_by_AIM(AHFA_of_EIM(eim) ,(aim) )
212 #define NO_SOURCE (0U)
213 #define SOURCE_IS_TOKEN (1U)
214 #define SOURCE_IS_COMPLETION (2U)
215 #define SOURCE_IS_LEO (3U)
216 #define SOURCE_IS_AMBIGUOUS (4U)
217 #define Source_Type_of_EIM(item) ((item) ->t_source_type)
218 #define Earley_Item_has_No_Source(item) ((item) ->t_source_type==NO_SOURCE)
219 #define Earley_Item_has_Token_Source(item) ((item) ->t_source_type==SOURCE_IS_TOKEN)
220 #define Earley_Item_has_Complete_Source(item) ((item) ->t_source_type==SOURCE_IS_COMPLETION)
221 #define Earley_Item_has_Leo_Source(item) ((item) ->t_source_type==SOURCE_IS_LEO)
222 #define Earley_Item_is_Ambiguous(item) ((item) ->t_source_type==SOURCE_IS_AMBIGUOUS)
223 #define Next_PIM_of_EIX(eix) ((eix) ->t_next)
224 #define LV_Next_PIM_of_EIX(eix) Next_PIM_of_EIX(eix)
225 #define EIM_of_EIX(eix) ((eix) ->t_earley_item)
226 #define LV_EIM_of_EIX(eix) EIM_of_EIX(eix)
227 #define Postdot_SYMID_of_EIX(eix) ((eix) ->t_postdot_symid)
228 #define LV_Postdot_SYMID_of_EIX(eix) Postdot_SYMID_of_EIX(eix)
229 #define EIX_of_LIM(lim) ((EIX) (lim) )
230 #define Postdot_SYMID_of_LIM(leo) (Postdot_SYMID_of_EIX(EIX_of_LIM(leo) ) )
231 #define Next_PIM_of_LIM(leo) (Next_PIM_of_EIX(EIX_of_LIM(leo) ) )
232 #define LV_Next_PIM_of_LIM(leo) Next_PIM_of_LIM(leo)
233 #define Origin_of_LIM(leo) ((leo) ->t_origin)
234 #define LV_Origin_of_LIM(leo) Origin_of_LIM(leo)
235 #define Top_AHFA_of_LIM(leo) ((leo) ->t_top_ahfa)
236 #define LV_Top_AHFA_of_LIM(leo) Top_AHFA_of_LIM(leo)
237 #define Predecessor_LIM_of_LIM(leo) ((leo) ->t_predecessor)
238 #define LV_Predecessor_LIM_of_LIM(leo) Predecessor_LIM_of_LIM(leo)
239 #define Base_EIM_of_LIM(leo) ((leo) ->t_base)
240 #define LV_Base_EIM_of_LIM(leo) Base_EIM_of_LIM(leo)
241 #define ES_of_LIM(leo) ((leo) ->t_set)
242 #define LV_ES_of_LIM(leo) ES_of_LIM(leo)
243 #define Chain_Length_of_LIM(leo) ((leo) ->t_chain_length)
244 #define LV_Chain_Length_of_LIM(leo) Chain_Length_of_LIM(leo)
245 #define Earleme_of_LIM(lim) Earleme_of_ES(ES_of_LIM(lim) )
246 #define LIM_of_PIM(pim) ((LIM) (pim) )
247 #define EIX_of_PIM(pim) ((EIX) (pim) )
248 #define Postdot_SYMID_of_PIM(pim) (Postdot_SYMID_of_EIX(EIX_of_PIM(pim) ) )
249 #define LV_Postdot_SYMID_of_PIM(pim) Postdot_SYMID_of_PIM(pim)
250 #define EIM_of_PIM(pim) (EIM_of_EIX(EIX_of_PIM(pim) ) )
251 #define LV_EIM_of_PIM(pim) EIM_of_PIM(pim)
252 #define Next_PIM_of_PIM(pim) (Next_PIM_of_EIX(EIX_of_PIM(pim) ) )
253 #define LV_Next_PIM_of_PIM(pim) Next_PIM_of_PIM(pim)  \
254 
255 #define PIM_of_LIM(pim) ((PIM) (pim) )
256 #define PIM_is_LIM(pim) (EIM_of_EIX(EIX_of_PIM(pim) ) ==NULL)
257 #define SYMID_of_Postdot_Item(postdot) ((postdot) ->t_earley.transition_symid)  \
258 
259 #define Next_SRCL_of_SRCL(link) ((link) ->t_next)
260 #define LV_Next_SRCL_of_SRCL(link) Next_SRCL_of_SRCL(link)
261 #define Source_of_SRCL(link) ((link) ->t_source)
262 #define Source_of_EIM(eim) ((eim) ->t_container.t_unique)
263 #define Predecessor_of_Source(srcd) ((srcd) .t_predecessor)
264 #define Predecessor_of_SRC(source) Predecessor_of_Source(*(source) )
265 #define Predecessor_of_EIM(item) Predecessor_of_Source(Source_of_EIM(item) )
266 #define Predecessor_of_SRCL(link) Predecessor_of_Source(Source_of_SRCL(link) )
267 #define LV_Predecessor_of_SRCL(link) Predecessor_of_SRCL(link)
268 #define Cause_of_Source(srcd) ((srcd) .t_cause.t_completion)
269 #define Cause_of_SRC(source) Cause_of_Source(*(source) )
270 #define Cause_of_EIM(item) Cause_of_Source(Source_of_EIM(item) )
271 #define Cause_of_SRCL(link) Cause_of_Source(Source_of_SRCL(link) )
272 #define TOK_of_Source(srcd) ((srcd) .t_cause.t_token)
273 #define TOK_of_SRC(source) TOK_of_Source(*(source) )
274 #define TOK_of_EIM(eim) TOK_of_Source(Source_of_EIM(eim) )
275 #define TOK_of_SRCL(link) TOK_of_Source(Source_of_SRCL(link) )
276 #define SYMID_of_Source(srcd) SYMID_of_TOK(TOK_of_Source(srcd) )
277 #define SYMID_of_SRC(source) SYMID_of_Source(*(source) )
278 #define SYMID_of_EIM(eim) SYMID_of_Source(Source_of_EIM(eim) )
279 #define SYMID_of_SRCL(link) SYMID_of_Source(Source_of_SRCL(link) )  \
280 
281 #define Cause_AHFA_State_ID_of_SRC(source)  \
282 AHFAID_of_EIM((EIM) Cause_of_SRC(source) )
283 #define Leo_Transition_SYMID_of_SRC(leo_source)  \
284 Postdot_SYMID_of_LIM((LIM) Predecessor_of_SRC(leo_source) )  \
285 
286 #define First_Completion_Link_of_EIM(item) ((item) ->t_container.t_ambiguous.t_completion)
287 #define LV_First_Completion_Link_of_EIM(item) First_Completion_Link_of_EIM(item)
288 #define First_Token_Link_of_EIM(item) ((item) ->t_container.t_ambiguous.t_token)
289 #define LV_First_Token_Link_of_EIM(item) First_Token_Link_of_EIM(item)
290 #define First_Leo_SRCL_of_EIM(item) ((item) ->t_container.t_ambiguous.t_leo)
291 #define LV_First_Leo_SRCL_of_EIM(item) First_Leo_SRCL_of_EIM(item)  \
292 
293 #define Type_of_TOK(tok) ((tok) ->t_type)
294 #define SYMID_of_TOK(tok) ((tok) ->t_symbol_id)
295 #define Value_of_TOK(tok) ((tok) ->t_value)
296 #define TOK_Obs_of_R(r) (&(r) ->t_token_obs)
297 #define TOKs_by_SYMID_of_R(r) ((r) ->t_tokens_by_symid)
298 #define TOK_Obs TOK_Obs_of_R(r)
299 #define TOK_by_ID_of_R(r,symbol_id) (TOKs_by_SYMID_of_R(r) [symbol_id])
300 #define TOK_of_ALT(alt) ((alt) ->t_token)
301 #define SYMID_of_ALT(alt) SYMID_of_TOK(TOK_of_ALT(alt) )
302 #define Start_ES_of_ALT(alt) ((alt) ->t_start_earley_set)
303 #define Start_Earleme_of_ALT(alt) Earleme_of_ES(Start_ES_of_ALT(alt) )
304 #define End_Earleme_of_ALT(alt) ((alt) ->t_end_earleme)
305 #define INITIAL_ALTERNATIVES_CAPACITY 1
306 #define Work_EIMs_of_R(r) DSTACK_BASE((r) ->t_eim_work_stack,EIM)
307 #define Work_EIM_Count_of_R(r) DSTACK_LENGTH((r) ->t_eim_work_stack)
308 #define WORK_EIMS_CLEAR(r) DSTACK_CLEAR((r) ->t_eim_work_stack)
309 #define WORK_EIM_PUSH(r) DSTACK_PUSH((r) ->t_eim_work_stack,EIM)
310 #define P_ES_of_R_by_Ord(r,ord) DSTACK_INDEX((r) ->t_earley_set_stack,ES,(ord) )
311 #define ES_of_R_by_Ord(r,ord) (*P_ES_of_R_by_Ord((r) ,(ord) ) )
312 #define LIM_is_Populated(leo) (Origin_of_LIM(leo) !=NULL)
313 #define Prev_UR_of_UR(ur) ((ur) ->t_prev)
314 #define LV_Prev_UR_of_UR(ur) Prev_UR_of_UR(ur)
315 #define Next_UR_of_UR(ur) ((ur) ->t_next)
316 #define LV_Next_UR_of_UR(ur) Next_UR_of_UR(ur)
317 #define EIM_of_UR(ur) ((ur) ->t_earley_item)
318 #define LV_EIM_of_UR(ur) EIM_of_UR(ur)
319 #define AEX_of_UR(ur) ((ur) ->t_aex)
320 #define LV_AEX_of_UR(ur) AEX_of_UR(ur)  \
321 
322 #define URS_of_R(r) (&(r) ->t_ur_node_stack)
323 #define Set_boolean_in_PSIA_for_initial_nulls(eim,aim) { \
324 if(Position_of_AIM(aim) > 0) { \
325 const gint null_count= Null_Count_of_AIM(aim) ; \
326 if(null_count) { \
327 AEX aex= AEX_of_EIM_by_AIM((eim) , \
328 (aim) ) ; \
329 or_node_estimate+= null_count; \
330 psia_test_and_set(&bocage_setup_obs,per_es_data, \
331 (eim) ,aex) ; \
332 } \
333 } \
334 } \
335 
336 #define DUMMY_OR_NODE -1
337 #define TOKEN_OR_NODE -2
338 #define OR_is_Token(or) (Type_of_OR(or) ==TOKEN_OR_NODE)
339 #define Position_of_OR(or) ((or) ->t_final.t_position)
340 #define Type_of_OR(or) ((or) ->t_final.t_position)
341 #define RULE_of_OR(or) ((or) ->t_final.t_rule)
342 #define Origin_Ord_of_OR(or) ((or) ->t_final.t_start_set_ordinal)
343 #define ID_of_OR(or) ((or) ->t_final.t_id)
344 #define ES_Ord_of_OR(or) ((or) ->t_draft.t_end_set_ordinal)
345 #define DANDs_of_OR(or) ((or) ->t_draft.t_draft_and_node)
346 #define First_ANDID_of_OR(or) ((or) ->t_final.t_first_and_node_id)
347 #define AND_Count_of_OR(or) ((or) ->t_final.t_and_node_count)
348 #define TOK_of_OR(or) (&(or) ->t_token)
349 #define SYMID_of_OR(or) SYMID_of_TOK(TOK_of_OR(or) )
350 #define Value_of_OR(or) Value_of_TOK(TOK_of_OR(or) )
351 #define ORs_of_B(b) ((b) ->t_or_nodes)
352 #define OR_of_B_by_ID(b,id) (ORs_of_B(b) [(id) ])
353 #define OR_Count_of_B(b) ((b) ->t_or_node_count)
354 #define ANDs_of_B(b) ((b) ->t_and_nodes)
355 #define AND_Count_of_B(b) ((b) ->t_and_node_count)
356 #define Top_ORID_of_B(b) ((b) ->t_top_or_node_id)
357 #define Path_AIM_of_LIM(lim) (base_aim_of_lim(lim) +1)
358 #define Base_AIM_of_LIM(lim) (base_aim_of_lim(lim) )
359 #define WHEID_of_SYMID(symid) (rule_count_of_g+(symid) )
360 #define WHEID_of_RULEID(ruleid) (ruleid)
361 #define WHEID_of_RULE(rule) WHEID_of_RULEID(ID_of_RULE(rule) )
362 #define WHEID_of_OR(or) ( \
363 wheid= OR_is_Token(or) ? \
364 WHEID_of_SYMID(SYMID_of_OR(or) ) : \
365 WHEID_of_RULE(RULE_of_OR(or) )  \
366 )  \
367 
368 #define Next_DAND_of_DAND(dand) ((dand) ->t_next)
369 #define Predecessor_OR_of_DAND(dand) ((dand) ->t_predecessor)
370 #define Cause_OR_of_DAND(dand) ((dand) ->t_cause)
371 #define Move_OR_to_Proper_OR(or_node) { \
372 while(or_node) { \
373 DAND draft_and_node= DANDs_of_OR(or_node) ; \
374 OR predecessor_or; \
375 if(!draft_and_node) break; \
376 predecessor_or= Predecessor_OR_of_DAND(draft_and_node) ; \
377 if(predecessor_or&& \
378 ES_Ord_of_OR(predecessor_or) !=work_earley_set_ordinal)  \
379 break; \
380 or_node= predecessor_or; \
381 } \
382 } \
383 
384 #define Set_OR_from_Ord_and_SYMI(or_node,origin,symbol_instance) { \
385 const PSL or_psl_at_origin= per_es_data[(origin) ].t_or_psl; \
386 (or_node) = PSL_Datum(or_psl_at_origin,(symbol_instance) ) ; \
387 } \
388 
389 #define Set_OR_from_EIM_and_AEX(psia_or,psia_eim,psia_aex) { \
390 const EIM psia_earley_item= psia_eim; \
391 const gint psia_earley_set_ordinal= ES_Ord_of_EIM(psia_earley_item) ; \
392 OR**const psia_nodes_by_item=  \
393 per_es_data[psia_earley_set_ordinal].t_aexes_by_item; \
394 const gint psia_item_ordinal= Ord_of_EIM(psia_earley_item) ; \
395 OR*const psia_nodes_by_aex= psia_nodes_by_item[psia_item_ordinal]; \
396 psia_or= psia_nodes_by_aex?psia_nodes_by_aex[psia_aex]:NULL; \
397 } \
398 
399 #define OR_of_AND(and) ((and) ->t_current)
400 #define Predecessor_OR_of_AND(and) ((and) ->t_predecessor)
401 #define Cause_OR_of_AND(and) ((and) ->t_cause)
402 #define B_of_R(r) ((r) ->t_bocage)
403 #define OBS_of_B(b) ((b) ->t_obs)
404 #define TREE_is_Initialized(tree) ((tree) ->t_parse_count>=0)
405 #define TREE_is_Exhausted(tree) (TREE_is_Initialized(tree)  \
406 &&!FSTACK_IS_INITIALIZED((tree) ->t_fork_stack) )
407 #define VAL_of_TREE(tree) (&(tree) ->t_val)
408 #define Size_of_TREE(tree) FSTACK_LENGTH((tree) ->t_fork_stack)
409 #define FORK_of_TREE_by_IX(tree,fork_id)  \
410 FSTACK_INDEX((tree) ->t_fork_stack,FORK_Object,fork_id)
411 #define TREE_of_RANK(rank) (&(rank) ->t_tree)
412 #define OBS_of_RANK(rank) ((rank) ->t_obs)
413 #define RANK_of_B(b) (&(b) ->t_rank)
414 #define OR_of_FORK(fork) ((fork) ->t_or_node)
415 #define Choice_of_FORK(fork) ((fork) ->t_choice)
416 #define Parent_of_FORK(fork) ((fork) ->t_parent)
417 #define FORK_Cause_is_Ready(fork) ((fork) ->t_is_cause_ready)
418 #define FORK_is_Cause(fork) ((fork) ->t_is_cause_of_parent)
419 #define FORK_Predecessor_is_Ready(fork) ((fork) ->t_is_predecessor_ready)
420 #define FORK_is_Predecessor(fork) ((fork) ->t_is_predecessor_of_parent)
421 #define SYMID_of_EVE(eve) ((eve) ->marpa_token_id)
422 #define Value_of_EVE(eve) ((eve) ->marpa_value)
423 #define RULEID_of_EVE(eve) ((eve) ->marpa_rule_id)
424 #define Arg0_of_EVE(eve) ((eve) ->marpa_arg_0)
425 #define ArgN_of_EVE(eve) ((eve) ->marpa_arg_n)
426 #define VAL_is_Active(val) ((val) ->t_active)
427 #define VAL_is_Trace(val) ((val) ->t_trace)
428 #define FORK_of_VAL(val) ((val) ->t_fork)
429 #define TOS_of_VAL(val) ((val) ->t_tos)
430 #define VStack_of_VAL(val) ((val) ->t_virtual_stack)
431 #define BV_BITS(bv) *(bv-3)
432 #define BV_SIZE(bv) *(bv-2)
433 #define BV_MASK(bv) *(bv-1)
434 #define FSTACK_DECLARE(stack,type) struct{gint t_count;type*t_base;}stack;
435 #define FSTACK_CLEAR(stack) ((stack) .t_count= 0)
436 #define FSTACK_INIT(stack,type,n) (FSTACK_CLEAR(stack) ,((stack) .t_base= g_new(type,n) ) )
437 #define FSTACK_SAFE(stack) ((stack) .t_base= NULL)
438 #define FSTACK_BASE(stack,type) ((type*) (stack) .t_base)
439 #define FSTACK_INDEX(this,type,ix) (FSTACK_BASE((this) ,type) +(ix) )
440 #define FSTACK_TOP(this,type) (FSTACK_LENGTH(this) <=0 \
441 ?NULL \
442 :FSTACK_INDEX((this) ,type,FSTACK_LENGTH(this) -1) )
443 #define FSTACK_LENGTH(stack) ((stack) .t_count)
444 #define FSTACK_PUSH(stack) ((stack) .t_base+stack.t_count++)
445 #define FSTACK_POP(stack) ((stack) .t_count<=0?NULL:(stack) .t_base+(--(stack) .t_count) )
446 #define FSTACK_IS_INITIALIZED(stack) ((stack) .t_base)
447 #define FSTACK_DESTROY(stack) (g_free((stack) .t_base) )  \
448 
449 #define DSTACK_DECLARE(this) struct s_dstack this
450 #define DSTACK_INIT(this,type,initial_size)  \
451 (((this) .t_count= 0) , \
452 ((this) .t_base= g_new(type,((this) .t_capacity= (initial_size) ) ) ) )  \
453 
454 #define DSTACK_IS_INITIALIZED(this) ((this) .t_base)
455 #define DSTACK_SAFE(this)  \
456 (((this) .t_count= (this) .t_capacity= 0) ,((this) .t_base= NULL) )  \
457 
458 #define DSTACK_CLEAR(this) ((this) .t_count= 0)
459 #define DSTACK_PUSH(this,type)  \
460 (((this) .t_count>=(this) .t_capacity?dstack_resize(&(this) ,sizeof(type) ) :0) , \
461 ((type*) (this) .t_base+(this) .t_count++) )
462 #define DSTACK_POP(this,type) ((this) .t_count<=0?NULL: \
463 ((type*) (this) .t_base+(--(this) .t_count) ) )
464 #define DSTACK_INDEX(this,type,ix) (DSTACK_BASE((this) ,type) +(ix) )
465 #define DSTACK_TOP(this,type) (DSTACK_LENGTH(this) <=0 \
466 ?NULL \
467 :DSTACK_INDEX((this) ,type,DSTACK_LENGTH(this) -1) )
468 #define DSTACK_BASE(this,type) ((type*) (this) .t_base)
469 #define DSTACK_LENGTH(this) ((this) .t_count)  \
470 
471 #define STOLEN_DSTACK_DATA_FREE(data) ((data) &&(g_free(data) ,1) )
472 #define DSTACK_DESTROY(this) STOLEN_DSTACK_DATA_FREE(this.t_base)  \
473 
474 #define DQUEUE_DECLARE(this) struct s_dqueue this
475 #define DQUEUE_INIT(this,type,initial_size)  \
476 ((this.t_current= 0) ,DSTACK_INIT(this.t_stack,type,initial_size) )
477 #define DQUEUE_PUSH(this,type) DSTACK_PUSH(this.t_stack,type)
478 #define DQUEUE_POP(this,type) DSTACK_POP(this.t_stack,type)
479 #define DQUEUE_NEXT(this,type) (this.t_current>=DSTACK_LENGTH(this.t_stack)  \
480 ?NULL \
481 :(DSTACK_BASE(this.t_stack,type) ) +this.t_current++)
482 #define DQUEUE_BASE(this,type) DSTACK_BASE(this.t_stack,type)
483 #define DQUEUE_END(this) DSTACK_LENGTH(this.t_stack)
484 #define STOLEN_DQUEUE_DATA_FREE(data) STOLEN_DSTACK_DATA_FREE(data)  \
485 
486 #define Sizeof_PSL(psar)  \
487 (sizeof(PSL_Object) +(psar->t_psl_length-1) *sizeof(gpointer) )
488 #define PSL_Datum(psl,i) ((psl) ->t_data[(i) ])
489 #define Dot_PSAR_of_R(r) (&(r) ->t_dot_psar_object)
490 #define Dot_PSL_of_ES(es) ((es) ->t_dot_psl)
491 #define obstack_chunk_alloc g_malloc
492 #define obstack_chunk_free g_free \
493 
494 #define FATAL_FLAG (0x1u)
495 #define CONTEXT_FLAG (0x2u)
496 #define R_ERROR(message) (r_error(r,(message) ,0u) )
497 #define R_ERROR_CXT(message) (r_error(r,(message) ,CONTEXT_FLAG) )
498 #define R_FATAL(message) (r_error(r,(message) ,FATAL_FLAG) )
499 #define R_FATAL_CXT(message) (r_error(r,(message) ,CONTEXT_FLAG|FATAL_FLAG) )
500 #define Message_Callback_of_R(r) ((r) ->t_message_callback)
501 #define Message_Callback_Arg_of_R(r) ((r) ->t_message_callback_arg)
502 #define MARPA_OFF_DEBUG1(a)
503 #define MARPA_OFF_DEBUG2(a,b)
504 #define MARPA_OFF_DEBUG3(a,b,c)
505 #define MARPA_OFF_DEBUG4(a,b,c,d)
506 #define MARPA_OFF_DEBUG5(a,b,c,d,e)
507 #define MARPA_OFF_ASSERT(expr)
508 
509 #line 13578 "./marpa.w"
510 
511 #include "marpa_obs.h"
512 /*1379:*/
513 #line 13268 "./marpa.w"
514 
515 #undef G_LOG_DOMAIN
516 #define G_LOG_DOMAIN "Marpa"
517 
518 /*:1379*/
519 #line 13580 "./marpa.w"
520 
521 /*136:*/
522 #line 1118 "./marpa.w"
523 
524 struct s_symbol;
525 typedef struct s_symbol*SYM;
526 typedef const struct s_symbol*SYM_Const;
527 /*:136*//*447:*/
528 #line 3546 "./marpa.w"
529 
530 struct s_AHFA_item;
531 typedef struct s_AHFA_item*AIM;
532 typedef Marpa_AHFA_Item_ID AIMID;
533 
534 /*:447*//*492:*/
535 #line 3951 "./marpa.w"
536 struct s_AHFA_state;
537 /*:492*//*579:*/
538 #line 5192 "./marpa.w"
539 
540 struct s_transition;
541 typedef struct s_transition*TRANS;
542 struct s_ur_transition;
543 typedef struct s_ur_transition*URTRANS;
544 /*:579*//*706:*/
545 #line 5900 "./marpa.w"
546 
547 struct s_earley_set;
548 typedef struct s_earley_set*ES;
549 typedef const struct s_earley_set*ES_Const;
550 struct s_earley_set_key;
551 typedef struct s_earley_set_key*ESK;
552 /*:706*//*735:*/
553 #line 6129 "./marpa.w"
554 
555 struct s_earley_item;
556 typedef struct s_earley_item*EIM;
557 typedef const struct s_earley_item*EIM_Const;
558 struct s_earley_item_key;
559 typedef struct s_earley_item_key*EIK;
560 
561 /*:735*//*762:*/
562 #line 6438 "./marpa.w"
563 
564 struct s_earley_ix;
565 typedef struct s_earley_ix*EIX;
566 union u_postdot_item;
567 /*:762*//*765:*/
568 #line 6480 "./marpa.w"
569 
570 struct s_leo_item;
571 typedef struct s_leo_item*LIM;
572 /*:765*//*870:*/
573 #line 7647 "./marpa.w"
574 
575 struct s_token;
576 typedef struct s_token*TOK;
577 /*:870*//*878:*/
578 #line 7728 "./marpa.w"
579 
580 struct s_alternative;
581 typedef struct s_alternative*ALT;
582 typedef const struct s_alternative*ALT_Const;
583 /*:878*//*980:*/
584 #line 8875 "./marpa.w"
585 
586 struct s_ur_node_stack;
587 struct s_ur_node;
588 typedef struct s_ur_node_stack*URS;
589 typedef struct s_ur_node*UR;
590 typedef const struct s_ur_node*UR_Const;
591 /*:980*//*1016:*/
592 #line 9354 "./marpa.w"
593 
594 union u_or_node;
595 typedef union u_or_node*OR;
596 /*:1016*//*1045:*/
597 #line 9796 "./marpa.w"
598 
599 struct s_draft_and_node;
600 typedef struct s_draft_and_node*DAND;
601 /*:1045*//*1073:*/
602 #line 10216 "./marpa.w"
603 
604 struct s_and_node;
605 typedef struct s_and_node*AND;
606 /*:1073*//*1094:*/
607 #line 10421 "./marpa.w"
608 
609 struct s_bocage;
610 typedef struct s_bocage*BOC;
611 /*:1094*//*1106:*/
612 #line 10512 "./marpa.w"
613 
614 struct s_bocage_setup_per_es;
615 /*:1106*//*1138:*/
616 #line 10855 "./marpa.w"
617 
618 struct s_tree;
619 typedef struct s_tree*TREE;
620 /*:1138*//*1163:*/
621 #line 11220 "./marpa.w"
622 
623 struct s_bocage_rank;
624 typedef struct s_bocage_rank*RANK;
625 /*:1163*//*1183:*/
626 #line 11485 "./marpa.w"
627 
628 struct s_fork;
629 typedef struct s_fork*FORK;
630 /*:1183*//*1204:*/
631 #line 11668 "./marpa.w"
632 
633 struct s_value;
634 typedef struct s_value*VAL;
635 /*:1204*//*1308:*/
636 #line 12665 "./marpa.w"
637 
638 struct s_dstack;
639 typedef struct s_dstack*DSTACK;
640 /*:1308*//*1312:*/
641 #line 12700 "./marpa.w"
642 
643 struct s_dqueue;
644 typedef struct s_dqueue*DQUEUE;
645 /*:1312*//*1319:*/
646 #line 12765 "./marpa.w"
647 
648 struct s_per_earley_set_list;
649 typedef struct s_per_earley_set_list*PSL;
650 /*:1319*//*1321:*/
651 #line 12780 "./marpa.w"
652 
653 struct s_per_earley_set_arena;
654 typedef struct s_per_earley_set_arena*PSAR;
655 /*:1321*/
656 #line 13581 "./marpa.w"
657 
658 /*42:*/
659 #line 679 "./marpa.w"
660 
661 typedef struct marpa_g*GRAMMAR;
662 typedef const struct marpa_g*GRAMMAR_Const;
663 
664 /*:42*//*135:*/
665 #line 1116 "./marpa.w"
666 
667 typedef gint SYMID;
668 /*:135*//*213:*/
669 #line 1511 "./marpa.w"
670 
671 struct s_rule;
672 typedef struct s_rule*RULE;
673 typedef Marpa_Rule_ID RULEID;
674 
675 /*:213*//*338:*/
676 #line 2342 "./marpa.w"
677 typedef gint SYMI;
678 /*:338*//*504:*/
679 #line 4037 "./marpa.w"
680 
681 typedef struct s_AHFA_state*AHFA;
682 typedef gint AHFAID;
683 
684 /*:504*//*580:*/
685 #line 5197 "./marpa.w"
686 typedef gint AEX;
687 /*:580*//*603:*/
688 #line 5360 "./marpa.w"
689 
690 typedef struct marpa_r*RECCE;
691 /*:603*//*703:*/
692 #line 5890 "./marpa.w"
693 typedef Marpa_Earleme EARLEME;
694 
695 /*:703*//*705:*/
696 #line 5894 "./marpa.w"
697 typedef Marpa_Earley_Set_ID ESID;
698 /*:705*//*802:*/
699 #line 6881 "./marpa.w"
700 
701 struct s_source;
702 typedef struct s_source*SRC;
703 /*:802*//*804:*/
704 #line 6893 "./marpa.w"
705 
706 struct s_source_link;
707 typedef struct s_source_link*SRCL;
708 /*:804*//*1008:*/
709 #line 9290 "./marpa.w"
710 
711 typedef Marpa_Or_Node_ID ORID;
712 
713 /*:1008*//*1044:*/
714 #line 9785 "./marpa.w"
715 
716 typedef gint WHEID;
717 
718 
719 /*:1044*//*1072:*/
720 #line 10213 "./marpa.w"
721 
722 typedef Marpa_And_Node_ID ANDID;
723 
724 /*:1072*//*1182:*/
725 #line 11482 "./marpa.w"
726 
727 typedef Marpa_Fork_ID FORKID;
728 /*:1182*//*1203:*/
729 #line 11649 "./marpa.w"
730 
731 typedef Marpa_Event*EVE;
732 
733 /*:1203*//*1222:*/
734 #line 11939 "./marpa.w"
735 
736 typedef guint Bit_Vector_Word;
737 typedef Bit_Vector_Word*Bit_Vector;
738 /*:1222*//*1281:*/
739 #line 12426 "./marpa.w"
740 
741 typedef Bit_Vector_Word*Bit_Matrix;
742 
743 /*:1281*/
744 #line 13582 "./marpa.w"
745 
746 /*36:*/
747 #line 630 "./marpa.w"
748 
749 const guint marpa_major_version= MARPA_MAJOR_VERSION;
750 const guint marpa_minor_version= MARPA_MINOR_VERSION;
751 const guint marpa_micro_version= MARPA_MICRO_VERSION;
752 const guint marpa_interface_age= MARPA_INTERFACE_AGE;
753 const guint marpa_binary_age= MARPA_BINARY_AGE;
754 /*:36*//*50:*/
755 #line 712 "./marpa.w"
756 static gint next_grammar_id= 1;
757 /*:50*//*612:*/
758 #line 5419 "./marpa.w"
759 static gint next_recce_id= 1;
760 /*:612*//*1022:*/
761 #line 9408 "./marpa.w"
762 
763 static const gint dummy_or_node_type= DUMMY_OR_NODE;
764 static const OR dummy_or_node= (OR)&dummy_or_node_type;
765 
766 /*:1022*//*1223:*/
767 #line 11946 "./marpa.w"
768 
769 static const guint bv_wordbits= sizeof(Bit_Vector_Word)*8u;
770 static const guint bv_modmask= sizeof(Bit_Vector_Word)*8u-1u;
771 static const guint bv_hiddenwords= 3;
772 static const guint bv_lsb= 1u;
773 static const guint bv_msb= (1u<<(sizeof(Bit_Vector_Word)*8u-1u));
774 
775 /*:1223*/
776 #line 13583 "./marpa.w"
777 
778 /*1309:*/
779 #line 12668 "./marpa.w"
780 
781 struct s_dstack{gint t_count;gint t_capacity;gpointer t_base;};
782 /*:1309*/
783 #line 13584 "./marpa.w"
784 
785 /*41:*/
786 #line 673 "./marpa.w"
787 struct marpa_g{
788 /*54:*/
789 #line 725 "./marpa.w"
790 GArray*t_symbols;
791 /*:54*//*64:*/
792 #line 774 "./marpa.w"
793 GArray*t_rules;
794 /*:64*//*72:*/
795 #line 812 "./marpa.w"
796 gpointer t_default_value;
797 /*:72*//*107:*/
798 #line 962 "./marpa.w"
799 Bit_Vector t_bv_symid_is_terminal;
800 /*:107*//*110:*/
801 #line 976 "./marpa.w"
802 GHashTable*t_context;
803 /*:110*//*125:*/
804 #line 1075 "./marpa.w"
805 
806 struct obstack t_obs;
807 struct obstack t_obs_tricky;
808 /*:125*//*129:*/
809 #line 1097 "./marpa.w"
810 Marpa_Error_ID t_error;
811 /*:129*//*205:*/
812 #line 1470 "./marpa.w"
813 
814 Marpa_Symbol_Callback*t_symbol_callback;
815 gpointer t_symbol_callback_arg;
816 /*:205*//*313:*/
817 #line 2246 "./marpa.w"
818 
819 Marpa_Rule_Callback*t_rule_callback;
820 gpointer t_rule_callback_arg;
821 /*:313*//*449:*/
822 #line 3563 "./marpa.w"
823 
824 AIM t_AHFA_items;
825 AIM*t_AHFA_items_by_rule;
826 /*:449*//*505:*/
827 #line 4041 "./marpa.w"
828 struct s_AHFA_state*t_AHFA;
829 /*:505*//*1383:*/
830 #line 13310 "./marpa.w"
831 
832 Marpa_G_Message_Callback*t_message_callback;
833 gpointer t_message_callback_arg;
834 /*:1383*/
835 #line 674 "./marpa.w"
836 
837 /*48:*/
838 #line 710 "./marpa.w"
839 gint t_id;
840 /*:48*//*78:*/
841 #line 832 "./marpa.w"
842 Marpa_Symbol_ID t_start_symid;
843 /*:78*//*84:*/
844 #line 857 "./marpa.w"
845 
846 RULE t_null_start_rule;
847 RULE t_proper_start_rule;
848 /*:84*//*87:*/
849 #line 884 "./marpa.w"
850 int t_size;
851 /*:87*//*90:*/
852 #line 897 "./marpa.w"
853 gint t_max_rule_length;
854 /*:90*//*339:*/
855 #line 2344 "./marpa.w"
856 
857 gint t_symbol_instance_count;
858 /*:339*//*450:*/
859 #line 3569 "./marpa.w"
860 
861 guint t_aim_count;
862 /*:450*//*506:*/
863 #line 4044 "./marpa.w"
864 gint t_AHFA_len;
865 /*:506*/
866 #line 675 "./marpa.w"
867 
868 /*94:*/
869 #line 905 "./marpa.w"
870 guint t_is_precomputed:1;
871 /*:94*//*97:*/
872 #line 913 "./marpa.w"
873 guint t_has_loop:1;
874 /*:97*//*101:*/
875 #line 928 "./marpa.w"
876 guint t_is_lhs_terminal_ok:1;
877 /*:101*/
878 #line 676 "./marpa.w"
879 
880 };
881 typedef struct marpa_g GRAMMARD;
882 /*:41*//*137:*/
883 #line 1125 "./marpa.w"
884 
885 struct s_symbol{
886 /*146:*/
887 #line 1178 "./marpa.w"
888 GArray*t_lhs;
889 /*:146*//*153:*/
890 #line 1208 "./marpa.w"
891 GArray*t_rhs;
892 /*:153*//*192:*/
893 #line 1378 "./marpa.w"
894 
895 struct s_symbol*t_alias;
896 /*:192*/
897 #line 1127 "./marpa.w"
898 
899 /*144:*/
900 #line 1169 "./marpa.w"
901 SYMID t_symbol_id;
902 /*:144*/
903 #line 1128 "./marpa.w"
904 
905 /*160:*/
906 #line 1230 "./marpa.w"
907 guint t_is_accessible:1;
908 /*:160*//*164:*/
909 #line 1248 "./marpa.w"
910 guint t_is_counted:1;
911 /*:164*//*168:*/
912 #line 1266 "./marpa.w"
913 guint t_is_nullable:1;
914 /*:168*//*172:*/
915 #line 1285 "./marpa.w"
916 guint t_is_nulling:1;
917 /*:172*//*176:*/
918 #line 1305 "./marpa.w"
919 guint t_is_terminal:1;
920 /*:176*//*182:*/
921 #line 1331 "./marpa.w"
922 guint t_is_productive:1;
923 /*:182*//*186:*/
924 #line 1349 "./marpa.w"
925 guint t_is_start:1;
926 /*:186*//*191:*/
927 #line 1375 "./marpa.w"
928 
929 guint t_is_proper_alias:1;
930 guint t_is_nulling_alias:1;
931 /*:191*/
932 #line 1129 "./marpa.w"
933 
934 };
935 typedef struct s_symbol SYM_Object;
936 
937 /*:137*//*212:*/
938 #line 1502 "./marpa.w"
939 
940 struct s_rule{
941 /*241:*/
942 #line 1906 "./marpa.w"
943 gint t_rhs_length;
944 /*:241*//*258:*/
945 #line 1978 "./marpa.w"
946 Marpa_Rule_ID t_id;
947 /*:258*//*303:*/
948 #line 2209 "./marpa.w"
949 gint t_virtual_start;
950 /*:303*//*307:*/
951 #line 2225 "./marpa.w"
952 gint t_virtual_end;
953 /*:307*//*324:*/
954 #line 2282 "./marpa.w"
955 Marpa_Rule_ID t_original;
956 /*:324*//*329:*/
957 #line 2301 "./marpa.w"
958 gint t_real_symbol_count;
959 /*:329*//*340:*/
960 #line 2355 "./marpa.w"
961 
962 gint t_symbol_instance_base;
963 gint t_last_proper_symi;
964 /*:340*/
965 #line 1504 "./marpa.w"
966 
967 /*261:*/
968 #line 1990 "./marpa.w"
969 guint t_is_discard:1;
970 /*:261*//*275:*/
971 #line 2074 "./marpa.w"
972 guint t_is_loop:1;
973 /*:275*//*280:*/
974 #line 2095 "./marpa.w"
975 guint t_is_virtual_loop:1;
976 /*:280*//*287:*/
977 #line 2130 "./marpa.w"
978 guint t_is_used:1;
979 /*:287*//*291:*/
980 #line 2146 "./marpa.w"
981 guint t_is_start:1;
982 /*:291*//*295:*/
983 #line 2177 "./marpa.w"
984 guint t_is_virtual_lhs:1;
985 /*:295*//*299:*/
986 #line 2192 "./marpa.w"
987 guint t_is_virtual_rhs:1;
988 /*:299*//*333:*/
989 #line 2314 "./marpa.w"
990 guint t_is_semantic_equivalent:1;
991 /*:333*/
992 #line 1505 "./marpa.w"
993 
994 /*242:*/
995 #line 1909 "./marpa.w"
996 Marpa_Symbol_ID t_symbols[1];
997 
998 /*:242*/
999 #line 1506 "./marpa.w"
1000 
1001 };
1002 /*:212*//*446:*/
1003 #line 3540 "./marpa.w"
1004 
1005 struct s_AHFA_item{
1006 gint t_sort_key;
1007 /*456:*/
1008 #line 3595 "./marpa.w"
1009 
1010 RULE t_rule;
1011 
1012 /*:456*/
1013 #line 3543 "./marpa.w"
1014 
1015 /*457:*/
1016 #line 3601 "./marpa.w"
1017 
1018 gint t_position;
1019 
1020 /*:457*//*458:*/
1021 #line 3610 "./marpa.w"
1022 Marpa_Symbol_ID t_postdot;
1023 
1024 /*:458*//*459:*/
1025 #line 3619 "./marpa.w"
1026 
1027 gint t_leading_nulls;
1028 
1029 /*:459*/
1030 #line 3544 "./marpa.w"
1031 
1032 };
1033 /*:446*//*493:*/
1034 #line 3952 "./marpa.w"
1035 
1036 struct s_AHFA_state_key{
1037 Marpa_AHFA_State_ID t_id;
1038 };
1039 struct s_AHFA_state{
1040 struct s_AHFA_state_key t_key;
1041 struct s_AHFA_state*t_empty_transition;
1042 /*496:*/
1043 #line 3973 "./marpa.w"
1044 
1045 SYMID*t_complete_symbols;
1046 
1047 /*:496*//*498:*/
1048 #line 3983 "./marpa.w"
1049 
1050 AIM*t_items;
1051 /*:498*//*513:*/
1052 #line 4085 "./marpa.w"
1053 Marpa_Symbol_ID*t_postdot_symid_ary;
1054 /*:513*//*582:*/
1055 #line 5210 "./marpa.w"
1056 
1057 TRANS*t_transitions;
1058 /*:582*/
1059 #line 3959 "./marpa.w"
1060 
1061 /*495:*/
1062 #line 3971 "./marpa.w"
1063 
1064 guint t_complete_symbol_count;
1065 /*:495*//*499:*/
1066 #line 3985 "./marpa.w"
1067 
1068 guint t_item_count;
1069 /*:499*//*514:*/
1070 #line 4086 "./marpa.w"
1071 guint t_postdot_sym_count;
1072 
1073 /*:514*//*528:*/
1074 #line 4217 "./marpa.w"
1075 SYMID t_leo_lhs_sym;
1076 /*:528*/
1077 #line 3960 "./marpa.w"
1078 
1079 guint t_has_completed_start_rule:1;
1080 /*503:*/
1081 #line 4034 "./marpa.w"
1082 
1083 guint t_is_predict:1;
1084 
1085 /*:503*/
1086 #line 3962 "./marpa.w"
1087 
1088 };
1089 typedef struct s_AHFA_state AHFA_Object;
1090 
1091 /*:493*//*581:*/
1092 #line 5198 "./marpa.w"
1093 
1094 struct s_ur_transition{
1095 AHFA t_to_ahfa;
1096 gint t_completion_count;
1097 };
1098 struct s_transition{
1099 struct s_ur_transition t_ur;
1100 AEX t_leo_base_aex;
1101 AEX t_aex[1];
1102 };
1103 /*:581*//*707:*/
1104 #line 5906 "./marpa.w"
1105 
1106 struct s_earley_set_key{
1107 EARLEME t_earleme;
1108 };
1109 typedef struct s_earley_set_key ESK_Object;
1110 /*:707*//*708:*/
1111 #line 5911 "./marpa.w"
1112 
1113 struct s_earley_set{
1114 ESK_Object t_key;
1115 gint t_postdot_sym_count;
1116 /*709:*/
1117 #line 5923 "./marpa.w"
1118 
1119 gint t_eim_count;
1120 /*:709*//*711:*/
1121 #line 5937 "./marpa.w"
1122 
1123 gint t_ordinal;
1124 /*:711*/
1125 #line 5915 "./marpa.w"
1126 
1127 union u_postdot_item**t_postdot_ary;
1128 ES t_next_earley_set;
1129 /*710:*/
1130 #line 5926 "./marpa.w"
1131 
1132 EIM*t_earley_items;
1133 
1134 /*:710*//*1330:*/
1135 #line 12855 "./marpa.w"
1136 
1137 PSL t_dot_psl;
1138 /*:1330*/
1139 #line 5918 "./marpa.w"
1140 
1141 };
1142 
1143 /*:708*//*763:*/
1144 #line 6442 "./marpa.w"
1145 
1146 struct s_earley_ix{
1147 union u_postdot_item*t_next;
1148 SYMID t_postdot_symid;
1149 EIM t_earley_item;
1150 };
1151 typedef struct s_earley_ix EIX_Object;
1152 
1153 /*:763*//*766:*/
1154 #line 6483 "./marpa.w"
1155 
1156 struct s_leo_item{
1157 EIX_Object t_earley_ix;
1158 ES t_origin;
1159 AHFA t_top_ahfa;
1160 LIM t_predecessor;
1161 EIM t_base;
1162 ES t_set;
1163 gint t_chain_length;
1164 };
1165 typedef struct s_leo_item LIM_Object;
1166 
1167 /*:766*//*779:*/
1168 #line 6628 "./marpa.w"
1169 
1170 union u_postdot_item{
1171 LIM_Object t_leo;
1172 EIX_Object t_earley;
1173 };
1174 typedef union u_postdot_item*PIM;
1175 
1176 /*:779*//*871:*/
1177 #line 7655 "./marpa.w"
1178 
1179 struct s_token{
1180 gint t_type;
1181 SYMID t_symbol_id;
1182 gpointer t_value;
1183 };
1184 typedef struct s_token TOK_Object;
1185 
1186 /*:871*//*879:*/
1187 #line 7738 "./marpa.w"
1188 
1189 struct s_alternative{
1190 TOK t_token;
1191 ES t_start_earley_set;
1192 EARLEME t_end_earleme;
1193 };
1194 typedef struct s_alternative ALT_Object;
1195 
1196 /*:879*//*982:*/
1197 #line 8897 "./marpa.w"
1198 
1199 struct s_ur_node_stack{
1200 struct obstack t_obs;
1201 UR t_base;
1202 UR t_top;
1203 };
1204 struct s_ur_node{
1205 UR t_prev;
1206 UR t_next;
1207 EIM t_earley_item;
1208 AEX t_aex;
1209 };
1210 /*:982*//*1019:*/
1211 #line 9383 "./marpa.w"
1212 
1213 struct s_draft_or_node
1214 {
1215 /*1018:*/
1216 #line 9377 "./marpa.w"
1217 
1218 gint t_position;
1219 gint t_end_set_ordinal;
1220 RULE t_rule;
1221 gint t_start_set_ordinal;
1222 ORID t_id;
1223 /*:1018*/
1224 #line 9386 "./marpa.w"
1225 
1226 DAND t_draft_and_node;
1227 };
1228 /*:1019*//*1020:*/
1229 #line 9389 "./marpa.w"
1230 
1231 struct s_final_or_node
1232 {
1233 /*1018:*/
1234 #line 9377 "./marpa.w"
1235 
1236 gint t_position;
1237 gint t_end_set_ordinal;
1238 RULE t_rule;
1239 gint t_start_set_ordinal;
1240 ORID t_id;
1241 /*:1018*/
1242 #line 9392 "./marpa.w"
1243 
1244 gint t_first_and_node_id;
1245 gint t_and_node_count;
1246 };
1247 /*:1020*//*1021:*/
1248 #line 9400 "./marpa.w"
1249 
1250 union u_or_node{
1251 struct s_draft_or_node t_draft;
1252 struct s_final_or_node t_final;
1253 struct s_token t_token;
1254 };
1255 typedef union u_or_node OR_Object;
1256 
1257 /*:1021*//*1046:*/
1258 #line 9803 "./marpa.w"
1259 
1260 struct s_draft_and_node{
1261 DAND t_next;
1262 OR t_predecessor;
1263 OR t_cause;
1264 };
1265 typedef struct s_draft_and_node DAND_Object;
1266 
1267 /*:1046*//*1074:*/
1268 #line 10223 "./marpa.w"
1269 
1270 struct s_and_node{
1271 OR t_current;
1272 OR t_predecessor;
1273 OR t_cause;
1274 };
1275 typedef struct s_and_node AND_Object;
1276 
1277 /*:1074*//*1107:*/
1278 #line 10514 "./marpa.w"
1279 
1280 struct s_bocage_setup_per_es{
1281 OR**t_aexes_by_item;
1282 PSL t_or_psl;
1283 PSL t_and_psl;
1284 };
1285 /*:1107*//*1139:*/
1286 #line 10871 "./marpa.w"
1287 
1288 /*1184:*/
1289 #line 11496 "./marpa.w"
1290 
1291 struct s_fork{
1292 OR t_or_node;
1293 gint t_choice;
1294 FORKID t_parent;
1295 guint t_is_cause_ready:1;
1296 guint t_is_predecessor_ready:1;
1297 guint t_is_cause_of_parent:1;
1298 guint t_is_predecessor_of_parent:1;
1299 };
1300 typedef struct s_fork FORK_Object;
1301 
1302 /*:1184*/
1303 #line 10872 "./marpa.w"
1304 
1305 /*1205:*/
1306 #line 11685 "./marpa.w"
1307 
1308 struct s_value{
1309 DSTACK_DECLARE(t_virtual_stack);
1310 FORKID t_fork;
1311 gint t_tos;
1312 guint t_trace:1;
1313 guint t_active:1;
1314 };
1315 typedef struct s_value VAL_Object;
1316 
1317 /*:1205*/
1318 #line 10873 "./marpa.w"
1319 
1320 struct s_tree{
1321 FSTACK_DECLARE(t_fork_stack,FORK_Object)
1322 FSTACK_DECLARE(t_fork_worklist,gint)
1323 Bit_Vector t_and_node_in_use;
1324 gint t_parse_count;
1325 VAL_Object t_val;
1326 };
1327 typedef struct s_tree TREE_Object;
1328 
1329 /*:1139*//*1164:*/
1330 #line 11230 "./marpa.w"
1331 
1332 struct s_bocage_rank{
1333 struct obstack t_obs;
1334 Bit_Vector t_and_node_in_use;
1335 ANDID**t_and_node_orderings;
1336 TREE_Object t_tree;
1337 };
1338 typedef struct s_bocage_rank RANK_Object;
1339 
1340 /*:1164*//*1313:*/
1341 #line 12703 "./marpa.w"
1342 
1343 struct s_dqueue{gint t_current;struct s_dstack t_stack;};
1344 
1345 /*:1313*//*1320:*/
1346 #line 12771 "./marpa.w"
1347 
1348 struct s_per_earley_set_list{
1349 PSL t_prev;
1350 PSL t_next;
1351 PSL*t_owner;
1352 gpointer t_data[1];
1353 };
1354 typedef struct s_per_earley_set_list PSL_Object;
1355 /*:1320*//*1322:*/
1356 #line 12795 "./marpa.w"
1357 
1358 struct s_per_earley_set_arena{
1359 gint t_psl_length;
1360 PSL t_first_psl;
1361 PSL t_first_free_psl;
1362 };
1363 typedef struct s_per_earley_set_arena PSAR_Object;
1364 /*:1322*/
1365 #line 13585 "./marpa.w"
1366 
1367 /*604:*/
1368 #line 5362 "./marpa.w"
1369 
1370 struct marpa_r{
1371 /*617:*/
1372 #line 5431 "./marpa.w"
1373 const struct marpa_g*t_grammar;
1374 
1375 /*:617*//*624:*/
1376 #line 5473 "./marpa.w"
1377 
1378 ES t_first_earley_set;
1379 ES t_latest_earley_set;
1380 EARLEME t_current_earleme;
1381 /*:624*//*642:*/
1382 #line 5553 "./marpa.w"
1383 gpointer*t_sym_workarea;
1384 /*:642*//*646:*/
1385 #line 5568 "./marpa.w"
1386 gpointer*t_workarea2;
1387 /*:646*//*650:*/
1388 #line 5589 "./marpa.w"
1389 
1390 Bit_Vector t_bv_sym;
1391 Bit_Vector t_bv_sym2;
1392 Bit_Vector t_bv_sym3;
1393 /*:650*//*654:*/
1394 #line 5615 "./marpa.w"
1395 Bit_Vector t_bv_symid_is_expected;
1396 /*:654*//*679:*/
1397 #line 5779 "./marpa.w"
1398 GHashTable*t_context;
1399 /*:679*//*690:*/
1400 #line 5834 "./marpa.w"
1401 struct obstack t_obs;
1402 /*:690*//*694:*/
1403 #line 5848 "./marpa.w"
1404 
1405 Marpa_Error_ID t_error;
1406 Marpa_Error_ID t_fatal_error;
1407 /*:694*//*718:*/
1408 #line 5990 "./marpa.w"
1409 
1410 struct s_earley_set*t_trace_earley_set;
1411 /*:718*//*746:*/
1412 #line 6272 "./marpa.w"
1413 
1414 EIM t_trace_earley_item;
1415 /*:746*//*785:*/
1416 #line 6681 "./marpa.w"
1417 
1418 union u_postdot_item**t_trace_pim_sym_p;
1419 union u_postdot_item*t_trace_postdot_item;
1420 /*:785*//*827:*/
1421 #line 7166 "./marpa.w"
1422 
1423 SRC t_trace_source;
1424 SRCL t_trace_next_source_link;
1425 /*:827*//*872:*/
1426 #line 7679 "./marpa.w"
1427 
1428 struct obstack t_token_obs;
1429 TOK*t_tokens_by_symid;
1430 /*:872*//*880:*/
1431 #line 7746 "./marpa.w"
1432 
1433 DSTACK_DECLARE(t_alternatives);
1434 /*:880*//*906:*/
1435 #line 8049 "./marpa.w"
1436 DSTACK_DECLARE(t_eim_work_stack);
1437 /*:906*//*910:*/
1438 #line 8060 "./marpa.w"
1439 DSTACK_DECLARE(t_completion_stack);
1440 /*:910*//*914:*/
1441 #line 8071 "./marpa.w"
1442 DSTACK_DECLARE(t_earley_set_stack);
1443 /*:914*//*983:*/
1444 #line 8910 "./marpa.w"
1445 
1446 struct s_ur_node_stack t_ur_node_stack;
1447 /*:983*//*1096:*/
1448 #line 10432 "./marpa.w"
1449 
1450 BOC t_bocage;
1451 /*:1096*//*1323:*/
1452 #line 12803 "./marpa.w"
1453 
1454 PSAR_Object t_dot_psar_object;
1455 /*:1323*//*1391:*/
1456 #line 13347 "./marpa.w"
1457 
1458 Marpa_R_Message_Callback*t_message_callback;
1459 gpointer t_message_callback_arg;
1460 /*:1391*/
1461 #line 5364 "./marpa.w"
1462 
1463 /*610:*/
1464 #line 5417 "./marpa.w"
1465 gint t_id;
1466 /*:610*//*620:*/
1467 #line 5460 "./marpa.w"
1468 
1469 Marpa_Phase t_phase;
1470 /*:620*//*631:*/
1471 #line 5506 "./marpa.w"
1472 guint t_earley_item_warning_threshold;
1473 /*:631*//*637:*/
1474 #line 5534 "./marpa.w"
1475 EARLEME t_furthest_earleme;
1476 /*:637*//*712:*/
1477 #line 5941 "./marpa.w"
1478 
1479 gint t_earley_set_count;
1480 /*:712*/
1481 #line 5365 "./marpa.w"
1482 
1483 /*669:*/
1484 #line 5709 "./marpa.w"
1485 
1486 guint t_use_leo_flag:1;
1487 guint t_is_using_leo:1;
1488 /*:669*//*675:*/
1489 #line 5753 "./marpa.w"
1490 guint t_is_exhausted:1;
1491 /*:675*//*828:*/
1492 #line 7169 "./marpa.w"
1493 
1494 guint t_trace_source_type:3;
1495 /*:828*/
1496 #line 5366 "./marpa.w"
1497 
1498 };
1499 
1500 /*:604*/
1501 #line 13586 "./marpa.w"
1502 
1503 /*803:*/
1504 #line 6884 "./marpa.w"
1505 
1506 struct s_source{
1507 gpointer t_predecessor;
1508 union{
1509 gpointer t_completion;
1510 TOK t_token;
1511 }t_cause;
1512 };
1513 
1514 /*:803*//*805:*/
1515 #line 6896 "./marpa.w"
1516 
1517 struct s_source_link{
1518 SRCL t_next;
1519 struct s_source t_source;
1520 };
1521 
1522 /*:805*//*806:*/
1523 #line 6902 "./marpa.w"
1524 
1525 struct s_ambiguous_source{
1526 SRCL t_leo;
1527 SRCL t_token;
1528 SRCL t_completion;
1529 };
1530 
1531 /*:806*//*807:*/
1532 #line 6909 "./marpa.w"
1533 
1534 union u_source_container{
1535 struct s_ambiguous_source t_ambiguous;
1536 struct s_source t_unique;
1537 };
1538 
1539 /*:807*/
1540 #line 13587 "./marpa.w"
1541 
1542 /*736:*/
1543 #line 6136 "./marpa.w"
1544 
1545 struct s_earley_item_key{
1546 AHFA t_state;
1547 ES t_origin;
1548 ES t_set;
1549 };
1550 typedef struct s_earley_item_key EIK_Object;
1551 struct s_earley_item{
1552 EIK_Object t_key;
1553 union u_source_container t_container;
1554 gint t_ordinal;
1555 /*743:*/
1556 #line 6243 "./marpa.w"
1557 
1558 guint t_source_type:3;
1559 
1560 /*:743*/
1561 #line 6147 "./marpa.w"
1562 
1563 };
1564 typedef struct s_earley_item EIM_Object;
1565 
1566 /*:736*/
1567 #line 13588 "./marpa.w"
1568 
1569 /*1095:*/
1570 #line 10424 "./marpa.w"
1571 
1572 struct s_bocage{
1573 /*1023:*/
1574 #line 9418 "./marpa.w"
1575 
1576 OR*t_or_nodes;
1577 AND t_and_nodes;
1578 /*:1023*//*1098:*/
1579 #line 10440 "./marpa.w"
1580 
1581 struct obstack t_obs;
1582 /*:1098*//*1165:*/
1583 #line 11241 "./marpa.w"
1584 
1585 RANK_Object t_rank;
1586 /*:1165*/
1587 #line 10426 "./marpa.w"
1588 
1589 /*1024:*/
1590 #line 9421 "./marpa.w"
1591 
1592 gint t_or_node_count;
1593 gint t_and_node_count;
1594 ORID t_top_or_node_id;
1595 
1596 /*:1024*/
1597 #line 10427 "./marpa.w"
1598 
1599 /*1099:*/
1600 #line 10442 "./marpa.w"
1601 
1602 unsigned int is_obstack_initialized:1;
1603 /*:1099*/
1604 #line 10428 "./marpa.w"
1605 
1606 };
1607 typedef struct s_bocage BOC_Object;
1608 /*:1095*/
1609 #line 13589 "./marpa.w"
1610 
1611 /*63:*/
1612 #line 766 "./marpa.w"
1613 
1614 static inline gint symbol_is_valid(
1615 const struct marpa_g*g,const Marpa_Symbol_ID symid);
1616 
1617 /*:63*//*118:*/
1618 #line 1032 "./marpa.w"
1619 
1620 static inline
1621 void g_context_int_add(struct marpa_g*g,const gchar*key,gint value);
1622 /*:118*//*120:*/
1623 #line 1045 "./marpa.w"
1624 
1625 static inline
1626 void context_const_add(struct marpa_g*g,const gchar*key,const gchar*value);
1627 
1628 /*:120*//*122:*/
1629 #line 1054 "./marpa.w"
1630 
1631 static inline void g_context_clear(struct marpa_g*g);
1632 
1633 /*:122*//*138:*/
1634 #line 1133 "./marpa.w"
1635 
1636 static inline
1637 SYM symbol_new(struct marpa_g*g);
1638 /*:138*//*143:*/
1639 #line 1163 "./marpa.w"
1640 
1641 static inline void symbol_free(SYM symbol);
1642 
1643 /*:143*//*152:*/
1644 #line 1199 "./marpa.w"
1645 
1646 void
1647 marpa_symbol_lhs_add(struct marpa_g*g,Marpa_Symbol_ID symid,Marpa_Rule_ID rule_id);
1648 
1649 /*:152*//*159:*/
1650 #line 1226 "./marpa.w"
1651 static inline
1652 void symbol_rhs_add(SYM symbol,Marpa_Rule_ID rule_id);
1653 
1654 /*:159*//*189:*/
1655 #line 1362 "./marpa.w"
1656 
1657 static inline
1658 gint symbol_is_start(SYM symbol);
1659 /*:189*//*195:*/
1660 #line 1403 "./marpa.w"
1661 
1662 static inline SYM symbol_proper_alias(SYM symbol);
1663 /*:195*//*198:*/
1664 #line 1431 "./marpa.w"
1665 
1666 static inline SYM symbol_null_alias(SYM symbol);
1667 /*:198*//*201:*/
1668 #line 1442 "./marpa.w"
1669 
1670 static inline
1671 SYM symbol_alias_create(GRAMMAR g,SYM symbol);
1672 /*:201*//*210:*/
1673 #line 1495 "./marpa.w"
1674 
1675 static inline void symbol_callback(struct marpa_g*g,Marpa_Symbol_ID id);
1676 
1677 /*:210*//*216:*/
1678 #line 1521 "./marpa.w"
1679 
1680 PRIVATE_NOT_INLINE
1681 RULE rule_start(GRAMMAR g,
1682 SYMID lhs,SYMID*rhs,gint length);
1683 /*:216*//*234:*/
1684 #line 1751 "./marpa.w"
1685 
1686 static inline
1687 gboolean is_rule_duplicate(struct marpa_g*g,
1688 Marpa_Symbol_ID lhs_id,Marpa_Symbol_ID*rhs_ids,gint length);
1689 /*:234*//*246:*/
1690 #line 1931 "./marpa.w"
1691 
1692 static inline Marpa_Symbol_ID rule_lhs_get(RULE rule);
1693 /*:246*//*250:*/
1694 #line 1943 "./marpa.w"
1695 
1696 static inline Marpa_Symbol_ID*rule_rhs_get(RULE rule);
1697 /*:250*//*254:*/
1698 #line 1959 "./marpa.w"
1699 
1700 static inline gsize rule_length_get(RULE rule);
1701 /*:254*//*268:*/
1702 #line 2039 "./marpa.w"
1703 
1704 static inline gint rule_is_accessible(struct marpa_g*g,RULE rule);
1705 /*:268*//*272:*/
1706 #line 2063 "./marpa.w"
1707 
1708 static inline gint rule_is_productive(struct marpa_g*g,RULE rule);
1709 /*:272*//*286:*/
1710 #line 2125 "./marpa.w"
1711 
1712 static inline gint rule_is_nulling(GRAMMAR g,RULE rule);
1713 
1714 /*:286*//*321:*/
1715 #line 2268 "./marpa.w"
1716 
1717 static inline void rule_callback(struct marpa_g*g,Marpa_Rule_ID id);
1718 /*:321*//*342:*/
1719 #line 2360 "./marpa.w"
1720 
1721 static inline gint symbol_instance_of_ahfa_item_get(AIM aim);
1722 /*:342*//*349:*/
1723 #line 2478 "./marpa.w"
1724 
1725 static struct marpa_g*census(struct marpa_g*g);
1726 /*:349*//*386:*/
1727 #line 2829 "./marpa.w"
1728 
1729 static inline struct marpa_g*CHAF_rewrite(struct marpa_g*g);
1730 /*:386*//*425:*/
1731 #line 3202 "./marpa.w"
1732 
1733 static inline
1734 Marpa_Symbol_ID alias_by_id(struct marpa_g*g,Marpa_Symbol_ID proper_id);
1735 
1736 /*:425*//*428:*/
1737 #line 3223 "./marpa.w"
1738 
1739 static inline struct marpa_g*g_augment(struct marpa_g*g);
1740 
1741 /*:428*//*436:*/
1742 #line 3353 "./marpa.w"
1743 
1744 static inline
1745 void loop_detect(struct marpa_g*g);
1746 
1747 /*:436*//*455:*/
1748 #line 3587 "./marpa.w"
1749 
1750 static inline gboolean item_is_valid(
1751 GRAMMAR_Const g,AIMID item_id);
1752 
1753 /*:455*//*472:*/
1754 #line 3708 "./marpa.w"
1755 
1756 static inline void create_AHFA_items(struct marpa_g*g);
1757 
1758 /*:472*//*477:*/
1759 #line 3783 "./marpa.w"
1760 
1761 static gint cmp_by_aimid(gconstpointer a,
1762 gconstpointer b,gpointer user_data);
1763 /*:477*//*480:*/
1764 #line 3802 "./marpa.w"
1765 
1766 static gint cmp_by_postdot_and_aimid(gconstpointer a,
1767 gconstpointer b,gpointer user_data);
1768 /*:480*//*500:*/
1769 #line 3989 "./marpa.w"
1770 
1771 static inline AEX aex_of_ahfa_by_aim_get(AHFA ahfa,AIM aim_sought);
1772 /*:500*//*512:*/
1773 #line 4075 "./marpa.w"
1774 
1775 static inline gint AHFA_state_id_is_valid(
1776 const struct marpa_g*g,AHFAID AHFA_state_id);
1777 
1778 
1779 /*:512*//*532:*/
1780 #line 4248 "./marpa.w"
1781 
1782 static gint AHFA_state_cmp(gconstpointer a,gconstpointer b);
1783 /*:532*//*535:*/
1784 #line 4274 "./marpa.w"
1785 
1786 PRIVATE_NOT_INLINE void create_AHFA_states(struct marpa_g*g);
1787 /*:535*//*554:*/
1788 #line 4784 "./marpa.w"
1789 
1790 static inline AHFA assign_AHFA_state(
1791 AHFA state_p,GTree*duplicates);
1792 /*:554*//*567:*/
1793 #line 4981 "./marpa.w"
1794 static
1795 gint cmp_by_rule_sort_key(gconstpointer ap,
1796 gconstpointer bp,gpointer user_data);
1797 
1798 /*:567*//*570:*/
1799 #line 5038 "./marpa.w"
1800 
1801 static AHFA
1802 create_predicted_AHFA_state(
1803 struct marpa_g*g,
1804 Bit_Vector prediction_rule_vector,
1805 RULE*rule_by_sort_key,
1806 DQUEUE states_p,
1807 GTree*duplicates
1808 );
1809 /*:570*//*583:*/
1810 #line 5212 "./marpa.w"
1811 
1812 static inline AHFA to_ahfa_of_transition_get(TRANS transition);
1813 /*:583*//*585:*/
1814 #line 5219 "./marpa.w"
1815 
1816 static inline gint completion_count_of_transition_get(TRANS transition);
1817 /*:585*//*587:*/
1818 #line 5227 "./marpa.w"
1819 
1820 static inline
1821 URTRANS transition_new(struct obstack*obstack,AHFA to_ahfa,gint aim_ix);
1822 /*:587*//*589:*/
1823 #line 5240 "./marpa.w"
1824 static inline
1825 TRANS*transitions_new(struct marpa_g*g);
1826 /*:589*//*591:*/
1827 #line 5254 "./marpa.w"
1828 
1829 static inline
1830 void transition_add(struct obstack*obstack,AHFA from_ahfa,SYMID symid,AHFA to_ahfa);
1831 /*:591*//*593:*/
1832 #line 5271 "./marpa.w"
1833 
1834 static inline
1835 void completion_count_inc(struct obstack*obstack,AHFA from_ahfa,SYMID symid);
1836 /*:593*//*629:*/
1837 #line 5494 "./marpa.w"
1838 
1839 static inline ES current_es_of_r(RECCE r);
1840 /*:629*//*683:*/
1841 #line 5800 "./marpa.w"
1842 
1843 static inline
1844 void r_context_int_add(struct marpa_r*r,const gchar*key,gint value);
1845 /*:683*//*685:*/
1846 #line 5812 "./marpa.w"
1847 
1848 static inline
1849 void r_context_const_add(struct marpa_r*r,const gchar*key,const gchar*value);
1850 
1851 /*:685*//*687:*/
1852 #line 5821 "./marpa.w"
1853 
1854 static inline void r_context_clear(struct marpa_r*r);
1855 
1856 /*:687*//*714:*/
1857 #line 5947 "./marpa.w"
1858 
1859 static inline ES earley_set_new(RECCE r,EARLEME id);
1860 /*:714*//*737:*/
1861 #line 6157 "./marpa.w"
1862 
1863 static inline EIM earley_item_create(const RECCE r,
1864 const EIK_Object key);
1865 /*:737*//*739:*/
1866 #line 6179 "./marpa.w"
1867 
1868 static inline
1869 EIM earley_item_assign(const RECCE r,const ES set,const ES origin,const AHFA state);
1870 /*:739*//*744:*/
1871 #line 6246 "./marpa.w"
1872 
1873 static const char*invalid_source_type_message(guint type);
1874 /*:744*//*758:*/
1875 #line 6399 "./marpa.w"
1876 
1877 static inline void trace_earley_item_clear(struct marpa_r*r);
1878 /*:758*//*760:*/
1879 #line 6408 "./marpa.w"
1880 
1881 Marpa_Earley_Set_ID marpa_earley_item_origin(struct marpa_r*r);
1882 /*:760*//*768:*/
1883 #line 6500 "./marpa.w"
1884 
1885 Marpa_Symbol_ID marpa_leo_predecessor_symbol(struct marpa_r*r);
1886 /*:768*//*771:*/
1887 #line 6541 "./marpa.w"
1888 
1889 Marpa_AHFA_State_ID marpa_leo_base_state(struct marpa_r*r);
1890 /*:771*//*773:*/
1891 #line 6562 "./marpa.w"
1892 
1893 Marpa_AHFA_State_ID marpa_leo_expansion_ahfa(struct marpa_r*r);
1894 /*:773*//*781:*/
1895 #line 6644 "./marpa.w"
1896 
1897 static inline PIM*pim_sym_p_find(ES set,SYMID symid);
1898 /*:781*//*783:*/
1899 #line 6666 "./marpa.w"
1900 
1901 static inline PIM first_pim_of_es_by_symid(ES set,SYMID symid);
1902 /*:783*//*794:*/
1903 #line 6809 "./marpa.w"
1904 
1905 Marpa_AHFA_State_ID marpa_postdot_item_symbol(struct marpa_r*r);
1906 /*:794*//*811:*/
1907 #line 6949 "./marpa.w"
1908 static inline void
1909 token_link_add(struct marpa_r*r,
1910 EIM item,
1911 EIM predecessor,
1912 TOK token);
1913 /*:811*//*813:*/
1914 #line 6981 "./marpa.w"
1915 static inline void
1916 completion_link_add(struct marpa_r*r,
1917 EIM item,
1918 EIM predecessor,
1919 EIM cause);
1920 /*:813*//*820:*/
1921 #line 7088 "./marpa.w"
1922 static inline void
1923 leo_link_add(struct marpa_r*r,
1924 EIM item,
1925 LIM predecessor,
1926 EIM cause);
1927 
1928 /*:820*//*823:*/
1929 #line 7129 "./marpa.w"
1930 static
1931 void earley_item_ambiguate(struct marpa_r*r,EIM item);
1932 
1933 /*:823*//*853:*/
1934 #line 7424 "./marpa.w"
1935 
1936 static inline void trace_source_link_clear(struct marpa_r*r);
1937 /*:853*//*875:*/
1938 #line 7705 "./marpa.w"
1939 
1940 static inline
1941 TOK token_new(struct marpa_r*r,SYMID symbol_id,gpointer value);
1942 /*:875*//*883:*/
1943 #line 7761 "./marpa.w"
1944 
1945 static inline gint alternative_insertion_point(RECCE r,ALT new_alternative);
1946 /*:883*//*885:*/
1947 #line 7802 "./marpa.w"
1948 
1949 static inline gint alternative_cmp(const ALT_Const a,const ALT_Const b);
1950 /*:885*//*887:*/
1951 #line 7826 "./marpa.w"
1952 
1953 static inline ALT alternative_pop(RECCE r,EARLEME earleme);
1954 /*:887*//*889:*/
1955 #line 7843 "./marpa.w"
1956 
1957 static inline gint alternative_insert(RECCE r,ALT alternative);
1958 /*:889*//*932:*/
1959 #line 8297 "./marpa.w"
1960 
1961 static inline void earley_set_update_items(RECCE r,ES set);
1962 /*:932*//*934:*/
1963 #line 8321 "./marpa.w"
1964 
1965 static inline void r_update_earley_sets(RECCE r);
1966 /*:934*//*937:*/
1967 #line 8347 "./marpa.w"
1968 
1969 static void
1970 postdot_items_create(struct marpa_r*r,ES set);
1971 /*:937*//*986:*/
1972 #line 8921 "./marpa.w"
1973 
1974 static inline void ur_node_stack_init(URS stack);
1975 /*:986*//*988:*/
1976 #line 8931 "./marpa.w"
1977 
1978 static inline void ur_node_stack_reset(URS stack);
1979 /*:988*//*990:*/
1980 #line 8938 "./marpa.w"
1981 
1982 static inline void ur_node_stack_destroy(URS stack);
1983 /*:990*//*992:*/
1984 #line 8948 "./marpa.w"
1985 
1986 static inline UR ur_node_new(URS stack,UR prev);
1987 /*:992*//*994:*/
1988 #line 8959 "./marpa.w"
1989 
1990 static inline void ur_node_push(URS stack,EIM earley_item,AEX aex);
1991 /*:994*//*996:*/
1992 #line 8977 "./marpa.w"
1993 
1994 static inline UR ur_node_pop(URS stack);
1995 /*:996*//*1001:*/
1996 #line 9074 "./marpa.w"
1997 
1998 static inline gint psia_test_and_set(
1999 struct obstack*obs,
2000 struct s_bocage_setup_per_es*per_es_data,
2001 EIM earley_item,
2002 AEX ahfa_element_ix);
2003 /*:1001*//*1038:*/
2004 #line 9677 "./marpa.w"
2005 
2006 static inline AEX lim_base_data_get(LIM leo_item,EIM*p_base);
2007 /*:1038*//*1040:*/
2008 #line 9691 "./marpa.w"
2009 
2010 static inline AIM base_aim_of_lim(LIM leo_item);
2011 /*:1040*//*1047:*/
2012 #line 9811 "./marpa.w"
2013 
2014 static inline
2015 DAND draft_and_node_new(struct obstack*obs,OR predecessor,OR cause);
2016 /*:1047*//*1050:*/
2017 #line 9837 "./marpa.w"
2018 
2019 static inline
2020 void draft_and_node_add(struct obstack*obs,OR parent,OR predecessor,OR cause);
2021 /*:1050*//*1078:*/
2022 #line 10276 "./marpa.w"
2023 
2024 gint marpa_and_node_count(struct marpa_r*r);
2025 /*:1078*//*1081:*/
2026 #line 10314 "./marpa.w"
2027 
2028 gint marpa_and_node_parent(struct marpa_r*r,int and_node_id);
2029 /*:1081*//*1083:*/
2030 #line 10325 "./marpa.w"
2031 
2032 gint marpa_and_node_predecessor(struct marpa_r*r,int and_node_id);
2033 /*:1083*//*1085:*/
2034 #line 10341 "./marpa.w"
2035 
2036 gint marpa_and_node_cause(struct marpa_r*r,int and_node_id);
2037 /*:1085*//*1087:*/
2038 #line 10357 "./marpa.w"
2039 
2040 gint marpa_and_node_symbol(struct marpa_r*r,int and_node_id);
2041 /*:1087*//*1091:*/
2042 #line 10401 "./marpa.w"
2043 
2044 SYMID and_node_token(AND and_node,gpointer*value_p);
2045 /*:1091*//*1120:*/
2046 #line 10722 "./marpa.w"
2047 
2048 static inline void bocage_destroy(struct marpa_r*r);
2049 /*:1120*//*1124:*/
2050 #line 10765 "./marpa.w"
2051 
2052 gint marpa_or_node_set(struct marpa_r*r,int or_node_id);
2053 /*:1124*//*1126:*/
2054 #line 10776 "./marpa.w"
2055 
2056 gint marpa_or_node_origin(struct marpa_r*r,int or_node_id);
2057 /*:1126*//*1128:*/
2058 #line 10787 "./marpa.w"
2059 
2060 gint marpa_or_node_rule(struct marpa_r*r,int or_node_id);
2061 /*:1128*//*1130:*/
2062 #line 10798 "./marpa.w"
2063 
2064 gint marpa_or_node_position(struct marpa_r*r,int or_node_id);
2065 /*:1130*//*1132:*/
2066 #line 10809 "./marpa.w"
2067 
2068 gint marpa_or_node_first_and(struct marpa_r*r,int or_node_id);
2069 /*:1132*//*1134:*/
2070 #line 10820 "./marpa.w"
2071 
2072 gint marpa_or_node_last_and(struct marpa_r*r,int or_node_id);
2073 /*:1134*//*1136:*/
2074 #line 10832 "./marpa.w"
2075 
2076 gint marpa_or_node_and_count(struct marpa_r*r,int or_node_id);
2077 /*:1136*//*1140:*/
2078 #line 10883 "./marpa.w"
2079 
2080 static inline void tree_exhaust(TREE tree);
2081 /*:1140*//*1142:*/
2082 #line 10904 "./marpa.w"
2083 
2084 static inline void tree_safe(TREE tree);
2085 /*:1142*//*1146:*/
2086 #line 10962 "./marpa.w"
2087 
2088 static inline void tree_and_node_claim(TREE tree,ANDID and_node_id);
2089 static inline void tree_and_node_release(TREE tree,ANDID and_node_id);
2090 static inline gint tree_and_node_try(TREE tree,ANDID and_node_id);
2091 /*:1146*//*1153:*/
2092 #line 11117 "./marpa.w"
2093 
2094 static inline gint or_node_next_choice(BOC b,TREE tree,OR or_node,gint start_choice);
2095 /*:1153*//*1157:*/
2096 #line 11159 "./marpa.w"
2097 
2098 static inline void tree_destroy(TREE tree);
2099 /*:1157*//*1161:*/
2100 #line 11195 "./marpa.w"
2101 
2102 gint marpa_tree_size(struct marpa_r*r);
2103 /*:1161*//*1167:*/
2104 #line 11246 "./marpa.w"
2105 
2106 static inline void rank_safe(RANK rank);
2107 /*:1167*//*1170:*/
2108 #line 11258 "./marpa.w"
2109 
2110 static inline void rank_freeze(RANK rank);
2111 static inline void rank_destroy(RANK rank);
2112 /*:1170*//*1178:*/
2113 #line 11420 "./marpa.w"
2114 
2115 static inline ANDID and_order_get(BOC b,OR or_node,gint ix);
2116 /*:1178*//*1187:*/
2117 #line 11542 "./marpa.w"
2118 
2119 gint marpa_fork_or_node(struct marpa_r*r,int fork_id);
2120 /*:1187*//*1189:*/
2121 #line 11554 "./marpa.w"
2122 
2123 gint marpa_fork_choice(struct marpa_r*r,int fork_id);
2124 /*:1189*//*1191:*/
2125 #line 11574 "./marpa.w"
2126 
2127 gint marpa_fork_parent(struct marpa_r*r,int fork_id);
2128 /*:1191*//*1193:*/
2129 #line 11586 "./marpa.w"
2130 
2131 gint marpa_fork_cause_is_ready(struct marpa_r*r,int fork_id);
2132 /*:1193*//*1195:*/
2133 #line 11598 "./marpa.w"
2134 
2135 gint marpa_fork_predecessor_is_ready(struct marpa_r*r,int fork_id);
2136 /*:1195*//*1197:*/
2137 #line 11610 "./marpa.w"
2138 
2139 gint marpa_fork_is_cause(struct marpa_r*r,int fork_id);
2140 /*:1197*//*1199:*/
2141 #line 11622 "./marpa.w"
2142 
2143 gint marpa_fork_is_predecessor(struct marpa_r*r,int fork_id);
2144 /*:1199*//*1206:*/
2145 #line 11695 "./marpa.w"
2146 
2147 static inline void val_safe(VAL val);
2148 /*:1206*//*1212:*/
2149 #line 11777 "./marpa.w"
2150 
2151 static inline void val_destroy(VAL val);
2152 /*:1212*//*1225:*/
2153 #line 11959 "./marpa.w"
2154 
2155 static inline guint bv_bits_to_size(guint bits);
2156 /*:1225*//*1227:*/
2157 #line 11969 "./marpa.w"
2158 
2159 static inline guint bv_bits_to_unused_mask(guint bits);
2160 
2161 /*:1227*//*1228:*/
2162 #line 11973 "./marpa.w"
2163 
2164 static inline Bit_Vector bv_create(guint bits);
2165 /*:1228*//*1230:*/
2166 #line 11993 "./marpa.w"
2167 
2168 static inline Bit_Vector bv_obs_create(struct obstack*obs,guint bits);
2169 /*:1230*//*1233:*/
2170 #line 12026 "./marpa.w"
2171 
2172 static inline Bit_Vector bv_shadow(Bit_Vector bv);
2173 
2174 /*:1233*//*1235:*/
2175 #line 12045 "./marpa.w"
2176 
2177 static inline
2178 Bit_Vector bv_copy(Bit_Vector bv_to,Bit_Vector bv_from);
2179 
2180 /*:1235*//*1237:*/
2181 #line 12058 "./marpa.w"
2182 
2183 static inline
2184 Bit_Vector bv_clone(Bit_Vector bv);
2185 
2186 /*:1237*//*1239:*/
2187 #line 12068 "./marpa.w"
2188 
2189 static inline void bv_free(Bit_Vector vector);
2190 
2191 /*:1239*//*1241:*/
2192 #line 12076 "./marpa.w"
2193 
2194 static inline gint bv_bytes(Bit_Vector bv);
2195 
2196 /*:1241*//*1243:*/
2197 #line 12089 "./marpa.w"
2198 
2199 static inline void bv_fill(Bit_Vector bv);
2200 
2201 /*:1243*//*1245:*/
2202 #line 12093 "./marpa.w"
2203 
2204 static inline void bv_clear(Bit_Vector bv);
2205 /*:1245*//*1247:*/
2206 #line 12109 "./marpa.w"
2207 
2208 static inline void bv_over_clear(Bit_Vector bv,guint bit);
2209 /*:1247*//*1251:*/
2210 #line 12123 "./marpa.w"
2211 
2212 static inline void bv_bit_set(Bit_Vector vector,guint bit);
2213 
2214 /*:1251*//*1253:*/
2215 #line 12131 "./marpa.w"
2216 
2217 static inline void bv_bit_clear(Bit_Vector vector,guint bit);
2218 
2219 /*:1253*//*1255:*/
2220 #line 12139 "./marpa.w"
2221 
2222 static inline gboolean bv_bit_test(Bit_Vector vector,guint bit);
2223 
2224 /*:1255*//*1257:*/
2225 #line 12144 "./marpa.w"
2226 
2227 static inline gboolean bv_bit_test_and_set(Bit_Vector vector,guint bit);
2228 /*:1257*//*1261:*/
2229 #line 12172 "./marpa.w"
2230 
2231 static inline
2232 gboolean bv_is_empty(Bit_Vector addr);
2233 
2234 /*:1261*//*1263:*/
2235 #line 12185 "./marpa.w"
2236 
2237 static inline void bv_not(Bit_Vector X,Bit_Vector Y);
2238 
2239 /*:1263*//*1265:*/
2240 #line 12197 "./marpa.w"
2241 
2242 static inline void bv_and(Bit_Vector X,Bit_Vector Y,Bit_Vector Z);
2243 
2244 /*:1265*//*1267:*/
2245 #line 12209 "./marpa.w"
2246 
2247 static inline void bv_or(Bit_Vector X,Bit_Vector Y,Bit_Vector Z);
2248 
2249 /*:1267*//*1269:*/
2250 #line 12221 "./marpa.w"
2251 
2252 static inline void bv_or_assign(Bit_Vector X,Bit_Vector Y);
2253 
2254 /*:1269*//*1271:*/
2255 #line 12295 "./marpa.w"
2256 
2257 static inline
2258 gboolean bv_scan(
2259 Bit_Vector bv,guint start,guint*min,guint*max);
2260 
2261 /*:1271*//*1273:*/
2262 #line 12313 "./marpa.w"
2263 
2264 static inline guint bv_count(Bit_Vector v);
2265 
2266 /*:1273*//*1279:*/
2267 #line 12402 "./marpa.w"
2268 
2269 static void rhs_closure(struct marpa_g*g,Bit_Vector bv);
2270 
2271 /*:1279*//*1284:*/
2272 #line 12450 "./marpa.w"
2273 
2274 static inline Bit_Matrix matrix_create(guint rows,guint columns);
2275 
2276 /*:1284*//*1286:*/
2277 #line 12458 "./marpa.w"
2278 
2279 static inline void matrix_free(Bit_Matrix matrix);
2280 
2281 /*:1286*//*1288:*/
2282 #line 12472 "./marpa.w"
2283 
2284 static inline gint matrix_columns(Bit_Matrix matrix);
2285 
2286 /*:1288*//*1290:*/
2287 #line 12490 "./marpa.w"
2288 
2289 static inline Bit_Vector matrix_row(Bit_Matrix matrix,guint row);
2290 
2291 /*:1290*//*1293:*/
2292 #line 12499 "./marpa.w"
2293 
2294 static inline void matrix_bit_set(Bit_Matrix matrix,guint row,guint column);
2295 
2296 /*:1293*//*1296:*/
2297 #line 12508 "./marpa.w"
2298 
2299 static inline void matrix_bit_clear(Bit_Matrix matrix,guint row,guint column);
2300 
2301 /*:1296*//*1299:*/
2302 #line 12517 "./marpa.w"
2303 
2304 static inline gboolean matrix_bit_test(Bit_Matrix matrix,guint row,guint column);
2305 
2306 /*:1299*//*1301:*/
2307 #line 12570 "./marpa.w"
2308 
2309 static void transitive_closure(Bit_Matrix matrix);
2310 
2311 /*:1301*//*1311:*/
2312 #line 12676 "./marpa.w"
2313 
2314 static inline gpointer dstack_resize(struct s_dstack*this,gsize type_size);
2315 
2316 /*:1311*//*1326:*/
2317 #line 12809 "./marpa.w"
2318 
2319 static inline void psar_init(const PSAR psar,gint length);
2320 static inline void psar_destroy(const PSAR psar);
2321 static inline PSL psl_new(const PSAR psar);
2322 /*:1326*//*1332:*/
2323 #line 12867 "./marpa.w"
2324 
2325 static inline void psar_reset(const PSAR psar);
2326 /*:1332*//*1334:*/
2327 #line 12886 "./marpa.w"
2328 
2329 static inline void psar_dealloc(const PSAR psar);
2330 /*:1334*//*1336:*/
2331 #line 12907 "./marpa.w"
2332 
2333 static inline void psl_claim(
2334 PSL*const psl_owner,const PSAR psar);
2335 /*:1336*//*1340:*/
2336 #line 12933 "./marpa.w"
2337 
2338 static inline PSL psl_alloc(const PSAR psar);
2339 /*:1340*//*1376:*/
2340 #line 13235 "./marpa.w"
2341 
2342 static void r_error(struct marpa_r*r,Marpa_Message_ID message,guint flags);
2343 /*:1376*//*1388:*/
2344 #line 13337 "./marpa.w"
2345 
2346 static inline void grammar_message(struct marpa_g*g,Marpa_Message_ID id);
2347 
2348 /*:1388*//*1396:*/
2349 #line 13368 "./marpa.w"
2350 
2351 static inline void r_message(struct marpa_r*r,Marpa_Message_ID id);
2352 
2353 /*:1396*//*1398:*/
2354 #line 13411 "./marpa.w"
2355 
2356 #if MARPA_DEBUG
2357 PRIVATE_NOT_INLINE gchar*eim_tag_safe(gchar*buffer,EIM eim);
2358 PRIVATE_NOT_INLINE gchar*eim_tag(EIM eim);
2359 #endif
2360 /*:1398*//*1400:*/
2361 #line 13439 "./marpa.w"
2362 
2363 #if MARPA_DEBUG
2364 PRIVATE_NOT_INLINE gchar*lim_tag_safe(gchar*buffer,LIM lim);
2365 PRIVATE_NOT_INLINE gchar*lim_tag(LIM lim);
2366 #endif
2367 /*:1400*//*1402:*/
2368 #line 13469 "./marpa.w"
2369 
2370 #if MARPA_DEBUG
2371 PRIVATE_NOT_INLINE const gchar*or_tag_safe(gchar*buffer,OR or);
2372 PRIVATE_NOT_INLINE const gchar*or_tag(OR or);
2373 #endif
2374 /*:1402*//*1404:*/
2375 #line 13505 "./marpa.w"
2376 
2377 #if MARPA_DEBUG
2378 PRIVATE_NOT_INLINE const gchar*aim_tag_safe(gchar*buffer,AIM aim);
2379 PRIVATE_NOT_INLINE const gchar*aim_tag(AIM aim);
2380 #endif
2381 /*:1404*/
2382 #line 13590 "./marpa.w"
2383 
2384 /*61:*/
2385 #line 750 "./marpa.w"
2386 
2387 static inline
g_symbol_add(struct marpa_g * g,Marpa_Symbol_ID symid,SYM symbol)2388 void g_symbol_add(
2389 struct marpa_g*g,
2390 Marpa_Symbol_ID symid,
2391 SYM symbol)
2392 {
2393 g_array_insert_val(g->t_symbols,(unsigned)symid,symbol);
2394 }
2395 
2396 /*:61*//*70:*/
2397 #line 794 "./marpa.w"
2398 
2399 static inline
rule_add(struct marpa_g * g,RULEID rule_id,RULE rule)2400 void rule_add(
2401 struct marpa_g*g,
2402 RULEID rule_id,
2403 RULE rule)
2404 {
2405 g_array_insert_val(g->t_rules,(unsigned)rule_id,rule);
2406 LV_Size_of_G(g)+= 1+Length_of_RULE(rule);
2407 g->t_max_rule_length= MAX(Length_of_RULE(rule),g->t_max_rule_length);
2408 }
2409 
2410 /*:70*/
2411 #line 13591 "./marpa.w"
2412 
2413 /*37:*/
2414 #line 637 "./marpa.w"
2415 
marpa_version(int * version)2416 void marpa_version(int*version){
2417 version[0]= MARPA_MAJOR_VERSION;
2418 version[1]= MARPA_MINOR_VERSION,
2419 version[2]= MARPA_MICRO_VERSION;
2420 }
2421 /*:37*//*43:*/
2422 #line 683 "./marpa.w"
2423 
marpa_g_new(void)2424 struct marpa_g*marpa_g_new(void)
2425 {struct marpa_g*g= g_slice_new(struct marpa_g);
2426 /*51:*/
2427 #line 713 "./marpa.w"
2428 
2429 g->t_id= g_atomic_int_exchange_and_add(&next_grammar_id,1);
2430 /*:51*//*55:*/
2431 #line 726 "./marpa.w"
2432 
2433 g->t_symbols= g_array_new(FALSE,FALSE,sizeof(SYM));
2434 /*:55*//*65:*/
2435 #line 775 "./marpa.w"
2436 
2437 g->t_rules= g_array_new(FALSE,FALSE,sizeof(RULE));
2438 /*:65*//*73:*/
2439 #line 813 "./marpa.w"
2440 
2441 Default_Value_of_G(g)= NULL;
2442 /*:73*//*79:*/
2443 #line 833 "./marpa.w"
2444 
2445 g->t_start_symid= -1;
2446 /*:79*//*85:*/
2447 #line 860 "./marpa.w"
2448 
2449 g->t_null_start_rule= NULL;
2450 g->t_proper_start_rule= NULL;
2451 
2452 /*:85*//*88:*/
2453 #line 885 "./marpa.w"
2454 
2455 LV_Size_of_G(g)= 0;
2456 
2457 /*:88*//*91:*/
2458 #line 898 "./marpa.w"
2459 
2460 g->t_max_rule_length= 0;
2461 
2462 /*:91*//*95:*/
2463 #line 906 "./marpa.w"
2464 
2465 g->t_is_precomputed= FALSE;
2466 /*:95*//*98:*/
2467 #line 914 "./marpa.w"
2468 
2469 g->t_has_loop= FALSE;
2470 /*:98*//*102:*/
2471 #line 929 "./marpa.w"
2472 
2473 g->t_is_lhs_terminal_ok= TRUE;
2474 /*:102*//*108:*/
2475 #line 963 "./marpa.w"
2476 g->t_bv_symid_is_terminal= NULL;
2477 /*:108*//*111:*/
2478 #line 977 "./marpa.w"
2479 
2480 g->t_context= g_hash_table_new_full(g_str_hash,g_str_equal,NULL,g_free);
2481 /*:111*//*126:*/
2482 #line 1078 "./marpa.w"
2483 
2484 obstack_init(&g->t_obs);
2485 obstack_init(&g->t_obs_tricky);
2486 /*:126*//*130:*/
2487 #line 1098 "./marpa.w"
2488 
2489 g->t_error= NULL;
2490 /*:130*//*206:*/
2491 #line 1473 "./marpa.w"
2492 
2493 g->t_symbol_callback_arg= NULL;
2494 g->t_symbol_callback= NULL;
2495 /*:206*//*314:*/
2496 #line 2249 "./marpa.w"
2497 
2498 g->t_rule_callback_arg= NULL;
2499 g->t_rule_callback= NULL;
2500 /*:314*//*452:*/
2501 #line 3574 "./marpa.w"
2502 
2503 g->t_AHFA_items= NULL;
2504 g->t_AHFA_items_by_rule= NULL;
2505 /*:452*//*507:*/
2506 #line 4045 "./marpa.w"
2507 
2508 g->t_AHFA= NULL;
2509 AHFA_Count_of_G(g)= 0;
2510 /*:507*//*1384:*/
2511 #line 13313 "./marpa.w"
2512 
2513 g->t_message_callback_arg= NULL;
2514 g->t_message_callback= NULL;
2515 /*:1384*/
2516 #line 686 "./marpa.w"
2517 
2518 return g;}
2519 /*:43*//*45:*/
2520 #line 691 "./marpa.w"
2521 
marpa_g_free(struct marpa_g * g)2522 void marpa_g_free(struct marpa_g*g)
2523 {/*56:*/
2524 #line 728 "./marpa.w"
2525 
2526 {Marpa_Symbol_ID id;for(id= 0;id<(Marpa_Symbol_ID)g->t_symbols->len;id++)
2527 {symbol_free(SYM_by_ID(id));}}
2528 g_array_free(g->t_symbols,TRUE);
2529 
2530 /*:56*//*66:*/
2531 #line 777 "./marpa.w"
2532 
2533 g_array_free(g->t_rules,TRUE);
2534 
2535 /*:66*//*109:*/
2536 #line 964 "./marpa.w"
2537 
2538 if(g->t_bv_symid_is_terminal){bv_free(g->t_bv_symid_is_terminal);}
2539 
2540 /*:109*//*112:*/
2541 #line 979 "./marpa.w"
2542 g_hash_table_destroy(Context_of_G(g));
2543 
2544 /*:112*//*127:*/
2545 #line 1081 "./marpa.w"
2546 
2547 obstack_free(&g->t_obs,NULL);
2548 obstack_free(&g->t_obs_tricky,NULL);
2549 
2550 /*:127*//*453:*/
2551 #line 3577 "./marpa.w"
2552 
2553 if(g->t_AHFA_items){g_free(g->t_AHFA_items);};
2554 if(g->t_AHFA_items_by_rule){g_free(g->t_AHFA_items_by_rule);};
2555 
2556 /*:453*//*508:*/
2557 #line 4049 "./marpa.w"
2558 if(g->t_AHFA){
2559 AHFAID id;
2560 for(id= 0;id<AHFA_Count_of_G(g);id++){
2561 AHFA ahfa_state= AHFA_of_G_by_ID(g,id);
2562 /*509:*/
2563 #line 4059 "./marpa.w"
2564 {
2565 TRANS*ahfa_transitions= LV_TRANSs_of_AHFA(ahfa_state);
2566 if(ahfa_transitions)
2567 g_free(TRANSs_of_AHFA(ahfa_state));
2568 }
2569 
2570 /*:509*/
2571 #line 4053 "./marpa.w"
2572 
2573 }
2574 STOLEN_DQUEUE_DATA_FREE(g->t_AHFA);
2575 }
2576 
2577 /*:508*/
2578 #line 693 "./marpa.w"
2579 
2580 g_slice_free(struct marpa_g,g);
2581 }
2582 /*:45*//*52:*/
2583 #line 715 "./marpa.w"
2584 
marpa_grammar_id(struct marpa_g * g)2585 gint marpa_grammar_id(struct marpa_g*g){return g->t_id;}
2586 /*:52*//*57:*/
2587 #line 736 "./marpa.w"
2588 
marpa_g_symbols_peek(struct marpa_g * g)2589 GArray*marpa_g_symbols_peek(struct marpa_g*g)
2590 {return g->t_symbols;}
2591 /*:57*//*62:*/
2592 #line 761 "./marpa.w"
2593 
symbol_is_valid(const struct marpa_g * g,const Marpa_Symbol_ID symid)2594 static inline gint symbol_is_valid(
2595 const struct marpa_g*g,const Marpa_Symbol_ID symid){
2596 return symid>=0&&(guint)symid<g->t_symbols->len;
2597 }
2598 /*:62*//*67:*/
2599 #line 783 "./marpa.w"
2600 
marpa_g_rules_peek(struct marpa_g * g)2601 GArray*marpa_g_rules_peek(struct marpa_g*g)
2602 {return g->t_rules;}
2603 /*:67*//*75:*/
2604 #line 817 "./marpa.w"
2605 
marpa_default_value(struct marpa_g * g)2606 gpointer marpa_default_value(struct marpa_g*g)
2607 {return Default_Value_of_G(g);}
2608 /*:75*//*77:*/
2609 #line 822 "./marpa.w"
2610 
marpa_default_value_set(struct marpa_g * g,gpointer default_value)2611 gboolean marpa_default_value_set(struct marpa_g*g,gpointer default_value)
2612 {
2613 /*1355:*/
2614 #line 13083 "./marpa.w"
2615 const gboolean failure_indicator= FALSE;
2616 /*:1355*/
2617 #line 825 "./marpa.w"
2618 
2619 /*1358:*/
2620 #line 13093 "./marpa.w"
2621 
2622 if(G_is_Precomputed(g)){
2623 g_context_clear(g);
2624 g->t_error= "grammar precomputed";
2625 return failure_indicator;
2626 }
2627 /*:1358*/
2628 #line 826 "./marpa.w"
2629 
2630 Default_Value_of_G(g)= default_value;
2631 return TRUE;
2632 }
2633 
2634 /*:77*//*80:*/
2635 #line 835 "./marpa.w"
2636 
marpa_start_symbol(struct marpa_g * g)2637 Marpa_Symbol_ID marpa_start_symbol(struct marpa_g*g)
2638 {return g->t_start_symid;}
2639 /*:80*//*82:*/
2640 #line 842 "./marpa.w"
2641 
marpa_start_symbol_set(struct marpa_g * g,Marpa_Symbol_ID symid)2642 gboolean marpa_start_symbol_set(struct marpa_g*g,Marpa_Symbol_ID symid)
2643 {
2644 /*1355:*/
2645 #line 13083 "./marpa.w"
2646 const gboolean failure_indicator= FALSE;
2647 /*:1355*/
2648 #line 845 "./marpa.w"
2649 
2650 /*1358:*/
2651 #line 13093 "./marpa.w"
2652 
2653 if(G_is_Precomputed(g)){
2654 g_context_clear(g);
2655 g->t_error= "grammar precomputed";
2656 return failure_indicator;
2657 }
2658 /*:1358*/
2659 #line 846 "./marpa.w"
2660 
2661 /*1360:*/
2662 #line 13105 "./marpa.w"
2663 
2664 if(!symbol_is_valid(g,symid)){
2665 g_context_clear(g);
2666 g_context_int_add(g,"symid",symid);
2667 g->t_error= "invalid symbol id";
2668 return failure_indicator;
2669 }
2670 /*:1360*/
2671 #line 847 "./marpa.w"
2672 
2673 g->t_start_symid= symid;
2674 return TRUE;
2675 }
2676 /*:82*//*96:*/
2677 #line 908 "./marpa.w"
2678 
marpa_is_precomputed(const struct marpa_g * const g)2679 gboolean marpa_is_precomputed(const struct marpa_g*const g)
2680 {return G_is_Precomputed(g);}
2681 
2682 /*:96*//*99:*/
2683 #line 917 "./marpa.w"
2684 
marpa_has_loop(struct marpa_g * g)2685 gboolean marpa_has_loop(struct marpa_g*g)
2686 {return g->t_has_loop;}
2687 /*:99*//*103:*/
2688 #line 932 "./marpa.w"
2689 
marpa_is_lhs_terminal_ok(struct marpa_g * g)2690 gboolean marpa_is_lhs_terminal_ok(struct marpa_g*g)
2691 {return g->t_is_lhs_terminal_ok;}
2692 /*:103*//*105:*/
2693 #line 939 "./marpa.w"
2694 
marpa_is_lhs_terminal_ok_set(struct marpa_g * g,gboolean value)2695 gboolean marpa_is_lhs_terminal_ok_set(
2696 struct marpa_g*g,gboolean value)
2697 {
2698 if(G_is_Precomputed(g)){
2699 g->t_error= "precomputed";
2700 return FALSE;
2701 }
2702 g->t_is_lhs_terminal_ok= value;
2703 return TRUE;
2704 }
2705 /*:105*//*117:*/
2706 #line 1022 "./marpa.w"
2707 
2708 static inline
g_context_int_add(struct marpa_g * g,const gchar * key,gint payload)2709 void g_context_int_add(struct marpa_g*g,const gchar*key,gint payload)
2710 {
2711 struct marpa_context_int_value*value
2712 = g_new(struct marpa_context_int_value,1);
2713 value->t_type= MARPA_CONTEXT_INT;
2714 value->t_data= payload;
2715 g_hash_table_insert(Context_of_G(g),(gpointer)key,value);
2716 }
2717 /*:117*//*119:*/
2718 #line 1035 "./marpa.w"
2719 
2720 static inline
context_const_add(struct marpa_g * g,const gchar * key,const gchar * payload)2721 void context_const_add(struct marpa_g*g,const gchar*key,const gchar*payload)
2722 {
2723 struct marpa_context_const_value*value
2724 = g_new(struct marpa_context_const_value,1);
2725 value->t_type= MARPA_CONTEXT_CONST;
2726 value->t_data= payload;
2727 g_hash_table_insert(Context_of_G(g),(gpointer)key,value);
2728 }
2729 /*:119*//*121:*/
2730 #line 1051 "./marpa.w"
2731 
g_context_clear(struct marpa_g * g)2732 static inline void g_context_clear(struct marpa_g*g){
2733 g_hash_table_remove_all(Context_of_G(g));}
2734 /*:121*//*123:*/
2735 #line 1057 "./marpa.w"
2736 
marpa_g_context_value(struct marpa_g * g,const gchar * key)2737 union marpa_context_value*marpa_g_context_value(struct marpa_g*g,const gchar*key)
2738 {return g_hash_table_lookup(Context_of_G(g),key);}
2739 /*:123*//*132:*/
2740 #line 1106 "./marpa.w"
2741 
marpa_g_error(const struct marpa_g * g)2742 Marpa_Error_ID marpa_g_error(const struct marpa_g*g)
2743 {return g->t_error?g->t_error:"unknown error";}
2744 /*:132*//*139:*/
2745 #line 1136 "./marpa.w"
2746 
2747 static inline SYM
symbol_new(struct marpa_g * g)2748 symbol_new(struct marpa_g*g)
2749 {
2750 SYM symbol= g_malloc(sizeof(SYM_Object));
2751 /*145:*/
2752 #line 1170 "./marpa.w"
2753 LV_ID_of_SYM(symbol)= g->t_symbols->len;
2754 
2755 /*:145*//*147:*/
2756 #line 1179 "./marpa.w"
2757 
2758 symbol->t_lhs= g_array_new(FALSE,FALSE,sizeof(Marpa_Rule_ID));
2759 /*:147*//*154:*/
2760 #line 1209 "./marpa.w"
2761 
2762 symbol->t_rhs= g_array_new(FALSE,FALSE,sizeof(Marpa_Rule_ID));
2763 /*:154*//*161:*/
2764 #line 1231 "./marpa.w"
2765 
2766 symbol->t_is_accessible= FALSE;
2767 /*:161*//*165:*/
2768 #line 1249 "./marpa.w"
2769 
2770 symbol->t_is_counted= FALSE;
2771 /*:165*//*169:*/
2772 #line 1267 "./marpa.w"
2773 
2774 symbol->t_is_nullable= FALSE;
2775 /*:169*//*173:*/
2776 #line 1286 "./marpa.w"
2777 
2778 symbol->t_is_nulling= FALSE;
2779 /*:173*//*177:*/
2780 #line 1306 "./marpa.w"
2781 
2782 symbol->t_is_terminal= FALSE;
2783 /*:177*//*183:*/
2784 #line 1332 "./marpa.w"
2785 
2786 symbol->t_is_productive= FALSE;
2787 /*:183*//*187:*/
2788 #line 1350 "./marpa.w"
2789 symbol->t_is_start= FALSE;
2790 /*:187*//*193:*/
2791 #line 1380 "./marpa.w"
2792 
2793 symbol->t_is_proper_alias= FALSE;
2794 symbol->t_is_nulling_alias= FALSE;
2795 symbol->t_alias= NULL;
2796 
2797 /*:193*/
2798 #line 1141 "./marpa.w"
2799 
2800 {
2801 SYMID id= ID_of_SYM(symbol);
2802 g_symbol_add(g,id,symbol);
2803 }
2804 return symbol;
2805 }
2806 
2807 /*:139*//*141:*/
2808 #line 1151 "./marpa.w"
2809 
2810 Marpa_Symbol_ID
marpa_symbol_new(struct marpa_g * g)2811 marpa_symbol_new(struct marpa_g*g)
2812 {
2813 SYMID id= ID_of_SYM(symbol_new(g));
2814 symbol_callback(g,id);
2815 return id;
2816 }
2817 
2818 /*:141*//*142:*/
2819 #line 1160 "./marpa.w"
2820 
symbol_free(SYM symbol)2821 static inline void symbol_free(SYM symbol)
2822 {/*148:*/
2823 #line 1181 "./marpa.w"
2824 
2825 g_array_free(symbol->t_lhs,TRUE);
2826 /*:148*//*155:*/
2827 #line 1211 "./marpa.w"
2828 g_array_free(symbol->t_rhs,TRUE);
2829 
2830 /*:155*/
2831 #line 1162 "./marpa.w"
2832 g_free(symbol);}
2833 /*:142*//*149:*/
2834 #line 1186 "./marpa.w"
2835 
marpa_symbol_lhs_peek(struct marpa_g * g,Marpa_Symbol_ID symid)2836 GArray*marpa_symbol_lhs_peek(struct marpa_g*g,Marpa_Symbol_ID symid)
2837 {/*1356:*/
2838 #line 13085 "./marpa.w"
2839 const gpointer failure_indicator= NULL;
2840 /*:1356*/
2841 #line 1188 "./marpa.w"
2842 
2843 /*1360:*/
2844 #line 13105 "./marpa.w"
2845 
2846 if(!symbol_is_valid(g,symid)){
2847 g_context_clear(g);
2848 g_context_int_add(g,"symid",symid);
2849 g->t_error= "invalid symbol id";
2850 return failure_indicator;
2851 }
2852 /*:1360*/
2853 #line 1189 "./marpa.w"
2854 
2855 return SYM_by_ID(symid)->t_lhs;}
2856 /*:149*//*151:*/
2857 #line 1193 "./marpa.w"
2858 static inline
symbol_lhs_add(SYM symbol,Marpa_Rule_ID rule_id)2859 void symbol_lhs_add(SYM symbol,Marpa_Rule_ID rule_id)
2860 {g_array_append_val(symbol->t_lhs,rule_id);}
2861 void
marpa_symbol_lhs_add(struct marpa_g * g,Marpa_Symbol_ID symid,Marpa_Rule_ID rule_id)2862 marpa_symbol_lhs_add(struct marpa_g*g,Marpa_Symbol_ID symid,Marpa_Rule_ID rule_id)
2863 {symbol_lhs_add(SYM_by_ID(symid),rule_id);}
2864 /*:151*//*156:*/
2865 #line 1216 "./marpa.w"
2866 
marpa_symbol_rhs_peek(struct marpa_g * g,Marpa_Symbol_ID symid)2867 GArray*marpa_symbol_rhs_peek(struct marpa_g*g,Marpa_Symbol_ID symid)
2868 {/*1356:*/
2869 #line 13085 "./marpa.w"
2870 const gpointer failure_indicator= NULL;
2871 /*:1356*/
2872 #line 1218 "./marpa.w"
2873 
2874 /*1360:*/
2875 #line 13105 "./marpa.w"
2876 
2877 if(!symbol_is_valid(g,symid)){
2878 g_context_clear(g);
2879 g_context_int_add(g,"symid",symid);
2880 g->t_error= "invalid symbol id";
2881 return failure_indicator;
2882 }
2883 /*:1360*/
2884 #line 1219 "./marpa.w"
2885 
2886 return SYM_by_ID(symid)->t_rhs;}
2887 /*:156*//*158:*/
2888 #line 1223 "./marpa.w"
2889 static inline
symbol_rhs_add(SYM symbol,Marpa_Rule_ID rule_id)2890 void symbol_rhs_add(SYM symbol,Marpa_Rule_ID rule_id)
2891 {g_array_append_val(symbol->t_rhs,rule_id);}
2892 /*:158*//*162:*/
2893 #line 1241 "./marpa.w"
2894 
marpa_symbol_is_accessible(struct marpa_g * g,Marpa_Symbol_ID id)2895 gboolean marpa_symbol_is_accessible(struct marpa_g*g,Marpa_Symbol_ID id)
2896 {return SYM_by_ID(id)->t_is_accessible;}
2897 /*:162*//*166:*/
2898 #line 1259 "./marpa.w"
2899 
marpa_symbol_is_counted(struct marpa_g * g,Marpa_Symbol_ID id)2900 gboolean marpa_symbol_is_counted(struct marpa_g*g,Marpa_Symbol_ID id)
2901 {return SYM_by_ID(id)->t_is_counted;}
2902 /*:166*//*170:*/
2903 #line 1277 "./marpa.w"
2904 
marpa_symbol_is_nullable(struct marpa_g * g,Marpa_Symbol_ID id)2905 gboolean marpa_symbol_is_nullable(struct marpa_g*g,Marpa_Symbol_ID id)
2906 {return SYM_by_ID(id)->t_is_nullable;}
2907 /*:170*//*174:*/
2908 #line 1296 "./marpa.w"
2909 
marpa_symbol_is_nulling(struct marpa_g * g,Marpa_Symbol_ID symid)2910 gint marpa_symbol_is_nulling(struct marpa_g*g,Marpa_Symbol_ID symid)
2911 {/*1357:*/
2912 #line 13088 "./marpa.w"
2913 const int failure_indicator= -2;
2914 
2915 /*:1357*/
2916 #line 1298 "./marpa.w"
2917 
2918 /*1360:*/
2919 #line 13105 "./marpa.w"
2920 
2921 if(!symbol_is_valid(g,symid)){
2922 g_context_clear(g);
2923 g_context_int_add(g,"symid",symid);
2924 g->t_error= "invalid symbol id";
2925 return failure_indicator;
2926 }
2927 /*:1360*/
2928 #line 1299 "./marpa.w"
2929 
2930 return SYM_is_Nulling(SYM_by_ID(symid));}
2931 /*:174*//*178:*/
2932 #line 1318 "./marpa.w"
2933 
marpa_symbol_is_terminal(struct marpa_g * g,Marpa_Symbol_ID id)2934 gboolean marpa_symbol_is_terminal(struct marpa_g*g,Marpa_Symbol_ID id)
2935 {return SYMID_is_Terminal(id);}
2936 /*:178*//*180:*/
2937 #line 1323 "./marpa.w"
2938 
marpa_symbol_is_terminal_set(struct marpa_g * g,Marpa_Symbol_ID id,gboolean value)2939 void marpa_symbol_is_terminal_set(
2940 struct marpa_g*g,Marpa_Symbol_ID id,gboolean value)
2941 {SYMID_is_Terminal(id)= value;}
2942 /*:180*//*184:*/
2943 #line 1342 "./marpa.w"
2944 
marpa_symbol_is_productive(struct marpa_g * g,Marpa_Symbol_ID id)2945 gboolean marpa_symbol_is_productive(struct marpa_g*g,Marpa_Symbol_ID id)
2946 {return SYM_by_ID(id)->t_is_productive;}
2947 /*:184*//*188:*/
2948 #line 1353 "./marpa.w"
2949 
2950 static inline
symbol_is_start(SYM symbol)2951 gint symbol_is_start(SYM symbol)
2952 {return symbol->t_is_start;}
marpa_symbol_is_start(struct marpa_g * g,Marpa_Symbol_ID symid)2953 gint marpa_symbol_is_start(struct marpa_g*g,Marpa_Symbol_ID symid)
2954 {/*1357:*/
2955 #line 13088 "./marpa.w"
2956 const int failure_indicator= -2;
2957 
2958 /*:1357*/
2959 #line 1358 "./marpa.w"
2960 
2961 /*1360:*/
2962 #line 13105 "./marpa.w"
2963 
2964 if(!symbol_is_valid(g,symid)){
2965 g_context_clear(g);
2966 g_context_int_add(g,"symid",symid);
2967 g->t_error= "invalid symbol id";
2968 return failure_indicator;
2969 }
2970 /*:1360*/
2971 #line 1359 "./marpa.w"
2972 
2973 return symbol_is_start(SYM_by_ID(symid));
2974 }
2975 /*:188*//*194:*/
2976 #line 1389 "./marpa.w"
2977 
2978 static inline
symbol_proper_alias(SYM symbol)2979 SYM symbol_proper_alias(SYM symbol)
2980 {return symbol->t_is_nulling_alias?symbol->t_alias:NULL;}
marpa_symbol_proper_alias(struct marpa_g * g,Marpa_Symbol_ID symid)2981 Marpa_Symbol_ID marpa_symbol_proper_alias(struct marpa_g*g,Marpa_Symbol_ID symid)
2982 {
2983 SYM symbol;
2984 SYM proper_alias;
2985 /*1357:*/
2986 #line 13088 "./marpa.w"
2987 const int failure_indicator= -2;
2988 
2989 /*:1357*/
2990 #line 1397 "./marpa.w"
2991 
2992 /*1360:*/
2993 #line 13105 "./marpa.w"
2994 
2995 if(!symbol_is_valid(g,symid)){
2996 g_context_clear(g);
2997 g_context_int_add(g,"symid",symid);
2998 g->t_error= "invalid symbol id";
2999 return failure_indicator;
3000 }
3001 /*:1360*/
3002 #line 1398 "./marpa.w"
3003 
3004 symbol= SYM_by_ID(symid);
3005 proper_alias= symbol_proper_alias(symbol);
3006 return proper_alias==NULL?-1:ID_of_SYM(proper_alias);
3007 }
3008 /*:194*//*197:*/
3009 #line 1412 "./marpa.w"
3010 
3011 static inline
symbol_null_alias(SYM symbol)3012 SYM symbol_null_alias(SYM symbol)
3013 {return symbol->t_is_proper_alias?symbol->t_alias:NULL;}
marpa_symbol_null_alias(struct marpa_g * g,Marpa_Symbol_ID symid)3014 Marpa_Symbol_ID marpa_symbol_null_alias(struct marpa_g*g,Marpa_Symbol_ID symid)
3015 {
3016 SYM symbol;
3017 SYM alias;
3018 /*1357:*/
3019 #line 13088 "./marpa.w"
3020 const int failure_indicator= -2;
3021 
3022 /*:1357*/
3023 #line 1420 "./marpa.w"
3024 
3025 /*1360:*/
3026 #line 13105 "./marpa.w"
3027 
3028 if(!symbol_is_valid(g,symid)){
3029 g_context_clear(g);
3030 g_context_int_add(g,"symid",symid);
3031 g->t_error= "invalid symbol id";
3032 return failure_indicator;
3033 }
3034 /*:1360*/
3035 #line 1421 "./marpa.w"
3036 
3037 symbol= SYM_by_ID(symid);
3038 alias= symbol_null_alias(symbol);
3039 if(alias==NULL){
3040 g_context_int_add(g,"symid",symid);
3041 g->t_error= "no alias";
3042 return-1;
3043 }
3044 return ID_of_SYM(alias);
3045 }
3046 /*:197*//*202:*/
3047 #line 1445 "./marpa.w"
3048 static inline
symbol_alias_create(GRAMMAR g,SYM symbol)3049 SYM symbol_alias_create(GRAMMAR g,SYM symbol)
3050 {
3051 SYM alias= symbol_new(g);
3052 symbol->t_is_proper_alias= TRUE;
3053 SYM_is_Nulling(symbol)= FALSE;
3054 symbol->t_is_nullable= FALSE;
3055 symbol->t_alias= alias;
3056 alias->t_is_nulling_alias= TRUE;
3057 SYM_is_Nulling(alias)= TRUE;
3058 alias->t_is_nullable= TRUE;
3059 alias->t_is_productive= TRUE;
3060 alias->t_is_accessible= symbol->t_is_accessible;
3061 alias->t_alias= symbol;
3062 return alias;
3063 }
3064 
3065 /*:202*//*207:*/
3066 #line 1476 "./marpa.w"
3067 
marpa_symbol_callback_set(struct marpa_g * g,Marpa_Symbol_Callback * cb)3068 void marpa_symbol_callback_set(struct marpa_g*g,Marpa_Symbol_Callback*cb)
3069 {g->t_symbol_callback= cb;}
marpa_symbol_callback_arg_set(struct marpa_g * g,gpointer cb_arg)3070 void marpa_symbol_callback_arg_set(struct marpa_g*g,gpointer cb_arg)
3071 {g->t_symbol_callback_arg= cb_arg;}
marpa_symbol_callback_arg(struct marpa_g * g)3072 gpointer marpa_symbol_callback_arg(struct marpa_g*g)
3073 {return g->t_symbol_callback_arg;}
3074 /*:207*//*209:*/
3075 #line 1491 "./marpa.w"
3076 
symbol_callback(struct marpa_g * g,Marpa_Symbol_ID id)3077 static inline void symbol_callback(struct marpa_g*g,Marpa_Symbol_ID id)
3078 {Marpa_Symbol_Callback*cb= g->t_symbol_callback;
3079 if(cb){(*cb)(g,id);}}
3080 /*:209*//*217:*/
3081 #line 1527 "./marpa.w"
3082 
3083 PRIVATE_NOT_INLINE
rule_start(GRAMMAR g,SYMID lhs,SYMID * rhs,gint length)3084 RULE rule_start(GRAMMAR g,
3085 SYMID lhs,SYMID*rhs,gint length)
3086 {
3087 /*1356:*/
3088 #line 13085 "./marpa.w"
3089 const gpointer failure_indicator= NULL;
3090 /*:1356*/
3091 #line 1532 "./marpa.w"
3092 
3093 RULE rule;
3094 const gint rule_sizeof= G_STRUCT_OFFSET(struct s_rule,t_symbols)+
3095 (length+1)*sizeof(rule->t_symbols[0]);
3096 /*243:*/
3097 #line 1911 "./marpa.w"
3098 
3099 {
3100 SYMID symid= lhs;
3101 /*1360:*/
3102 #line 13105 "./marpa.w"
3103 
3104 if(!symbol_is_valid(g,symid)){
3105 g_context_clear(g);
3106 g_context_int_add(g,"symid",symid);
3107 g->t_error= "invalid symbol id";
3108 return failure_indicator;
3109 }
3110 /*:1360*/
3111 #line 1914 "./marpa.w"
3112 
3113 }
3114 {gint rh_index;
3115 for(rh_index= 0;rh_index<length;rh_index++){
3116 SYMID symid= rhs[rh_index];
3117 /*1360:*/
3118 #line 13105 "./marpa.w"
3119 
3120 if(!symbol_is_valid(g,symid)){
3121 g_context_clear(g);
3122 g_context_int_add(g,"symid",symid);
3123 g->t_error= "invalid symbol id";
3124 return failure_indicator;
3125 }
3126 /*:1360*/
3127 #line 1919 "./marpa.w"
3128 
3129 }
3130 }
3131 
3132 /*:243*/
3133 #line 1536 "./marpa.w"
3134 
3135 rule= obstack_alloc(&g->t_obs,rule_sizeof);
3136 /*244:*/
3137 #line 1923 "./marpa.w"
3138 
3139 Length_of_RULE(rule)= length;
3140 rule->t_symbols[0]= lhs;
3141 {gint i;for(i= 0;i<length;i++){
3142 rule->t_symbols[i+1]= rhs[i];}}
3143 /*:244*/
3144 #line 1538 "./marpa.w"
3145 
3146 /*259:*/
3147 #line 1979 "./marpa.w"
3148 rule->t_id= g->t_rules->len;
3149 
3150 /*:259*//*262:*/
3151 #line 1991 "./marpa.w"
3152 
3153 rule->t_is_discard= FALSE;
3154 /*:262*//*276:*/
3155 #line 2075 "./marpa.w"
3156 
3157 rule->t_is_loop= FALSE;
3158 /*:276*//*281:*/
3159 #line 2096 "./marpa.w"
3160 
3161 rule->t_is_virtual_loop= FALSE;
3162 /*:281*//*288:*/
3163 #line 2131 "./marpa.w"
3164 
3165 RULE_is_Used(rule)= 1;
3166 /*:288*//*292:*/
3167 #line 2147 "./marpa.w"
3168 
3169 rule->t_is_start= FALSE;
3170 /*:292*//*296:*/
3171 #line 2178 "./marpa.w"
3172 
3173 RULE_is_Virtual_LHS(rule)= FALSE;
3174 /*:296*//*300:*/
3175 #line 2193 "./marpa.w"
3176 
3177 RULE_is_Virtual_RHS(rule)= FALSE;
3178 /*:300*//*304:*/
3179 #line 2210 "./marpa.w"
3180 rule->t_virtual_start= -1;
3181 /*:304*//*308:*/
3182 #line 2226 "./marpa.w"
3183 rule->t_virtual_end= -1;
3184 /*:308*//*325:*/
3185 #line 2283 "./marpa.w"
3186 rule->t_original= -1;
3187 /*:325*//*330:*/
3188 #line 2302 "./marpa.w"
3189 Real_SYM_Count_of_RULE(rule)= 0;
3190 /*:330*//*334:*/
3191 #line 2315 "./marpa.w"
3192 
3193 rule->t_is_semantic_equivalent= FALSE;
3194 /*:334*//*341:*/
3195 #line 2358 "./marpa.w"
3196 
3197 Last_Proper_SYMI_of_RULE(rule)= -1;
3198 /*:341*/
3199 #line 1539 "./marpa.w"
3200 
3201 rule_add(g,rule->t_id,rule);
3202 /*236:*/
3203 #line 1789 "./marpa.w"
3204 
3205 symbol_lhs_add(SYM_by_ID(rule->t_symbols[0]),rule->t_id);
3206 if(Length_of_RULE(rule)> 0){
3207 gint rh_list_ix;
3208 const guint alloc_size= Length_of_RULE(rule)*sizeof(SYMID);
3209 Marpa_Symbol_ID*rh_symbol_list= g_slice_alloc(alloc_size);
3210 gint rh_symbol_list_length= 1;
3211 /*240:*/
3212 #line 1856 "./marpa.w"
3213 
3214 {
3215 
3216 gint rhs_ix= Length_of_RULE(rule)-1;
3217 rh_symbol_list[0]= RHS_ID_of_RULE(rule,(unsigned)rhs_ix);
3218 rh_symbol_list_length= 1;
3219 rhs_ix--;
3220 for(;rhs_ix>=0;rhs_ix--){
3221 gint higher_ix;
3222 Marpa_Symbol_ID new_symid= RHS_ID_of_RULE(rule,(unsigned)rhs_ix);
3223 gint next_highest_ix= rh_symbol_list_length-1;
3224 while(next_highest_ix>=0){
3225 Marpa_Symbol_ID current_symid= rh_symbol_list[next_highest_ix];
3226 if(current_symid==new_symid)goto ignore_this_symbol;
3227 if(current_symid<new_symid)break;
3228 next_highest_ix--;
3229 }
3230 
3231 for(higher_ix= rh_symbol_list_length-1;
3232 higher_ix> next_highest_ix;
3233 higher_ix--){
3234 rh_symbol_list[higher_ix+1]= rh_symbol_list[higher_ix];
3235 }
3236 
3237 rh_symbol_list[next_highest_ix+1]= new_symid;
3238 rh_symbol_list_length++;
3239 ignore_this_symbol:;
3240 }
3241 }
3242 
3243 /*:240*/
3244 #line 1797 "./marpa.w"
3245 
3246 for(rh_list_ix= 0;
3247 rh_list_ix<rh_symbol_list_length;
3248 rh_list_ix++){
3249 symbol_rhs_add(
3250 SYM_by_ID(rh_symbol_list[rh_list_ix]),
3251 rule->t_id);
3252 }
3253 g_slice_free1(alloc_size,rh_symbol_list);
3254 }
3255 
3256 /*:236*/
3257 #line 1541 "./marpa.w"
3258 
3259 return rule;
3260 }
3261 
3262 /*:217*//*219:*/
3263 #line 1548 "./marpa.w"
3264 
marpa_rule_new(struct marpa_g * g,Marpa_Symbol_ID lhs,Marpa_Symbol_ID * rhs,gint length)3265 Marpa_Rule_ID marpa_rule_new(struct marpa_g*g,
3266 Marpa_Symbol_ID lhs,Marpa_Symbol_ID*rhs,gint length)
3267 {
3268 Marpa_Rule_ID rule_id;
3269 RULE rule;
3270 if(length> MAX_RHS_LENGTH){
3271 g->t_error= (Marpa_Error_ID)"rhs too long";
3272 return-1;
3273 }
3274 if(is_rule_duplicate(g,lhs,rhs,length)==TRUE){
3275 g->t_error= (Marpa_Error_ID)"duplicate rule";
3276 return-1;
3277 }
3278 rule= rule_start(g,lhs,rhs,length);
3279 if(!rule){return-1;}
3280 rule_id= rule->t_id;
3281 rule_callback(g,rule_id);
3282 return rule_id;
3283 }
3284 
3285 /*:219*//*221:*/
3286 #line 1573 "./marpa.w"
3287 
marpa_sequence_new(struct marpa_g * g,Marpa_Symbol_ID lhs_id,Marpa_Symbol_ID rhs_id,Marpa_Symbol_ID separator_id,gint min,gint flags)3288 Marpa_Rule_ID marpa_sequence_new(struct marpa_g*g,
3289 Marpa_Symbol_ID lhs_id,Marpa_Symbol_ID rhs_id,Marpa_Symbol_ID separator_id,
3290 gint min,gint flags)
3291 {
3292 /*1357:*/
3293 #line 13088 "./marpa.w"
3294 const int failure_indicator= -2;
3295 
3296 /*:1357*/
3297 #line 1578 "./marpa.w"
3298 
3299 Marpa_Rule_ID original_rule_id;
3300 RULE original_rule;
3301 Marpa_Symbol_ID internal_lhs_id,*temp_rhs;
3302 if(is_rule_duplicate(g,lhs_id,&rhs_id,1)==TRUE){
3303 g_context_clear(g);
3304 g->t_error= (Marpa_Error_ID)"duplicate rule";
3305 return failure_indicator;
3306 }
3307 
3308 /*222:*/
3309 #line 1605 "./marpa.w"
3310 
3311 original_rule= rule_start(g,lhs_id,&rhs_id,1);
3312 if(!original_rule){
3313 g_context_clear(g);
3314 g->t_error= "internal_error";
3315 return failure_indicator;
3316 }
3317 RULE_is_Used(original_rule)= 0;
3318 original_rule_id= original_rule->t_id;
3319 original_rule->t_is_discard= !(flags&MARPA_KEEP_SEPARATION)
3320 &&separator_id>=0;
3321 rule_callback(g,original_rule_id);
3322 
3323 /*:222*/
3324 #line 1588 "./marpa.w"
3325 
3326 /*223:*/
3327 #line 1618 "./marpa.w"
3328 
3329 if(separator_id!=-1&&!symbol_is_valid(g,separator_id)){
3330 g_context_clear(g);
3331 g_context_int_add(g,"symid",separator_id);
3332 g->t_error= "bad separator";
3333 return failure_indicator;
3334 }
3335 
3336 /*:223*/
3337 #line 1589 "./marpa.w"
3338 
3339 /*224:*/
3340 #line 1626 "./marpa.w"
3341 
3342 SYM_by_ID(rhs_id)->t_is_counted= 1;
3343 if(separator_id>=0){SYM_by_ID(separator_id)->t_is_counted= 1;}
3344 /*:224*/
3345 #line 1590 "./marpa.w"
3346 
3347 if(min==0){/*225:*/
3348 #line 1629 "./marpa.w"
3349 
3350 {RULE rule= rule_start(g,lhs_id,0,0);
3351 if(!rule){/*1365:*/
3352 #line 13140 "./marpa.w"
3353 {
3354 g_context_clear(g);
3355 g->t_error= "internal error";
3356 return failure_indicator;
3357 }
3358 
3359 /*:1365*/
3360 #line 1631 "./marpa.w"
3361 }
3362 rule->t_is_semantic_equivalent= TRUE;
3363 rule->t_original= original_rule_id;
3364 rule_callback(g,rule->t_id);
3365 }
3366 /*:225*/
3367 #line 1591 "./marpa.w"
3368 }
3369 min= 1;
3370 /*226:*/
3371 #line 1636 "./marpa.w"
3372 
3373 internal_lhs_id= ID_of_SYM(symbol_new(g));
3374 symbol_callback(g,internal_lhs_id);
3375 /*:226*/
3376 #line 1593 "./marpa.w"
3377 
3378 /*227:*/
3379 #line 1650 "./marpa.w"
3380 
3381 temp_rhs= g_new(Marpa_Symbol_ID,(3+(separator_id<0?1:2)*min));
3382 /*:227*/
3383 #line 1594 "./marpa.w"
3384 
3385 /*229:*/
3386 #line 1653 "./marpa.w"
3387 
3388 {RULE rule;
3389 temp_rhs[0]= internal_lhs_id;
3390 rule= rule_start(g,lhs_id,temp_rhs,1);
3391 if(!rule){/*1365:*/
3392 #line 13140 "./marpa.w"
3393 {
3394 g_context_clear(g);
3395 g->t_error= "internal error";
3396 return failure_indicator;
3397 }
3398 
3399 /*:1365*/
3400 #line 1657 "./marpa.w"
3401 }
3402 rule->t_original= original_rule_id;
3403 rule->t_is_semantic_equivalent= TRUE;
3404 
3405 RULE_is_Virtual_RHS(rule)= TRUE;
3406 rule_callback(g,rule->t_id);
3407 }
3408 /*:229*/
3409 #line 1595 "./marpa.w"
3410 
3411 if(separator_id>=0&&!(flags&MARPA_PROPER_SEPARATION)){
3412 /*230:*/
3413 #line 1665 "./marpa.w"
3414 
3415 {RULE rule;
3416 temp_rhs[0]= internal_lhs_id;
3417 temp_rhs[1]= separator_id;
3418 rule= rule_start(g,lhs_id,temp_rhs,2);
3419 if(!rule){/*1365:*/
3420 #line 13140 "./marpa.w"
3421 {
3422 g_context_clear(g);
3423 g->t_error= "internal error";
3424 return failure_indicator;
3425 }
3426 
3427 /*:1365*/
3428 #line 1670 "./marpa.w"
3429 }
3430 rule->t_original= original_rule_id;
3431 rule->t_is_semantic_equivalent= TRUE;
3432 RULE_is_Virtual_RHS(rule)= TRUE;
3433 Real_SYM_Count_of_RULE(rule)= 1;
3434 rule_callback(g,rule->t_id);
3435 }
3436 /*:230*/
3437 #line 1597 "./marpa.w"
3438 
3439 }
3440 /*231:*/
3441 #line 1680 "./marpa.w"
3442 
3443 {RULE rule;
3444 gint rhs_ix,i;
3445 temp_rhs[0]= rhs_id;
3446 rhs_ix= 1;
3447 for(i= 0;i<min-1;i++){
3448 if(separator_id>=0)temp_rhs[rhs_ix++]= separator_id;
3449 temp_rhs[rhs_ix++]= rhs_id;
3450 }
3451 rule= rule_start(g,internal_lhs_id,temp_rhs,rhs_ix);
3452 if(!rule){/*1365:*/
3453 #line 13140 "./marpa.w"
3454 {
3455 g_context_clear(g);
3456 g->t_error= "internal error";
3457 return failure_indicator;
3458 }
3459 
3460 /*:1365*/
3461 #line 1690 "./marpa.w"
3462 }
3463 RULE_is_Virtual_LHS(rule)= 1;
3464 Real_SYM_Count_of_RULE(rule)= rhs_ix;
3465 rule_callback(g,rule->t_id);
3466 }
3467 /*:231*/
3468 #line 1599 "./marpa.w"
3469 
3470 /*232:*/
3471 #line 1695 "./marpa.w"
3472 
3473 {RULE rule;
3474 gint rhs_ix= 0;
3475 temp_rhs[rhs_ix++]= internal_lhs_id;
3476 if(separator_id>=0)temp_rhs[rhs_ix++]= separator_id;
3477 temp_rhs[rhs_ix++]= rhs_id;
3478 rule= rule_start(g,internal_lhs_id,temp_rhs,rhs_ix);
3479 if(!rule){/*1365:*/
3480 #line 13140 "./marpa.w"
3481 {
3482 g_context_clear(g);
3483 g->t_error= "internal error";
3484 return failure_indicator;
3485 }
3486 
3487 /*:1365*/
3488 #line 1702 "./marpa.w"
3489 }
3490 RULE_is_Virtual_LHS(rule)= 1;
3491 RULE_is_Virtual_RHS(rule)= 1;
3492 Real_SYM_Count_of_RULE(rule)= rhs_ix-1;
3493 rule_callback(g,rule->t_id);
3494 }
3495 
3496 /*:232*/
3497 #line 1600 "./marpa.w"
3498 
3499 /*228:*/
3500 #line 1652 "./marpa.w"
3501 g_free(temp_rhs);
3502 /*:228*/
3503 #line 1601 "./marpa.w"
3504 
3505 return original_rule_id;
3506 }
3507 /*:221*//*235:*/
3508 #line 1755 "./marpa.w"
3509 
3510 static inline
is_rule_duplicate(struct marpa_g * g,Marpa_Symbol_ID lhs_id,Marpa_Symbol_ID * rhs_ids,gint length)3511 gboolean is_rule_duplicate(struct marpa_g*g,
3512 Marpa_Symbol_ID lhs_id,Marpa_Symbol_ID*rhs_ids,gint length)
3513 {
3514 gint ix;
3515 SYM lhs= SYM_by_ID(lhs_id);
3516 GArray*same_lhs_array= lhs->t_lhs;
3517 gint same_lhs_count= same_lhs_array->len;
3518 for(ix= 0;ix<same_lhs_count;ix++){
3519 RULEID same_lhs_rule_id= ((RULEID*)(same_lhs_array->data))[ix];
3520 gint rhs_position;
3521 RULE rule= RULE_by_ID(g,same_lhs_rule_id);
3522 const gint rule_length= Length_of_RULE(rule);
3523 if(rule_length!=length){goto RULE_IS_NOT_DUPLICATE;}
3524 for(rhs_position= 0;rhs_position<rule_length;rhs_position++){
3525 if(RHS_ID_of_RULE(rule,rhs_position)!=rhs_ids[rhs_position]){
3526 goto RULE_IS_NOT_DUPLICATE;
3527 }
3528 }
3529 return TRUE;
3530 RULE_IS_NOT_DUPLICATE:;
3531 }
3532 return FALSE;
3533 }
3534 
3535 /*:235*//*245:*/
3536 #line 1928 "./marpa.w"
3537 
rule_lhs_get(RULE rule)3538 static inline Marpa_Symbol_ID rule_lhs_get(RULE rule){
3539 return rule->t_symbols[0];}
3540 /*:245*//*247:*/
3541 #line 1933 "./marpa.w"
3542 
marpa_rule_lhs(struct marpa_g * g,Marpa_Rule_ID rule_id)3543 Marpa_Symbol_ID marpa_rule_lhs(struct marpa_g*g,Marpa_Rule_ID rule_id){
3544 /*1357:*/
3545 #line 13088 "./marpa.w"
3546 const int failure_indicator= -2;
3547 
3548 /*:1357*/
3549 #line 1935 "./marpa.w"
3550 
3551 /*1361:*/
3552 #line 13112 "./marpa.w"
3553 
3554 if(!RULEID_of_G_is_Valid(g,rule_id)){
3555 g_context_clear(g);
3556 g_context_int_add(g,"rule_id",rule_id);
3557 g->t_error= "invalid rule id";
3558 return failure_indicator;
3559 }
3560 /*:1361*/
3561 #line 1936 "./marpa.w"
3562 
3563 return rule_lhs_get(RULE_by_ID(g,rule_id));}
3564 /*:247*//*249:*/
3565 #line 1940 "./marpa.w"
3566 
rule_rhs_get(RULE rule)3567 static inline Marpa_Symbol_ID*rule_rhs_get(RULE rule){
3568 return rule->t_symbols+1;}
3569 /*:249*//*252:*/
3570 #line 1947 "./marpa.w"
3571 
marpa_rule_rh_symbol(struct marpa_g * g,Marpa_Rule_ID rule_id,gint ix)3572 Marpa_Symbol_ID marpa_rule_rh_symbol(struct marpa_g*g,Marpa_Rule_ID rule_id,gint ix){
3573 RULE rule;
3574 /*1357:*/
3575 #line 13088 "./marpa.w"
3576 const int failure_indicator= -2;
3577 
3578 /*:1357*/
3579 #line 1950 "./marpa.w"
3580 
3581 /*1361:*/
3582 #line 13112 "./marpa.w"
3583 
3584 if(!RULEID_of_G_is_Valid(g,rule_id)){
3585 g_context_clear(g);
3586 g_context_int_add(g,"rule_id",rule_id);
3587 g->t_error= "invalid rule id";
3588 return failure_indicator;
3589 }
3590 /*:1361*/
3591 #line 1951 "./marpa.w"
3592 
3593 rule= RULE_by_ID(g,rule_id);
3594 if(Length_of_RULE(rule)<=ix)return-1;
3595 return RHS_ID_of_RULE(rule,ix);
3596 }
3597 /*:252*//*253:*/
3598 #line 1956 "./marpa.w"
3599 
rule_length_get(RULE rule)3600 static inline gsize rule_length_get(RULE rule){
3601 return Length_of_RULE(rule);}
3602 /*:253*//*255:*/
3603 #line 1961 "./marpa.w"
3604 
marpa_rule_length(struct marpa_g * g,Marpa_Rule_ID rule_id)3605 gint marpa_rule_length(struct marpa_g*g,Marpa_Rule_ID rule_id){
3606 /*1357:*/
3607 #line 13088 "./marpa.w"
3608 const int failure_indicator= -2;
3609 
3610 /*:1357*/
3611 #line 1963 "./marpa.w"
3612 
3613 /*1361:*/
3614 #line 13112 "./marpa.w"
3615 
3616 if(!RULEID_of_G_is_Valid(g,rule_id)){
3617 g_context_clear(g);
3618 g_context_int_add(g,"rule_id",rule_id);
3619 g->t_error= "invalid rule id";
3620 return failure_indicator;
3621 }
3622 /*:1361*/
3623 #line 1964 "./marpa.w"
3624 
3625 return rule_length_get(RULE_by_ID(g,rule_id));}
3626 /*:255*//*263:*/
3627 #line 1993 "./marpa.w"
3628 
marpa_rule_is_discard_separation(struct marpa_g * g,Marpa_Rule_ID id)3629 gboolean marpa_rule_is_discard_separation(struct marpa_g*g,Marpa_Rule_ID id)
3630 {return RULE_by_ID(g,id)->t_is_discard;}
3631 /*:263*//*267:*/
3632 #line 2026 "./marpa.w"
3633 
rule_is_accessible(struct marpa_g * g,RULE rule)3634 static inline gint rule_is_accessible(struct marpa_g*g,RULE rule)
3635 {
3636 Marpa_Symbol_ID lhs_id= LHS_ID_of_RULE(rule);
3637 return SYM_by_ID(lhs_id)->t_is_accessible;}
marpa_rule_is_accessible(struct marpa_g * g,Marpa_Rule_ID rule_id)3638 gint marpa_rule_is_accessible(struct marpa_g*g,Marpa_Rule_ID rule_id)
3639 {
3640 /*1357:*/
3641 #line 13088 "./marpa.w"
3642 const int failure_indicator= -2;
3643 
3644 /*:1357*/
3645 #line 2033 "./marpa.w"
3646 
3647 RULE rule;
3648 /*1361:*/
3649 #line 13112 "./marpa.w"
3650 
3651 if(!RULEID_of_G_is_Valid(g,rule_id)){
3652 g_context_clear(g);
3653 g_context_int_add(g,"rule_id",rule_id);
3654 g->t_error= "invalid rule id";
3655 return failure_indicator;
3656 }
3657 /*:1361*/
3658 #line 2035 "./marpa.w"
3659 
3660 rule= RULE_by_ID(g,rule_id);
3661 return rule_is_accessible(g,rule);
3662 }
3663 /*:267*//*271:*/
3664 #line 2046 "./marpa.w"
3665 
rule_is_productive(struct marpa_g * g,RULE rule)3666 static inline gint rule_is_productive(struct marpa_g*g,RULE rule)
3667 {
3668 gint rh_ix;
3669 for(rh_ix= 0;rh_ix<Length_of_RULE(rule);rh_ix++){
3670 Marpa_Symbol_ID rhs_id= RHS_ID_of_RULE(rule,rh_ix);
3671 if(!SYM_by_ID(rhs_id)->t_is_productive)return FALSE;
3672 }
3673 return TRUE;}
marpa_rule_is_productive(struct marpa_g * g,Marpa_Rule_ID rule_id)3674 gint marpa_rule_is_productive(struct marpa_g*g,Marpa_Rule_ID rule_id)
3675 {
3676 /*1357:*/
3677 #line 13088 "./marpa.w"
3678 const int failure_indicator= -2;
3679 
3680 /*:1357*/
3681 #line 2057 "./marpa.w"
3682 
3683 RULE rule;
3684 /*1361:*/
3685 #line 13112 "./marpa.w"
3686 
3687 if(!RULEID_of_G_is_Valid(g,rule_id)){
3688 g_context_clear(g);
3689 g_context_int_add(g,"rule_id",rule_id);
3690 g->t_error= "invalid rule id";
3691 return failure_indicator;
3692 }
3693 /*:1361*/
3694 #line 2059 "./marpa.w"
3695 
3696 rule= RULE_by_ID(g,rule_id);
3697 return rule_is_productive(g,rule);
3698 }
3699 /*:271*//*277:*/
3700 #line 2079 "./marpa.w"
3701 
marpa_rule_is_loop(struct marpa_g * g,Marpa_Rule_ID rule_id)3702 gint marpa_rule_is_loop(struct marpa_g*g,Marpa_Rule_ID rule_id)
3703 {
3704 /*1357:*/
3705 #line 13088 "./marpa.w"
3706 const int failure_indicator= -2;
3707 
3708 /*:1357*/
3709 #line 2082 "./marpa.w"
3710 
3711 /*1361:*/
3712 #line 13112 "./marpa.w"
3713 
3714 if(!RULEID_of_G_is_Valid(g,rule_id)){
3715 g_context_clear(g);
3716 g_context_int_add(g,"rule_id",rule_id);
3717 g->t_error= "invalid rule id";
3718 return failure_indicator;
3719 }
3720 /*:1361*/
3721 #line 2083 "./marpa.w"
3722 
3723 return RULE_by_ID(g,rule_id)->t_is_loop;}
3724 /*:277*//*282:*/
3725 #line 2100 "./marpa.w"
3726 
marpa_rule_is_virtual_loop(struct marpa_g * g,Marpa_Rule_ID rule_id)3727 gint marpa_rule_is_virtual_loop(struct marpa_g*g,Marpa_Rule_ID rule_id)
3728 {
3729 /*1357:*/
3730 #line 13088 "./marpa.w"
3731 const int failure_indicator= -2;
3732 
3733 /*:1357*/
3734 #line 2103 "./marpa.w"
3735 
3736 /*1361:*/
3737 #line 13112 "./marpa.w"
3738 
3739 if(!RULEID_of_G_is_Valid(g,rule_id)){
3740 g_context_clear(g);
3741 g_context_int_add(g,"rule_id",rule_id);
3742 g->t_error= "invalid rule id";
3743 return failure_indicator;
3744 }
3745 /*:1361*/
3746 #line 2104 "./marpa.w"
3747 
3748 return RULE_by_ID(g,rule_id)->t_is_virtual_loop;}
3749 /*:282*//*285:*/
3750 #line 2112 "./marpa.w"
3751 
3752 static inline gint
rule_is_nulling(GRAMMAR g,RULE rule)3753 rule_is_nulling(GRAMMAR g,RULE rule)
3754 {
3755 gint rh_ix;
3756 for(rh_ix= 0;rh_ix<Length_of_RULE(rule);rh_ix++)
3757 {
3758 SYMID rhs_id= RHS_ID_of_RULE(rule,rh_ix);
3759 if(!SYM_is_Nulling(SYM_by_ID(rhs_id)))
3760 return FALSE;
3761 }
3762 return TRUE;
3763 }
3764 /*:285*//*289:*/
3765 #line 2135 "./marpa.w"
3766 
marpa_rule_is_used(struct marpa_g * g,Marpa_Rule_ID rule_id)3767 gint marpa_rule_is_used(struct marpa_g*g,Marpa_Rule_ID rule_id)
3768 {
3769 /*1357:*/
3770 #line 13088 "./marpa.w"
3771 const int failure_indicator= -2;
3772 
3773 /*:1357*/
3774 #line 2138 "./marpa.w"
3775 
3776 /*1361:*/
3777 #line 13112 "./marpa.w"
3778 
3779 if(!RULEID_of_G_is_Valid(g,rule_id)){
3780 g_context_clear(g);
3781 g_context_int_add(g,"rule_id",rule_id);
3782 g->t_error= "invalid rule id";
3783 return failure_indicator;
3784 }
3785 /*:1361*/
3786 #line 2139 "./marpa.w"
3787 
3788 return RULE_is_Used(RULE_by_ID(g,rule_id));}
3789 /*:289*//*293:*/
3790 #line 2151 "./marpa.w"
3791 
marpa_rule_is_start(struct marpa_g * g,Marpa_Rule_ID rule_id)3792 gint marpa_rule_is_start(struct marpa_g*g,Marpa_Rule_ID rule_id)
3793 {
3794 /*1357:*/
3795 #line 13088 "./marpa.w"
3796 const int failure_indicator= -2;
3797 
3798 /*:1357*/
3799 #line 2154 "./marpa.w"
3800 
3801 /*1361:*/
3802 #line 13112 "./marpa.w"
3803 
3804 if(!RULEID_of_G_is_Valid(g,rule_id)){
3805 g_context_clear(g);
3806 g_context_int_add(g,"rule_id",rule_id);
3807 g->t_error= "invalid rule id";
3808 return failure_indicator;
3809 }
3810 /*:1361*/
3811 #line 2155 "./marpa.w"
3812 
3813 return RULE_by_ID(g,rule_id)->t_is_start;}
3814 /*:293*//*297:*/
3815 #line 2181 "./marpa.w"
3816 
marpa_rule_is_virtual_lhs(struct marpa_g * g,Marpa_Rule_ID rule_id)3817 gboolean marpa_rule_is_virtual_lhs(struct marpa_g*g,Marpa_Rule_ID rule_id)
3818 {
3819 /*1357:*/
3820 #line 13088 "./marpa.w"
3821 const int failure_indicator= -2;
3822 
3823 /*:1357*/
3824 #line 2184 "./marpa.w"
3825 
3826 /*1361:*/
3827 #line 13112 "./marpa.w"
3828 
3829 if(!RULEID_of_G_is_Valid(g,rule_id)){
3830 g_context_clear(g);
3831 g_context_int_add(g,"rule_id",rule_id);
3832 g->t_error= "invalid rule id";
3833 return failure_indicator;
3834 }
3835 /*:1361*/
3836 #line 2185 "./marpa.w"
3837 
3838 return RULE_is_Virtual_LHS(RULE_by_ID(g,rule_id));}
3839 /*:297*//*301:*/
3840 #line 2196 "./marpa.w"
3841 
marpa_rule_is_virtual_rhs(struct marpa_g * g,Marpa_Rule_ID rule_id)3842 gboolean marpa_rule_is_virtual_rhs(struct marpa_g*g,Marpa_Rule_ID rule_id)
3843 {
3844 /*1357:*/
3845 #line 13088 "./marpa.w"
3846 const int failure_indicator= -2;
3847 
3848 /*:1357*/
3849 #line 2199 "./marpa.w"
3850 
3851 /*1361:*/
3852 #line 13112 "./marpa.w"
3853 
3854 if(!RULEID_of_G_is_Valid(g,rule_id)){
3855 g_context_clear(g);
3856 g_context_int_add(g,"rule_id",rule_id);
3857 g->t_error= "invalid rule id";
3858 return failure_indicator;
3859 }
3860 /*:1361*/
3861 #line 2200 "./marpa.w"
3862 
3863 return RULE_is_Virtual_RHS(RULE_by_ID(g,rule_id));}
3864 /*:301*//*305:*/
3865 #line 2211 "./marpa.w"
3866 
marpa_virtual_start(struct marpa_g * g,Marpa_Rule_ID rule_id)3867 guint marpa_virtual_start(struct marpa_g*g,Marpa_Rule_ID rule_id)
3868 {
3869 /*1357:*/
3870 #line 13088 "./marpa.w"
3871 const int failure_indicator= -2;
3872 
3873 /*:1357*/
3874 #line 2214 "./marpa.w"
3875 
3876 /*1361:*/
3877 #line 13112 "./marpa.w"
3878 
3879 if(!RULEID_of_G_is_Valid(g,rule_id)){
3880 g_context_clear(g);
3881 g_context_int_add(g,"rule_id",rule_id);
3882 g->t_error= "invalid rule id";
3883 return failure_indicator;
3884 }
3885 /*:1361*/
3886 #line 2215 "./marpa.w"
3887 
3888 return RULE_by_ID(g,rule_id)->t_virtual_start;
3889 }
3890 /*:305*//*309:*/
3891 #line 2227 "./marpa.w"
3892 
marpa_virtual_end(struct marpa_g * g,Marpa_Rule_ID rule_id)3893 guint marpa_virtual_end(struct marpa_g*g,Marpa_Rule_ID rule_id)
3894 {
3895 /*1357:*/
3896 #line 13088 "./marpa.w"
3897 const int failure_indicator= -2;
3898 
3899 /*:1357*/
3900 #line 2230 "./marpa.w"
3901 
3902 /*1361:*/
3903 #line 13112 "./marpa.w"
3904 
3905 if(!RULEID_of_G_is_Valid(g,rule_id)){
3906 g_context_clear(g);
3907 g_context_int_add(g,"rule_id",rule_id);
3908 g->t_error= "invalid rule id";
3909 return failure_indicator;
3910 }
3911 /*:1361*/
3912 #line 2231 "./marpa.w"
3913 
3914 return RULE_by_ID(g,rule_id)->t_virtual_end;
3915 }
3916 /*:309*//*315:*/
3917 #line 2252 "./marpa.w"
3918 
marpa_rule_callback_set(struct marpa_g * g,Marpa_Rule_Callback * cb)3919 void marpa_rule_callback_set(struct marpa_g*g,Marpa_Rule_Callback*cb)
3920 {g->t_rule_callback= cb;}
3921 /*:315*//*317:*/
3922 #line 2257 "./marpa.w"
3923 
marpa_rule_callback_arg_set(struct marpa_g * g,gpointer cb_arg)3924 void marpa_rule_callback_arg_set(struct marpa_g*g,gpointer cb_arg)
3925 {g->t_rule_callback_arg= cb_arg;}
3926 /*:317*//*319:*/
3927 #line 2262 "./marpa.w"
3928 
marpa_rule_callback_arg(struct marpa_g * g)3929 gpointer marpa_rule_callback_arg(struct marpa_g*g)
3930 {return g->t_rule_callback_arg;}
3931 /*:319*//*322:*/
3932 #line 2273 "./marpa.w"
3933 
rule_callback(struct marpa_g * g,Marpa_Rule_ID id)3934 static inline void rule_callback(struct marpa_g*g,Marpa_Rule_ID id)
3935 {Marpa_Rule_Callback*cb= g->t_rule_callback;
3936 if(cb){(*cb)(g,id);}}
3937 
3938 /*:322*//*326:*/
3939 #line 2284 "./marpa.w"
3940 
marpa_rule_original(struct marpa_g * g,Marpa_Rule_ID rule_id)3941 Marpa_Rule_ID marpa_rule_original(struct marpa_g*g,Marpa_Rule_ID rule_id)
3942 {
3943 /*1357:*/
3944 #line 13088 "./marpa.w"
3945 const int failure_indicator= -2;
3946 
3947 /*:1357*/
3948 #line 2287 "./marpa.w"
3949 
3950 /*1361:*/
3951 #line 13112 "./marpa.w"
3952 
3953 if(!RULEID_of_G_is_Valid(g,rule_id)){
3954 g_context_clear(g);
3955 g_context_int_add(g,"rule_id",rule_id);
3956 g->t_error= "invalid rule id";
3957 return failure_indicator;
3958 }
3959 /*:1361*/
3960 #line 2288 "./marpa.w"
3961 
3962 return RULE_by_ID(g,rule_id)->t_original;
3963 }
3964 /*:326*//*332:*/
3965 #line 2305 "./marpa.w"
3966 
marpa_real_symbol_count(struct marpa_g * g,Marpa_Rule_ID rule_id)3967 gint marpa_real_symbol_count(struct marpa_g*g,Marpa_Rule_ID rule_id)
3968 {
3969 /*1357:*/
3970 #line 13088 "./marpa.w"
3971 const int failure_indicator= -2;
3972 
3973 /*:1357*/
3974 #line 2308 "./marpa.w"
3975 
3976 /*1361:*/
3977 #line 13112 "./marpa.w"
3978 
3979 if(!RULEID_of_G_is_Valid(g,rule_id)){
3980 g_context_clear(g);
3981 g_context_int_add(g,"rule_id",rule_id);
3982 g->t_error= "invalid rule id";
3983 return failure_indicator;
3984 }
3985 /*:1361*/
3986 #line 2309 "./marpa.w"
3987 
3988 return Real_SYM_Count_of_RULE(RULE_by_ID(g,rule_id));
3989 }
3990 
3991 /*:332*//*337:*/
3992 #line 2328 "./marpa.w"
3993 
3994 Marpa_Rule_ID
marpa_rule_semantic_equivalent(struct marpa_g * g,Marpa_Rule_ID rule_id)3995 marpa_rule_semantic_equivalent(struct marpa_g*g,Marpa_Rule_ID rule_id)
3996 {
3997 RULE rule;
3998 /*1357:*/
3999 #line 13088 "./marpa.w"
4000 const int failure_indicator= -2;
4001 
4002 /*:1357*/
4003 #line 2333 "./marpa.w"
4004 
4005 /*1361:*/
4006 #line 13112 "./marpa.w"
4007 
4008 if(!RULEID_of_G_is_Valid(g,rule_id)){
4009 g_context_clear(g);
4010 g_context_int_add(g,"rule_id",rule_id);
4011 g->t_error= "invalid rule id";
4012 return failure_indicator;
4013 }
4014 /*:1361*/
4015 #line 2334 "./marpa.w"
4016 
4017 rule= RULE_by_ID(g,rule_id);
4018 if(RULE_is_Virtual_LHS(rule))return-1;
4019 if(rule->t_is_semantic_equivalent)return rule->t_original;
4020 return rule_id;
4021 }
4022 
4023 /*:337*//*344:*/
4024 #line 2374 "./marpa.w"
4025 
4026 static inline gint
symbol_instance_of_ahfa_item_get(AIM aim)4027 symbol_instance_of_ahfa_item_get(AIM aim)
4028 {
4029 gint position= Position_of_AIM(aim);
4030 const gint null_count= Null_Count_of_AIM(aim);
4031 if(position<0||position-null_count> 0){
4032 
4033 const RULE rule= RULE_of_AIM(aim);
4034 position= Position_of_AIM(aim-1);
4035 return SYMI_of_RULE(rule)+position;
4036 }
4037 return-1;
4038 }
4039 
4040 /*:344*//*345:*/
4041 #line 2400 "./marpa.w"
4042 
marpa_precompute(struct marpa_g * g)4043 struct marpa_g*marpa_precompute(struct marpa_g*g)
4044 {
4045 if(!census(g))return NULL;
4046 if(!CHAF_rewrite(g))return NULL;
4047 if(!g_augment(g))return NULL;
4048 loop_detect(g);
4049 create_AHFA_items(g);
4050 create_AHFA_states(g);
4051 /*601:*/
4052 #line 5346 "./marpa.w"
4053 {
4054 gint symbol_count= SYM_Count_of_G(g);
4055 gint symid;
4056 Bit_Vector bv_is_terminal= bv_create((guint)symbol_count);
4057 g->t_bv_symid_is_terminal= bv_is_terminal;
4058 for(symid= 0;symid<symbol_count;symid++){
4059 if(!SYMID_is_Terminal(symid))continue;
4060 bv_bit_set(bv_is_terminal,(guint)symid);
4061 }
4062 }
4063 
4064 /*:601*/
4065 #line 2409 "./marpa.w"
4066 
4067 return g;
4068 }
4069 /*:345*//*348:*/
4070 #line 2447 "./marpa.w"
4071 
census(struct marpa_g * g)4072 static struct marpa_g*census(struct marpa_g*g)
4073 {
4074 /*1356:*/
4075 #line 13085 "./marpa.w"
4076 const gpointer failure_indicator= NULL;
4077 /*:1356*/
4078 #line 2450 "./marpa.w"
4079 
4080 /*350:*/
4081 #line 2480 "./marpa.w"
4082 
4083 guint pre_rewrite_rule_count= g->t_rules->len;
4084 guint pre_rewrite_symbol_count= g->t_symbols->len;
4085 
4086 /*:350*//*355:*/
4087 #line 2517 "./marpa.w"
4088 
4089 Marpa_Symbol_ID original_start_symid= g->t_start_symid;
4090 SYM original_start_symbol;
4091 
4092 /*:355*//*359:*/
4093 #line 2556 "./marpa.w"
4094 
4095 Bit_Vector terminal_v;
4096 gboolean have_marked_terminals= 0;
4097 
4098 /*:359*//*365:*/
4099 #line 2615 "./marpa.w"
4100 
4101 Bit_Vector lhs_v;
4102 Bit_Vector empty_lhs_v;
4103 gboolean have_empty_rule= 0;
4104 
4105 /*:365*//*367:*/
4106 #line 2642 "./marpa.w"
4107 
4108 Bit_Vector nullable_v;
4109 /*:367*//*371:*/
4110 #line 2668 "./marpa.w"
4111 
4112 Bit_Vector productive_v;
4113 /*:371*//*374:*/
4114 #line 2709 "./marpa.w"
4115 Bit_Matrix reach_matrix;
4116 /*:374*//*377:*/
4117 #line 2727 "./marpa.w"
4118 
4119 Bit_Vector accessible_v;
4120 
4121 /*:377*/
4122 #line 2451 "./marpa.w"
4123 
4124 /*351:*/
4125 #line 2484 "./marpa.w"
4126 
4127 if(g->t_rules->len<=0){g->t_error= "no rules";return NULL;}
4128 /*:351*/
4129 #line 2452 "./marpa.w"
4130 
4131 /*352:*/
4132 #line 2491 "./marpa.w"
4133 
4134 if(G_is_Precomputed(g)){g->t_error= "precomputed";return NULL;}
4135 /*:352*/
4136 #line 2453 "./marpa.w"
4137 
4138 /*354:*/
4139 #line 2497 "./marpa.w"
4140 
4141 if(original_start_symid<0){
4142 g_context_clear(g);
4143 g->t_error= "no start symbol";
4144 return failure_indicator;
4145 }
4146 if(!symbol_is_valid(g,original_start_symid)){
4147 g_context_clear(g);
4148 g_context_int_add(g,"symid",original_start_symid);
4149 g->t_error= "invalid start symbol";
4150 return failure_indicator;
4151 }
4152 original_start_symbol= SYM_by_ID(original_start_symid);
4153 if(original_start_symbol->t_lhs->len<=0){
4154 g_context_clear(g);
4155 g_context_int_add(g,"symid",original_start_symid);
4156 g->t_error= "start symbol not on LHS";
4157 return failure_indicator;
4158 }
4159 
4160 /*:354*/
4161 #line 2454 "./marpa.w"
4162 
4163 /*356:*/
4164 #line 2521 "./marpa.w"
4165 
4166 {Marpa_Rule_ID rule_id;
4167 lhs_v= bv_create(pre_rewrite_symbol_count);
4168 empty_lhs_v= bv_shadow(lhs_v);
4169 for(rule_id= 0;
4170 rule_id<(Marpa_Rule_ID)pre_rewrite_rule_count;
4171 rule_id++){
4172 RULE rule= RULE_by_ID(g,rule_id);
4173 Marpa_Symbol_ID lhs_id= LHS_ID_of_RULE(rule);
4174 bv_bit_set(lhs_v,(guint)lhs_id);
4175 if(Length_of_RULE(rule)<=0){
4176 bv_bit_set(empty_lhs_v,(guint)lhs_id);
4177 have_empty_rule= 1;
4178 }
4179 }
4180 }
4181 /*:356*/
4182 #line 2455 "./marpa.w"
4183 
4184 /*357:*/
4185 #line 2540 "./marpa.w"
4186 
4187 {Marpa_Symbol_ID symid;
4188 terminal_v= bv_create(pre_rewrite_symbol_count);
4189 for(symid= 0;
4190 symid<(Marpa_Symbol_ID)pre_rewrite_symbol_count;
4191 symid++){
4192 SYM symbol= SYM_by_ID(symid);
4193 if(SYM_is_Terminal(symbol)){
4194 bv_bit_set(terminal_v,(guint)symid);
4195 have_marked_terminals= 1;
4196 }
4197 }}
4198 /*:357*/
4199 #line 2456 "./marpa.w"
4200 
4201 if(have_marked_terminals){
4202 /*361:*/
4203 #line 2571 "./marpa.w"
4204 
4205 if(!g->t_is_lhs_terminal_ok){
4206 gboolean have_bad_lhs= 0;
4207 guint start= 0;
4208 guint min,max;
4209 Bit_Vector bad_lhs_v= bv_clone(terminal_v);
4210 bv_and(bad_lhs_v,bad_lhs_v,lhs_v);
4211 while(bv_scan(bad_lhs_v,start,&min,&max)){
4212 Marpa_Symbol_ID i;
4213 for(i= (Marpa_Symbol_ID)min;i<=(Marpa_Symbol_ID)max;i++){
4214 g_context_clear(g);
4215 g_context_int_add(g,"symid",i);
4216 grammar_message(g,"lhs is terminal");
4217 }
4218 start= max+2;
4219 have_bad_lhs= 1;
4220 }
4221 bv_free(bad_lhs_v);
4222 if(have_bad_lhs){
4223 g->t_error= "lhs is terminal";
4224 return NULL;
4225 }
4226 }
4227 
4228 /*:361*/
4229 #line 2458 "./marpa.w"
4230 
4231 }else{
4232 /*360:*/
4233 #line 2560 "./marpa.w"
4234 
4235 if(have_empty_rule&&g->t_is_lhs_terminal_ok){
4236 g->t_error= "empty rule and unmarked terminals";
4237 return NULL;
4238 }
4239 /*:360*/
4240 #line 2460 "./marpa.w"
4241 ;
4242 if(g->t_is_lhs_terminal_ok){
4243 /*362:*/
4244 #line 2595 "./marpa.w"
4245 
4246 {Marpa_Symbol_ID symid;
4247 bv_fill(terminal_v);
4248 for(symid= 0;symid<(Marpa_Symbol_ID)g->t_symbols->len;symid++)
4249 {SYMID_is_Terminal(symid)= 1;}}
4250 /*:362*/
4251 #line 2462 "./marpa.w"
4252 
4253 }else{
4254 /*363:*/
4255 #line 2600 "./marpa.w"
4256 
4257 {guint start= 0;
4258 guint min,max;
4259 bv_not(terminal_v,lhs_v);
4260 while(bv_scan(terminal_v,start,&min,&max)){
4261 Marpa_Symbol_ID symid;
4262 for(symid= (Marpa_Symbol_ID)min;symid<=(Marpa_Symbol_ID)max;symid++){
4263 SYMID_is_Terminal(symid)= 1;
4264 }
4265 start= max+2;
4266 }
4267 }
4268 /*:363*/
4269 #line 2464 "./marpa.w"
4270 
4271 }
4272 }
4273 /*366:*/
4274 #line 2620 "./marpa.w"
4275 
4276 nullable_v= bv_clone(empty_lhs_v);
4277 rhs_closure(g,nullable_v);
4278 {guint min,max,start;
4279 Marpa_Symbol_ID symid;
4280 gint counted_nullables= 0;
4281 for(start= 0;bv_scan(nullable_v,start,&min,&max);start= max+2){
4282 for(symid= (Marpa_Symbol_ID)min;symid<=(Marpa_Symbol_ID)max;symid++){
4283 SYM symbol= SYM_by_ID(symid);
4284 if(symbol->t_is_counted){
4285 g_context_clear(g);
4286 g_context_int_add(g,"symid",symid);
4287 grammar_message(g,"counted nullable");
4288 counted_nullables++;
4289 }
4290 symbol->t_is_nullable= 1;
4291 }}
4292 if(counted_nullables){
4293 g->t_error= "counted nullable";
4294 return NULL;
4295 }
4296 }
4297 /*:366*/
4298 #line 2467 "./marpa.w"
4299 
4300 /*369:*/
4301 #line 2647 "./marpa.w"
4302 
4303 productive_v= bv_shadow(nullable_v);
4304 bv_or(productive_v,nullable_v,terminal_v);
4305 rhs_closure(g,productive_v);
4306 {guint min,max,start;
4307 Marpa_Symbol_ID symid;
4308 for(start= 0;bv_scan(productive_v,start,&min,&max);start= max+2){
4309 for(symid= (Marpa_Symbol_ID)min;
4310 symid<=(Marpa_Symbol_ID)max;
4311 symid++){
4312 SYM symbol= SYM_by_ID(symid);
4313 symbol->t_is_productive= 1;
4314 }}
4315 }
4316 /*:369*/
4317 #line 2468 "./marpa.w"
4318 
4319 /*370:*/
4320 #line 2661 "./marpa.w"
4321 
4322 if(!bv_bit_test(productive_v,(guint)g->t_start_symid))
4323 {
4324 g_context_int_add(g,"symid",g->t_start_symid);
4325 g->t_error= "unproductive start symbol";
4326 return NULL;
4327 }
4328 /*:370*/
4329 #line 2469 "./marpa.w"
4330 
4331 /*373:*/
4332 #line 2691 "./marpa.w"
4333 
4334 reach_matrix
4335 = matrix_create(pre_rewrite_symbol_count,pre_rewrite_symbol_count);
4336 {guint symid,no_of_symbols= SYM_Count_of_G(g);
4337 for(symid= 0;symid<no_of_symbols;symid++){
4338 matrix_bit_set(reach_matrix,symid,symid);
4339 }}
4340 {Marpa_Rule_ID rule_id;
4341 guint no_of_rules= RULE_Count_of_G(g);
4342 for(rule_id= 0;rule_id<(Marpa_Rule_ID)no_of_rules;rule_id++){
4343 RULE rule= RULE_by_ID(g,rule_id);
4344 Marpa_Symbol_ID lhs_id= LHS_ID_of_RULE(rule);
4345 guint rhs_ix,rule_length= Length_of_RULE(rule);
4346 for(rhs_ix= 0;rhs_ix<rule_length;rhs_ix++){
4347 matrix_bit_set(reach_matrix,
4348 (guint)lhs_id,(guint)RHS_ID_of_RULE(rule,rhs_ix));
4349 }}}
4350 transitive_closure(reach_matrix);
4351 /*:373*/
4352 #line 2470 "./marpa.w"
4353 
4354 /*376:*/
4355 #line 2713 "./marpa.w"
4356 
4357 accessible_v= matrix_row(reach_matrix,(guint)original_start_symid);
4358 {guint min,max,start;
4359 Marpa_Symbol_ID symid;
4360 for(start= 0;bv_scan(accessible_v,start,&min,&max);start= max+2){
4361 for(symid= (Marpa_Symbol_ID)min;
4362 symid<=(Marpa_Symbol_ID)max;
4363 symid++){
4364 SYM symbol= SYM_by_ID(symid);
4365 symbol->t_is_accessible= 1;
4366 }}
4367 }
4368 /*:376*/
4369 #line 2471 "./marpa.w"
4370 
4371 /*378:*/
4372 #line 2732 "./marpa.w"
4373 
4374 {
4375 Bit_Vector reaches_terminal_v= bv_shadow(terminal_v);
4376 guint min,max,start;
4377 for(start= 0;bv_scan(productive_v,start,&min,&max);start= max+2)
4378 {
4379 Marpa_Symbol_ID productive_id;
4380 for(productive_id= (Marpa_Symbol_ID)min;
4381 productive_id<=(Marpa_Symbol_ID)max;productive_id++)
4382 {
4383 bv_and(reaches_terminal_v,terminal_v,
4384 matrix_row(reach_matrix,(guint)productive_id));
4385 if(bv_is_empty(reaches_terminal_v))
4386 SYM_is_Nulling(SYM_by_ID(productive_id))= 1;
4387 }
4388 }
4389 bv_free(reaches_terminal_v);
4390 }
4391 
4392 /*:378*/
4393 #line 2472 "./marpa.w"
4394 
4395 /*358:*/
4396 #line 2552 "./marpa.w"
4397 
4398 bv_free(terminal_v);
4399 /*:358*//*364:*/
4400 #line 2612 "./marpa.w"
4401 
4402 bv_free(lhs_v);
4403 bv_free(empty_lhs_v);
4404 /*:364*//*368:*/
4405 #line 2644 "./marpa.w"
4406 
4407 bv_free(nullable_v);
4408 
4409 /*:368*//*372:*/
4410 #line 2670 "./marpa.w"
4411 
4412 bv_free(productive_v);
4413 
4414 /*:372*/
4415 #line 2473 "./marpa.w"
4416 
4417 /*375:*/
4418 #line 2710 "./marpa.w"
4419 
4420 matrix_free(reach_matrix);
4421 
4422 /*:375*/
4423 #line 2474 "./marpa.w"
4424 
4425 g->t_is_precomputed= TRUE;
4426 return g;
4427 }
4428 /*:348*//*385:*/
4429 #line 2808 "./marpa.w"
4430 
CHAF_rewrite(struct marpa_g * g)4431 static inline struct marpa_g*CHAF_rewrite(struct marpa_g*g)
4432 {
4433 /*387:*/
4434 #line 2831 "./marpa.w"
4435 
4436 Marpa_Rule_ID rule_id;
4437 gint no_of_rules;
4438 
4439 /*:387*//*391:*/
4440 #line 2882 "./marpa.w"
4441 
4442 gint factor_count;
4443 gint*factor_positions;
4444 /*:391*//*396:*/
4445 #line 2931 "./marpa.w"
4446 
4447 Marpa_Symbol_ID*piece_rhs;
4448 Marpa_Symbol_ID*remaining_rhs;
4449 /*:396*/
4450 #line 2811 "./marpa.w"
4451 
4452 /*392:*/
4453 #line 2885 "./marpa.w"
4454 
4455 factor_positions= g_new(gint,g->t_max_rule_length);
4456 /*:392*//*397:*/
4457 #line 2934 "./marpa.w"
4458 
4459 piece_rhs= g_new(Marpa_Symbol_ID,g->t_max_rule_length);
4460 remaining_rhs= g_new(Marpa_Symbol_ID,g->t_max_rule_length);
4461 /*:397*/
4462 #line 2812 "./marpa.w"
4463 
4464 /*389:*/
4465 #line 2843 "./marpa.w"
4466 
4467 {gint no_of_symbols= SYM_Count_of_G(g);
4468 Marpa_Symbol_ID symid;
4469 for(symid= 0;symid<no_of_symbols;symid++){
4470 SYM symbol= SYM_by_ID(symid);
4471 SYM alias;
4472 if(!symbol->t_is_nullable)continue;
4473 if(SYM_is_Nulling(symbol))continue;
4474 if(!symbol->t_is_accessible)continue;
4475 if(!symbol->t_is_productive)continue;
4476 if(symbol_null_alias(symbol))continue;
4477 alias= symbol_alias_create(g,symbol);
4478 symbol_callback(g,ID_of_SYM(alias));
4479 }}
4480 
4481 /*:389*/
4482 #line 2813 "./marpa.w"
4483 
4484 no_of_rules= RULE_Count_of_G(g);
4485 for(rule_id= 0;rule_id<no_of_rules;rule_id++){
4486 RULE rule= RULE_by_ID(g,rule_id);
4487 const gint rule_length= Length_of_RULE(rule);
4488 gint nullable_suffix_ix= 0;
4489 /*388:*/
4490 #line 2835 "./marpa.w"
4491 
4492 if(!RULE_is_Used(rule)){goto NEXT_RULE;}
4493 if(rule_is_nulling(g,rule)){RULE_is_Used(rule)= 0;goto NEXT_RULE;}
4494 if(!rule_is_accessible(g,rule)){RULE_is_Used(rule)= 0;goto NEXT_RULE;}
4495 if(!rule_is_productive(g,rule)){RULE_is_Used(rule)= 0;goto NEXT_RULE;}
4496 
4497 /*:388*/
4498 #line 2819 "./marpa.w"
4499 
4500 /*390:*/
4501 #line 2866 "./marpa.w"
4502 
4503 {gint rhs_ix;
4504 factor_count= 0;
4505 for(rhs_ix= 0;rhs_ix<rule_length;rhs_ix++){
4506 Marpa_Symbol_ID symid= RHS_ID_of_RULE(rule,rhs_ix);
4507 SYM symbol= SYM_by_ID(symid);
4508 if(SYM_is_Nulling(symbol))continue;
4509 if(symbol_null_alias(symbol)){
4510 
4511 factor_positions[factor_count++]= rhs_ix;
4512 continue;
4513 }
4514 nullable_suffix_ix= rhs_ix+1;
4515 
4516 
4517 }}
4518 /*:390*/
4519 #line 2820 "./marpa.w"
4520 
4521 
4522 if(factor_count<=0)goto NEXT_RULE;
4523 /*394:*/
4524 #line 2891 "./marpa.w"
4525 
4526 RULE_is_Used(rule)= 0;
4527 {gint unprocessed_factor_count;
4528 
4529 gint factor_position_ix= 0;
4530 Marpa_Symbol_ID current_lhs_id= LHS_ID_of_RULE(rule);
4531 gint piece_end,piece_start= 0;
4532 
4533 for(unprocessed_factor_count= factor_count-factor_position_ix;
4534 unprocessed_factor_count>=3;
4535 unprocessed_factor_count= factor_count-factor_position_ix){
4536 /*400:*/
4537 #line 2944 "./marpa.w"
4538 
4539 Marpa_Symbol_ID chaf_virtual_symid;
4540 gint first_factor_position= factor_positions[factor_position_ix];
4541 gint first_factor_piece_position= first_factor_position-piece_start;
4542 gint second_factor_position= factor_positions[factor_position_ix+1];
4543 if(second_factor_position>=nullable_suffix_ix){
4544 piece_end= second_factor_position-1;
4545 
4546 /*395:*/
4547 #line 2910 "./marpa.w"
4548 {
4549 SYM chaf_virtual_symbol= symbol_new(g);
4550 chaf_virtual_symbol->t_is_accessible= 1;
4551 chaf_virtual_symbol->t_is_productive= 1;
4552 chaf_virtual_symid= ID_of_SYM(chaf_virtual_symbol);
4553 g_context_clear(g);
4554 g_context_int_add(g,"rule_id",rule_id);
4555 g_context_int_add(g,"lhs_id",LHS_ID_of_RULE(rule));
4556 g_context_int_add(g,"virtual_end",(gint)piece_end);
4557 symbol_callback(g,chaf_virtual_symid);
4558 }
4559 
4560 /*:395*/
4561 #line 2952 "./marpa.w"
4562 
4563 /*401:*/
4564 #line 2971 "./marpa.w"
4565 
4566 {
4567 gint remaining_rhs_length,piece_rhs_length;
4568 /*402:*/
4569 #line 2983 "./marpa.w"
4570 
4571 {
4572 gint real_symbol_count= piece_end-piece_start+1;
4573 for(piece_rhs_length= 0;piece_rhs_length<real_symbol_count;piece_rhs_length++){
4574 remaining_rhs[piece_rhs_length]=
4575 piece_rhs[piece_rhs_length]= RHS_ID_of_RULE(rule,piece_start+piece_rhs_length);
4576 }
4577 piece_rhs[piece_rhs_length++]= chaf_virtual_symid;
4578 }
4579 {RULE chaf_rule;
4580 gint real_symbol_count= piece_rhs_length-1;
4581 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4582 /*423:*/
4583 #line 3182 "./marpa.w"
4584 
4585 RULE_is_Used(chaf_rule)= 1;
4586 chaf_rule->t_original= rule_id;
4587 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4588 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4589 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4590 chaf_rule->t_virtual_start= piece_start;
4591 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4592 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4593 rule_callback(g,chaf_rule->t_id);
4594 
4595 /*:423*/
4596 #line 2995 "./marpa.w"
4597 
4598 }
4599 
4600 /*:402*/
4601 #line 2974 "./marpa.w"
4602 ;
4603 /*403:*/
4604 #line 2998 "./marpa.w"
4605 
4606 {
4607 gint chaf_rule_length= Length_of_RULE(rule)-piece_start;
4608 for(remaining_rhs_length= piece_rhs_length-1;
4609 remaining_rhs_length<chaf_rule_length;remaining_rhs_length++)
4610 {
4611 Marpa_Symbol_ID original_id=
4612 RHS_ID_of_RULE(rule,piece_start+remaining_rhs_length);
4613 SYM alias= symbol_null_alias(SYM_by_ID(original_id));
4614 remaining_rhs[remaining_rhs_length]=
4615 alias?ID_of_SYM(alias):original_id;
4616 }
4617 }
4618 {
4619 RULE chaf_rule;
4620 gint real_symbol_count= remaining_rhs_length;
4621 chaf_rule=
4622 rule_start(g,current_lhs_id,remaining_rhs,remaining_rhs_length);
4623 /*423:*/
4624 #line 3182 "./marpa.w"
4625 
4626 RULE_is_Used(chaf_rule)= 1;
4627 chaf_rule->t_original= rule_id;
4628 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4629 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4630 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4631 chaf_rule->t_virtual_start= piece_start;
4632 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4633 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4634 rule_callback(g,chaf_rule->t_id);
4635 
4636 /*:423*/
4637 #line 3016 "./marpa.w"
4638 
4639 }
4640 
4641 /*:403*/
4642 #line 2975 "./marpa.w"
4643 ;
4644 /*404:*/
4645 #line 3021 "./marpa.w"
4646 {
4647 Marpa_Symbol_ID proper_id= RHS_ID_of_RULE(rule,first_factor_position);
4648 SYM alias= symbol_null_alias(SYM_by_ID(proper_id));
4649 remaining_rhs[first_factor_piece_position]=
4650 piece_rhs[first_factor_piece_position]=
4651 ID_of_SYM(alias);
4652 }
4653 {RULE chaf_rule;
4654 gint real_symbol_count= piece_rhs_length-1;
4655 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4656 /*423:*/
4657 #line 3182 "./marpa.w"
4658 
4659 RULE_is_Used(chaf_rule)= 1;
4660 chaf_rule->t_original= rule_id;
4661 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4662 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4663 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4664 chaf_rule->t_virtual_start= piece_start;
4665 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4666 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4667 rule_callback(g,chaf_rule->t_id);
4668 
4669 /*:423*/
4670 #line 3031 "./marpa.w"
4671 
4672 }
4673 
4674 /*:404*/
4675 #line 2976 "./marpa.w"
4676 ;
4677 /*405:*/
4678 #line 3040 "./marpa.w"
4679 
4680 if(piece_start<nullable_suffix_ix){
4681 RULE chaf_rule;
4682 gint real_symbol_count= remaining_rhs_length;
4683 chaf_rule= rule_start(g,current_lhs_id,remaining_rhs,remaining_rhs_length);
4684 /*423:*/
4685 #line 3182 "./marpa.w"
4686 
4687 RULE_is_Used(chaf_rule)= 1;
4688 chaf_rule->t_original= rule_id;
4689 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4690 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4691 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4692 chaf_rule->t_virtual_start= piece_start;
4693 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4694 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4695 rule_callback(g,chaf_rule->t_id);
4696 
4697 /*:423*/
4698 #line 3045 "./marpa.w"
4699 
4700 }
4701 
4702 /*:405*/
4703 #line 2977 "./marpa.w"
4704 ;
4705 }
4706 
4707 /*:401*/
4708 #line 2953 "./marpa.w"
4709 
4710 factor_position_ix++;
4711 }else{
4712 gint second_factor_piece_position= second_factor_position-piece_start;
4713 piece_end= second_factor_position;
4714 /*395:*/
4715 #line 2910 "./marpa.w"
4716 {
4717 SYM chaf_virtual_symbol= symbol_new(g);
4718 chaf_virtual_symbol->t_is_accessible= 1;
4719 chaf_virtual_symbol->t_is_productive= 1;
4720 chaf_virtual_symid= ID_of_SYM(chaf_virtual_symbol);
4721 g_context_clear(g);
4722 g_context_int_add(g,"rule_id",rule_id);
4723 g_context_int_add(g,"lhs_id",LHS_ID_of_RULE(rule));
4724 g_context_int_add(g,"virtual_end",(gint)piece_end);
4725 symbol_callback(g,chaf_virtual_symid);
4726 }
4727 
4728 /*:395*/
4729 #line 2958 "./marpa.w"
4730 
4731 /*407:*/
4732 #line 3050 "./marpa.w"
4733 {
4734 gint piece_rhs_length;
4735 RULE chaf_rule;
4736 gint real_symbol_count;
4737 Marpa_Symbol_ID first_factor_proper_id,second_factor_proper_id,
4738 first_factor_alias_id,second_factor_alias_id;
4739 real_symbol_count= piece_end-piece_start+1;
4740 
4741 /*:407*//*408:*/
4742 #line 3059 "./marpa.w"
4743 
4744 for(piece_rhs_length= 0;piece_rhs_length<real_symbol_count;piece_rhs_length++){
4745 piece_rhs[piece_rhs_length]= RHS_ID_of_RULE(rule,piece_start+piece_rhs_length);
4746 }
4747 piece_rhs[piece_rhs_length++]= chaf_virtual_symid;
4748 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4749 /*423:*/
4750 #line 3182 "./marpa.w"
4751 
4752 RULE_is_Used(chaf_rule)= 1;
4753 chaf_rule->t_original= rule_id;
4754 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4755 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4756 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4757 chaf_rule->t_virtual_start= piece_start;
4758 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4759 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4760 rule_callback(g,chaf_rule->t_id);
4761 
4762 /*:423*/
4763 #line 3065 "./marpa.w"
4764 
4765 
4766 /*:408*//*409:*/
4767 #line 3068 "./marpa.w"
4768 
4769 second_factor_proper_id= RHS_ID_of_RULE(rule,second_factor_position);
4770 piece_rhs[second_factor_piece_position]
4771 = second_factor_alias_id= alias_by_id(g,second_factor_proper_id);
4772 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4773 /*423:*/
4774 #line 3182 "./marpa.w"
4775 
4776 RULE_is_Used(chaf_rule)= 1;
4777 chaf_rule->t_original= rule_id;
4778 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4779 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4780 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4781 chaf_rule->t_virtual_start= piece_start;
4782 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4783 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4784 rule_callback(g,chaf_rule->t_id);
4785 
4786 /*:423*/
4787 #line 3073 "./marpa.w"
4788 
4789 
4790 /*:409*//*410:*/
4791 #line 3076 "./marpa.w"
4792 
4793 first_factor_proper_id= RHS_ID_of_RULE(rule,first_factor_position);
4794 piece_rhs[first_factor_piece_position]
4795 = first_factor_alias_id= alias_by_id(g,first_factor_proper_id);
4796 piece_rhs[second_factor_piece_position]= second_factor_proper_id;
4797 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4798 /*423:*/
4799 #line 3182 "./marpa.w"
4800 
4801 RULE_is_Used(chaf_rule)= 1;
4802 chaf_rule->t_original= rule_id;
4803 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4804 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4805 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4806 chaf_rule->t_virtual_start= piece_start;
4807 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4808 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4809 rule_callback(g,chaf_rule->t_id);
4810 
4811 /*:423*/
4812 #line 3082 "./marpa.w"
4813 
4814 
4815 /*:410*//*411:*/
4816 #line 3085 "./marpa.w"
4817 
4818 piece_rhs[second_factor_piece_position]= second_factor_alias_id;
4819 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4820 /*423:*/
4821 #line 3182 "./marpa.w"
4822 
4823 RULE_is_Used(chaf_rule)= 1;
4824 chaf_rule->t_original= rule_id;
4825 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4826 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4827 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4828 chaf_rule->t_virtual_start= piece_start;
4829 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4830 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4831 rule_callback(g,chaf_rule->t_id);
4832 
4833 /*:423*/
4834 #line 3088 "./marpa.w"
4835 
4836 
4837 /*:411*//*412:*/
4838 #line 3091 "./marpa.w"
4839 }
4840 
4841 /*:412*/
4842 #line 2959 "./marpa.w"
4843 
4844 factor_position_ix+= 2;
4845 }
4846 current_lhs_id= chaf_virtual_symid;
4847 piece_start= piece_end+1;
4848 
4849 /*:400*/
4850 #line 2902 "./marpa.w"
4851 
4852 }
4853 if(unprocessed_factor_count==2){
4854 /*413:*/
4855 #line 3095 "./marpa.w"
4856 {
4857 gint first_factor_position= factor_positions[factor_position_ix];
4858 gint first_factor_piece_position= first_factor_position-piece_start;
4859 gint second_factor_position= factor_positions[factor_position_ix+1];
4860 gint second_factor_piece_position= second_factor_position-piece_start;
4861 gint real_symbol_count;
4862 gint piece_rhs_length;
4863 RULE chaf_rule;
4864 Marpa_Symbol_ID first_factor_proper_id,second_factor_proper_id,
4865 first_factor_alias_id,second_factor_alias_id;
4866 piece_end= Length_of_RULE(rule)-1;
4867 real_symbol_count= piece_end-piece_start+1;
4868 
4869 /*:413*//*414:*/
4870 #line 3109 "./marpa.w"
4871 
4872 for(piece_rhs_length= 0;piece_rhs_length<real_symbol_count;piece_rhs_length++){
4873 piece_rhs[piece_rhs_length]= RHS_ID_of_RULE(rule,piece_start+piece_rhs_length);
4874 }
4875 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4876 /*423:*/
4877 #line 3182 "./marpa.w"
4878 
4879 RULE_is_Used(chaf_rule)= 1;
4880 chaf_rule->t_original= rule_id;
4881 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4882 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4883 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4884 chaf_rule->t_virtual_start= piece_start;
4885 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4886 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4887 rule_callback(g,chaf_rule->t_id);
4888 
4889 /*:423*/
4890 #line 3114 "./marpa.w"
4891 
4892 
4893 /*:414*//*415:*/
4894 #line 3117 "./marpa.w"
4895 
4896 second_factor_proper_id= RHS_ID_of_RULE(rule,second_factor_position);
4897 piece_rhs[second_factor_piece_position]
4898 = second_factor_alias_id= alias_by_id(g,second_factor_proper_id);
4899 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4900 /*423:*/
4901 #line 3182 "./marpa.w"
4902 
4903 RULE_is_Used(chaf_rule)= 1;
4904 chaf_rule->t_original= rule_id;
4905 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4906 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4907 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4908 chaf_rule->t_virtual_start= piece_start;
4909 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4910 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4911 rule_callback(g,chaf_rule->t_id);
4912 
4913 /*:423*/
4914 #line 3122 "./marpa.w"
4915 
4916 
4917 /*:415*//*416:*/
4918 #line 3125 "./marpa.w"
4919 
4920 first_factor_proper_id= RHS_ID_of_RULE(rule,first_factor_position);
4921 piece_rhs[first_factor_piece_position]
4922 = first_factor_alias_id= alias_by_id(g,first_factor_proper_id);
4923 piece_rhs[second_factor_piece_position]= second_factor_proper_id;
4924 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4925 /*423:*/
4926 #line 3182 "./marpa.w"
4927 
4928 RULE_is_Used(chaf_rule)= 1;
4929 chaf_rule->t_original= rule_id;
4930 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4931 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4932 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4933 chaf_rule->t_virtual_start= piece_start;
4934 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4935 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4936 rule_callback(g,chaf_rule->t_id);
4937 
4938 /*:423*/
4939 #line 3131 "./marpa.w"
4940 
4941 
4942 /*:416*//*417:*/
4943 #line 3135 "./marpa.w"
4944 
4945 if(piece_start<nullable_suffix_ix){
4946 piece_rhs[second_factor_piece_position]= second_factor_alias_id;
4947 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4948 /*423:*/
4949 #line 3182 "./marpa.w"
4950 
4951 RULE_is_Used(chaf_rule)= 1;
4952 chaf_rule->t_original= rule_id;
4953 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4954 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
4955 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
4956 chaf_rule->t_virtual_start= piece_start;
4957 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
4958 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
4959 rule_callback(g,chaf_rule->t_id);
4960 
4961 /*:423*/
4962 #line 3139 "./marpa.w"
4963 
4964 }
4965 
4966 /*:417*//*418:*/
4967 #line 3143 "./marpa.w"
4968 }
4969 
4970 /*:418*/
4971 #line 2905 "./marpa.w"
4972 
4973 }else{
4974 /*419:*/
4975 #line 3146 "./marpa.w"
4976 {
4977 gint piece_rhs_length;
4978 RULE chaf_rule;
4979 Marpa_Symbol_ID first_factor_proper_id,first_factor_alias_id;
4980 gint real_symbol_count;
4981 gint first_factor_position= factor_positions[factor_position_ix];
4982 gint first_factor_piece_position= factor_positions[factor_position_ix]-piece_start;
4983 piece_end= Length_of_RULE(rule)-1;
4984 real_symbol_count= piece_end-piece_start+1;
4985 
4986 /*:419*//*420:*/
4987 #line 3157 "./marpa.w"
4988 
4989 for(piece_rhs_length= 0;piece_rhs_length<real_symbol_count;piece_rhs_length++){
4990 piece_rhs[piece_rhs_length]= RHS_ID_of_RULE(rule,piece_start+piece_rhs_length);
4991 }
4992 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
4993 /*423:*/
4994 #line 3182 "./marpa.w"
4995 
4996 RULE_is_Used(chaf_rule)= 1;
4997 chaf_rule->t_original= rule_id;
4998 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
4999 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
5000 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
5001 chaf_rule->t_virtual_start= piece_start;
5002 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
5003 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
5004 rule_callback(g,chaf_rule->t_id);
5005 
5006 /*:423*/
5007 #line 3162 "./marpa.w"
5008 
5009 
5010 /*:420*//*421:*/
5011 #line 3166 "./marpa.w"
5012 
5013 if(piece_start<nullable_suffix_ix){
5014 first_factor_proper_id= RHS_ID_of_RULE(rule,first_factor_position);
5015 first_factor_alias_id= alias_by_id(g,first_factor_proper_id);
5016 piece_rhs[first_factor_piece_position]= first_factor_alias_id;
5017 chaf_rule= rule_start(g,current_lhs_id,piece_rhs,piece_rhs_length);
5018 /*423:*/
5019 #line 3182 "./marpa.w"
5020 
5021 RULE_is_Used(chaf_rule)= 1;
5022 chaf_rule->t_original= rule_id;
5023 RULE_is_Virtual_LHS(chaf_rule)= piece_start> 0;
5024 chaf_rule->t_is_semantic_equivalent= !RULE_is_Virtual_LHS(chaf_rule);
5025 RULE_is_Virtual_RHS(chaf_rule)= Length_of_RULE(chaf_rule)> real_symbol_count;
5026 chaf_rule->t_virtual_start= piece_start;
5027 chaf_rule->t_virtual_end= piece_start+real_symbol_count-1;
5028 Real_SYM_Count_of_RULE(chaf_rule)= real_symbol_count;
5029 rule_callback(g,chaf_rule->t_id);
5030 
5031 /*:423*/
5032 #line 3172 "./marpa.w"
5033 
5034 }
5035 
5036 /*:421*//*422:*/
5037 #line 3176 "./marpa.w"
5038 }
5039 
5040 /*:422*/
5041 #line 2907 "./marpa.w"
5042 
5043 }}
5044 
5045 /*:394*/
5046 #line 2823 "./marpa.w"
5047 
5048 NEXT_RULE:;
5049 }
5050 /*393:*/
5051 #line 2887 "./marpa.w"
5052 
5053 g_free(factor_positions);
5054 
5055 /*:393*//*398:*/
5056 #line 2937 "./marpa.w"
5057 
5058 g_free(piece_rhs);
5059 g_free(remaining_rhs);
5060 
5061 /*:398*/
5062 #line 2826 "./marpa.w"
5063 
5064 return g;
5065 }
5066 /*:385*//*424:*/
5067 #line 3196 "./marpa.w"
5068 
5069 static inline
alias_by_id(struct marpa_g * g,Marpa_Symbol_ID proper_id)5070 Marpa_Symbol_ID alias_by_id(struct marpa_g*g,Marpa_Symbol_ID proper_id){
5071 SYM alias= symbol_null_alias(SYM_by_ID(proper_id));
5072 return ID_of_SYM(alias);
5073 }
5074 /*:424*//*427:*/
5075 #line 3210 "./marpa.w"
5076 
5077 static inline
g_augment(struct marpa_g * g)5078 struct marpa_g*g_augment(struct marpa_g*g){
5079 Marpa_Symbol_ID proper_new_start_id= -1;
5080 SYM proper_old_start= NULL;
5081 SYM nulling_old_start= NULL;
5082 SYM proper_new_start= NULL;
5083 SYM old_start= SYM_by_ID(g->t_start_symid);
5084 /*429:*/
5085 #line 3226 "./marpa.w"
5086 
5087 if(SYM_is_Nulling(old_start)){
5088 old_start->t_is_accessible= 0;
5089 nulling_old_start= old_start;
5090 }else{
5091 proper_old_start= old_start;
5092 nulling_old_start= symbol_null_alias(old_start);
5093 }
5094 old_start->t_is_start= 0;
5095 
5096 /*:429*/
5097 #line 3218 "./marpa.w"
5098 
5099 if(proper_old_start){/*430:*/
5100 #line 3236 "./marpa.w"
5101 {
5102 RULE new_start_rule;
5103 proper_old_start->t_is_start= 0;
5104 proper_new_start= symbol_new(g);
5105 proper_new_start_id= ID_of_SYM(proper_new_start);
5106 g->t_start_symid= proper_new_start_id;
5107 proper_new_start->t_is_accessible= TRUE;
5108 proper_new_start->t_is_productive= TRUE;
5109 proper_new_start->t_is_start= TRUE;
5110 g_context_clear(g);
5111 g_context_int_add(g,"old_start_id",ID_of_SYM(old_start));
5112 symbol_callback(g,proper_new_start_id);
5113 new_start_rule= rule_start(g,proper_new_start_id,&LV_ID_of_SYM(old_start),1);
5114 new_start_rule->t_is_start= 1;
5115 RULE_is_Virtual_LHS(new_start_rule)= 1;
5116 Real_SYM_Count_of_RULE(new_start_rule)= 1;
5117 RULE_is_Used(new_start_rule)= 1;
5118 g->t_proper_start_rule= new_start_rule;
5119 rule_callback(g,new_start_rule->t_id);
5120 }
5121 
5122 /*:430*/
5123 #line 3219 "./marpa.w"
5124 }
5125 if(nulling_old_start){/*431:*/
5126 #line 3261 "./marpa.w"
5127 {
5128 Marpa_Symbol_ID nulling_new_start_id;
5129 RULE new_start_rule;
5130 SYM nulling_new_start;
5131 if(proper_new_start)
5132 {
5133 nulling_new_start= symbol_alias_create(g,proper_new_start);
5134 nulling_new_start_id= ID_of_SYM(nulling_new_start);
5135 }
5136 else
5137 {
5138 nulling_new_start= symbol_new(g);
5139 nulling_new_start_id= ID_of_SYM(nulling_new_start);
5140 g->t_start_symid= nulling_new_start_id;
5141 SYM_is_Nulling(nulling_new_start)= TRUE;
5142 nulling_new_start->t_is_nullable= TRUE;
5143 nulling_new_start->t_is_productive= TRUE;
5144 nulling_new_start->t_is_accessible= TRUE;
5145 }
5146 nulling_new_start->t_is_start= TRUE;
5147 g_context_clear(g);
5148 g_context_int_add(g,"old_start_id",ID_of_SYM(old_start));
5149 symbol_callback(g,nulling_new_start_id);
5150 new_start_rule= rule_start(g,nulling_new_start_id,0,0);
5151 new_start_rule->t_is_start= 1;
5152 RULE_is_Virtual_LHS(new_start_rule)= 1;
5153 Real_SYM_Count_of_RULE(new_start_rule)= 1;
5154 RULE_is_Used(new_start_rule)= TRUE;
5155 g->t_null_start_rule= new_start_rule;
5156 rule_callback(g,new_start_rule->t_id);
5157 }
5158 
5159 /*:431*/
5160 #line 3220 "./marpa.w"
5161 }
5162 return g;
5163 }
5164 /*:427*//*435:*/
5165 #line 3339 "./marpa.w"
5166 
5167 static inline
loop_detect(struct marpa_g * g)5168 void loop_detect(struct marpa_g*g)
5169 {gint no_of_rules= RULE_Count_of_G(g);
5170 gint loop_rule_count= 0;
5171 Bit_Matrix unit_transition_matrix
5172 = matrix_create((guint)no_of_rules,(guint)no_of_rules);
5173 /*437:*/
5174 #line 3362 "./marpa.w"
5175 {
5176 Marpa_Rule_ID rule_id;
5177 for(rule_id= 0;rule_id<(Marpa_Rule_ID)no_of_rules;rule_id++){
5178 RULE rule= RULE_by_ID(g,rule_id);
5179 Marpa_Symbol_ID proper_id;
5180 gint rhs_ix,rule_length;
5181 if(!RULE_is_Used(rule))continue;
5182 rule_length= Length_of_RULE(rule);
5183 proper_id= -1;
5184 for(rhs_ix= 0;rhs_ix<rule_length;rhs_ix++){
5185 Marpa_Symbol_ID symid= RHS_ID_of_RULE(rule,rhs_ix);
5186 SYM symbol= SYM_by_ID(symid);
5187 if(symbol->t_is_nullable)continue;
5188 if(proper_id>=0)goto NEXT_RULE;
5189 
5190 proper_id= symid;
5191 }
5192 
5193 if(proper_id<0)continue;
5194 
5195 {SYM rhs_symbol= SYM_by_ID(proper_id);
5196 GArray*lhs_rules= rhs_symbol->t_lhs;
5197 gint ix,no_of_lhs_rules= lhs_rules->len;
5198 for(ix= 0;ix<no_of_lhs_rules;ix++){
5199 
5200 
5201 matrix_bit_set(unit_transition_matrix,(guint)rule_id,
5202 (guint)g_array_index(lhs_rules,Marpa_Rule_ID,ix));
5203 }}
5204 NEXT_RULE:;
5205 }}
5206 
5207 /*:437*/
5208 #line 3346 "./marpa.w"
5209 
5210 transitive_closure(unit_transition_matrix);
5211 /*438:*/
5212 #line 3401 "./marpa.w"
5213 {Marpa_Rule_ID rule_id;
5214 for(rule_id= 0;rule_id<(Marpa_Rule_ID)no_of_rules;rule_id++){
5215 RULE rule;
5216 if(!matrix_bit_test(unit_transition_matrix,(guint)rule_id,(guint)rule_id))
5217 continue;
5218 loop_rule_count++;
5219 rule= RULE_by_ID(g,rule_id);
5220 rule->t_is_loop= TRUE;
5221 rule->t_is_virtual_loop= rule->t_virtual_start<0||!RULE_is_Virtual_RHS(rule);
5222 g_context_clear(g);
5223 g_context_int_add(g,"rule_id",rule_id);
5224 grammar_message(g,"loop rule");
5225 }}
5226 
5227 /*:438*/
5228 #line 3348 "./marpa.w"
5229 
5230 if(loop_rule_count)g->t_has_loop= TRUE;
5231 /*439:*/
5232 #line 3422 "./marpa.w"
5233 
5234 g_context_clear(g);
5235 g_context_int_add(g,"loop_rule_count",loop_rule_count);
5236 grammar_message(g,"loop rule tally");
5237 
5238 /*:439*/
5239 #line 3350 "./marpa.w"
5240 
5241 matrix_free(unit_transition_matrix);
5242 }
5243 /*:435*//*454:*/
5244 #line 3582 "./marpa.w"
5245 
item_is_valid(GRAMMAR_Const g,AIMID item_id)5246 static inline gboolean item_is_valid(
5247 GRAMMAR_Const g,AIMID item_id){
5248 return item_id<(AIMID)AIM_Count_of_G(g)&&item_id>=0;
5249 }
5250 /*:454*//*460:*/
5251 #line 3623 "./marpa.w"
5252 
marpa_AHFA_item_count(struct marpa_g * g)5253 guint marpa_AHFA_item_count(struct marpa_g*g){
5254 /*1357:*/
5255 #line 13088 "./marpa.w"
5256 const int failure_indicator= -2;
5257 
5258 /*:1357*/
5259 #line 3625 "./marpa.w"
5260 
5261 /*1359:*/
5262 #line 13099 "./marpa.w"
5263 
5264 if(!G_is_Precomputed(g)){
5265 g_context_clear(g);
5266 g->t_error= "grammar not precomputed";
5267 return failure_indicator;
5268 }
5269 /*:1359*/
5270 #line 3626 "./marpa.w"
5271 
5272 return AIM_Count_of_G(g);
5273 }
5274 /*:460*//*462:*/
5275 #line 3632 "./marpa.w"
5276 
marpa_AHFA_item_rule(struct marpa_g * g,Marpa_AHFA_Item_ID item_id)5277 Marpa_Rule_ID marpa_AHFA_item_rule(struct marpa_g*g,
5278 Marpa_AHFA_Item_ID item_id){
5279 /*1357:*/
5280 #line 13088 "./marpa.w"
5281 const int failure_indicator= -2;
5282 
5283 /*:1357*/
5284 #line 3635 "./marpa.w"
5285 
5286 /*1359:*/
5287 #line 13099 "./marpa.w"
5288 
5289 if(!G_is_Precomputed(g)){
5290 g_context_clear(g);
5291 g->t_error= "grammar not precomputed";
5292 return failure_indicator;
5293 }
5294 /*:1359*/
5295 #line 3636 "./marpa.w"
5296 
5297 /*1362:*/
5298 #line 13119 "./marpa.w"
5299 
5300 if(!item_is_valid(g,item_id)){
5301 g_context_clear(g);
5302 g_context_int_add(g,"item_id",item_id);
5303 g->t_error= "invalid item id";
5304 return failure_indicator;
5305 }
5306 /*:1362*/
5307 #line 3637 "./marpa.w"
5308 
5309 return RULE_of_AIM(AIM_by_ID(item_id))->t_id;
5310 }
5311 /*:462*//*465:*/
5312 #line 3646 "./marpa.w"
5313 
marpa_AHFA_item_position(struct marpa_g * g,Marpa_AHFA_Item_ID item_id)5314 gint marpa_AHFA_item_position(struct marpa_g*g,
5315 Marpa_AHFA_Item_ID item_id){
5316 /*1357:*/
5317 #line 13088 "./marpa.w"
5318 const int failure_indicator= -2;
5319 
5320 /*:1357*/
5321 #line 3649 "./marpa.w"
5322 
5323 /*1359:*/
5324 #line 13099 "./marpa.w"
5325 
5326 if(!G_is_Precomputed(g)){
5327 g_context_clear(g);
5328 g->t_error= "grammar not precomputed";
5329 return failure_indicator;
5330 }
5331 /*:1359*/
5332 #line 3650 "./marpa.w"
5333 
5334 /*1362:*/
5335 #line 13119 "./marpa.w"
5336 
5337 if(!item_is_valid(g,item_id)){
5338 g_context_clear(g);
5339 g_context_int_add(g,"item_id",item_id);
5340 g->t_error= "invalid item id";
5341 return failure_indicator;
5342 }
5343 /*:1362*/
5344 #line 3651 "./marpa.w"
5345 
5346 return Position_of_AIM(AIM_by_ID(item_id));
5347 }
5348 
5349 /*:465*//*467:*/
5350 #line 3658 "./marpa.w"
5351 
marpa_AHFA_item_postdot(struct marpa_g * g,Marpa_AHFA_Item_ID item_id)5352 Marpa_Symbol_ID marpa_AHFA_item_postdot(struct marpa_g*g,
5353 Marpa_AHFA_Item_ID item_id){
5354 /*1357:*/
5355 #line 13088 "./marpa.w"
5356 const int failure_indicator= -2;
5357 
5358 /*:1357*/
5359 #line 3661 "./marpa.w"
5360 
5361 /*1359:*/
5362 #line 13099 "./marpa.w"
5363 
5364 if(!G_is_Precomputed(g)){
5365 g_context_clear(g);
5366 g->t_error= "grammar not precomputed";
5367 return failure_indicator;
5368 }
5369 /*:1359*/
5370 #line 3662 "./marpa.w"
5371 
5372 /*1362:*/
5373 #line 13119 "./marpa.w"
5374 
5375 if(!item_is_valid(g,item_id)){
5376 g_context_clear(g);
5377 g_context_int_add(g,"item_id",item_id);
5378 g->t_error= "invalid item id";
5379 return failure_indicator;
5380 }
5381 /*:1362*/
5382 #line 3663 "./marpa.w"
5383 
5384 return Postdot_SYMID_of_AIM(AIM_by_ID(item_id));
5385 }
5386 
5387 /*:467*//*469:*/
5388 #line 3669 "./marpa.w"
5389 
marpa_AHFA_item_sort_key(struct marpa_g * g,Marpa_AHFA_Item_ID item_id)5390 gint marpa_AHFA_item_sort_key(struct marpa_g*g,
5391 Marpa_AHFA_Item_ID item_id){
5392 /*1357:*/
5393 #line 13088 "./marpa.w"
5394 const int failure_indicator= -2;
5395 
5396 /*:1357*/
5397 #line 3672 "./marpa.w"
5398 
5399 /*1359:*/
5400 #line 13099 "./marpa.w"
5401 
5402 if(!G_is_Precomputed(g)){
5403 g_context_clear(g);
5404 g->t_error= "grammar not precomputed";
5405 return failure_indicator;
5406 }
5407 /*:1359*/
5408 #line 3673 "./marpa.w"
5409 
5410 /*1362:*/
5411 #line 13119 "./marpa.w"
5412 
5413 if(!item_is_valid(g,item_id)){
5414 g_context_clear(g);
5415 g_context_int_add(g,"item_id",item_id);
5416 g->t_error= "invalid item id";
5417 return failure_indicator;
5418 }
5419 /*:1362*/
5420 #line 3674 "./marpa.w"
5421 
5422 return Sort_Key_of_AIM(AIM_by_ID(item_id));
5423 }
5424 
5425 /*:469*//*471:*/
5426 #line 3685 "./marpa.w"
5427 
5428 static inline
create_AHFA_items(GRAMMAR g)5429 void create_AHFA_items(GRAMMAR g){
5430 RULEID rule_id;
5431 guint no_of_items;
5432 guint no_of_rules= RULE_Count_of_G(g);
5433 AIM base_item= g_new(struct s_AHFA_item,Size_of_G(g));
5434 AIM current_item= base_item;
5435 guint symbol_instance_of_next_rule= 0;
5436 for(rule_id= 0;rule_id<(Marpa_Rule_ID)no_of_rules;rule_id++){
5437 RULE rule= RULE_by_ID(g,rule_id);
5438 if(RULE_is_Used(rule)){
5439 /*473:*/
5440 #line 3711 "./marpa.w"
5441 
5442 {
5443 gint leading_nulls= 0;
5444 gint rhs_ix;
5445 for(rhs_ix= 0;rhs_ix<Length_of_RULE(rule);rhs_ix++)
5446 {
5447 SYMID rh_symid= RHS_ID_of_RULE(rule,rhs_ix);
5448 SYM symbol= SYM_by_ID(rh_symid);
5449 if(!symbol->t_is_nullable)
5450 {
5451 Last_Proper_SYMI_of_RULE(rule)= symbol_instance_of_next_rule+rhs_ix;
5452 /*474:*/
5453 #line 3735 "./marpa.w"
5454 
5455 {
5456 RULE_of_AIM(current_item)= rule;
5457 Sort_Key_of_AIM(current_item)= current_item-base_item;
5458 Null_Count_of_AIM(current_item)= leading_nulls;
5459 Postdot_SYMID_of_AIM(current_item)= rh_symid;
5460 Position_of_AIM(current_item)= rhs_ix;
5461 }
5462 
5463 /*:474*/
5464 #line 3722 "./marpa.w"
5465 
5466 leading_nulls= 0;
5467 current_item++;
5468 }
5469 else
5470 {
5471 leading_nulls++;
5472 }
5473 }
5474 /*475:*/
5475 #line 3744 "./marpa.w"
5476 
5477 {
5478 RULE_of_AIM(current_item)= rule;
5479 Sort_Key_of_AIM(current_item)= current_item-base_item;
5480 Null_Count_of_AIM(current_item)= leading_nulls;
5481 Postdot_SYMID_of_AIM(current_item)= -1;
5482 Position_of_AIM(current_item)= -1;
5483 }
5484 
5485 /*:475*/
5486 #line 3731 "./marpa.w"
5487 
5488 current_item++;
5489 }
5490 
5491 /*:473*/
5492 #line 3697 "./marpa.w"
5493 
5494 SYMI_of_RULE(rule)= symbol_instance_of_next_rule;
5495 symbol_instance_of_next_rule+= Length_of_RULE(rule);
5496 }
5497 }
5498 SYMI_Count_of_G(g)= symbol_instance_of_next_rule;
5499 no_of_items= LV_AIM_Count_of_G(g)= current_item-base_item;
5500 g->t_AHFA_items= g_renew(struct s_AHFA_item,base_item,no_of_items);
5501 /*476:*/
5502 #line 3758 "./marpa.w"
5503 
5504 {
5505 AIM*items_by_rule= g_new(AIM,no_of_rules);
5506 AIM items= g->t_AHFA_items;
5507 
5508 Marpa_Rule_ID highest_found_rule_id= -1;
5509 Marpa_AHFA_Item_ID item_id;
5510 
5511 
5512 for(rule_id= 0;rule_id<(Marpa_Rule_ID)no_of_rules;rule_id++)
5513 {
5514 items_by_rule[rule_id]= NULL;
5515 }
5516 for(item_id= 0;item_id<(Marpa_AHFA_Item_ID)no_of_items;item_id++)
5517 {
5518 AIM item= items+item_id;
5519 Marpa_Rule_ID rule_id_for_item= RULE_of_AIM(item)->t_id;
5520 if(rule_id_for_item<=highest_found_rule_id)
5521 continue;
5522 items_by_rule[rule_id_for_item]= item;
5523 highest_found_rule_id= rule_id_for_item;
5524 }
5525 g->t_AHFA_items_by_rule= items_by_rule;
5526 }
5527 
5528 /*:476*/
5529 #line 3705 "./marpa.w"
5530 
5531 /*483:*/
5532 #line 3834 "./marpa.w"
5533 
5534 {
5535 Marpa_AHFA_Item_ID item_id;
5536 AIM*sort_array= g_new(struct s_AHFA_item*,no_of_items);
5537 AIM items= g->t_AHFA_items;
5538 for(item_id= 0;item_id<(Marpa_AHFA_Item_ID)no_of_items;item_id++)
5539 {
5540 sort_array[item_id]= items+item_id;
5541 }
5542 g_qsort_with_data(sort_array,
5543 (gint)no_of_items,sizeof(AIM),cmp_by_postdot_and_aimid,
5544 (gpointer)NULL);
5545 for(item_id= 0;item_id<(Marpa_AHFA_Item_ID)no_of_items;item_id++)
5546 {
5547 Sort_Key_of_AIM(sort_array[item_id])= item_id;
5548 }
5549 g_free(sort_array);
5550 }
5551 
5552 /*:483*/
5553 #line 3706 "./marpa.w"
5554 
5555 }
5556 /*:471*//*479:*/
5557 #line 3793 "./marpa.w"
5558 
cmp_by_aimid(gconstpointer ap,gconstpointer bp,gpointer user_data G_GNUC_UNUSED)5559 static gint cmp_by_aimid(gconstpointer ap,
5560 gconstpointer bp,
5561 gpointer user_data G_GNUC_UNUSED){
5562 AIM a= *(AIM*)ap;
5563 AIM b= *(AIM*)bp;
5564 return a-b;
5565 }
5566 
5567 /*:479*//*482:*/
5568 #line 3811 "./marpa.w"
5569 
cmp_by_postdot_and_aimid(gconstpointer ap,gconstpointer bp,gpointer user_data G_GNUC_UNUSED)5570 static gint cmp_by_postdot_and_aimid(gconstpointer ap,
5571 gconstpointer bp,gpointer user_data G_GNUC_UNUSED){
5572 AIM a= *(AIM*)ap;
5573 AIM b= *(AIM*)bp;
5574 gint a_postdot= Postdot_SYMID_of_AIM(a);
5575 gint b_postdot= Postdot_SYMID_of_AIM(b);
5576 if(a_postdot==b_postdot)
5577 return Sort_Key_of_AIM(a)-Sort_Key_of_AIM(b);
5578 if(a_postdot<0)return 1;
5579 if(b_postdot<0)return-1;
5580 return a_postdot-b_postdot;
5581 }
5582 
5583 /*:482*//*501:*/
5584 #line 3999 "./marpa.w"
5585 
aex_of_ahfa_by_aim_get(AHFA ahfa,AIM sought_aim)5586 static inline AEX aex_of_ahfa_by_aim_get(AHFA ahfa,AIM sought_aim)
5587 {
5588 AIM*const aims= AIMs_of_AHFA(ahfa);
5589 gint aim_count= AIM_Count_of_AHFA(ahfa);
5590 gint hi= aim_count-1;
5591 gint lo= 0;
5592 while(hi>=lo){
5593 gint trial_aex= lo+(hi-lo)/2;
5594 AIM trial_aim= aims[trial_aex];
5595 if(trial_aim==sought_aim)return trial_aex;
5596 if(trial_aim<sought_aim){
5597 lo= trial_aex+1;
5598 }else{
5599 hi= trial_aex-1;
5600 }
5601 }
5602 return-1;
5603 }
5604 
5605 /*:501*//*511:*/
5606 #line 4070 "./marpa.w"
5607 
AHFA_state_id_is_valid(const struct marpa_g * g,AHFAID AHFA_state_id)5608 static inline gint AHFA_state_id_is_valid(
5609 const struct marpa_g*g,AHFAID AHFA_state_id){
5610 return AHFA_state_id<AHFA_Count_of_G(g)&&AHFA_state_id>=0;
5611 }
5612 /*:511*//*515:*/
5613 #line 4089 "./marpa.w"
5614 
marpa_AHFA_state_count(struct marpa_g * g)5615 guint marpa_AHFA_state_count(struct marpa_g*g){
5616 return AHFA_Count_of_G(g);
5617 }
5618 /*:515*//*517:*/
5619 #line 4096 "./marpa.w"
5620 
5621 gint
marpa_AHFA_state_item_count(struct marpa_g * g,AHFAID AHFA_state_id)5622 marpa_AHFA_state_item_count(struct marpa_g*g,AHFAID AHFA_state_id)
5623 {/*1357:*/
5624 #line 13088 "./marpa.w"
5625 const int failure_indicator= -2;
5626 
5627 /*:1357*/
5628 #line 4099 "./marpa.w"
5629 
5630 AHFA state;
5631 /*1359:*/
5632 #line 13099 "./marpa.w"
5633 
5634 if(!G_is_Precomputed(g)){
5635 g_context_clear(g);
5636 g->t_error= "grammar not precomputed";
5637 return failure_indicator;
5638 }
5639 /*:1359*/
5640 #line 4101 "./marpa.w"
5641 
5642 /*1363:*/
5643 #line 13126 "./marpa.w"
5644 
5645 if(!AHFA_state_id_is_valid(g,AHFA_state_id)){
5646 g_context_clear(g);
5647 g_context_int_add(g,"AHFA_state_id",AHFA_state_id);
5648 g->t_error= "invalid AHFA state id";
5649 return failure_indicator;
5650 }
5651 /*:1363*/
5652 #line 4102 "./marpa.w"
5653 
5654 state= AHFA_of_G_by_ID(g,AHFA_state_id);
5655 return state->t_item_count;
5656 }
5657 /*:517*//*520:*/
5658 #line 4115 "./marpa.w"
5659 
marpa_AHFA_state_item(struct marpa_g * g,AHFAID AHFA_state_id,guint item_ix)5660 Marpa_AHFA_Item_ID marpa_AHFA_state_item(struct marpa_g*g,
5661 AHFAID AHFA_state_id,
5662 guint item_ix){
5663 AHFA state;
5664 /*1357:*/
5665 #line 13088 "./marpa.w"
5666 const int failure_indicator= -2;
5667 
5668 /*:1357*/
5669 #line 4120 "./marpa.w"
5670 
5671 /*1359:*/
5672 #line 13099 "./marpa.w"
5673 
5674 if(!G_is_Precomputed(g)){
5675 g_context_clear(g);
5676 g->t_error= "grammar not precomputed";
5677 return failure_indicator;
5678 }
5679 /*:1359*/
5680 #line 4121 "./marpa.w"
5681 
5682 /*1363:*/
5683 #line 13126 "./marpa.w"
5684 
5685 if(!AHFA_state_id_is_valid(g,AHFA_state_id)){
5686 g_context_clear(g);
5687 g_context_int_add(g,"AHFA_state_id",AHFA_state_id);
5688 g->t_error= "invalid AHFA state id";
5689 return failure_indicator;
5690 }
5691 /*:1363*/
5692 #line 4122 "./marpa.w"
5693 
5694 state= AHFA_of_G_by_ID(g,AHFA_state_id);
5695 if(item_ix>=state->t_item_count){
5696 g_context_clear(g);
5697 g_context_int_add(g,"item_ix",(gint)item_ix);
5698 g_context_int_add(g,"AHFA_state_id",AHFA_state_id);
5699 g->t_error= "invalid state item ix";
5700 return failure_indicator;
5701 }
5702 return AIMID_of_AHFA_by_AEX(g,state,item_ix);
5703 }
5704 
5705 /*:520*//*521:*/
5706 #line 4134 "./marpa.w"
5707 
marpa_AHFA_state_is_predict(struct marpa_g * g,AHFAID AHFA_state_id)5708 gint marpa_AHFA_state_is_predict(struct marpa_g*g,
5709 AHFAID AHFA_state_id){
5710 AHFA state;
5711 /*1357:*/
5712 #line 13088 "./marpa.w"
5713 const int failure_indicator= -2;
5714 
5715 /*:1357*/
5716 #line 4138 "./marpa.w"
5717 
5718 /*1359:*/
5719 #line 13099 "./marpa.w"
5720 
5721 if(!G_is_Precomputed(g)){
5722 g_context_clear(g);
5723 g->t_error= "grammar not precomputed";
5724 return failure_indicator;
5725 }
5726 /*:1359*/
5727 #line 4139 "./marpa.w"
5728 
5729 /*1363:*/
5730 #line 13126 "./marpa.w"
5731 
5732 if(!AHFA_state_id_is_valid(g,AHFA_state_id)){
5733 g_context_clear(g);
5734 g_context_int_add(g,"AHFA_state_id",AHFA_state_id);
5735 g->t_error= "invalid AHFA state id";
5736 return failure_indicator;
5737 }
5738 /*:1363*/
5739 #line 4140 "./marpa.w"
5740 
5741 state= AHFA_of_G_by_ID(g,AHFA_state_id);
5742 return AHFA_is_Predicted(state);
5743 }
5744 /*:521*//*526:*/
5745 #line 4179 "./marpa.w"
5746 
marpa_AHFA_completed_start_rule(struct marpa_g * g,Marpa_AHFA_State_ID AHFA_state_id)5747 Marpa_Rule_ID marpa_AHFA_completed_start_rule(struct marpa_g*g,
5748 Marpa_AHFA_State_ID AHFA_state_id){
5749 const gint no_completed_start_rule= -1;
5750 /*1357:*/
5751 #line 13088 "./marpa.w"
5752 const int failure_indicator= -2;
5753 
5754 /*:1357*/
5755 #line 4183 "./marpa.w"
5756 
5757 AHFA state;
5758 /*1359:*/
5759 #line 13099 "./marpa.w"
5760 
5761 if(!G_is_Precomputed(g)){
5762 g_context_clear(g);
5763 g->t_error= "grammar not precomputed";
5764 return failure_indicator;
5765 }
5766 /*:1359*/
5767 #line 4185 "./marpa.w"
5768 
5769 /*1363:*/
5770 #line 13126 "./marpa.w"
5771 
5772 if(!AHFA_state_id_is_valid(g,AHFA_state_id)){
5773 g_context_clear(g);
5774 g_context_int_add(g,"AHFA_state_id",AHFA_state_id);
5775 g->t_error= "invalid AHFA state id";
5776 return failure_indicator;
5777 }
5778 /*:1363*/
5779 #line 4186 "./marpa.w"
5780 
5781 state= AHFA_of_G_by_ID(g,AHFA_state_id);
5782 if(AHFA_has_Completed_Start_Rule(state)){
5783 const gint ahfa_item_count= state->t_item_count;
5784 const AIM*ahfa_items= state->t_items;
5785 gint ahfa_ix;
5786 for(ahfa_ix= 0;ahfa_ix<ahfa_item_count;ahfa_ix++)
5787 {
5788 const AIM ahfa_item= ahfa_items[ahfa_ix];
5789 if(AIM_is_Completion(ahfa_item))
5790 {
5791 const RULE rule= RULE_of_AIM(ahfa_item);
5792 if(RULE_is_Start(rule))
5793 return ID_of_RULE(rule);
5794 }
5795 }
5796 /*1365:*/
5797 #line 13140 "./marpa.w"
5798 {
5799 g_context_clear(g);
5800 g->t_error= "internal error";
5801 return failure_indicator;
5802 }
5803 
5804 /*:1365*/
5805 #line 4202 "./marpa.w"
5806 
5807 }
5808 return no_completed_start_rule;
5809 }
5810 
5811 /*:526*//*530:*/
5812 #line 4221 "./marpa.w"
5813 
marpa_AHFA_state_leo_lhs_symbol(struct marpa_g * g,Marpa_AHFA_State_ID AHFA_state_id)5814 Marpa_Symbol_ID marpa_AHFA_state_leo_lhs_symbol(struct marpa_g*g,
5815 Marpa_AHFA_State_ID AHFA_state_id){
5816 /*1357:*/
5817 #line 13088 "./marpa.w"
5818 const int failure_indicator= -2;
5819 
5820 /*:1357*/
5821 #line 4224 "./marpa.w"
5822 
5823 AHFA state;
5824 /*1359:*/
5825 #line 13099 "./marpa.w"
5826 
5827 if(!G_is_Precomputed(g)){
5828 g_context_clear(g);
5829 g->t_error= "grammar not precomputed";
5830 return failure_indicator;
5831 }
5832 /*:1359*/
5833 #line 4226 "./marpa.w"
5834 
5835 /*1363:*/
5836 #line 13126 "./marpa.w"
5837 
5838 if(!AHFA_state_id_is_valid(g,AHFA_state_id)){
5839 g_context_clear(g);
5840 g_context_int_add(g,"AHFA_state_id",AHFA_state_id);
5841 g->t_error= "invalid AHFA state id";
5842 return failure_indicator;
5843 }
5844 /*:1363*/
5845 #line 4227 "./marpa.w"
5846 
5847 state= AHFA_of_G_by_ID(g,AHFA_state_id);
5848 return Leo_LHS_ID_of_AHFA(state);
5849 }
5850 
5851 /*:530*//*533:*/
5852 #line 4250 "./marpa.w"
5853 
AHFA_state_cmp(gconstpointer ap,gconstpointer bp)5854 static gint AHFA_state_cmp(
5855 gconstpointer ap,
5856 gconstpointer bp)
5857 {
5858 guint i;
5859 AIM*items_a;
5860 AIM*items_b;
5861 const AHFA state_a= (AHFA)ap;
5862 const AHFA state_b= (AHFA)bp;
5863 guint length= state_a->t_item_count;
5864 gint subkey= length-state_b->t_item_count;
5865 if(subkey)return subkey;
5866 if(length!=state_b->t_item_count)return FALSE;
5867 items_a= state_a->t_items;
5868 items_b= state_b->t_items;
5869 for(i= 0;i<length;i++){
5870 subkey= Sort_Key_of_AIM(items_a[i])-Sort_Key_of_AIM(items_b[i]);
5871 if(subkey)return subkey;
5872 }
5873 return 0;
5874 }
5875 
5876 /*:533*//*536:*/
5877 #line 4276 "./marpa.w"
5878 
5879 PRIVATE_NOT_INLINE
create_AHFA_states(struct marpa_g * g)5880 void create_AHFA_states(struct marpa_g*g){
5881 /*537:*/
5882 #line 4295 "./marpa.w"
5883 
5884 AHFA p_working_state;
5885 const guint initial_no_of_states= 2*Size_of_G(g);
5886 AIM AHFA_item_0_p= g->t_AHFA_items;
5887 const guint symbol_count_of_g= SYM_Count_of_G(g);
5888 const guint rule_count_of_g= RULE_Count_of_G(g);
5889 Bit_Matrix prediction_matrix;
5890 RULE*rule_by_sort_key= g_new(RULE,rule_count_of_g);
5891 GTree*duplicates;
5892 AHFA*singleton_duplicates;
5893 DQUEUE_DECLARE(states);
5894 struct obstack ahfa_work_obs;
5895 gint ahfa_count_of_g;
5896 AHFA ahfas_of_g;
5897 
5898 /*:537*/
5899 #line 4279 "./marpa.w"
5900 
5901 /*538:*/
5902 #line 4310 "./marpa.w"
5903 
5904 /*539:*/
5905 #line 4314 "./marpa.w"
5906 
5907 {
5908 guint item_id;
5909 guint no_of_items_in_grammar= AIM_Count_of_G(g);
5910 obstack_init(&ahfa_work_obs);
5911 duplicates= g_tree_new(AHFA_state_cmp);
5912 singleton_duplicates= g_new(AHFA,no_of_items_in_grammar);
5913 for(item_id= 0;item_id<no_of_items_in_grammar;item_id++)
5914 {
5915 singleton_duplicates[item_id]= NULL;
5916 }
5917 }
5918 
5919 /*:539*/
5920 #line 4311 "./marpa.w"
5921 
5922 DQUEUE_INIT(states,AHFA_Object,initial_no_of_states);
5923 
5924 /*:538*/
5925 #line 4280 "./marpa.w"
5926 
5927 /*561:*/
5928 #line 4860 "./marpa.w"
5929 {
5930 Bit_Matrix symbol_by_symbol_matrix=
5931 matrix_create(symbol_count_of_g,symbol_count_of_g);
5932 /*562:*/
5933 #line 4869 "./marpa.w"
5934 
5935 {
5936 RULEID rule_id;
5937 SYMID symid;
5938 AIM*items_by_rule= g->t_AHFA_items_by_rule;
5939 for(symid= 0;symid<(SYMID)symbol_count_of_g;symid++)
5940 {
5941 
5942 SYM symbol= SYM_by_ID(symid);
5943 if(!SYMBOL_LHS_RULE_COUNT(symbol))
5944 continue;
5945 matrix_bit_set(symbol_by_symbol_matrix,(guint)symid,(guint)symid);
5946 }
5947 for(rule_id= 0;rule_id<(RULEID)rule_count_of_g;rule_id++)
5948 {
5949 SYMID from,to;
5950 
5951 AIM item= items_by_rule[rule_id];
5952 
5953 if(!item)
5954 continue;
5955 from= LHS_ID_of_AIM(item);
5956 to= Postdot_SYMID_of_AIM(item);
5957 
5958 if(to<0)
5959 continue;
5960 
5961 matrix_bit_set(symbol_by_symbol_matrix,(guint)from,(guint)to);
5962 }
5963 }
5964 
5965 /*:562*/
5966 #line 4863 "./marpa.w"
5967 
5968 transitive_closure(symbol_by_symbol_matrix);
5969 /*563:*/
5970 #line 4906 "./marpa.w"
5971 {
5972 AIM*items_by_rule= g->t_AHFA_items_by_rule;
5973 SYMID from_symid;
5974 guint*sort_key_by_rule_id= g_new(guint,rule_count_of_g);
5975 guint no_of_predictable_rules= 0;
5976 /*564:*/
5977 #line 4936 "./marpa.w"
5978 
5979 {
5980 RULEID rule_id;
5981 for(rule_id= 0;rule_id<(RULEID)rule_count_of_g;rule_id++)
5982 {
5983 AIM item= items_by_rule[rule_id];
5984 SYMID postdot;
5985 if(!item)
5986 goto NOT_A_PREDICTABLE_RULE;
5987 postdot= Postdot_SYMID_of_AIM(item);
5988 if(postdot<0)
5989 goto NOT_A_PREDICTABLE_RULE;
5990 sort_key_by_rule_id[rule_id]= postdot;
5991 no_of_predictable_rules++;
5992 continue;
5993 NOT_A_PREDICTABLE_RULE:
5994 sort_key_by_rule_id[rule_id]= G_MAXINT;
5995 }
5996 }
5997 
5998 /*:564*/
5999 #line 4912 "./marpa.w"
6000 
6001 /*565:*/
6002 #line 4956 "./marpa.w"
6003 
6004 {
6005 RULEID rule_id;
6006 for(rule_id= 0;rule_id<(RULEID)rule_count_of_g;rule_id++)
6007 {
6008 rule_by_sort_key[rule_id]= RULE_by_ID(g,rule_id);
6009 }
6010 g_qsort_with_data(rule_by_sort_key,(gint)rule_count_of_g,
6011 sizeof(RULE),cmp_by_rule_sort_key,
6012 (gpointer)sort_key_by_rule_id);
6013 }
6014 
6015 /*:565*/
6016 #line 4913 "./marpa.w"
6017 
6018 /*568:*/
6019 #line 4988 "./marpa.w"
6020 
6021 {
6022 guint sort_key;
6023 for(sort_key= 0;sort_key<rule_count_of_g;sort_key++)
6024 {
6025 RULE rule= rule_by_sort_key[sort_key];
6026 sort_key_by_rule_id[rule->t_id]= sort_key;
6027 }
6028 }
6029 
6030 /*:568*/
6031 #line 4914 "./marpa.w"
6032 
6033 /*569:*/
6034 #line 4998 "./marpa.w"
6035 
6036 {
6037 prediction_matrix= matrix_create(symbol_count_of_g,no_of_predictable_rules);
6038 for(from_symid= 0;from_symid<(SYMID)symbol_count_of_g;
6039 from_symid++)
6040 {
6041 
6042 guint min,max,start;
6043 for(start= 0;
6044 bv_scan(matrix_row
6045 (symbol_by_symbol_matrix,(guint)from_symid),start,
6046 &min,&max);start= max+2)
6047 {
6048 Marpa_Symbol_ID to_symid;
6049 for(to_symid= min;to_symid<=(Marpa_Symbol_ID)max;
6050 to_symid++)
6051 {
6052 
6053 SYM to_symbol= SYM_by_ID(to_symid);
6054 GArray*lhs_rules= to_symbol->t_lhs;
6055 guint ix,no_of_lhs_rules= lhs_rules->len;
6056 for(ix= 0;ix<no_of_lhs_rules;ix++)
6057 {
6058 
6059 Marpa_Rule_ID rule_with_this_lhs_symbol=
6060 g_array_index(lhs_rules,Marpa_Rule_ID,ix);
6061 guint sort_key=
6062 sort_key_by_rule_id[rule_with_this_lhs_symbol];
6063 if(sort_key>=no_of_predictable_rules)
6064 continue;
6065 
6066 matrix_bit_set(prediction_matrix,(guint)from_symid,
6067 sort_key);
6068 
6069 }
6070 }
6071 }
6072 }
6073 }
6074 
6075 /*:569*/
6076 #line 4915 "./marpa.w"
6077 
6078 g_free(sort_key_by_rule_id);
6079 }
6080 
6081 /*:563*/
6082 #line 4865 "./marpa.w"
6083 
6084 matrix_free(symbol_by_symbol_matrix);
6085 }
6086 
6087 /*:561*/
6088 #line 4281 "./marpa.w"
6089 
6090 /*546:*/
6091 #line 4448 "./marpa.w"
6092 {
6093 AHFA p_initial_state= DQUEUE_PUSH(states,AHFA_Object);
6094 Marpa_Rule_ID start_rule_id;
6095 AIM start_item;
6096 SYM start_symbol= SYM_by_ID(g->t_start_symid);
6097 SYM start_alias
6098 = symbol_null_alias(start_symbol);
6099 gint no_of_items_in_new_state= start_alias?2:1;
6100 AIM*item_list
6101 = obstack_alloc(&g->t_obs,no_of_items_in_new_state*sizeof(AIM));
6102 start_rule_id= g_array_index(start_symbol->t_lhs,Marpa_Rule_ID,0);
6103 
6104 start_item= g->t_AHFA_items_by_rule[start_rule_id];
6105 
6106 item_list[0]= start_item;
6107 if(start_alias){
6108 Marpa_Rule_ID alias_rule_id
6109 = g_array_index(start_alias->t_lhs,Marpa_Rule_ID,0);
6110 
6111 
6112 item_list[1]= g->t_AHFA_items_by_rule[alias_rule_id];
6113 }
6114 p_initial_state->t_items= item_list;
6115 p_initial_state->t_item_count= no_of_items_in_new_state;
6116 p_initial_state->t_key.t_id= 0;
6117 LV_AHFA_is_Predicted(p_initial_state)= 0;
6118 LV_Leo_LHS_ID_of_AHFA(p_initial_state)= -1;
6119 LV_TRANSs_of_AHFA(p_initial_state)= transitions_new(g);
6120 p_initial_state->t_empty_transition= NULL;
6121 if(SYM_is_Nulling(start_symbol))
6122 {
6123 SYMID*complete_symids= obstack_alloc(&g->t_obs,sizeof(SYMID));
6124 SYMID completed_symbol_id= ID_of_SYM(start_symbol);
6125 *complete_symids= completed_symbol_id;
6126 completion_count_inc(&ahfa_work_obs,p_initial_state,completed_symbol_id);
6127 LV_Complete_SYMIDs_of_AHFA(p_initial_state)= complete_symids;
6128 LV_Complete_SYM_Count_of_AHFA(p_initial_state)= 1;
6129 p_initial_state->t_has_completed_start_rule= 1;
6130 LV_Postdot_SYM_Count_of_AHFA(p_initial_state)= 0;
6131 }
6132 else
6133 {
6134 SYMID*postdot_symbol_ids;
6135 LV_Postdot_SYM_Count_of_AHFA(p_initial_state)= 1;
6136 postdot_symbol_ids= LV_Postdot_SYMID_Ary_of_AHFA(p_initial_state)=
6137 obstack_alloc(&g->t_obs,sizeof(SYMID));
6138 *postdot_symbol_ids= Postdot_SYMID_of_AIM(start_item);
6139 if(start_alias)
6140 {
6141 SYMID*complete_symids= obstack_alloc(&g->t_obs,sizeof(SYMID));
6142 SYMID completed_symbol_id= ID_of_SYM(start_alias);
6143 *complete_symids= completed_symbol_id;
6144 completion_count_inc(&ahfa_work_obs,p_initial_state,completed_symbol_id);
6145 LV_Complete_SYMIDs_of_AHFA(p_initial_state)= complete_symids;
6146 LV_Complete_SYM_Count_of_AHFA(p_initial_state)= 1;
6147 p_initial_state->t_has_completed_start_rule= 1;
6148 }
6149 else
6150 {
6151 LV_Complete_SYM_Count_of_AHFA(p_initial_state)= 0;
6152 p_initial_state->t_has_completed_start_rule= 0;
6153 }
6154 p_initial_state->t_empty_transition=
6155 create_predicted_AHFA_state(g,
6156 matrix_row(prediction_matrix,
6157 (guint)
6158 Postdot_SYMID_of_AIM(start_item)),
6159 rule_by_sort_key,&states,duplicates);
6160 }
6161 }
6162 
6163 /*:546*/
6164 #line 4282 "./marpa.w"
6165 
6166 while((p_working_state= DQUEUE_NEXT(states,AHFA_Object))){
6167 /*540:*/
6168 #line 4327 "./marpa.w"
6169 {
6170 guint no_of_items= p_working_state->t_item_count;
6171 guint current_item_ix= 0;
6172 AIM*item_list;
6173 Marpa_Symbol_ID working_symbol;
6174 item_list= p_working_state->t_items;
6175 working_symbol= Postdot_SYMID_of_AIM(item_list[0]);
6176 
6177 if(working_symbol<0)goto NEXT_AHFA_STATE;
6178 
6179 while(1){
6180 guint first_working_item_ix= current_item_ix;
6181 guint no_of_items_in_new_state;
6182 for(current_item_ix++;
6183 current_item_ix<no_of_items;
6184 current_item_ix++){
6185 if(Postdot_SYMID_of_AIM(item_list[current_item_ix])!=working_symbol)break;
6186 }
6187 no_of_items_in_new_state= current_item_ix-first_working_item_ix;
6188 if(no_of_items_in_new_state==1){
6189 /*548:*/
6190 #line 4549 "./marpa.w"
6191 {
6192 AHFA p_new_state;
6193 AIM*new_state_item_list;
6194 AIM single_item_p= item_list[first_working_item_ix];
6195 Marpa_AHFA_Item_ID single_item_id;
6196 Marpa_Symbol_ID postdot;
6197 single_item_p++;
6198 single_item_id= single_item_p-AHFA_item_0_p;
6199 p_new_state= singleton_duplicates[single_item_id];
6200 if(p_new_state)
6201 {
6202 transition_add(&ahfa_work_obs,p_working_state,working_symbol,p_new_state);
6203 goto NEXT_WORKING_SYMBOL;
6204 }
6205 p_new_state= DQUEUE_PUSH(states,AHFA_Object);
6206 
6207 singleton_duplicates[single_item_id]= p_new_state;
6208 new_state_item_list= p_new_state->t_items=
6209 obstack_alloc(&g->t_obs,sizeof(AIM));
6210 new_state_item_list[0]= single_item_p;
6211 p_new_state->t_item_count= 1;
6212 LV_AHFA_is_Predicted(p_new_state)= 0;
6213 if(AIM_has_Completed_Start_Rule(single_item_p)){
6214 p_new_state->t_has_completed_start_rule= 1;
6215 }else{
6216 p_new_state->t_has_completed_start_rule= 0;
6217 }
6218 LV_Leo_LHS_ID_of_AHFA(p_new_state)= -1;
6219 p_new_state->t_key.t_id= p_new_state-DQUEUE_BASE(states,AHFA_Object);
6220 LV_TRANSs_of_AHFA(p_new_state)= transitions_new(g);
6221 transition_add(&ahfa_work_obs,p_working_state,working_symbol,p_new_state);
6222 postdot= Postdot_SYMID_of_AIM(single_item_p);
6223 if(postdot>=0)
6224 {
6225 LV_Complete_SYM_Count_of_AHFA(p_new_state)= 0;
6226 p_new_state->t_postdot_sym_count= 1;
6227 p_new_state->t_postdot_symid_ary=
6228 obstack_alloc(&g->t_obs,sizeof(SYMID));
6229 *(p_new_state->t_postdot_symid_ary)= postdot;
6230 
6231 
6232 p_new_state->t_empty_transition=
6233 create_predicted_AHFA_state(g,
6234 matrix_row(prediction_matrix,
6235 (guint)postdot),
6236 rule_by_sort_key,&states,duplicates);
6237 }
6238 else
6239 {
6240 SYMID lhs_id= LHS_ID_of_AIM(single_item_p);
6241 SYMID*complete_symids= obstack_alloc(&g->t_obs,sizeof(SYMID));
6242 *complete_symids= lhs_id;
6243 LV_Complete_SYMIDs_of_AHFA(p_new_state)= complete_symids;
6244 completion_count_inc(&ahfa_work_obs,p_new_state,lhs_id);
6245 LV_Complete_SYM_Count_of_AHFA(p_new_state)= 1;
6246 p_new_state->t_postdot_sym_count= 0;
6247 p_new_state->t_empty_transition= NULL;
6248 /*550:*/
6249 #line 4639 "./marpa.w"
6250 {
6251 AIM previous_ahfa_item= single_item_p-1;
6252 SYMID predot_symid= Postdot_SYMID_of_AIM(previous_ahfa_item);
6253 if(SYMBOL_LHS_RULE_COUNT(SYM_by_ID(predot_symid))
6254 > 0)
6255 {
6256 LV_Leo_LHS_ID_of_AHFA(p_new_state)= lhs_id;
6257 }
6258 }
6259 
6260 /*:550*/
6261 #line 4607 "./marpa.w"
6262 
6263 }
6264 }
6265 
6266 /*:548*/
6267 #line 4347 "./marpa.w"
6268 
6269 }else{
6270 /*551:*/
6271 #line 4664 "./marpa.w"
6272 {
6273 AHFA p_new_state;
6274 guint predecessor_ix;
6275 guint no_of_new_items_so_far= 0;
6276 AIM*item_list_for_new_state;
6277 AHFA queued_AHFA_state;
6278 p_new_state= DQUEUE_PUSH(states,AHFA_Object);
6279 item_list_for_new_state= p_new_state->t_items= obstack_alloc(&g->t_obs_tricky,
6280 no_of_items_in_new_state*sizeof(AIM));
6281 p_new_state->t_item_count= no_of_items_in_new_state;
6282 for(predecessor_ix= first_working_item_ix;
6283 predecessor_ix<current_item_ix;predecessor_ix++)
6284 {
6285 gint pre_insertion_point_ix= no_of_new_items_so_far-1;
6286 AIM new_item_p= item_list[predecessor_ix]+1;
6287 while(pre_insertion_point_ix>=0)
6288 {
6289 AIM*current_item_pp=
6290 item_list_for_new_state+pre_insertion_point_ix;
6291 if(Sort_Key_of_AIM(new_item_p)>=
6292 Sort_Key_of_AIM(*current_item_pp))
6293 break;
6294 *(current_item_pp+1)= *current_item_pp;
6295 pre_insertion_point_ix--;
6296 }
6297 item_list_for_new_state[pre_insertion_point_ix+1]= new_item_p;
6298 no_of_new_items_so_far++;
6299 }
6300 queued_AHFA_state= assign_AHFA_state(p_new_state,duplicates);
6301 if(queued_AHFA_state)
6302 {
6303 
6304 (void)DQUEUE_POP(states,AHFA_Object);
6305 obstack_free(&g->t_obs_tricky,item_list_for_new_state);
6306 transition_add(&ahfa_work_obs,p_working_state,working_symbol,queued_AHFA_state);
6307 
6308 
6309 goto NEXT_WORKING_SYMBOL;
6310 }
6311 
6312 p_new_state->t_key.t_id= p_new_state-DQUEUE_BASE(states,AHFA_Object);
6313 LV_AHFA_is_Predicted(p_new_state)= 0;
6314 p_new_state->t_has_completed_start_rule= 0;
6315 LV_Leo_LHS_ID_of_AHFA(p_new_state)= -1;
6316 LV_TRANSs_of_AHFA(p_new_state)= transitions_new(g);
6317 /*552:*/
6318 #line 4715 "./marpa.w"
6319 
6320 {
6321 guint symbol_count= SYM_Count_of_G(g);
6322 guint item_ix;
6323 guint no_of_postdot_symbols;
6324 guint no_of_complete_symbols;
6325 Bit_Vector complete_v= bv_create(symbol_count);
6326 Bit_Vector postdot_v= bv_create(symbol_count);
6327 for(item_ix= 0;item_ix<no_of_items_in_new_state;item_ix++)
6328 {
6329 AIM item= item_list_for_new_state[item_ix];
6330 Marpa_Symbol_ID postdot= Postdot_SYMID_of_AIM(item);
6331 if(postdot<0)
6332 {
6333 gint complete_symbol_id= LHS_ID_of_AIM(item);
6334 completion_count_inc(&ahfa_work_obs,p_new_state,complete_symbol_id);
6335 bv_bit_set(complete_v,(guint)complete_symbol_id);
6336 }
6337 else
6338 {
6339 bv_bit_set(postdot_v,(guint)postdot);
6340 }
6341 }
6342 if((no_of_postdot_symbols= p_new_state->t_postdot_sym_count=
6343 bv_count(postdot_v)))
6344 {
6345 guint min,max,start;
6346 Marpa_Symbol_ID*p_symbol= p_new_state->t_postdot_symid_ary=
6347 obstack_alloc(&g->t_obs,
6348 no_of_postdot_symbols*sizeof(SYMID));
6349 for(start= 0;bv_scan(postdot_v,start,&min,&max);start= max+2)
6350 {
6351 Marpa_Symbol_ID postdot;
6352 for(postdot= (Marpa_Symbol_ID)min;
6353 postdot<=(Marpa_Symbol_ID)max;postdot++)
6354 {
6355 *p_symbol++= postdot;
6356 }
6357 }
6358 }
6359 if((no_of_complete_symbols=
6360 LV_Complete_SYM_Count_of_AHFA(p_new_state)= bv_count(complete_v)))
6361 {
6362 guint min,max,start;
6363 SYMID*complete_symids= obstack_alloc(&g->t_obs,
6364 no_of_complete_symbols*
6365 sizeof(SYMID));
6366 SYMID*p_symbol= complete_symids;
6367 LV_Complete_SYMIDs_of_AHFA(p_new_state)= complete_symids;
6368 for(start= 0;bv_scan(complete_v,start,&min,&max);start= max+2)
6369 {
6370 SYMID complete_symbol_id;
6371 for(complete_symbol_id= (SYMID)min;complete_symbol_id<=(SYMID)max;
6372 complete_symbol_id++)
6373 {
6374 *p_symbol++= complete_symbol_id;
6375 }
6376 }
6377 }
6378 bv_free(postdot_v);
6379 bv_free(complete_v);
6380 }
6381 
6382 /*:552*/
6383 #line 4709 "./marpa.w"
6384 
6385 transition_add(&ahfa_work_obs,p_working_state,working_symbol,p_new_state);
6386 /*556:*/
6387 #line 4798 "./marpa.w"
6388 {
6389 guint item_ix;
6390 Marpa_Symbol_ID postdot= -1;
6391 for(item_ix= 0;item_ix<no_of_items_in_new_state;item_ix++){
6392 postdot= Postdot_SYMID_of_AIM(item_list_for_new_state[item_ix]);
6393 if(postdot>=0)break;
6394 }
6395 p_new_state->t_empty_transition= NULL;
6396 if(postdot>=0)
6397 {
6398 Bit_Vector predicted_rule_vector
6399 = bv_shadow(matrix_row(prediction_matrix,(guint)postdot));
6400 for(item_ix= 0;item_ix<no_of_items_in_new_state;item_ix++)
6401 {
6402 
6403 postdot= Postdot_SYMID_of_AIM(item_list_for_new_state[item_ix]);
6404 if(postdot<0)
6405 continue;
6406 bv_or_assign(predicted_rule_vector,
6407 matrix_row(prediction_matrix,(guint)postdot));
6408 }
6409 
6410 p_new_state->t_empty_transition= create_predicted_AHFA_state(g,
6411 predicted_rule_vector,
6412 rule_by_sort_key,
6413 &states,
6414 duplicates);
6415 bv_free(predicted_rule_vector);
6416 }
6417 }
6418 
6419 /*:556*/
6420 #line 4712 "./marpa.w"
6421 
6422 }
6423 
6424 /*:551*/
6425 #line 4349 "./marpa.w"
6426 
6427 }
6428 NEXT_WORKING_SYMBOL:;
6429 if(current_item_ix>=no_of_items)break;
6430 working_symbol= Postdot_SYMID_of_AIM(item_list[current_item_ix]);
6431 if(working_symbol<0)break;
6432 }
6433 NEXT_AHFA_STATE:;
6434 }
6435 
6436 /*:540*/
6437 #line 4284 "./marpa.w"
6438 
6439 }
6440 ahfas_of_g= g->t_AHFA= DQUEUE_BASE(states,AHFA_Object);
6441 
6442 ahfa_count_of_g= AHFA_Count_of_G(g)= DQUEUE_END(states);
6443 /*541:*/
6444 #line 4359 "./marpa.w"
6445 
6446 {
6447 gint ahfa_id;
6448 for(ahfa_id= 0;ahfa_id<ahfa_count_of_g;ahfa_id++){
6449 guint symbol_id;
6450 AHFA ahfa= AHFA_of_G_by_ID(g,ahfa_id);
6451 TRANS*const transitions= TRANSs_of_AHFA(ahfa);
6452 for(symbol_id= 0;symbol_id<symbol_count_of_g;symbol_id++){
6453 TRANS working_transition= transitions[symbol_id];
6454 if(working_transition){
6455 gint completion_count= Completion_Count_of_TRANS(working_transition);
6456 gint sizeof_transition=
6457 G_STRUCT_OFFSET(struct s_transition,t_aex)+completion_count*
6458 sizeof(transitions[0]->t_aex[0]);
6459 TRANS new_transition= obstack_alloc(&g->t_obs,sizeof_transition);
6460 LV_To_AHFA_of_TRANS(new_transition)= To_AHFA_of_TRANS(working_transition);
6461 LV_Completion_Count_of_TRANS(new_transition)= 0;
6462 transitions[symbol_id]= new_transition;
6463 }
6464 }
6465 }
6466 }
6467 
6468 /*:541*/
6469 #line 4289 "./marpa.w"
6470 
6471 /*543:*/
6472 #line 4411 "./marpa.w"
6473 
6474 {
6475 gint ahfa_id;
6476 for(ahfa_id= 0;ahfa_id<ahfa_count_of_g;ahfa_id++)
6477 {
6478 AHFA ahfa= AHFA_of_G_by_ID(g,ahfa_id);
6479 TRANS*const transitions= TRANSs_of_AHFA(ahfa);
6480 AIM*aims= AIMs_of_AHFA(ahfa);
6481 gint aim_count= AIM_Count_of_AHFA(ahfa);
6482 AEX aex;
6483 g_qsort_with_data(aims,aim_count,sizeof(AIM*),cmp_by_aimid,NULL);
6484 for(aex= 0;aex<aim_count;aex++)
6485 {
6486 AIM ahfa_item= aims[aex];
6487 SYMID postdot= Postdot_SYMID_of_AIM(ahfa_item);
6488 if(postdot>=0)
6489 {
6490 TRANS transition= transitions[postdot];
6491 AHFA to_ahfa= To_AHFA_of_TRANS(transition);
6492 if(!AHFA_is_Leo_Completion(to_ahfa))
6493 continue;
6494 Leo_Base_AEX_of_TRANS(transition)= aex;
6495 }
6496 }
6497 }
6498 }
6499 
6500 /*:543*/
6501 #line 4290 "./marpa.w"
6502 
6503 /*542:*/
6504 #line 4382 "./marpa.w"
6505 
6506 {
6507 gint ahfa_id;
6508 for(ahfa_id= 0;ahfa_id<ahfa_count_of_g;ahfa_id++){
6509 const AHFA ahfa= AHFA_of_G_by_ID(g,ahfa_id);
6510 TRANS*const transitions= TRANSs_of_AHFA(ahfa);
6511 if(Complete_SYM_Count_of_AHFA(ahfa)> 0){
6512 AIM*aims= AIMs_of_AHFA(ahfa);
6513 gint aim_count= AIM_Count_of_AHFA(ahfa);
6514 AEX aex;
6515 for(aex= 0;aex<aim_count;aex++){
6516 AIM ahfa_item= aims[aex];
6517 if(AIM_is_Completion(ahfa_item)){
6518 SYMID completed_symbol_id= LHS_ID_of_AIM(ahfa_item);
6519 TRANS transition= transitions[completed_symbol_id];
6520 AEX*aexes= AEXs_of_TRANS(transition);
6521 gint aex_ix= LV_Completion_Count_of_TRANS(transition)++;
6522 MARPA_OFF_DEBUG4("Added completion aex at %d for ahfa_id=%d sym=%d",
6523 aex_ix,ahfa_id,completed_symbol_id);
6524 aexes[aex_ix]= aex;
6525 }
6526 }
6527 }
6528 }
6529 }
6530 
6531 /*:542*/
6532 #line 4291 "./marpa.w"
6533 
6534 /*544:*/
6535 #line 4438 "./marpa.w"
6536 
6537 g_free(rule_by_sort_key);
6538 matrix_free(prediction_matrix);
6539 /*545:*/
6540 #line 4444 "./marpa.w"
6541 
6542 g_free(singleton_duplicates);
6543 g_tree_destroy(duplicates);
6544 
6545 /*:545*/
6546 #line 4441 "./marpa.w"
6547 
6548 obstack_free(&ahfa_work_obs,NULL);
6549 
6550 /*:544*/
6551 #line 4292 "./marpa.w"
6552 
6553 }
6554 
6555 /*:536*//*555:*/
6556 #line 4787 "./marpa.w"
6557 
6558 static inline AHFA
assign_AHFA_state(AHFA sought_state,GTree * duplicates)6559 assign_AHFA_state(AHFA sought_state,GTree*duplicates)
6560 {
6561 const AHFA state_found= g_tree_lookup(duplicates,sought_state);
6562 if(state_found)return state_found;
6563 g_tree_insert(duplicates,sought_state,sought_state);
6564 return NULL;
6565 }
6566 
6567 /*:555*//*566:*/
6568 #line 4968 "./marpa.w"
6569 static gint
cmp_by_rule_sort_key(gconstpointer ap,gconstpointer bp,gpointer user_data)6570 cmp_by_rule_sort_key(gconstpointer ap,
6571 gconstpointer bp,gpointer user_data){
6572 RULE a= *(RULE*)ap;
6573 RULE b= *(RULE*)bp;
6574 guint*sort_key_by_rule_id= (guint*)user_data;
6575 Marpa_Rule_ID a_id= a->t_id;
6576 Marpa_Rule_ID b_id= b->t_id;
6577 guint sort_key_a= sort_key_by_rule_id[a_id];
6578 guint sort_key_b= sort_key_by_rule_id[b_id];
6579 if(sort_key_a==sort_key_b)return a_id-b_id;
6580 return sort_key_a-sort_key_b;
6581 }
6582 /*:566*//*571:*/
6583 #line 5047 "./marpa.w"
6584 
6585 static AHFA
create_predicted_AHFA_state(struct marpa_g * g,Bit_Vector prediction_rule_vector,RULE * rule_by_sort_key,DQUEUE states_p,GTree * duplicates)6586 create_predicted_AHFA_state(
6587 struct marpa_g*g,
6588 Bit_Vector prediction_rule_vector,
6589 RULE*rule_by_sort_key,
6590 DQUEUE states_p,
6591 GTree*duplicates
6592 ){
6593 AIM*item_list_for_new_state;
6594 AHFA p_new_state;
6595 guint item_list_ix= 0;
6596 guint no_of_items_in_new_state= bv_count(prediction_rule_vector);
6597 if(no_of_items_in_new_state==0)return NULL;
6598 item_list_for_new_state= obstack_alloc(&g->t_obs,
6599 no_of_items_in_new_state*sizeof(AIM));
6600 {
6601 guint start,min,max;
6602 for(start= 0;bv_scan(prediction_rule_vector,start,&min,&max);
6603 start= max+2)
6604 {
6605 guint rule_sort_key;
6606 for(rule_sort_key= min;rule_sort_key<=max;rule_sort_key++)
6607 {
6608 
6609 RULE rule= rule_by_sort_key[rule_sort_key];
6610 item_list_for_new_state[item_list_ix++]=
6611 g->t_AHFA_items_by_rule[rule->t_id];
6612 }
6613 }
6614 }
6615 p_new_state= DQUEUE_PUSH((*states_p),AHFA_Object);
6616 p_new_state->t_items= item_list_for_new_state;
6617 p_new_state->t_item_count= no_of_items_in_new_state;
6618 {AHFA queued_AHFA_state= assign_AHFA_state(p_new_state,duplicates);
6619 if(queued_AHFA_state){
6620 
6621 
6622 (void)DQUEUE_POP((*states_p),AHFA_Object);
6623 obstack_free(&g->t_obs,item_list_for_new_state);
6624 return queued_AHFA_state;
6625 }
6626 }
6627 
6628 p_new_state->t_key.t_id= p_new_state-DQUEUE_BASE((*states_p),AHFA_Object);
6629 LV_AHFA_is_Predicted(p_new_state)= 1;
6630 p_new_state->t_has_completed_start_rule= 0;
6631 LV_Leo_LHS_ID_of_AHFA(p_new_state)= -1;
6632 p_new_state->t_empty_transition= NULL;
6633 LV_TRANSs_of_AHFA(p_new_state)= transitions_new(g);
6634 LV_Complete_SYM_Count_of_AHFA(p_new_state)= 0;
6635 /*572:*/
6636 #line 5102 "./marpa.w"
6637 
6638 {
6639 guint symbol_count= SYM_Count_of_G(g);
6640 guint item_ix;
6641 guint no_of_postdot_symbols;
6642 Bit_Vector postdot_v= bv_create(symbol_count);
6643 for(item_ix= 0;item_ix<no_of_items_in_new_state;item_ix++)
6644 {
6645 AIM item= item_list_for_new_state[item_ix];
6646 SYMID postdot= Postdot_SYMID_of_AIM(item);
6647 if(postdot>=0)
6648 bv_bit_set(postdot_v,(guint)postdot);
6649 }
6650 if((no_of_postdot_symbols= p_new_state->t_postdot_sym_count=
6651 bv_count(postdot_v)))
6652 {
6653 guint min,max,start;
6654 Marpa_Symbol_ID*p_symbol= p_new_state->t_postdot_symid_ary=
6655 obstack_alloc(&g->t_obs,
6656 no_of_postdot_symbols*sizeof(SYMID));
6657 for(start= 0;bv_scan(postdot_v,start,&min,&max);start= max+2)
6658 {
6659 Marpa_Symbol_ID postdot;
6660 for(postdot= (Marpa_Symbol_ID)min;
6661 postdot<=(Marpa_Symbol_ID)max;postdot++)
6662 {
6663 *p_symbol++= postdot;
6664 }
6665 }
6666 }
6667 bv_free(postdot_v);
6668 }
6669 
6670 /*:572*/
6671 #line 5098 "./marpa.w"
6672 
6673 return p_new_state;
6674 }
6675 
6676 /*:571*//*584:*/
6677 #line 5214 "./marpa.w"
6678 
to_ahfa_of_transition_get(TRANS transition)6679 static inline AHFA to_ahfa_of_transition_get(TRANS transition){
6680 if(!transition)return NULL;
6681 return transition->t_ur.t_to_ahfa;
6682 }
6683 /*:584*//*586:*/
6684 #line 5221 "./marpa.w"
6685 
completion_count_of_transition_get(TRANS transition)6686 static inline gint completion_count_of_transition_get(TRANS transition){
6687 if(!transition)return 0;
6688 return transition->t_ur.t_completion_count;
6689 }
6690 
6691 /*:586*//*588:*/
6692 #line 5230 "./marpa.w"
6693 
6694 static inline
transition_new(struct obstack * obstack,AHFA to_ahfa,gint aim_ix)6695 URTRANS transition_new(struct obstack*obstack,AHFA to_ahfa,gint aim_ix){
6696 URTRANS transition;
6697 transition= obstack_alloc(obstack,sizeof(transition[0]));
6698 transition->t_to_ahfa= to_ahfa;
6699 transition->t_completion_count= aim_ix;
6700 return transition;
6701 }
6702 
6703 /*:588*//*590:*/
6704 #line 5242 "./marpa.w"
6705 static inline
transitions_new(struct marpa_g * g)6706 TRANS*transitions_new(struct marpa_g*g){
6707 gint symbol_count= SYM_Count_of_G(g);
6708 gint symid= 0;
6709 TRANS*transitions;
6710 transitions= g_malloc(symbol_count*sizeof(transitions[0]));
6711 while(symid<symbol_count)transitions[symid++]= NULL;
6712 
6713 
6714 return transitions;
6715 }
6716 
6717 /*:590*//*592:*/
6718 #line 5257 "./marpa.w"
6719 
6720 static inline
transition_add(struct obstack * obstack,AHFA from_ahfa,SYMID symid,AHFA to_ahfa)6721 void transition_add(struct obstack*obstack,AHFA from_ahfa,SYMID symid,AHFA to_ahfa)
6722 {
6723 TRANS*transitions= TRANSs_of_AHFA(from_ahfa);
6724 TRANS transition= transitions[symid];
6725 if(!transition){
6726 transitions[symid]= (TRANS)transition_new(obstack,to_ahfa,0);
6727 return;
6728 }
6729 LV_To_AHFA_of_TRANS(transition)= to_ahfa;
6730 return;
6731 }
6732 
6733 /*:592*//*594:*/
6734 #line 5274 "./marpa.w"
6735 
6736 static inline
completion_count_inc(struct obstack * obstack,AHFA from_ahfa,SYMID symid)6737 void completion_count_inc(struct obstack*obstack,AHFA from_ahfa,SYMID symid)
6738 {
6739 TRANS*transitions= TRANSs_of_AHFA(from_ahfa);
6740 TRANS transition= transitions[symid];
6741 if(!transition){
6742 transitions[symid]= (TRANS)transition_new(obstack,NULL,1);
6743 return;
6744 }
6745 LV_Completion_Count_of_TRANS(transition)++;
6746 return;
6747 }
6748 
6749 /*:594*//*596:*/
6750 #line 5293 "./marpa.w"
6751 
marpa_AHFA_state_transitions(struct marpa_g * g,Marpa_AHFA_State_ID AHFA_state_id,GArray * result)6752 gint marpa_AHFA_state_transitions(struct marpa_g*g,
6753 Marpa_AHFA_State_ID AHFA_state_id,
6754 GArray*result){
6755 
6756 /*1357:*/
6757 #line 13088 "./marpa.w"
6758 const int failure_indicator= -2;
6759 
6760 /*:1357*/
6761 #line 5298 "./marpa.w"
6762 
6763 AHFA from_ahfa_state;
6764 TRANS*transitions;
6765 SYMID symid;
6766 gint symbol_count;
6767 
6768 /*1359:*/
6769 #line 13099 "./marpa.w"
6770 
6771 if(!G_is_Precomputed(g)){
6772 g_context_clear(g);
6773 g->t_error= "grammar not precomputed";
6774 return failure_indicator;
6775 }
6776 /*:1359*/
6777 #line 5304 "./marpa.w"
6778 
6779 /*1363:*/
6780 #line 13126 "./marpa.w"
6781 
6782 if(!AHFA_state_id_is_valid(g,AHFA_state_id)){
6783 g_context_clear(g);
6784 g_context_int_add(g,"AHFA_state_id",AHFA_state_id);
6785 g->t_error= "invalid AHFA state id";
6786 return failure_indicator;
6787 }
6788 /*:1363*/
6789 #line 5305 "./marpa.w"
6790 
6791 /*1364:*/
6792 #line 13133 "./marpa.w"
6793 
6794 if(sizeof(gint)!=g_array_get_element_size(result)){
6795 g_context_clear(g);
6796 g_context_int_add(g,"expected size",sizeof(gint));
6797 g->t_error= "garray size mismatch";
6798 return failure_indicator;
6799 }
6800 /*:1364*/
6801 #line 5306 "./marpa.w"
6802 
6803 from_ahfa_state= AHFA_of_G_by_ID(g,AHFA_state_id);
6804 transitions= TRANSs_of_AHFA(from_ahfa_state);
6805 symbol_count= SYM_Count_of_G(g);
6806 g_array_set_size(result,0);
6807 for(symid= 0;symid<symbol_count;symid++){
6808 AHFA to_ahfa_state= To_AHFA_of_TRANS(transitions[symid]);
6809 if(!to_ahfa_state)continue;
6810 g_array_append_val(result,symid);
6811 g_array_append_val(result,ID_of_AHFA(to_ahfa_state));
6812 }
6813 return result->len;
6814 }
6815 
6816 /*:596*//*600:*/
6817 #line 5329 "./marpa.w"
6818 
marpa_AHFA_state_empty_transition(struct marpa_g * g,AHFAID AHFA_state_id)6819 AHFAID marpa_AHFA_state_empty_transition(struct marpa_g*g,
6820 AHFAID AHFA_state_id){
6821 AHFA state;
6822 AHFA empty_transition_state;
6823 /*1357:*/
6824 #line 13088 "./marpa.w"
6825 const int failure_indicator= -2;
6826 
6827 /*:1357*/
6828 #line 5334 "./marpa.w"
6829 
6830 /*1359:*/
6831 #line 13099 "./marpa.w"
6832 
6833 if(!G_is_Precomputed(g)){
6834 g_context_clear(g);
6835 g->t_error= "grammar not precomputed";
6836 return failure_indicator;
6837 }
6838 /*:1359*/
6839 #line 5335 "./marpa.w"
6840 
6841 /*1363:*/
6842 #line 13126 "./marpa.w"
6843 
6844 if(!AHFA_state_id_is_valid(g,AHFA_state_id)){
6845 g_context_clear(g);
6846 g_context_int_add(g,"AHFA_state_id",AHFA_state_id);
6847 g->t_error= "invalid AHFA state id";
6848 return failure_indicator;
6849 }
6850 /*:1363*/
6851 #line 5336 "./marpa.w"
6852 
6853 state= AHFA_of_G_by_ID(g,AHFA_state_id);
6854 empty_transition_state= Empty_Transition_of_AHFA(state);
6855 if(empty_transition_state)
6856 return ID_of_AHFA(empty_transition_state);
6857 return-1;
6858 }
6859 
6860 
6861 /*:600*//*606:*/
6862 #line 5377 "./marpa.w"
6863 
marpa_r_new(struct marpa_g * g)6864 struct marpa_r*marpa_r_new(struct marpa_g*g)
6865 {RECCE r;
6866 gint symbol_count_of_g;
6867 /*1356:*/
6868 #line 13085 "./marpa.w"
6869 const gpointer failure_indicator= NULL;
6870 /*:1356*/
6871 #line 5381 "./marpa.w"
6872 
6873 if(!G_is_Precomputed(g)){
6874 g->t_error= "precomputed";
6875 return failure_indicator;
6876 }
6877 r= g_slice_new(struct marpa_r);
6878 r->t_grammar= g;
6879 symbol_count_of_g= SYM_Count_of_G(g);
6880 /*691:*/
6881 #line 5835 "./marpa.w"
6882 obstack_init(&r->t_obs);
6883 /*:691*/
6884 #line 5389 "./marpa.w"
6885 
6886 /*613:*/
6887 #line 5420 "./marpa.w"
6888 
6889 r->t_id= g_atomic_int_exchange_and_add(&next_recce_id,1);
6890 /*:613*//*621:*/
6891 #line 5462 "./marpa.w"
6892 
6893 Phase_of_R(r)= initial_phase;
6894 /*:621*//*625:*/
6895 #line 5477 "./marpa.w"
6896 
6897 r->t_first_earley_set= NULL;
6898 r->t_latest_earley_set= NULL;
6899 r->t_current_earleme= -1;
6900 
6901 /*:625*//*632:*/
6902 #line 5507 "./marpa.w"
6903 
6904 r->t_earley_item_warning_threshold= MAX(DEFAULT_EIM_WARNING_THRESHOLD,AIM_Count_of_G(g)*2);
6905 /*:632*//*638:*/
6906 #line 5535 "./marpa.w"
6907 r->t_furthest_earleme= 0;
6908 /*:638*//*643:*/
6909 #line 5554 "./marpa.w"
6910 r->t_sym_workarea= NULL;
6911 /*:643*//*647:*/
6912 #line 5569 "./marpa.w"
6913 r->t_workarea2= NULL;
6914 /*:647*//*651:*/
6915 #line 5593 "./marpa.w"
6916 
6917 r->t_bv_sym= NULL;
6918 r->t_bv_sym2= NULL;
6919 r->t_bv_sym3= NULL;
6920 /*:651*//*655:*/
6921 #line 5616 "./marpa.w"
6922 r->t_bv_symid_is_expected= NULL;
6923 /*:655*//*670:*/
6924 #line 5712 "./marpa.w"
6925 
6926 r->t_use_leo_flag= 1;
6927 r->t_is_using_leo= 0;
6928 /*:670*//*676:*/
6929 #line 5754 "./marpa.w"
6930 r->t_is_exhausted= 0;
6931 /*:676*//*680:*/
6932 #line 5780 "./marpa.w"
6933 
6934 r->t_context= g_hash_table_new_full(g_str_hash,g_str_equal,NULL,g_free);
6935 /*:680*//*695:*/
6936 #line 5851 "./marpa.w"
6937 
6938 r->t_error= NULL;
6939 r->t_fatal_error= NULL;
6940 /*:695*//*713:*/
6941 #line 5943 "./marpa.w"
6942 
6943 r->t_earley_set_count= 0;
6944 
6945 /*:713*//*719:*/
6946 #line 5992 "./marpa.w"
6947 
6948 r->t_trace_earley_set= NULL;
6949 
6950 /*:719*//*747:*/
6951 #line 6274 "./marpa.w"
6952 
6953 r->t_trace_earley_item= NULL;
6954 /*:747*//*786:*/
6955 #line 6684 "./marpa.w"
6956 
6957 r->t_trace_pim_sym_p= NULL;
6958 r->t_trace_postdot_item= NULL;
6959 /*:786*//*829:*/
6960 #line 7171 "./marpa.w"
6961 
6962 r->t_trace_source= NULL;
6963 r->t_trace_next_source_link= NULL;
6964 r->t_trace_source_type= NO_SOURCE;
6965 
6966 /*:829*//*873:*/
6967 #line 7682 "./marpa.w"
6968 
6969 {
6970 gpointer default_value= Default_Value_of_G(g);
6971 gint i;
6972 TOK*tokens_by_symid;
6973 obstack_init(TOK_Obs);
6974 tokens_by_symid=
6975 obstack_alloc(TOK_Obs,sizeof(TOK)*symbol_count_of_g);
6976 for(i= 0;i<symbol_count_of_g;i++)
6977 {
6978 tokens_by_symid[i]= token_new(r,i,default_value);
6979 }
6980 TOKs_by_SYMID_of_R(r)= tokens_by_symid;
6981 }
6982 /*:873*//*881:*/
6983 #line 7754 "./marpa.w"
6984 
6985 DSTACK_INIT(r->t_alternatives,ALT_Object,INITIAL_ALTERNATIVES_CAPACITY);
6986 /*:881*//*907:*/
6987 #line 8050 "./marpa.w"
6988 DSTACK_SAFE(r->t_eim_work_stack);
6989 /*:907*//*911:*/
6990 #line 8061 "./marpa.w"
6991 DSTACK_SAFE(r->t_completion_stack);
6992 /*:911*//*915:*/
6993 #line 8072 "./marpa.w"
6994 DSTACK_SAFE(r->t_earley_set_stack);
6995 /*:915*//*984:*/
6996 #line 8916 "./marpa.w"
6997 
6998 ur_node_stack_init(URS_of_R(r));
6999 /*:984*//*1097:*/
7000 #line 10434 "./marpa.w"
7001 
7002 B_of_R(r)= NULL;
7003 
7004 /*:1097*//*1324:*/
7005 #line 12805 "./marpa.w"
7006 
7007 psar_init(Dot_PSAR_of_R(r),AHFA_Count_of_R(r));
7008 /*:1324*//*1392:*/
7009 #line 13350 "./marpa.w"
7010 
7011 r->t_message_callback_arg= NULL;
7012 r->t_message_callback= NULL;
7013 /*:1392*/
7014 #line 5390 "./marpa.w"
7015 
7016 return r;}
7017 
7018 /*:606*//*607:*/
7019 #line 5393 "./marpa.w"
7020 
marpa_r_free(struct marpa_r * r)7021 void marpa_r_free(struct marpa_r*r)
7022 {
7023 /*681:*/
7024 #line 5782 "./marpa.w"
7025 g_hash_table_destroy(Context_of_R(r));
7026 
7027 /*:681*//*716:*/
7028 #line 5969 "./marpa.w"
7029 
7030 {
7031 ES set;
7032 for(set= First_ES_of_R(r);set;set= Next_ES_of_ES(set))
7033 {
7034 if(EIMs_of_ES(set))
7035 g_free(EIMs_of_ES(set));
7036 }
7037 }
7038 
7039 /*:716*//*874:*/
7040 #line 7696 "./marpa.w"
7041 
7042 {
7043 TOK*tokens_by_symid= TOKs_by_SYMID_of_R(r);
7044 if(tokens_by_symid){
7045 obstack_free(TOK_Obs,NULL);
7046 TOKs_by_SYMID_of_R(r)= NULL;
7047 }
7048 }
7049 
7050 /*:874*//*882:*/
7051 #line 7756 "./marpa.w"
7052 DSTACK_DESTROY(r->t_alternatives);
7053 
7054 /*:882*//*909:*/
7055 #line 8054 "./marpa.w"
7056 DSTACK_DESTROY(r->t_eim_work_stack);
7057 
7058 /*:909*//*913:*/
7059 #line 8065 "./marpa.w"
7060 DSTACK_DESTROY(r->t_completion_stack);
7061 
7062 /*:913*//*916:*/
7063 #line 8073 "./marpa.w"
7064 DSTACK_DESTROY(r->t_earley_set_stack);
7065 
7066 /*:916*//*985:*/
7067 #line 8918 "./marpa.w"
7068 
7069 ur_node_stack_destroy(URS_of_R(r));
7070 
7071 /*:985*//*1117:*/
7072 #line 10703 "./marpa.w"
7073 bocage_destroy(r);
7074 
7075 /*:1117*//*1325:*/
7076 #line 12807 "./marpa.w"
7077 
7078 psar_destroy(Dot_PSAR_of_R(r));
7079 /*:1325*/
7080 #line 5396 "./marpa.w"
7081 
7082 if(r->t_sym_workarea)g_free(r->t_sym_workarea);
7083 if(r->t_workarea2)g_free(r->t_workarea2);
7084 /*653:*/
7085 #line 5602 "./marpa.w"
7086 
7087 if(r->t_bv_sym)bv_free(r->t_bv_sym);
7088 if(r->t_bv_sym2)bv_free(r->t_bv_sym2);
7089 if(r->t_bv_sym3)bv_free(r->t_bv_sym3);
7090 
7091 /*:653*//*657:*/
7092 #line 5619 "./marpa.w"
7093 
7094 if(r->t_bv_symid_is_expected){bv_free(r->t_bv_symid_is_expected);}
7095 /*:657*/
7096 #line 5399 "./marpa.w"
7097 
7098 /*692:*/
7099 #line 5836 "./marpa.w"
7100 obstack_free(&r->t_obs,NULL);
7101 
7102 /*:692*/
7103 #line 5400 "./marpa.w"
7104 
7105 g_slice_free(struct marpa_r,r);
7106 }
7107 /*:607*//*614:*/
7108 #line 5422 "./marpa.w"
7109 
marpa_r_id(struct marpa_r * r)7110 gint marpa_r_id(struct marpa_r*r){return r->t_id;}
7111 /*:614*//*623:*/
7112 #line 5466 "./marpa.w"
7113 
marpa_phase(struct marpa_r * r)7114 Marpa_Phase marpa_phase(struct marpa_r*r)
7115 {return Phase_of_R(r);}
7116 
7117 /*:623*//*628:*/
7118 #line 5489 "./marpa.w"
7119 
marpa_current_earleme(struct marpa_r * r)7120 guint marpa_current_earleme(struct marpa_r*r)
7121 {return Current_Earleme_of_R(r);}
7122 
7123 /*:628*//*630:*/
7124 #line 5496 "./marpa.w"
7125 
current_es_of_r(RECCE r)7126 static inline ES current_es_of_r(RECCE r)
7127 {
7128 const ES latest= Latest_ES_of_R(r);
7129 if(Earleme_of_ES(latest)==Current_Earleme_of_R(r))return latest;
7130 return NULL;
7131 }
7132 
7133 /*:630*//*634:*/
7134 #line 5511 "./marpa.w"
7135 
marpa_earley_item_warning_threshold(struct marpa_r * r)7136 guint marpa_earley_item_warning_threshold(struct marpa_r*r)
7137 {return r->t_earley_item_warning_threshold;}
7138 
7139 /*:634*//*636:*/
7140 #line 5519 "./marpa.w"
7141 
marpa_earley_item_warning_threshold_set(struct marpa_r * r,guint threshold)7142 gboolean marpa_earley_item_warning_threshold_set(struct marpa_r*r,guint threshold)
7143 {
7144 r->t_earley_item_warning_threshold= threshold==0?EIM_FATAL_THRESHOLD:threshold;
7145 return TRUE;
7146 }
7147 
7148 /*:636*//*640:*/
7149 #line 5538 "./marpa.w"
7150 
marpa_furthest_earleme(struct marpa_r * r)7151 guint marpa_furthest_earleme(struct marpa_r*r)
7152 {return Furthest_Earleme_of_R(r);}
7153 
7154 /*:640*//*659:*/
7155 #line 5631 "./marpa.w"
7156 
marpa_terminals_expected(struct marpa_r * r,GArray * result)7157 gint marpa_terminals_expected(struct marpa_r*r,GArray*result)
7158 {
7159 /*1357:*/
7160 #line 13088 "./marpa.w"
7161 const int failure_indicator= -2;
7162 
7163 /*:1357*/
7164 #line 5634 "./marpa.w"
7165 
7166 guint min,max,start;
7167 /*1373:*/
7168 #line 13190 "./marpa.w"
7169 
7170 if(sizeof(gint)!=g_array_get_element_size(result)){
7171 r_context_clear(r);
7172 r_context_int_add(r,"expected size",sizeof(gint));
7173 R_ERROR_CXT("garray size mismatch");
7174 return failure_indicator;
7175 }
7176 
7177 /*:1373*/
7178 #line 5636 "./marpa.w"
7179 
7180 g_array_set_size(result,0);
7181 for(start= 0;bv_scan(r->t_bv_symid_is_expected,start,&min,&max);
7182 start= max+2)
7183 {
7184 gint symid;
7185 for(symid= (gint)min;symid<=(gint)max;symid++)
7186 {
7187 g_array_append_val(result,symid);
7188 }
7189 }
7190 return(gint)result->len;
7191 }
7192 
7193 /*:659*//*672:*/
7194 #line 5720 "./marpa.w"
7195 
marpa_is_use_leo(struct marpa_r * r)7196 gint marpa_is_use_leo(struct marpa_r*r)
7197 {
7198 /*1357:*/
7199 #line 13088 "./marpa.w"
7200 const int failure_indicator= -2;
7201 
7202 /*:1357*/
7203 #line 5723 "./marpa.w"
7204 
7205 /*1371:*/
7206 #line 13178 "./marpa.w"
7207 
7208 if(Phase_of_R(r)==error_phase){
7209 R_ERROR(r->t_fatal_error);
7210 return failure_indicator;
7211 }
7212 /*:1371*/
7213 #line 5724 "./marpa.w"
7214 
7215 return r->t_use_leo_flag?1:0;
7216 }
7217 /*:672*//*673:*/
7218 #line 5729 "./marpa.w"
7219 
marpa_is_use_leo_set(struct marpa_r * r,gboolean value)7220 gboolean marpa_is_use_leo_set(
7221 struct marpa_r*r,gboolean value)
7222 {
7223 /*1355:*/
7224 #line 13083 "./marpa.w"
7225 const gboolean failure_indicator= FALSE;
7226 /*:1355*/
7227 #line 5733 "./marpa.w"
7228 
7229 /*1371:*/
7230 #line 13178 "./marpa.w"
7231 
7232 if(Phase_of_R(r)==error_phase){
7233 R_ERROR(r->t_fatal_error);
7234 return failure_indicator;
7235 }
7236 /*:1371*/
7237 #line 5734 "./marpa.w"
7238 
7239 /*1366:*/
7240 #line 13149 "./marpa.w"
7241 
7242 if(Phase_of_R(r)!=initial_phase){
7243 R_ERROR("not initial recce phase");
7244 return failure_indicator;
7245 }
7246 /*:1366*/
7247 #line 5735 "./marpa.w"
7248 
7249 r->t_use_leo_flag= value;
7250 return TRUE;
7251 }
7252 /*:673*//*678:*/
7253 #line 5760 "./marpa.w"
7254 
marpa_is_exhausted(struct marpa_r * r)7255 gint marpa_is_exhausted(struct marpa_r*r)
7256 {
7257 /*1357:*/
7258 #line 13088 "./marpa.w"
7259 const int failure_indicator= -2;
7260 
7261 /*:1357*/
7262 #line 5763 "./marpa.w"
7263 
7264 /*1371:*/
7265 #line 13178 "./marpa.w"
7266 
7267 if(Phase_of_R(r)==error_phase){
7268 R_ERROR(r->t_fatal_error);
7269 return failure_indicator;
7270 }
7271 /*:1371*/
7272 #line 5764 "./marpa.w"
7273 
7274 return r->t_is_exhausted?1:0;
7275 }
7276 
7277 /*:678*//*682:*/
7278 #line 5791 "./marpa.w"
7279 
7280 static inline
r_context_int_add(struct marpa_r * r,const gchar * key,gint payload)7281 void r_context_int_add(struct marpa_r*r,const gchar*key,gint payload)
7282 {
7283 struct marpa_context_int_value*value= g_new(struct marpa_context_int_value,1);
7284 value->t_type= MARPA_CONTEXT_INT;
7285 value->t_data= payload;
7286 g_hash_table_insert(Context_of_R(r),(gpointer)key,value);
7287 }
7288 /*:682*//*684:*/
7289 #line 5803 "./marpa.w"
7290 
7291 static inline
r_context_const_add(struct marpa_r * r,const gchar * key,const gchar * payload)7292 void r_context_const_add(struct marpa_r*r,const gchar*key,const gchar*payload)
7293 {
7294 struct marpa_context_const_value*value= g_new(struct marpa_context_const_value,1);
7295 value->t_type= MARPA_CONTEXT_CONST;
7296 value->t_data= payload;
7297 g_hash_table_insert(Context_of_R(r),(gpointer)key,value);
7298 }
7299 /*:684*//*686:*/
7300 #line 5818 "./marpa.w"
7301 
r_context_clear(struct marpa_r * r)7302 static inline void r_context_clear(struct marpa_r*r){
7303 g_hash_table_remove_all(Context_of_R(r));}
7304 /*:686*//*688:*/
7305 #line 5824 "./marpa.w"
7306 
marpa_r_context_value(struct marpa_r * r,const gchar * key)7307 union marpa_context_value*marpa_r_context_value(struct marpa_r*r,const gchar*key)
7308 {return g_hash_table_lookup(Context_of_R(r),key);}
7309 /*:688*//*697:*/
7310 #line 5860 "./marpa.w"
7311 
marpa_r_error(const struct marpa_r * r)7312 Marpa_Error_ID marpa_r_error(const struct marpa_r*r)
7313 {return r->t_error?r->t_error:"unknown error";}
7314 /*:697*//*715:*/
7315 #line 5949 "./marpa.w"
7316 
7317 static inline ES
earley_set_new(RECCE r,EARLEME id)7318 earley_set_new(RECCE r,EARLEME id)
7319 {
7320 ESK_Object key;
7321 ES set;
7322 set= obstack_alloc(&r->t_obs,sizeof(*set));
7323 key.t_earleme= id;
7324 set->t_key= key;
7325 set->t_postdot_ary= NULL;
7326 set->t_postdot_sym_count= 0;
7327 EIM_Count_of_ES(set)= 0;
7328 set->t_ordinal= r->t_earley_set_count++;
7329 EIMs_of_ES(set)= NULL;
7330 LV_Next_ES_of_ES(set)= NULL;
7331 /*1331:*/
7332 #line 12857 "./marpa.w"
7333 
7334 {set->t_dot_psl= NULL;}
7335 
7336 /*:1331*/
7337 #line 5964 "./marpa.w"
7338 
7339 return set;
7340 }
7341 
7342 /*:715*//*721:*/
7343 #line 5997 "./marpa.w"
7344 
marpa_trace_earley_set(struct marpa_r * r)7345 Marpa_Earley_Set_ID marpa_trace_earley_set(struct marpa_r*r)
7346 {
7347 /*1357:*/
7348 #line 13088 "./marpa.w"
7349 const int failure_indicator= -2;
7350 
7351 /*:1357*/
7352 #line 6000 "./marpa.w"
7353 
7354 ES trace_earley_set= r->t_trace_earley_set;
7355 /*1370:*/
7356 #line 13169 "./marpa.w"
7357 
7358 switch(Phase_of_R(r)){
7359 default:
7360 R_ERROR("recce not trace-safe");
7361 return failure_indicator;
7362 case input_phase:
7363 case evaluation_phase:
7364 break;
7365 }
7366 /*:1370*/
7367 #line 6002 "./marpa.w"
7368 
7369 if(!trace_earley_set){
7370 R_ERROR("no trace es");
7371 return failure_indicator;
7372 }
7373 return Ord_of_ES(trace_earley_set);
7374 }
7375 
7376 /*:721*//*723:*/
7377 #line 6012 "./marpa.w"
7378 
marpa_latest_earley_set(struct marpa_r * r)7379 Marpa_Earley_Set_ID marpa_latest_earley_set(struct marpa_r*r)
7380 {
7381 /*1357:*/
7382 #line 13088 "./marpa.w"
7383 const int failure_indicator= -2;
7384 
7385 /*:1357*/
7386 #line 6015 "./marpa.w"
7387 
7388 /*1370:*/
7389 #line 13169 "./marpa.w"
7390 
7391 switch(Phase_of_R(r)){
7392 default:
7393 R_ERROR("recce not trace-safe");
7394 return failure_indicator;
7395 case input_phase:
7396 case evaluation_phase:
7397 break;
7398 }
7399 /*:1370*/
7400 #line 6016 "./marpa.w"
7401 
7402 return Ord_of_ES(Latest_ES_of_R(r));
7403 }
7404 
7405 /*:723*//*725:*/
7406 #line 6030 "./marpa.w"
7407 
marpa_earleme(struct marpa_r * r,Marpa_Earley_Set_ID set_id)7408 Marpa_Earleme marpa_earleme(struct marpa_r*r,Marpa_Earley_Set_ID set_id)
7409 {
7410 const gint es_does_not_exist= -1;
7411 /*1357:*/
7412 #line 13088 "./marpa.w"
7413 const int failure_indicator= -2;
7414 
7415 /*:1357*/
7416 #line 6034 "./marpa.w"
7417 
7418 ES earley_set;
7419 /*1367:*/
7420 #line 13154 "./marpa.w"
7421 
7422 if(Phase_of_R(r)==initial_phase){
7423 R_ERROR("initial recce phase");
7424 return failure_indicator;
7425 }
7426 /*:1367*/
7427 #line 6036 "./marpa.w"
7428 
7429 /*1371:*/
7430 #line 13178 "./marpa.w"
7431 
7432 if(Phase_of_R(r)==error_phase){
7433 R_ERROR(r->t_fatal_error);
7434 return failure_indicator;
7435 }
7436 /*:1371*/
7437 #line 6037 "./marpa.w"
7438 
7439 if(set_id<0){
7440 R_ERROR("invalid es ordinal");
7441 return failure_indicator;
7442 }
7443 r_update_earley_sets(r);
7444 if(!ES_Ord_is_Valid(r,set_id))
7445 {
7446 return es_does_not_exist;
7447 }
7448 earley_set= ES_of_R_by_Ord(r,set_id);
7449 return Earleme_of_ES(earley_set);
7450 }
7451 
7452 /*:725*//*728:*/
7453 #line 6055 "./marpa.w"
7454 
marpa_earley_set_size(struct marpa_r * r,Marpa_Earley_Set_ID set_id)7455 gint marpa_earley_set_size(struct marpa_r*r,Marpa_Earley_Set_ID set_id)
7456 {
7457 /*1357:*/
7458 #line 13088 "./marpa.w"
7459 const int failure_indicator= -2;
7460 
7461 /*:1357*/
7462 #line 6058 "./marpa.w"
7463 
7464 ES earley_set;
7465 /*1367:*/
7466 #line 13154 "./marpa.w"
7467 
7468 if(Phase_of_R(r)==initial_phase){
7469 R_ERROR("initial recce phase");
7470 return failure_indicator;
7471 }
7472 /*:1367*/
7473 #line 6060 "./marpa.w"
7474 
7475 /*1371:*/
7476 #line 13178 "./marpa.w"
7477 
7478 if(Phase_of_R(r)==error_phase){
7479 R_ERROR(r->t_fatal_error);
7480 return failure_indicator;
7481 }
7482 /*:1371*/
7483 #line 6061 "./marpa.w"
7484 
7485 r_update_earley_sets(r);
7486 if(!ES_Ord_is_Valid(r,set_id))
7487 {
7488 R_ERROR("invalid es ordinal");
7489 return failure_indicator;
7490 }
7491 earley_set= ES_of_R_by_Ord(r,set_id);
7492 return EIM_Count_of_ES(earley_set);
7493 }
7494 
7495 /*:728*//*738:*/
7496 #line 6160 "./marpa.w"
7497 
earley_item_create(const RECCE r,const EIK_Object key)7498 static inline EIM earley_item_create(const RECCE r,
7499 const EIK_Object key)
7500 {
7501 /*1356:*/
7502 #line 13085 "./marpa.w"
7503 const gpointer failure_indicator= NULL;
7504 /*:1356*/
7505 #line 6164 "./marpa.w"
7506 
7507 EIM new_item;
7508 EIM*top_of_work_stack;
7509 const ES set= key.t_set;
7510 const guint count= ++EIM_Count_of_ES(set);
7511 /*741:*/
7512 #line 6214 "./marpa.w"
7513 
7514 if(count>=r->t_earley_item_warning_threshold)
7515 {
7516 if(G_UNLIKELY(count>=EIM_FATAL_THRESHOLD))
7517 {
7518 r_context_clear(r);
7519 R_FATAL("eim count exceeds fatal threshold");
7520 return failure_indicator;
7521 }
7522 r_context_clear(r);
7523 r_message(r,"earley item count exceeds threshold");
7524 }
7525 
7526 /*:741*/
7527 #line 6169 "./marpa.w"
7528 
7529 new_item= obstack_alloc(&r->t_obs,sizeof(*new_item));
7530 new_item->t_key= key;
7531 new_item->t_source_type= NO_SOURCE;
7532 Ord_of_EIM(new_item)= count-1;
7533 top_of_work_stack= WORK_EIM_PUSH(r);
7534 *top_of_work_stack= new_item;
7535 return new_item;
7536 }
7537 
7538 /*:738*//*740:*/
7539 #line 6182 "./marpa.w"
7540 
7541 static inline EIM
earley_item_assign(const RECCE r,const ES set,const ES origin,const AHFA state)7542 earley_item_assign(const RECCE r,const ES set,const ES origin,
7543 const AHFA state)
7544 {
7545 EIK_Object key;
7546 EIM eim;
7547 PSL psl;
7548 AHFAID ahfa_id= ID_of_AHFA(state);
7549 PSL*psl_owner= &Dot_PSL_of_ES(origin);
7550 if(!*psl_owner)
7551 {
7552 psl_claim(psl_owner,Dot_PSAR_of_R(r));
7553 }
7554 psl= *psl_owner;
7555 eim= PSL_Datum(psl,ahfa_id);
7556 if(eim
7557 &&Earleme_of_EIM(eim)==Earleme_of_ES(set)
7558 &&Earleme_of_ES(Origin_of_EIM(eim))==Earleme_of_ES(origin))
7559 {
7560 return eim;
7561 }
7562 key.t_origin= origin;
7563 key.t_state= state;
7564 key.t_set= set;
7565 eim= earley_item_create(r,key);
7566 PSL_Datum(psl,ahfa_id)= eim;
7567 return eim;
7568 }
7569 
7570 /*:740*//*745:*/
7571 #line 6250 "./marpa.w"
7572 
invalid_source_type_message(guint type)7573 static const char*invalid_source_type_message(guint type){
7574 switch(type){
7575 case NO_SOURCE:
7576 return"invalid source type: none";
7577 case SOURCE_IS_TOKEN:
7578 return"invalid source type: token";
7579 case SOURCE_IS_COMPLETION:
7580 return"invalid source type: completion";
7581 case SOURCE_IS_LEO:
7582 return"invalid source type: leo";
7583 case SOURCE_IS_AMBIGUOUS:
7584 return"invalid source type: ambiguous";
7585 }
7586 return"unknown source type";
7587 }
7588 
7589 /*:745*//*753:*/
7590 #line 6317 "./marpa.w"
7591 
7592 Marpa_Earleme
marpa_earley_set_trace(struct marpa_r * r,Marpa_Earley_Set_ID set_id)7593 marpa_earley_set_trace(struct marpa_r*r,Marpa_Earley_Set_ID set_id)
7594 {
7595 ES earley_set;
7596 const gint es_does_not_exist= -1;
7597 /*1357:*/
7598 #line 13088 "./marpa.w"
7599 const int failure_indicator= -2;
7600 
7601 /*:1357*/
7602 #line 6323 "./marpa.w"
7603 
7604 /*1370:*/
7605 #line 13169 "./marpa.w"
7606 
7607 switch(Phase_of_R(r)){
7608 default:
7609 R_ERROR("recce not trace-safe");
7610 return failure_indicator;
7611 case input_phase:
7612 case evaluation_phase:
7613 break;
7614 }
7615 /*:1370*/
7616 #line 6324 "./marpa.w"
7617 
7618 if(r->t_trace_earley_set&&Ord_of_ES(r->t_trace_earley_set)==set_id)
7619 {
7620 
7621 
7622 return Earleme_of_ES(r->t_trace_earley_set);
7623 }
7624 /*754:*/
7625 #line 6347 "./marpa.w"
7626 {
7627 r->t_trace_earley_set= NULL;
7628 trace_earley_item_clear(r);
7629 /*789:*/
7630 #line 6726 "./marpa.w"
7631 
7632 r->t_trace_pim_sym_p= NULL;
7633 r->t_trace_postdot_item= NULL;
7634 
7635 /*:789*/
7636 #line 6350 "./marpa.w"
7637 
7638 }
7639 
7640 /*:754*/
7641 #line 6331 "./marpa.w"
7642 
7643 if(set_id<0)
7644 {
7645 R_ERROR("invalid es ordinal");
7646 return failure_indicator;
7647 }
7648 r_update_earley_sets(r);
7649 if(set_id>=DSTACK_LENGTH(r->t_earley_set_stack))
7650 {
7651 return es_does_not_exist;
7652 }
7653 earley_set= ES_of_R_by_Ord(r,set_id);
7654 r->t_trace_earley_set= earley_set;
7655 return Earleme_of_ES(earley_set);
7656 }
7657 
7658 /*:753*//*756:*/
7659 #line 6357 "./marpa.w"
7660 
7661 Marpa_AHFA_State_ID
marpa_earley_item_trace(struct marpa_r * r,Marpa_Earley_Item_ID item_id)7662 marpa_earley_item_trace(struct marpa_r*r,Marpa_Earley_Item_ID item_id)
7663 {
7664 const gint eim_does_not_exist= -1;
7665 /*1357:*/
7666 #line 13088 "./marpa.w"
7667 const int failure_indicator= -2;
7668 
7669 /*:1357*/
7670 #line 6362 "./marpa.w"
7671 
7672 ES trace_earley_set;
7673 EIM earley_item;
7674 EIM*earley_items;
7675 /*1370:*/
7676 #line 13169 "./marpa.w"
7677 
7678 switch(Phase_of_R(r)){
7679 default:
7680 R_ERROR("recce not trace-safe");
7681 return failure_indicator;
7682 case input_phase:
7683 case evaluation_phase:
7684 break;
7685 }
7686 /*:1370*/
7687 #line 6366 "./marpa.w"
7688 
7689 trace_earley_set= r->t_trace_earley_set;
7690 if(!trace_earley_set)
7691 {
7692 /*754:*/
7693 #line 6347 "./marpa.w"
7694 {
7695 r->t_trace_earley_set= NULL;
7696 trace_earley_item_clear(r);
7697 /*789:*/
7698 #line 6726 "./marpa.w"
7699 
7700 r->t_trace_pim_sym_p= NULL;
7701 r->t_trace_postdot_item= NULL;
7702 
7703 /*:789*/
7704 #line 6350 "./marpa.w"
7705 
7706 }
7707 
7708 /*:754*/
7709 #line 6370 "./marpa.w"
7710 
7711 R_ERROR("no trace es");
7712 return failure_indicator;
7713 }
7714 trace_earley_item_clear(r);
7715 if(item_id<0)
7716 {
7717 R_ERROR("invalid eim ordinal");
7718 return failure_indicator;
7719 }
7720 if(item_id>=EIM_Count_of_ES(trace_earley_set))
7721 {
7722 return eim_does_not_exist;
7723 }
7724 earley_items= EIMs_of_ES(trace_earley_set);
7725 earley_item= earley_items[item_id];
7726 r->t_trace_earley_item= earley_item;
7727 return AHFAID_of_EIM(earley_item);
7728 }
7729 
7730 /*:756*//*759:*/
7731 #line 6401 "./marpa.w"
7732 
trace_earley_item_clear(struct marpa_r * r)7733 static inline void trace_earley_item_clear(struct marpa_r*r)
7734 {
7735 /*757:*/
7736 #line 6396 "./marpa.w"
7737 
7738 r->t_trace_earley_item= NULL;
7739 
7740 /*:757*/
7741 #line 6404 "./marpa.w"
7742 
7743 trace_source_link_clear(r);
7744 }
7745 
7746 /*:759*//*761:*/
7747 #line 6410 "./marpa.w"
7748 
marpa_earley_item_origin(struct marpa_r * r)7749 Marpa_Earley_Set_ID marpa_earley_item_origin(struct marpa_r*r)
7750 {
7751 /*1357:*/
7752 #line 13088 "./marpa.w"
7753 const int failure_indicator= -2;
7754 
7755 /*:1357*/
7756 #line 6413 "./marpa.w"
7757 
7758 EIM item= r->t_trace_earley_item;
7759 /*1367:*/
7760 #line 13154 "./marpa.w"
7761 
7762 if(Phase_of_R(r)==initial_phase){
7763 R_ERROR("initial recce phase");
7764 return failure_indicator;
7765 }
7766 /*:1367*/
7767 #line 6415 "./marpa.w"
7768 
7769 if(!item){
7770 /*757:*/
7771 #line 6396 "./marpa.w"
7772 
7773 r->t_trace_earley_item= NULL;
7774 
7775 /*:757*/
7776 #line 6417 "./marpa.w"
7777 
7778 R_ERROR("no trace eim");
7779 return failure_indicator;
7780 }
7781 return Origin_Ord_of_EIM(item);
7782 }
7783 
7784 /*:761*//*769:*/
7785 #line 6502 "./marpa.w"
7786 
marpa_leo_predecessor_symbol(struct marpa_r * r)7787 Marpa_Symbol_ID marpa_leo_predecessor_symbol(struct marpa_r*r)
7788 {
7789 const Marpa_Symbol_ID no_predecessor= -1;
7790 /*1357:*/
7791 #line 13088 "./marpa.w"
7792 const int failure_indicator= -2;
7793 
7794 /*:1357*/
7795 #line 6506 "./marpa.w"
7796 
7797 PIM postdot_item= r->t_trace_postdot_item;
7798 LIM predecessor_leo_item;
7799 /*1370:*/
7800 #line 13169 "./marpa.w"
7801 
7802 switch(Phase_of_R(r)){
7803 default:
7804 R_ERROR("recce not trace-safe");
7805 return failure_indicator;
7806 case input_phase:
7807 case evaluation_phase:
7808 break;
7809 }
7810 /*:1370*/
7811 #line 6509 "./marpa.w"
7812 
7813 if(!postdot_item){
7814 R_ERROR("no trace pim");
7815 return failure_indicator;
7816 }
7817 if(EIM_of_PIM(postdot_item)){
7818 R_ERROR("pim is not lim");
7819 return failure_indicator;
7820 }
7821 predecessor_leo_item= Predecessor_LIM_of_LIM(LIM_of_PIM(postdot_item));
7822 if(!predecessor_leo_item)return no_predecessor;
7823 return Postdot_SYMID_of_LIM(predecessor_leo_item);
7824 }
7825 
7826 Marpa_Earley_Set_ID marpa_leo_base_origin(struct marpa_r*r);
7827 /*:769*//*770:*/
7828 #line 6524 "./marpa.w"
7829 
marpa_leo_base_origin(struct marpa_r * r)7830 Marpa_Earley_Set_ID marpa_leo_base_origin(struct marpa_r*r)
7831 {
7832 const EARLEME pim_is_not_a_leo_item= -1;
7833 /*1357:*/
7834 #line 13088 "./marpa.w"
7835 const int failure_indicator= -2;
7836 
7837 /*:1357*/
7838 #line 6528 "./marpa.w"
7839 
7840 PIM postdot_item= r->t_trace_postdot_item;
7841 EIM base_earley_item;
7842 /*1370:*/
7843 #line 13169 "./marpa.w"
7844 
7845 switch(Phase_of_R(r)){
7846 default:
7847 R_ERROR("recce not trace-safe");
7848 return failure_indicator;
7849 case input_phase:
7850 case evaluation_phase:
7851 break;
7852 }
7853 /*:1370*/
7854 #line 6531 "./marpa.w"
7855 
7856 if(!postdot_item){
7857 R_ERROR("no trace pim");
7858 return failure_indicator;
7859 }
7860 if(EIM_of_PIM(postdot_item))return pim_is_not_a_leo_item;
7861 base_earley_item= Base_EIM_of_LIM(LIM_of_PIM(postdot_item));
7862 return Origin_Ord_of_EIM(base_earley_item);
7863 }
7864 
7865 /*:770*//*772:*/
7866 #line 6543 "./marpa.w"
7867 
marpa_leo_base_state(struct marpa_r * r)7868 Marpa_AHFA_State_ID marpa_leo_base_state(struct marpa_r*r)
7869 {
7870 const EARLEME pim_is_not_a_leo_item= -1;
7871 /*1357:*/
7872 #line 13088 "./marpa.w"
7873 const int failure_indicator= -2;
7874 
7875 /*:1357*/
7876 #line 6547 "./marpa.w"
7877 
7878 PIM postdot_item= r->t_trace_postdot_item;
7879 EIM base_earley_item;
7880 /*1370:*/
7881 #line 13169 "./marpa.w"
7882 
7883 switch(Phase_of_R(r)){
7884 default:
7885 R_ERROR("recce not trace-safe");
7886 return failure_indicator;
7887 case input_phase:
7888 case evaluation_phase:
7889 break;
7890 }
7891 /*:1370*/
7892 #line 6550 "./marpa.w"
7893 
7894 if(!postdot_item){
7895 R_ERROR("no trace pim");
7896 return failure_indicator;
7897 }
7898 if(EIM_of_PIM(postdot_item))return pim_is_not_a_leo_item;
7899 base_earley_item= Base_EIM_of_LIM(LIM_of_PIM(postdot_item));
7900 return AHFAID_of_EIM(base_earley_item);
7901 }
7902 
7903 /*:772*//*777:*/
7904 #line 6586 "./marpa.w"
7905 
marpa_leo_expansion_ahfa(struct marpa_r * r)7906 Marpa_AHFA_State_ID marpa_leo_expansion_ahfa(struct marpa_r*r)
7907 {
7908 const EARLEME pim_is_not_a_leo_item= -1;
7909 /*1357:*/
7910 #line 13088 "./marpa.w"
7911 const int failure_indicator= -2;
7912 
7913 /*:1357*/
7914 #line 6590 "./marpa.w"
7915 
7916 const PIM postdot_item= r->t_trace_postdot_item;
7917 /*1370:*/
7918 #line 13169 "./marpa.w"
7919 
7920 switch(Phase_of_R(r)){
7921 default:
7922 R_ERROR("recce not trace-safe");
7923 return failure_indicator;
7924 case input_phase:
7925 case evaluation_phase:
7926 break;
7927 }
7928 /*:1370*/
7929 #line 6592 "./marpa.w"
7930 
7931 if(!postdot_item)
7932 {
7933 R_ERROR("no trace pim");
7934 return failure_indicator;
7935 }
7936 if(!EIM_of_PIM(postdot_item))
7937 {
7938 const LIM leo_item= LIM_of_PIM(postdot_item);
7939 const EIM base_earley_item= Base_EIM_of_LIM(leo_item);
7940 const SYMID postdot_symbol= Postdot_SYMID_of_LIM(leo_item);
7941 const AHFA to_ahfa= To_AHFA_of_EIM_by_SYMID(base_earley_item,postdot_symbol);
7942 return ID_of_AHFA(to_ahfa);
7943 }
7944 return pim_is_not_a_leo_item;
7945 }
7946 
7947 
7948 /*:777*//*782:*/
7949 #line 6646 "./marpa.w"
7950 
7951 static inline PIM*
pim_sym_p_find(ES set,SYMID symid)7952 pim_sym_p_find(ES set,SYMID symid)
7953 {
7954 gint lo= 0;
7955 gint hi= Postdot_SYM_Count_of_ES(set)-1;
7956 PIM*postdot_array= set->t_postdot_ary;
7957 while(hi>=lo){
7958 gint trial= lo+(hi-lo)/2;
7959 PIM trial_pim= postdot_array[trial];
7960 SYMID trial_symid= Postdot_SYMID_of_PIM(trial_pim);
7961 if(trial_symid==symid)return postdot_array+trial;
7962 if(trial_symid<symid){
7963 lo= trial+1;
7964 }else{
7965 hi= trial-1;
7966 }
7967 }
7968 return NULL;
7969 }
7970 /*:782*//*784:*/
7971 #line 6668 "./marpa.w"
7972 
first_pim_of_es_by_symid(ES set,SYMID symid)7973 static inline PIM first_pim_of_es_by_symid(ES set,SYMID symid)
7974 {
7975 PIM*pim_sym_p= pim_sym_p_find(set,symid);
7976 return pim_sym_p?*pim_sym_p:NULL;
7977 }
7978 
7979 /*:784*//*788:*/
7980 #line 6702 "./marpa.w"
7981 
7982 Marpa_Symbol_ID
marpa_postdot_symbol_trace(struct marpa_r * r,Marpa_Symbol_ID symid)7983 marpa_postdot_symbol_trace(struct marpa_r*r,
7984 Marpa_Symbol_ID symid)
7985 {
7986 /*1357:*/
7987 #line 13088 "./marpa.w"
7988 const int failure_indicator= -2;
7989 
7990 /*:1357*/
7991 #line 6707 "./marpa.w"
7992 
7993 ES current_es= r->t_trace_earley_set;
7994 PIM*pim_sym_p;
7995 PIM pim;
7996 /*789:*/
7997 #line 6726 "./marpa.w"
7998 
7999 r->t_trace_pim_sym_p= NULL;
8000 r->t_trace_postdot_item= NULL;
8001 
8002 /*:789*/
8003 #line 6711 "./marpa.w"
8004 
8005 /*1370:*/
8006 #line 13169 "./marpa.w"
8007 
8008 switch(Phase_of_R(r)){
8009 default:
8010 R_ERROR("recce not trace-safe");
8011 return failure_indicator;
8012 case input_phase:
8013 case evaluation_phase:
8014 break;
8015 }
8016 /*:1370*/
8017 #line 6712 "./marpa.w"
8018 
8019 /*1372:*/
8020 #line 13183 "./marpa.w"
8021 
8022 if(!symbol_is_valid(G_of_R(r),symid)){
8023 r_context_clear(r);
8024 r_context_int_add(r,"symid",symid);
8025 R_ERROR_CXT("invalid symid");
8026 return failure_indicator;
8027 }
8028 /*:1372*/
8029 #line 6713 "./marpa.w"
8030 
8031 if(!current_es){
8032 R_ERROR("no pim");
8033 return failure_indicator;
8034 }
8035 pim_sym_p= PIM_SYM_P_of_ES_by_SYMID(current_es,symid);
8036 pim= *pim_sym_p;
8037 if(!pim)return-1;
8038 r->t_trace_pim_sym_p= pim_sym_p;
8039 r->t_trace_postdot_item= pim;
8040 return symid;
8041 }
8042 
8043 /*:788*//*791:*/
8044 #line 6739 "./marpa.w"
8045 
8046 Marpa_Symbol_ID
marpa_first_postdot_item_trace(struct marpa_r * r)8047 marpa_first_postdot_item_trace(struct marpa_r*r)
8048 {
8049 /*1357:*/
8050 #line 13088 "./marpa.w"
8051 const int failure_indicator= -2;
8052 
8053 /*:1357*/
8054 #line 6743 "./marpa.w"
8055 
8056 ES current_earley_set= r->t_trace_earley_set;
8057 PIM pim;
8058 PIM*pim_sym_p;
8059 /*789:*/
8060 #line 6726 "./marpa.w"
8061 
8062 r->t_trace_pim_sym_p= NULL;
8063 r->t_trace_postdot_item= NULL;
8064 
8065 /*:789*/
8066 #line 6747 "./marpa.w"
8067 
8068 /*1370:*/
8069 #line 13169 "./marpa.w"
8070 
8071 switch(Phase_of_R(r)){
8072 default:
8073 R_ERROR("recce not trace-safe");
8074 return failure_indicator;
8075 case input_phase:
8076 case evaluation_phase:
8077 break;
8078 }
8079 /*:1370*/
8080 #line 6748 "./marpa.w"
8081 
8082 if(!current_earley_set){
8083 /*757:*/
8084 #line 6396 "./marpa.w"
8085 
8086 r->t_trace_earley_item= NULL;
8087 
8088 /*:757*/
8089 #line 6750 "./marpa.w"
8090 
8091 R_ERROR("no trace es");
8092 return failure_indicator;
8093 }
8094 if(current_earley_set->t_postdot_sym_count<=0)return-1;
8095 pim_sym_p= current_earley_set->t_postdot_ary+0;
8096 pim= pim_sym_p[0];
8097 r->t_trace_pim_sym_p= pim_sym_p;
8098 r->t_trace_postdot_item= pim;
8099 return Postdot_SYMID_of_PIM(pim);
8100 }
8101 
8102 /*:791*//*793:*/
8103 #line 6772 "./marpa.w"
8104 
8105 Marpa_Symbol_ID
marpa_next_postdot_item_trace(struct marpa_r * r)8106 marpa_next_postdot_item_trace(struct marpa_r*r)
8107 {
8108 const SYMID no_more_postdot_symbols= -1;
8109 /*1357:*/
8110 #line 13088 "./marpa.w"
8111 const int failure_indicator= -2;
8112 
8113 /*:1357*/
8114 #line 6777 "./marpa.w"
8115 
8116 ES current_set= r->t_trace_earley_set;
8117 PIM pim;
8118 PIM*pim_sym_p;
8119 
8120 pim_sym_p= r->t_trace_pim_sym_p;
8121 pim= r->t_trace_postdot_item;
8122 /*789:*/
8123 #line 6726 "./marpa.w"
8124 
8125 r->t_trace_pim_sym_p= NULL;
8126 r->t_trace_postdot_item= NULL;
8127 
8128 /*:789*/
8129 #line 6784 "./marpa.w"
8130 
8131 if(!pim_sym_p||!pim){
8132 R_ERROR("no trace pim");
8133 return failure_indicator;
8134 }
8135 /*1370:*/
8136 #line 13169 "./marpa.w"
8137 
8138 switch(Phase_of_R(r)){
8139 default:
8140 R_ERROR("recce not trace-safe");
8141 return failure_indicator;
8142 case input_phase:
8143 case evaluation_phase:
8144 break;
8145 }
8146 /*:1370*/
8147 #line 6789 "./marpa.w"
8148 
8149 if(!current_set){
8150 R_ERROR("no trace es");
8151 return failure_indicator;
8152 }
8153 pim= Next_PIM_of_PIM(pim);
8154 if(!pim){
8155 
8156 pim_sym_p++;
8157 if(pim_sym_p-current_set->t_postdot_ary
8158 >=current_set->t_postdot_sym_count){
8159 return no_more_postdot_symbols;
8160 }
8161 pim= *pim_sym_p;
8162 }
8163 r->t_trace_pim_sym_p= pim_sym_p;
8164 r->t_trace_postdot_item= pim;
8165 return Postdot_SYMID_of_PIM(pim);
8166 }
8167 
8168 /*:793*//*795:*/
8169 #line 6811 "./marpa.w"
8170 
marpa_postdot_item_symbol(struct marpa_r * r)8171 Marpa_AHFA_State_ID marpa_postdot_item_symbol(struct marpa_r*r)
8172 {
8173 /*1357:*/
8174 #line 13088 "./marpa.w"
8175 const int failure_indicator= -2;
8176 
8177 /*:1357*/
8178 #line 6814 "./marpa.w"
8179 
8180 PIM postdot_item= r->t_trace_postdot_item;
8181 /*1370:*/
8182 #line 13169 "./marpa.w"
8183 
8184 switch(Phase_of_R(r)){
8185 default:
8186 R_ERROR("recce not trace-safe");
8187 return failure_indicator;
8188 case input_phase:
8189 case evaluation_phase:
8190 break;
8191 }
8192 /*:1370*/
8193 #line 6816 "./marpa.w"
8194 
8195 if(!postdot_item){
8196 R_ERROR("no trace pim");
8197 return failure_indicator;
8198 }
8199 return Postdot_SYMID_of_PIM(postdot_item);
8200 }
8201 
8202 
8203 /*:795*//*812:*/
8204 #line 6954 "./marpa.w"
8205 static inline
8206 void
token_link_add(struct marpa_r * r,EIM item,EIM predecessor,TOK token)8207 token_link_add(struct marpa_r*r,
8208 EIM item,
8209 EIM predecessor,
8210 TOK token)
8211 {
8212 SRCL new_link;
8213 guint previous_source_type= Source_Type_of_EIM(item);
8214 if(previous_source_type==NO_SOURCE)
8215 {
8216 Source_Type_of_EIM(item)= SOURCE_IS_TOKEN;
8217 item->t_container.t_unique.t_predecessor= predecessor;
8218 TOK_of_Source(item->t_container.t_unique)= token;
8219 return;
8220 }
8221 if(previous_source_type!=SOURCE_IS_AMBIGUOUS)
8222 {
8223 earley_item_ambiguate(r,item);
8224 }
8225 new_link= obstack_alloc(&r->t_obs,sizeof(*new_link));
8226 new_link->t_next= First_Token_Link_of_EIM(item);
8227 new_link->t_source.t_predecessor= predecessor;
8228 TOK_of_Source(new_link->t_source)= token;
8229 LV_First_Token_Link_of_EIM(item)= new_link;
8230 }
8231 
8232 /*:812*//*818:*/
8233 #line 7035 "./marpa.w"
8234 static inline
8235 void
completion_link_add(struct marpa_r * r,EIM item,EIM predecessor,EIM cause)8236 completion_link_add(struct marpa_r*r,
8237 EIM item,
8238 EIM predecessor,
8239 EIM cause)
8240 {
8241 SRCL new_link;
8242 guint previous_source_type= Source_Type_of_EIM(item);
8243 if(previous_source_type==NO_SOURCE)
8244 {
8245 Source_Type_of_EIM(item)= SOURCE_IS_COMPLETION;
8246 item->t_container.t_unique.t_predecessor= predecessor;
8247 Cause_of_Source(item->t_container.t_unique)= cause;
8248 return;
8249 }
8250 if(previous_source_type!=SOURCE_IS_AMBIGUOUS)
8251 {
8252 earley_item_ambiguate(r,item);
8253 }
8254 new_link= obstack_alloc(&r->t_obs,sizeof(*new_link));
8255 new_link->t_next= First_Completion_Link_of_EIM(item);
8256 new_link->t_source.t_predecessor= predecessor;
8257 Cause_of_Source(new_link->t_source)= cause;
8258 LV_First_Completion_Link_of_EIM(item)= new_link;
8259 }
8260 
8261 /*:818*//*819:*/
8262 #line 7062 "./marpa.w"
8263 static inline
8264 void
leo_link_add(struct marpa_r * r,EIM item,LIM predecessor,EIM cause)8265 leo_link_add(struct marpa_r*r,
8266 EIM item,
8267 LIM predecessor,
8268 EIM cause)
8269 {
8270 SRCL new_link;
8271 guint previous_source_type= Source_Type_of_EIM(item);
8272 if(previous_source_type==NO_SOURCE)
8273 {
8274 Source_Type_of_EIM(item)= SOURCE_IS_LEO;
8275 item->t_container.t_unique.t_predecessor= predecessor;
8276 Cause_of_Source(item->t_container.t_unique)= cause;
8277 return;
8278 }
8279 if(previous_source_type!=SOURCE_IS_AMBIGUOUS)
8280 {
8281 earley_item_ambiguate(r,item);
8282 }
8283 new_link= obstack_alloc(&r->t_obs,sizeof(*new_link));
8284 new_link->t_next= First_Leo_SRCL_of_EIM(item);
8285 new_link->t_source.t_predecessor= predecessor;
8286 Cause_of_Source(new_link->t_source)= cause;
8287 LV_First_Leo_SRCL_of_EIM(item)= new_link;
8288 }
8289 /*:819*//*822:*/
8290 #line 7114 "./marpa.w"
8291 static
earley_item_ambiguate(struct marpa_r * r,EIM item)8292 void earley_item_ambiguate(struct marpa_r*r,EIM item)
8293 {
8294 guint previous_source_type= Source_Type_of_EIM(item);
8295 Source_Type_of_EIM(item)= SOURCE_IS_AMBIGUOUS;
8296 switch(previous_source_type)
8297 {
8298 case SOURCE_IS_TOKEN:/*824:*/
8299 #line 7132 "./marpa.w"
8300 {
8301 SRCL new_link= obstack_alloc(&r->t_obs,sizeof(*new_link));
8302 new_link->t_next= NULL;
8303 new_link->t_source= item->t_container.t_unique;
8304 LV_First_Leo_SRCL_of_EIM(item)= NULL;
8305 LV_First_Completion_Link_of_EIM(item)= NULL;
8306 LV_First_Token_Link_of_EIM(item)= new_link;
8307 }
8308 
8309 /*:824*/
8310 #line 7121 "./marpa.w"
8311 
8312 return;
8313 case SOURCE_IS_COMPLETION:/*825:*/
8314 #line 7141 "./marpa.w"
8315 {
8316 SRCL new_link= obstack_alloc(&r->t_obs,sizeof(*new_link));
8317 new_link->t_next= NULL;
8318 new_link->t_source= item->t_container.t_unique;
8319 LV_First_Leo_SRCL_of_EIM(item)= NULL;
8320 LV_First_Completion_Link_of_EIM(item)= new_link;
8321 LV_First_Token_Link_of_EIM(item)= NULL;
8322 }
8323 
8324 /*:825*/
8325 #line 7123 "./marpa.w"
8326 
8327 return;
8328 case SOURCE_IS_LEO:/*826:*/
8329 #line 7150 "./marpa.w"
8330 {
8331 SRCL new_link= obstack_alloc(&r->t_obs,sizeof(*new_link));
8332 new_link->t_next= NULL;
8333 new_link->t_source= item->t_container.t_unique;
8334 LV_First_Leo_SRCL_of_EIM(item)= new_link;
8335 LV_First_Completion_Link_of_EIM(item)= NULL;
8336 LV_First_Token_Link_of_EIM(item)= NULL;
8337 }
8338 
8339 /*:826*/
8340 #line 7125 "./marpa.w"
8341 
8342 return;
8343 }
8344 }
8345 /*:822*//*832:*/
8346 #line 7184 "./marpa.w"
8347 
marpa_first_token_link_trace(struct marpa_r * r)8348 Marpa_Symbol_ID marpa_first_token_link_trace(struct marpa_r*r)
8349 {
8350 /*1357:*/
8351 #line 13088 "./marpa.w"
8352 const int failure_indicator= -2;
8353 
8354 /*:1357*/
8355 #line 7187 "./marpa.w"
8356 
8357 SRC source;
8358 guint source_type;
8359 EIM item= r->t_trace_earley_item;
8360 /*1370:*/
8361 #line 13169 "./marpa.w"
8362 
8363 switch(Phase_of_R(r)){
8364 default:
8365 R_ERROR("recce not trace-safe");
8366 return failure_indicator;
8367 case input_phase:
8368 case evaluation_phase:
8369 break;
8370 }
8371 /*:1370*/
8372 #line 7191 "./marpa.w"
8373 
8374 /*851:*/
8375 #line 7415 "./marpa.w"
8376 
8377 item= r->t_trace_earley_item;
8378 if(!item){
8379 trace_source_link_clear(r);
8380 R_ERROR("no eim");
8381 return failure_indicator;
8382 }
8383 
8384 /*:851*/
8385 #line 7192 "./marpa.w"
8386 
8387 source_type= Source_Type_of_EIM(item);
8388 switch(source_type)
8389 {
8390 case SOURCE_IS_TOKEN:
8391 r->t_trace_source_type= SOURCE_IS_TOKEN;
8392 source= &(item->t_container.t_unique);
8393 r->t_trace_source= source;
8394 r->t_trace_next_source_link= NULL;
8395 return SYMID_of_SRC(source);
8396 case SOURCE_IS_AMBIGUOUS:
8397 {
8398 SRCL full_link=
8399 First_Token_Link_of_EIM(item);
8400 if(full_link)
8401 {
8402 r->t_trace_source_type= SOURCE_IS_TOKEN;
8403 r->t_trace_next_source_link= Next_SRCL_of_SRCL(full_link);
8404 r->t_trace_source= &(full_link->t_source);
8405 return SYMID_of_SRCL(full_link);
8406 }
8407 }
8408 }
8409 trace_source_link_clear(r);
8410 return-1;
8411 }
8412 
8413 /*:832*//*836:*/
8414 #line 7229 "./marpa.w"
8415 
marpa_next_token_link_trace(struct marpa_r * r)8416 Marpa_Symbol_ID marpa_next_token_link_trace(struct marpa_r*r)
8417 {
8418 /*1357:*/
8419 #line 13088 "./marpa.w"
8420 const int failure_indicator= -2;
8421 
8422 /*:1357*/
8423 #line 7232 "./marpa.w"
8424 
8425 SRCL full_link;
8426 EIM item;
8427 /*1370:*/
8428 #line 13169 "./marpa.w"
8429 
8430 switch(Phase_of_R(r)){
8431 default:
8432 R_ERROR("recce not trace-safe");
8433 return failure_indicator;
8434 case input_phase:
8435 case evaluation_phase:
8436 break;
8437 }
8438 /*:1370*/
8439 #line 7235 "./marpa.w"
8440 
8441 /*851:*/
8442 #line 7415 "./marpa.w"
8443 
8444 item= r->t_trace_earley_item;
8445 if(!item){
8446 trace_source_link_clear(r);
8447 R_ERROR("no eim");
8448 return failure_indicator;
8449 }
8450 
8451 /*:851*/
8452 #line 7236 "./marpa.w"
8453 
8454 if(r->t_trace_source_type!=SOURCE_IS_TOKEN){
8455 trace_source_link_clear(r);
8456 R_ERROR("not tracing token links");
8457 return failure_indicator;
8458 }
8459 if(!r->t_trace_next_source_link){
8460 trace_source_link_clear(r);
8461 return-1;
8462 }
8463 full_link= r->t_trace_next_source_link;
8464 r->t_trace_next_source_link= Next_SRCL_of_SRCL(full_link);
8465 r->t_trace_source= &(full_link->t_source);
8466 return SYMID_of_SRCL(full_link);
8467 }
8468 
8469 /*:836*//*839:*/
8470 #line 7261 "./marpa.w"
8471 
marpa_first_completion_link_trace(struct marpa_r * r)8472 Marpa_Symbol_ID marpa_first_completion_link_trace(struct marpa_r*r)
8473 {
8474 /*1357:*/
8475 #line 13088 "./marpa.w"
8476 const int failure_indicator= -2;
8477 
8478 /*:1357*/
8479 #line 7264 "./marpa.w"
8480 
8481 SRC source;
8482 guint source_type;
8483 EIM item= r->t_trace_earley_item;
8484 /*1370:*/
8485 #line 13169 "./marpa.w"
8486 
8487 switch(Phase_of_R(r)){
8488 default:
8489 R_ERROR("recce not trace-safe");
8490 return failure_indicator;
8491 case input_phase:
8492 case evaluation_phase:
8493 break;
8494 }
8495 /*:1370*/
8496 #line 7268 "./marpa.w"
8497 
8498 /*851:*/
8499 #line 7415 "./marpa.w"
8500 
8501 item= r->t_trace_earley_item;
8502 if(!item){
8503 trace_source_link_clear(r);
8504 R_ERROR("no eim");
8505 return failure_indicator;
8506 }
8507 
8508 /*:851*/
8509 #line 7269 "./marpa.w"
8510 
8511 switch((source_type= Source_Type_of_EIM(item)))
8512 {
8513 case SOURCE_IS_COMPLETION:
8514 r->t_trace_source_type= SOURCE_IS_COMPLETION;
8515 source= &(item->t_container.t_unique);
8516 r->t_trace_source= source;
8517 r->t_trace_next_source_link= NULL;
8518 return Cause_AHFA_State_ID_of_SRC(source);
8519 case SOURCE_IS_AMBIGUOUS:
8520 {
8521 SRCL completion_link= First_Completion_Link_of_EIM(item);
8522 if(completion_link)
8523 {
8524 source= &(completion_link->t_source);
8525 r->t_trace_source_type= SOURCE_IS_COMPLETION;
8526 r->t_trace_next_source_link= Next_SRCL_of_SRCL(completion_link);
8527 r->t_trace_source= source;
8528 return Cause_AHFA_State_ID_of_SRC(source);
8529 }
8530 }
8531 }
8532 trace_source_link_clear(r);
8533 return-1;
8534 }
8535 
8536 /*:839*//*843:*/
8537 #line 7305 "./marpa.w"
8538 
marpa_next_completion_link_trace(struct marpa_r * r)8539 Marpa_Symbol_ID marpa_next_completion_link_trace(struct marpa_r*r)
8540 {
8541 /*1357:*/
8542 #line 13088 "./marpa.w"
8543 const int failure_indicator= -2;
8544 
8545 /*:1357*/
8546 #line 7308 "./marpa.w"
8547 
8548 SRC source;
8549 SRCL completion_link;
8550 EIM item;
8551 /*1370:*/
8552 #line 13169 "./marpa.w"
8553 
8554 switch(Phase_of_R(r)){
8555 default:
8556 R_ERROR("recce not trace-safe");
8557 return failure_indicator;
8558 case input_phase:
8559 case evaluation_phase:
8560 break;
8561 }
8562 /*:1370*/
8563 #line 7312 "./marpa.w"
8564 
8565 /*851:*/
8566 #line 7415 "./marpa.w"
8567 
8568 item= r->t_trace_earley_item;
8569 if(!item){
8570 trace_source_link_clear(r);
8571 R_ERROR("no eim");
8572 return failure_indicator;
8573 }
8574 
8575 /*:851*/
8576 #line 7313 "./marpa.w"
8577 
8578 if(r->t_trace_source_type!=SOURCE_IS_COMPLETION){
8579 trace_source_link_clear(r);
8580 R_ERROR("not tracing completion links");
8581 return failure_indicator;
8582 }
8583 if(!r->t_trace_next_source_link){
8584 trace_source_link_clear(r);
8585 return-1;
8586 }
8587 completion_link= r->t_trace_next_source_link;
8588 r->t_trace_next_source_link= Next_SRCL_of_SRCL(r->t_trace_next_source_link);
8589 source= &(completion_link->t_source);
8590 r->t_trace_source= source;
8591 return Cause_AHFA_State_ID_of_SRC(source);
8592 }
8593 
8594 /*:843*//*846:*/
8595 #line 7339 "./marpa.w"
8596 
8597 Marpa_Symbol_ID
marpa_first_leo_link_trace(struct marpa_r * r)8598 marpa_first_leo_link_trace(struct marpa_r*r)
8599 {
8600 /*1357:*/
8601 #line 13088 "./marpa.w"
8602 const int failure_indicator= -2;
8603 
8604 /*:1357*/
8605 #line 7343 "./marpa.w"
8606 
8607 SRC source;
8608 guint source_type;
8609 EIM item= r->t_trace_earley_item;
8610 /*1370:*/
8611 #line 13169 "./marpa.w"
8612 
8613 switch(Phase_of_R(r)){
8614 default:
8615 R_ERROR("recce not trace-safe");
8616 return failure_indicator;
8617 case input_phase:
8618 case evaluation_phase:
8619 break;
8620 }
8621 /*:1370*/
8622 #line 7347 "./marpa.w"
8623 
8624 /*851:*/
8625 #line 7415 "./marpa.w"
8626 
8627 item= r->t_trace_earley_item;
8628 if(!item){
8629 trace_source_link_clear(r);
8630 R_ERROR("no eim");
8631 return failure_indicator;
8632 }
8633 
8634 /*:851*/
8635 #line 7348 "./marpa.w"
8636 
8637 switch((source_type= Source_Type_of_EIM(item)))
8638 {
8639 case SOURCE_IS_LEO:
8640 r->t_trace_source_type= SOURCE_IS_LEO;
8641 source= &(item->t_container.t_unique);
8642 r->t_trace_source= source;
8643 r->t_trace_next_source_link= NULL;
8644 return Cause_AHFA_State_ID_of_SRC(source);
8645 case SOURCE_IS_AMBIGUOUS:
8646 {
8647 SRCL full_link=
8648 First_Leo_SRCL_of_EIM(item);
8649 if(full_link)
8650 {
8651 source= &(full_link->t_source);
8652 r->t_trace_source_type= SOURCE_IS_LEO;
8653 r->t_trace_next_source_link= (SRCL)
8654 Next_SRCL_of_SRCL(full_link);
8655 r->t_trace_source= source;
8656 return Cause_AHFA_State_ID_of_SRC(source);
8657 }
8658 }
8659 }
8660 trace_source_link_clear(r);
8661 return-1;
8662 }
8663 
8664 /*:846*//*850:*/
8665 #line 7386 "./marpa.w"
8666 
8667 Marpa_Symbol_ID
marpa_next_leo_link_trace(struct marpa_r * r)8668 marpa_next_leo_link_trace(struct marpa_r*r)
8669 {
8670 /*1357:*/
8671 #line 13088 "./marpa.w"
8672 const int failure_indicator= -2;
8673 
8674 /*:1357*/
8675 #line 7390 "./marpa.w"
8676 
8677 SRCL full_link;
8678 SRC source;
8679 EIM item;
8680 /*1370:*/
8681 #line 13169 "./marpa.w"
8682 
8683 switch(Phase_of_R(r)){
8684 default:
8685 R_ERROR("recce not trace-safe");
8686 return failure_indicator;
8687 case input_phase:
8688 case evaluation_phase:
8689 break;
8690 }
8691 /*:1370*/
8692 #line 7394 "./marpa.w"
8693 
8694 /*851:*/
8695 #line 7415 "./marpa.w"
8696 
8697 item= r->t_trace_earley_item;
8698 if(!item){
8699 trace_source_link_clear(r);
8700 R_ERROR("no eim");
8701 return failure_indicator;
8702 }
8703 
8704 /*:851*/
8705 #line 7395 "./marpa.w"
8706 
8707 if(r->t_trace_source_type!=SOURCE_IS_LEO)
8708 {
8709 trace_source_link_clear(r);
8710 R_ERROR("not tracing leo links");
8711 return failure_indicator;
8712 }
8713 if(!r->t_trace_next_source_link)
8714 {
8715 trace_source_link_clear(r);
8716 return-1;
8717 }
8718 full_link= r->t_trace_next_source_link;
8719 source= &(full_link->t_source);
8720 r->t_trace_source= source;
8721 r->t_trace_next_source_link=
8722 Next_SRCL_of_SRCL(r->t_trace_next_source_link);
8723 return Cause_AHFA_State_ID_of_SRC(source);
8724 }
8725 
8726 /*:850*//*854:*/
8727 #line 7426 "./marpa.w"
8728 
trace_source_link_clear(struct marpa_r * r)8729 static inline void trace_source_link_clear(struct marpa_r*r){
8730 r->t_trace_next_source_link= NULL;
8731 r->t_trace_source= NULL;
8732 r->t_trace_source_type= NO_SOURCE;
8733 }
8734 
8735 /*:854*//*856:*/
8736 #line 7443 "./marpa.w"
8737 
marpa_source_predecessor_state(struct marpa_r * r)8738 AHFAID marpa_source_predecessor_state(struct marpa_r*r)
8739 {
8740 /*1357:*/
8741 #line 13088 "./marpa.w"
8742 const int failure_indicator= -2;
8743 
8744 /*:1357*/
8745 #line 7446 "./marpa.w"
8746 
8747 guint source_type;
8748 SRC source;
8749 /*1370:*/
8750 #line 13169 "./marpa.w"
8751 
8752 switch(Phase_of_R(r)){
8753 default:
8754 R_ERROR("recce not trace-safe");
8755 return failure_indicator;
8756 case input_phase:
8757 case evaluation_phase:
8758 break;
8759 }
8760 /*:1370*/
8761 #line 7449 "./marpa.w"
8762 
8763 source_type= r->t_trace_source_type;
8764 /*865:*/
8765 #line 7596 "./marpa.w"
8766 
8767 source= r->t_trace_source;
8768 if(!source){
8769 R_ERROR("no trace source link");
8770 return failure_indicator;
8771 }
8772 
8773 /*:865*/
8774 #line 7451 "./marpa.w"
8775 
8776 switch(source_type)
8777 {
8778 case SOURCE_IS_TOKEN:
8779 case SOURCE_IS_COMPLETION:{
8780 EIM predecessor= Predecessor_of_SRC(source);
8781 if(!predecessor)return-1;
8782 return AHFAID_of_EIM(predecessor);
8783 }
8784 }
8785 R_ERROR(invalid_source_type_message(source_type));
8786 return failure_indicator;
8787 }
8788 
8789 /*:856*//*858:*/
8790 #line 7485 "./marpa.w"
8791 
marpa_source_token(struct marpa_r * r,gpointer * value_p)8792 Marpa_Symbol_ID marpa_source_token(struct marpa_r*r,gpointer*value_p)
8793 {
8794 /*1357:*/
8795 #line 13088 "./marpa.w"
8796 const int failure_indicator= -2;
8797 
8798 /*:1357*/
8799 #line 7488 "./marpa.w"
8800 
8801 guint source_type;
8802 SRC source;
8803 /*1370:*/
8804 #line 13169 "./marpa.w"
8805 
8806 switch(Phase_of_R(r)){
8807 default:
8808 R_ERROR("recce not trace-safe");
8809 return failure_indicator;
8810 case input_phase:
8811 case evaluation_phase:
8812 break;
8813 }
8814 /*:1370*/
8815 #line 7491 "./marpa.w"
8816 
8817 source_type= r->t_trace_source_type;
8818 /*865:*/
8819 #line 7596 "./marpa.w"
8820 
8821 source= r->t_trace_source;
8822 if(!source){
8823 R_ERROR("no trace source link");
8824 return failure_indicator;
8825 }
8826 
8827 /*:865*/
8828 #line 7493 "./marpa.w"
8829 
8830 if(source_type==SOURCE_IS_TOKEN){
8831 const TOK token= TOK_of_SRC(source);
8832 if(value_p)*value_p= Value_of_TOK(token);
8833 return SYMID_of_TOK(token);
8834 }
8835 R_ERROR(invalid_source_type_message(source_type));
8836 return failure_indicator;
8837 }
8838 
8839 /*:858*//*861:*/
8840 #line 7518 "./marpa.w"
8841 
marpa_source_leo_transition_symbol(struct marpa_r * r)8842 Marpa_Symbol_ID marpa_source_leo_transition_symbol(struct marpa_r*r)
8843 {
8844 /*1357:*/
8845 #line 13088 "./marpa.w"
8846 const int failure_indicator= -2;
8847 
8848 /*:1357*/
8849 #line 7521 "./marpa.w"
8850 
8851 guint source_type;
8852 SRC source;
8853 /*1370:*/
8854 #line 13169 "./marpa.w"
8855 
8856 switch(Phase_of_R(r)){
8857 default:
8858 R_ERROR("recce not trace-safe");
8859 return failure_indicator;
8860 case input_phase:
8861 case evaluation_phase:
8862 break;
8863 }
8864 /*:1370*/
8865 #line 7524 "./marpa.w"
8866 
8867 source_type= r->t_trace_source_type;
8868 /*865:*/
8869 #line 7596 "./marpa.w"
8870 
8871 source= r->t_trace_source;
8872 if(!source){
8873 R_ERROR("no trace source link");
8874 return failure_indicator;
8875 }
8876 
8877 /*:865*/
8878 #line 7526 "./marpa.w"
8879 
8880 switch(source_type)
8881 {
8882 case SOURCE_IS_LEO:
8883 return Leo_Transition_SYMID_of_SRC(source);
8884 }
8885 R_ERROR(invalid_source_type_message(source_type));
8886 return failure_indicator;
8887 }
8888 
8889 /*:861*//*864:*/
8890 #line 7565 "./marpa.w"
8891 
marpa_source_middle(struct marpa_r * r)8892 Marpa_Earley_Set_ID marpa_source_middle(struct marpa_r*r)
8893 {
8894 /*1357:*/
8895 #line 13088 "./marpa.w"
8896 const int failure_indicator= -2;
8897 
8898 /*:1357*/
8899 #line 7568 "./marpa.w"
8900 
8901 const EARLEME no_predecessor= -1;
8902 guint source_type;
8903 SRC source;
8904 /*1370:*/
8905 #line 13169 "./marpa.w"
8906 
8907 switch(Phase_of_R(r)){
8908 default:
8909 R_ERROR("recce not trace-safe");
8910 return failure_indicator;
8911 case input_phase:
8912 case evaluation_phase:
8913 break;
8914 }
8915 /*:1370*/
8916 #line 7572 "./marpa.w"
8917 
8918 source_type= r->t_trace_source_type;
8919 /*865:*/
8920 #line 7596 "./marpa.w"
8921 
8922 source= r->t_trace_source;
8923 if(!source){
8924 R_ERROR("no trace source link");
8925 return failure_indicator;
8926 }
8927 
8928 /*:865*/
8929 #line 7574 "./marpa.w"
8930 
8931 switch(source_type)
8932 {
8933 case SOURCE_IS_LEO:
8934 {
8935 LIM predecessor= Predecessor_of_SRC(source);
8936 if(!predecessor)return no_predecessor;
8937 return
8938 ES_Ord_of_EIM(Base_EIM_of_LIM(predecessor));
8939 }
8940 case SOURCE_IS_TOKEN:
8941 case SOURCE_IS_COMPLETION:
8942 {
8943 EIM predecessor= Predecessor_of_SRC(source);
8944 if(!predecessor)return no_predecessor;
8945 return ES_Ord_of_EIM(predecessor);
8946 }
8947 }
8948 R_ERROR(invalid_source_type_message(source_type));
8949 return failure_indicator;
8950 }
8951 
8952 /*:864*//*876:*/
8953 #line 7708 "./marpa.w"
8954 
8955 static inline
token_new(struct marpa_r * r,SYMID symbol_id,gpointer value)8956 TOK token_new(struct marpa_r*r,SYMID symbol_id,gpointer value)
8957 {
8958 TOK token;
8959 token= obstack_alloc(TOK_Obs,sizeof(*token));
8960 Type_of_TOK(token)= TOKEN_OR_NODE;
8961 SYMID_of_TOK(token)= symbol_id;
8962 Value_of_TOK(token)= value;
8963 return token;
8964 }
8965 
8966 /*:876*//*884:*/
8967 #line 7764 "./marpa.w"
8968 
8969 static inline gint
alternative_insertion_point(RECCE r,ALT new_alternative)8970 alternative_insertion_point(RECCE r,ALT new_alternative)
8971 {
8972 DSTACK alternatives= &r->t_alternatives;
8973 ALT alternative;
8974 gint hi= DSTACK_LENGTH(*alternatives)-1;
8975 gint lo= 0;
8976 gint trial;
8977 
8978 if(hi<0)
8979 return 0;
8980 alternative= DSTACK_BASE(*alternatives,ALT_Object);
8981 for(;;)
8982 {
8983 gint outcome;
8984 trial= lo+(hi-lo)/2;
8985 outcome= alternative_cmp(new_alternative,alternative+trial);
8986 if(outcome==0)
8987 return-1;
8988 if(outcome> 0)
8989 {
8990 lo= trial+1;
8991 }
8992 else
8993 {
8994 hi= trial-1;
8995 }
8996 if(hi<lo)
8997 return outcome> 0?trial+1:trial;
8998 }
8999 }
9000 
9001 /*:884*//*886:*/
9002 #line 7810 "./marpa.w"
9003 
alternative_cmp(const ALT_Const a,const ALT_Const b)9004 static inline gint alternative_cmp(const ALT_Const a,const ALT_Const b){
9005 gint subkey= End_Earleme_of_ALT(b)-End_Earleme_of_ALT(a);
9006 if(subkey)return subkey;
9007 subkey= SYMID_of_ALT(a)-SYMID_of_ALT(b);
9008 if(subkey)return subkey;
9009 return Start_Earleme_of_ALT(a)-Start_Earleme_of_ALT(b);
9010 }
9011 
9012 /*:886*//*888:*/
9013 #line 7828 "./marpa.w"
9014 
alternative_pop(RECCE r,EARLEME earleme)9015 static inline ALT alternative_pop(RECCE r,EARLEME earleme)
9016 {
9017 DSTACK alternatives= &r->t_alternatives;
9018 ALT top_of_stack= DSTACK_TOP(*alternatives,ALT_Object);
9019 if(!top_of_stack)return NULL;
9020 if(earleme!=End_Earleme_of_ALT(top_of_stack))return NULL;
9021 return DSTACK_POP(*alternatives,ALT_Object);
9022 }
9023 
9024 /*:888*//*890:*/
9025 #line 7845 "./marpa.w"
9026 
alternative_insert(RECCE r,ALT new_alternative)9027 static inline gint alternative_insert(RECCE r,ALT new_alternative)
9028 {
9029 ALT top_of_stack,base_of_stack;
9030 DSTACK alternatives= &r->t_alternatives;
9031 gint ix;
9032 gint insertion_point= alternative_insertion_point(r,new_alternative);
9033 if(insertion_point<0)
9034 return insertion_point;
9035 top_of_stack= DSTACK_PUSH(*alternatives,ALT_Object);
9036 base_of_stack= DSTACK_BASE(*alternatives,ALT_Object);
9037 for(ix= top_of_stack-base_of_stack;ix> insertion_point;ix--){
9038 base_of_stack[ix]= base_of_stack[ix-1];
9039 }
9040 base_of_stack[insertion_point]= *new_alternative;
9041 return insertion_point;
9042 }
9043 
9044 /*:890*//*893:*/
9045 #line 7865 "./marpa.w"
marpa_start_input(struct marpa_r * r)9046 gboolean marpa_start_input(struct marpa_r*r)
9047 {
9048 ES set0;
9049 EIM item;
9050 EIK_Object key;
9051 AHFA state;
9052 GRAMMAR_Const g= G_of_R(r);
9053 const gint symbol_count_of_g= SYM_Count_of_G(g);
9054 /*1355:*/
9055 #line 13083 "./marpa.w"
9056 const gboolean failure_indicator= FALSE;
9057 /*:1355*/
9058 #line 7873 "./marpa.w"
9059 
9060 /*1366:*/
9061 #line 13149 "./marpa.w"
9062 
9063 if(Phase_of_R(r)!=initial_phase){
9064 R_ERROR("not initial recce phase");
9065 return failure_indicator;
9066 }
9067 /*:1366*/
9068 #line 7874 "./marpa.w"
9069 
9070 /*648:*/
9071 #line 5570 "./marpa.w"
9072 
9073 {
9074 const guint sym_workarea_size= sizeof(gpointer)*symbol_count_of_g;
9075 /*644:*/
9076 #line 5555 "./marpa.w"
9077 
9078 r->t_sym_workarea= g_malloc(sym_workarea_size);
9079 
9080 /*:644*/
9081 #line 5573 "./marpa.w"
9082 
9083 r->t_workarea2= g_malloc(2u*sym_workarea_size);
9084 }
9085 
9086 /*:648*/
9087 #line 7875 "./marpa.w"
9088 
9089 psar_reset(Dot_PSAR_of_R(r));
9090 /*652:*/
9091 #line 5597 "./marpa.w"
9092 {
9093 r->t_bv_sym= bv_create((guint)symbol_count_of_g);
9094 r->t_bv_sym2= bv_create((guint)symbol_count_of_g);
9095 r->t_bv_sym3= bv_create((guint)symbol_count_of_g);
9096 }
9097 /*:652*//*656:*/
9098 #line 5617 "./marpa.w"
9099 
9100 r->t_bv_symid_is_expected= bv_create((guint)symbol_count_of_g);
9101 /*:656*/
9102 #line 7877 "./marpa.w"
9103 
9104 /*908:*/
9105 #line 8051 "./marpa.w"
9106 
9107 DSTACK_IS_INITIALIZED(r->t_eim_work_stack)||
9108 DSTACK_INIT(r->t_eim_work_stack,EIM,1024);
9109 /*:908*//*912:*/
9110 #line 8062 "./marpa.w"
9111 
9112 DSTACK_IS_INITIALIZED(r->t_completion_stack)||
9113 DSTACK_INIT(r->t_completion_stack,EIM,1024);
9114 /*:912*/
9115 #line 7878 "./marpa.w"
9116 
9117 Phase_of_R(r)= input_phase;
9118 LV_Current_Earleme_of_R(r)= 0;
9119 set0= earley_set_new(r,0);
9120 LV_Latest_ES_of_R(r)= set0;
9121 LV_First_ES_of_R(r)= set0;
9122 state= AHFA_of_G_by_ID(g,0);
9123 key.t_origin= set0;
9124 key.t_state= state;
9125 key.t_set= set0;
9126 item= earley_item_create(r,key);
9127 state= Empty_Transition_of_AHFA(state);
9128 if(state){
9129 key.t_state= state;
9130 item= earley_item_create(r,key);
9131 }
9132 postdot_items_create(r,set0);
9133 earley_set_update_items(r,set0);
9134 r->t_is_using_leo= r->t_use_leo_flag;
9135 return TRUE;
9136 }
9137 
9138 /*:893*//*901:*/
9139 #line 7950 "./marpa.w"
9140 
marpa_alternative(struct marpa_r * r,Marpa_Symbol_ID token_id,gpointer value,gint length)9141 gboolean marpa_alternative(struct marpa_r*r,
9142 Marpa_Symbol_ID token_id,gpointer value,gint length){
9143 /*1357:*/
9144 #line 13088 "./marpa.w"
9145 const int failure_indicator= -2;
9146 
9147 /*:1357*/
9148 #line 7953 "./marpa.w"
9149 
9150 GRAMMAR_Const g= G_of_R(r);
9151 const gint duplicate_token_indicator= -3;
9152 const gint unexpected_token_indicator= -1;
9153 ES current_earley_set;
9154 const EARLEME current_earleme= Current_Earleme_of_R(r);
9155 EARLEME target_earleme;
9156 /*1369:*/
9157 #line 13164 "./marpa.w"
9158 
9159 if(Phase_of_R(r)!=input_phase){
9160 R_ERROR("recce not in input phase");
9161 return failure_indicator;
9162 }
9163 /*:1369*/
9164 #line 7960 "./marpa.w"
9165 
9166 /*1368:*/
9167 #line 13159 "./marpa.w"
9168 
9169 if(R_is_Exhausted(r)){
9170 R_ERROR("recce exhausted");
9171 return failure_indicator;
9172 }
9173 /*:1368*/
9174 #line 7961 "./marpa.w"
9175 
9176 /*902:*/
9177 #line 7969 "./marpa.w"
9178 {
9179 const SYM_Const token= SYM_by_ID(token_id);
9180 if(!SYM_is_Terminal(token)){
9181 R_ERROR("token is not a terminal");
9182 return failure_indicator;
9183 }
9184 if(length<=0){
9185 R_ERROR("token length negative or zero");
9186 return failure_indicator;
9187 }
9188 if(length>=EARLEME_THRESHOLD){
9189 R_ERROR("token too long");
9190 return failure_indicator;
9191 }
9192 }
9193 
9194 /*:902*/
9195 #line 7962 "./marpa.w"
9196 
9197 /*904:*/
9198 #line 8002 "./marpa.w"
9199 {
9200 current_earley_set= Current_ES_of_R(r);
9201 if(!current_earley_set)return unexpected_token_indicator;
9202 if(!First_PIM_of_ES_by_SYMID(current_earley_set,token_id))
9203 return unexpected_token_indicator;
9204 }
9205 
9206 /*:904*/
9207 #line 7963 "./marpa.w"
9208 
9209 /*903:*/
9210 #line 7985 "./marpa.w"
9211 {
9212 target_earleme= current_earleme+length;
9213 if(target_earleme>=EARLEME_THRESHOLD){
9214 r_context_clear(r);
9215 r_context_int_add(r,"target_earleme",target_earleme);
9216 R_ERROR_CXT("parse too long");
9217 return failure_indicator;
9218 }
9219 }
9220 
9221 /*:903*/
9222 #line 7964 "./marpa.w"
9223 
9224 /*905:*/
9225 #line 8025 "./marpa.w"
9226 
9227 {
9228 TOK token= token_new(r,token_id,value);
9229 ALT_Object alternative;
9230 if(Furthest_Earleme_of_R(r)<target_earleme)
9231 LV_Furthest_Earleme_of_R(r)= target_earleme;
9232 alternative.t_token= token;
9233 alternative.t_start_earley_set= current_earley_set;
9234 alternative.t_end_earleme= target_earleme;
9235 if(alternative_insert(r,&alternative)<0)
9236 {
9237 /*877:*/
9238 #line 7723 "./marpa.w"
9239 obstack_free(TOK_Obs,token);
9240 
9241 /*:877*/
9242 #line 8036 "./marpa.w"
9243 
9244 return duplicate_token_indicator;
9245 }
9246 }
9247 
9248 /*:905*/
9249 #line 7965 "./marpa.w"
9250 
9251 return current_earleme;
9252 }
9253 
9254 /*:901*//*919:*/
9255 #line 8094 "./marpa.w"
9256 
9257 Marpa_Earleme
marpa_earleme_complete(struct marpa_r * r)9258 marpa_earleme_complete(struct marpa_r*r)
9259 {
9260 /*1357:*/
9261 #line 13088 "./marpa.w"
9262 const int failure_indicator= -2;
9263 
9264 /*:1357*/
9265 #line 8098 "./marpa.w"
9266 
9267 EIM*cause_p;
9268 ES current_earley_set;
9269 EARLEME current_earleme;
9270 gint count_of_expected_terminals;
9271 /*1369:*/
9272 #line 13164 "./marpa.w"
9273 
9274 if(Phase_of_R(r)!=input_phase){
9275 R_ERROR("recce not in input phase");
9276 return failure_indicator;
9277 }
9278 /*:1369*/
9279 #line 8103 "./marpa.w"
9280 
9281 /*1368:*/
9282 #line 13159 "./marpa.w"
9283 
9284 if(R_is_Exhausted(r)){
9285 R_ERROR("recce exhausted");
9286 return failure_indicator;
9287 }
9288 /*:1368*/
9289 #line 8104 "./marpa.w"
9290 
9291 psar_dealloc(Dot_PSAR_of_R(r));
9292 bv_clear(r->t_bv_symid_is_expected);
9293 /*920:*/
9294 #line 8130 "./marpa.w"
9295 {
9296 current_earleme= ++(LV_Current_Earleme_of_R(r));
9297 if(current_earleme> Furthest_Earleme_of_R(r))
9298 {
9299 LV_R_is_Exhausted(r)= 1;
9300 R_ERROR("parse exhausted");
9301 return failure_indicator;
9302 }
9303 }
9304 
9305 /*:920*/
9306 #line 8107 "./marpa.w"
9307 
9308 /*922:*/
9309 #line 8155 "./marpa.w"
9310 {
9311 ALT top_of_stack= DSTACK_TOP(r->t_alternatives,ALT_Object);
9312 if(!top_of_stack)return 0;
9313 if(current_earleme!=End_Earleme_of_ALT(top_of_stack))return 0;
9314 }
9315 
9316 /*:922*/
9317 #line 8108 "./marpa.w"
9318 
9319 /*921:*/
9320 #line 8142 "./marpa.w"
9321 {
9322 current_earley_set= earley_set_new(r,current_earleme);
9323 LV_Next_ES_of_ES(Latest_ES_of_R(r))= current_earley_set;
9324 LV_Latest_ES_of_R(r)= current_earley_set;
9325 }
9326 
9327 /*:921*/
9328 #line 8109 "./marpa.w"
9329 
9330 /*923:*/
9331 #line 8161 "./marpa.w"
9332 
9333 {
9334 ALT alternative;
9335 while((alternative= alternative_pop(r,current_earleme)))
9336 /*924:*/
9337 #line 8168 "./marpa.w"
9338 
9339 {
9340 ES start_earley_set= Start_ES_of_ALT(alternative);
9341 TOK token= TOK_of_ALT(alternative);
9342 SYMID token_id= SYMID_of_TOK(token);
9343 PIM pim= First_PIM_of_ES_by_SYMID(start_earley_set,token_id);
9344 for(;pim;pim= Next_PIM_of_PIM(pim)){
9345 AHFA scanned_AHFA,prediction_AHFA;
9346 EIM scanned_earley_item;
9347 EIM predecessor= EIM_of_PIM(pim);
9348 if(!predecessor)
9349 continue;
9350 scanned_AHFA= To_AHFA_of_EIM_by_SYMID(predecessor,token_id);
9351 scanned_earley_item= earley_item_assign(r,
9352 current_earley_set,
9353 Origin_of_EIM(predecessor),
9354 scanned_AHFA);
9355 token_link_add(r,scanned_earley_item,predecessor,token);
9356 prediction_AHFA= Empty_Transition_of_AHFA(scanned_AHFA);
9357 if(!prediction_AHFA)continue;
9358 scanned_earley_item= earley_item_assign(r,
9359 current_earley_set,
9360 current_earley_set,
9361 prediction_AHFA);
9362 }
9363 }
9364 
9365 /*:924*/
9366 #line 8165 "./marpa.w"
9367 
9368 }
9369 
9370 /*:923*/
9371 #line 8110 "./marpa.w"
9372 
9373 /*925:*/
9374 #line 8195 "./marpa.w"
9375 {
9376 EIM*work_earley_items= DSTACK_BASE(r->t_eim_work_stack,EIM);
9377 gint no_of_work_earley_items= DSTACK_LENGTH(r->t_eim_work_stack);
9378 gint ix;
9379 DSTACK_CLEAR(r->t_completion_stack);
9380 for(ix= 0;
9381 ix<no_of_work_earley_items;
9382 ix++){
9383 EIM earley_item= work_earley_items[ix];
9384 EIM*tos;
9385 if(!Earley_Item_is_Completion(earley_item))
9386 continue;
9387 tos= DSTACK_PUSH(r->t_completion_stack,EIM);
9388 *tos= earley_item;
9389 }
9390 }
9391 
9392 /*:925*/
9393 #line 8111 "./marpa.w"
9394 
9395 while((cause_p= DSTACK_POP(r->t_completion_stack,EIM))){
9396 EIM cause= *cause_p;
9397 /*926:*/
9398 #line 8214 "./marpa.w"
9399 
9400 {
9401 Marpa_Symbol_ID*complete_symbols= Complete_SYMIDs_of_EIM(cause);
9402 gint count= Complete_SYM_Count_of_EIM(cause);
9403 ES middle= Origin_of_EIM(cause);
9404 gint symbol_ix;
9405 for(symbol_ix= 0;symbol_ix<count;symbol_ix++)
9406 {
9407 Marpa_Symbol_ID complete_symbol= complete_symbols[symbol_ix];
9408 /*927:*/
9409 #line 8227 "./marpa.w"
9410 
9411 {
9412 PIM postdot_item;
9413 for(postdot_item= First_PIM_of_ES_by_SYMID(middle,complete_symbol);
9414 postdot_item;postdot_item= Next_PIM_of_PIM(postdot_item))
9415 {
9416 EIM predecessor= EIM_of_PIM(postdot_item);
9417 EIM effect;
9418 AHFA effect_AHFA_state;
9419 if(predecessor)
9420 {
9421 /*928:*/
9422 #line 8250 "./marpa.w"
9423 
9424 {
9425 ES origin= Origin_of_EIM(predecessor);
9426 effect_AHFA_state= To_AHFA_of_EIM_by_SYMID(predecessor,complete_symbol);
9427 effect= earley_item_assign(r,current_earley_set,
9428 origin,effect_AHFA_state);
9429 if(Earley_Item_has_No_Source(effect)){
9430 
9431 if(Earley_Item_is_Completion(effect)){
9432 /*929:*/
9433 #line 8266 "./marpa.w"
9434 {
9435 EIM*tos= DSTACK_PUSH(r->t_completion_stack,EIM);
9436 *tos= effect;
9437 }
9438 
9439 
9440 
9441 /*:929*/
9442 #line 8259 "./marpa.w"
9443 
9444 }
9445 /*930:*/
9446 #line 8273 "./marpa.w"
9447 {
9448 AHFA prediction_AHFA_state=
9449 Empty_Transition_of_AHFA(effect_AHFA_state);
9450 if(prediction_AHFA_state)
9451 {
9452 earley_item_assign(r,current_earley_set,current_earley_set,
9453 prediction_AHFA_state);
9454 }
9455 }
9456 
9457 /*:930*/
9458 #line 8261 "./marpa.w"
9459 
9460 }
9461 completion_link_add(r,effect,predecessor,cause);
9462 }
9463 
9464 /*:928*/
9465 #line 8238 "./marpa.w"
9466 
9467 }
9468 else
9469 {
9470 /*931:*/
9471 #line 8283 "./marpa.w"
9472 {
9473 LIM leo_item= LIM_of_PIM(postdot_item);
9474 ES origin= Origin_of_LIM(leo_item);
9475 effect_AHFA_state= Top_AHFA_of_LIM(leo_item);
9476 effect= earley_item_assign(r,current_earley_set,
9477 origin,effect_AHFA_state);
9478 if(Earley_Item_has_No_Source(effect))
9479 {
9480 
9481 /*929:*/
9482 #line 8266 "./marpa.w"
9483 {
9484 EIM*tos= DSTACK_PUSH(r->t_completion_stack,EIM);
9485 *tos= effect;
9486 }
9487 
9488 
9489 
9490 /*:929*/
9491 #line 8292 "./marpa.w"
9492 
9493 }
9494 leo_link_add(r,effect,leo_item,cause);
9495 }
9496 
9497 /*:931*/
9498 #line 8242 "./marpa.w"
9499 
9500 break;
9501 
9502 
9503 }
9504 }
9505 }
9506 
9507 /*:927*/
9508 #line 8223 "./marpa.w"
9509 
9510 }
9511 }
9512 
9513 /*:926*/
9514 #line 8114 "./marpa.w"
9515 
9516 }
9517 postdot_items_create(r,current_earley_set);
9518 
9519 count_of_expected_terminals= bv_count(r->t_bv_symid_is_expected);
9520 if(count_of_expected_terminals<=0
9521 &&Earleme_of_ES(current_earley_set)>=Furthest_Earleme_of_R(r))
9522 {
9523 
9524 
9525 LV_R_is_Exhausted(r)= 1;
9526 }
9527 earley_set_update_items(r,current_earley_set);
9528 return count_of_expected_terminals;
9529 }
9530 
9531 /*:919*//*933:*/
9532 #line 8299 "./marpa.w"
9533 
earley_set_update_items(RECCE r,ES set)9534 static inline void earley_set_update_items(RECCE r,ES set){
9535 EIM*working_earley_items;
9536 EIM*finished_earley_items;
9537 gint working_earley_item_count;
9538 gint i;
9539 if(!EIMs_of_ES(set)){
9540 EIMs_of_ES(set)= g_new(EIM,EIM_Count_of_ES(set));
9541 }else{
9542 EIMs_of_ES(set)= g_renew(EIM,EIMs_of_ES(set),EIM_Count_of_ES(set));
9543 }
9544 finished_earley_items= EIMs_of_ES(set);
9545 working_earley_items= Work_EIMs_of_R(r);
9546 working_earley_item_count= Work_EIM_Count_of_R(r);
9547 for(i= 0;i<working_earley_item_count;i++){
9548 EIM earley_item= working_earley_items[i];
9549 gint ordinal= Ord_of_EIM(earley_item);
9550 finished_earley_items[ordinal]= earley_item;
9551 }
9552 WORK_EIMS_CLEAR(r);
9553 }
9554 
9555 /*:933*//*935:*/
9556 #line 8325 "./marpa.w"
9557 
r_update_earley_sets(RECCE r)9558 static inline void r_update_earley_sets(RECCE r){
9559 ES set;
9560 ES first_unstacked_earley_set;
9561 if(!DSTACK_IS_INITIALIZED(r->t_earley_set_stack)){
9562 first_unstacked_earley_set= First_ES_of_R(r);
9563 DSTACK_INIT(r->t_earley_set_stack,ES,
9564 MAX(1024,ES_Count_of_R(r)));
9565 }else{
9566 ES*top_of_stack= DSTACK_TOP(r->t_earley_set_stack,ES);
9567 first_unstacked_earley_set= Next_ES_of_ES(*top_of_stack);
9568 }
9569 for(set= first_unstacked_earley_set;set;set= Next_ES_of_ES(set)){
9570 ES*top_of_stack= DSTACK_PUSH(r->t_earley_set_stack,ES);
9571 (*top_of_stack)= set;
9572 }
9573 }
9574 
9575 /*:935*//*939:*/
9576 #line 8363 "./marpa.w"
9577 
9578 static void
postdot_items_create(struct marpa_r * r,ES current_earley_set)9579 postdot_items_create(struct marpa_r*r,ES current_earley_set)
9580 {
9581 gpointer*const pim_workarea= r->t_sym_workarea;
9582 GRAMMAR_Const g= G_of_R(r);
9583 EARLEME current_earley_set_id= Earleme_of_ES(current_earley_set);
9584 Bit_Vector bv_pim_symbols= r->t_bv_sym;
9585 Bit_Vector bv_lim_symbols= r->t_bv_sym2;
9586 bv_clear(bv_pim_symbols);
9587 bv_clear(bv_lim_symbols);
9588 /*940:*/
9589 #line 8385 "./marpa.w"
9590 {
9591 EIM*work_earley_items= DSTACK_BASE(r->t_eim_work_stack,EIM);
9592 gint no_of_work_earley_items= DSTACK_LENGTH(r->t_eim_work_stack);
9593 gint ix;
9594 for(ix= 0;
9595 ix<no_of_work_earley_items;
9596 ix++){
9597 EIM earley_item= work_earley_items[ix];
9598 AHFA state= AHFA_of_EIM(earley_item);
9599 gint symbol_ix;
9600 gint postdot_symbol_count= Postdot_SYM_Count_of_AHFA(state);
9601 Marpa_Symbol_ID*postdot_symbols=
9602 Postdot_SYMID_Ary_of_AHFA(state);
9603 for(symbol_ix= 0;symbol_ix<postdot_symbol_count;symbol_ix++)
9604 {
9605 PIM old_pim= NULL;
9606 PIM new_pim;
9607 Marpa_Symbol_ID symid;
9608 new_pim= obstack_alloc(&r->t_obs,sizeof(EIX_Object));
9609 symid= postdot_symbols[symbol_ix];
9610 LV_Postdot_SYMID_of_PIM(new_pim)= symid;
9611 LV_EIM_of_PIM(new_pim)= earley_item;
9612 if(bv_bit_test(bv_pim_symbols,(guint)symid))
9613 old_pim= pim_workarea[symid];
9614 if(old_pim){
9615 LV_Next_PIM_of_PIM(new_pim)= old_pim;
9616 }else{
9617 LV_Next_PIM_of_PIM(new_pim)= NULL;
9618 current_earley_set->t_postdot_sym_count++;
9619 }
9620 pim_workarea[symid]= new_pim;
9621 bv_bit_set(bv_pim_symbols,(guint)symid);
9622 }
9623 }
9624 }
9625 
9626 /*:940*/
9627 #line 8374 "./marpa.w"
9628 
9629 if(r->t_is_using_leo){
9630 /*942:*/
9631 #line 8431 "./marpa.w"
9632 
9633 {
9634 guint min,max,start;
9635 for(start= 0;bv_scan(bv_pim_symbols,start,&min,&max);
9636 start= max+2)
9637 {
9638 SYMID symid;
9639 for(symid= (SYMID)min;symid<=(SYMID)max;symid++)
9640 {
9641 PIM this_pim= pim_workarea[symid];
9642 if(!Next_PIM_of_PIM(this_pim))
9643 {
9644 
9645 EIM leo_base= EIM_of_PIM(this_pim);
9646 AHFA base_to_ahfa= To_AHFA_of_EIM_by_SYMID(leo_base,symid);
9647 if(AHFA_is_Leo_Completion(base_to_ahfa))
9648 {
9649 /*943:*/
9650 #line 8461 "./marpa.w"
9651 {
9652 LIM new_lim;
9653 new_lim= obstack_alloc(&r->t_obs,sizeof(*new_lim));
9654 Postdot_SYMID_of_LIM(new_lim)= symid;
9655 LV_EIM_of_PIM(new_lim)= NULL;
9656 LV_Predecessor_LIM_of_LIM(new_lim)= NULL;
9657 LV_Origin_of_LIM(new_lim)= NULL;
9658 LV_Chain_Length_of_LIM(new_lim)= -1;
9659 LV_Top_AHFA_of_LIM(new_lim)= base_to_ahfa;
9660 LV_Base_EIM_of_LIM(new_lim)= leo_base;
9661 LV_ES_of_LIM(new_lim)= current_earley_set;
9662 LV_Next_PIM_of_LIM(new_lim)= this_pim;
9663 pim_workarea[symid]= new_lim;
9664 bv_bit_set(bv_lim_symbols,(guint)symid);
9665 }
9666 
9667 /*:943*/
9668 #line 8448 "./marpa.w"
9669 
9670 }
9671 }
9672 }
9673 }
9674 }
9675 
9676 /*:942*/
9677 #line 8376 "./marpa.w"
9678 
9679 /*952:*/
9680 #line 8546 "./marpa.w"
9681 {
9682 const Bit_Vector bv_ok_for_chain= r->t_bv_sym3;
9683 guint min,max,start;
9684 
9685 bv_copy(bv_ok_for_chain,bv_lim_symbols);
9686 for(start= 0;bv_scan(bv_lim_symbols,start,&min,&max);
9687 start= max+2)
9688 {
9689 
9690 SYMID main_loop_symbol_id;
9691 for(main_loop_symbol_id= (SYMID)min;
9692 main_loop_symbol_id<=(SYMID)max;
9693 main_loop_symbol_id++)
9694 {
9695 LIM predecessor_lim;
9696 LIM lim_to_process= pim_workarea[main_loop_symbol_id];
9697 if(LIM_is_Populated(lim_to_process))continue;
9698 
9699 /*955:*/
9700 #line 8605 "./marpa.w"
9701 {
9702 const EIM base_eim= Base_EIM_of_LIM(lim_to_process);
9703 const ES predecessor_set= Origin_of_EIM(base_eim);
9704 const AHFA base_to_ahfa= Top_AHFA_of_LIM(lim_to_process);
9705 const SYMID predecessor_transition_symbol= Leo_LHS_ID_of_AHFA(base_to_ahfa);
9706 PIM predecessor_pim;
9707 if(Earleme_of_ES(predecessor_set)<current_earley_set_id){
9708 predecessor_pim
9709 = First_PIM_of_ES_by_SYMID(predecessor_set,predecessor_transition_symbol);
9710 }else{
9711 predecessor_pim= pim_workarea[predecessor_transition_symbol];
9712 }
9713 predecessor_lim= PIM_is_LIM(predecessor_pim)?LIM_of_PIM(predecessor_pim):NULL;
9714 }
9715 
9716 /*:955*/
9717 #line 8564 "./marpa.w"
9718 
9719 if(predecessor_lim&&LIM_is_Populated(predecessor_lim)){
9720 /*961:*/
9721 #line 8697 "./marpa.w"
9722 {
9723 LV_Predecessor_LIM_of_LIM(lim_to_process)= predecessor_lim;
9724 LV_Origin_of_LIM(lim_to_process)= Origin_of_LIM(predecessor_lim);
9725 LV_Chain_Length_of_LIM(lim_to_process)=
9726 Chain_Length_of_LIM(lim_to_process)+1;
9727 LV_Top_AHFA_of_LIM(lim_to_process)= Top_AHFA_of_LIM(predecessor_lim);
9728 }
9729 
9730 /*:961*/
9731 #line 8566 "./marpa.w"
9732 
9733 continue;
9734 }
9735 if(!predecessor_lim){
9736 
9737 
9738 /*963:*/
9739 #line 8718 "./marpa.w"
9740 {
9741 EIM base_eim= Base_EIM_of_LIM(lim_to_process);
9742 LV_Origin_of_LIM(lim_to_process)= Origin_of_EIM(base_eim);
9743 LV_Chain_Length_of_LIM(lim_to_process)= 0;
9744 }
9745 
9746 /*:963*/
9747 #line 8572 "./marpa.w"
9748 
9749 continue;
9750 }
9751 /*956:*/
9752 #line 8620 "./marpa.w"
9753 {
9754 gpointer*const lim_chain= r->t_workarea2;
9755 gint lim_chain_ix;
9756 /*959:*/
9757 #line 8641 "./marpa.w"
9758 {
9759 SYMID postdot_symid_of_lim_to_process
9760 = Postdot_SYMID_of_LIM(lim_to_process);
9761 lim_chain_ix= 0;
9762 lim_chain[lim_chain_ix++]= LIM_of_PIM(lim_to_process);
9763 bv_bit_clear(bv_ok_for_chain,(guint)postdot_symid_of_lim_to_process);
9764 
9765 
9766 while(1){
9767 lim_to_process= predecessor_lim;
9768 
9769 
9770 
9771 
9772 
9773 
9774 postdot_symid_of_lim_to_process= Postdot_SYMID_of_LIM(lim_to_process);
9775 if(!bv_bit_test(bv_ok_for_chain,(guint)postdot_symid_of_lim_to_process)){
9776 
9777 
9778 
9779 
9780 
9781 break;
9782 }
9783 
9784 /*955:*/
9785 #line 8605 "./marpa.w"
9786 {
9787 const EIM base_eim= Base_EIM_of_LIM(lim_to_process);
9788 const ES predecessor_set= Origin_of_EIM(base_eim);
9789 const AHFA base_to_ahfa= Top_AHFA_of_LIM(lim_to_process);
9790 const SYMID predecessor_transition_symbol= Leo_LHS_ID_of_AHFA(base_to_ahfa);
9791 PIM predecessor_pim;
9792 if(Earleme_of_ES(predecessor_set)<current_earley_set_id){
9793 predecessor_pim
9794 = First_PIM_of_ES_by_SYMID(predecessor_set,predecessor_transition_symbol);
9795 }else{
9796 predecessor_pim= pim_workarea[predecessor_transition_symbol];
9797 }
9798 predecessor_lim= PIM_is_LIM(predecessor_pim)?LIM_of_PIM(predecessor_pim):NULL;
9799 }
9800 
9801 /*:955*/
9802 #line 8667 "./marpa.w"
9803 
9804 
9805 lim_chain[lim_chain_ix++]= LIM_of_PIM(lim_to_process);
9806 
9807 
9808 bv_bit_clear(bv_ok_for_chain,(guint)postdot_symid_of_lim_to_process);
9809 
9810 
9811 
9812 if(!predecessor_lim)break;
9813 
9814 
9815 if(LIM_is_Populated(predecessor_lim))break;
9816 
9817 
9818 
9819 }
9820 }
9821 
9822 /*:959*/
9823 #line 8623 "./marpa.w"
9824 
9825 /*960:*/
9826 #line 8686 "./marpa.w"
9827 
9828 for(lim_chain_ix--;lim_chain_ix>=0;lim_chain_ix--){
9829 lim_to_process= lim_chain[lim_chain_ix];
9830 if(predecessor_lim&&LIM_is_Populated(predecessor_lim)){
9831 /*961:*/
9832 #line 8697 "./marpa.w"
9833 {
9834 LV_Predecessor_LIM_of_LIM(lim_to_process)= predecessor_lim;
9835 LV_Origin_of_LIM(lim_to_process)= Origin_of_LIM(predecessor_lim);
9836 LV_Chain_Length_of_LIM(lim_to_process)=
9837 Chain_Length_of_LIM(lim_to_process)+1;
9838 LV_Top_AHFA_of_LIM(lim_to_process)= Top_AHFA_of_LIM(predecessor_lim);
9839 }
9840 
9841 /*:961*/
9842 #line 8690 "./marpa.w"
9843 
9844 }else{
9845 /*963:*/
9846 #line 8718 "./marpa.w"
9847 {
9848 EIM base_eim= Base_EIM_of_LIM(lim_to_process);
9849 LV_Origin_of_LIM(lim_to_process)= Origin_of_EIM(base_eim);
9850 LV_Chain_Length_of_LIM(lim_to_process)= 0;
9851 }
9852 
9853 /*:963*/
9854 #line 8692 "./marpa.w"
9855 
9856 }
9857 predecessor_lim= lim_to_process;
9858 }
9859 
9860 /*:960*/
9861 #line 8624 "./marpa.w"
9862 
9863 }
9864 
9865 /*:956*/
9866 #line 8575 "./marpa.w"
9867 
9868 }
9869 }
9870 }
9871 
9872 /*:952*/
9873 #line 8377 "./marpa.w"
9874 
9875 }
9876 /*964:*/
9877 #line 8724 "./marpa.w"
9878 {
9879 PIM*postdot_array
9880 = current_earley_set->t_postdot_ary
9881 = obstack_alloc(&r->t_obs,
9882 current_earley_set->t_postdot_sym_count*sizeof(PIM));
9883 guint min,max,start;
9884 gint postdot_array_ix= 0;
9885 for(start= 0;bv_scan(bv_pim_symbols,start,&min,&max);start= max+2){
9886 SYMID symid;
9887 for(symid= (SYMID)min;symid<=(SYMID)max;symid++){
9888 PIM this_pim= pim_workarea[symid];
9889 if(this_pim)postdot_array[postdot_array_ix++]= this_pim;
9890 }
9891 }
9892 }
9893 
9894 /*:964*/
9895 #line 8379 "./marpa.w"
9896 
9897 bv_and(r->t_bv_symid_is_expected,bv_pim_symbols,g->t_bv_symid_is_terminal);
9898 }
9899 
9900 /*:939*//*987:*/
9901 #line 8923 "./marpa.w"
9902 
ur_node_stack_init(URS stack)9903 static inline void ur_node_stack_init(URS stack){
9904 MARPA_OFF_DEBUG2("ur_node_stack_init %s",G_STRLOC);
9905 obstack_init(&stack->t_obs);
9906 stack->t_base= ur_node_new(stack,0);
9907 ur_node_stack_reset(stack);
9908 }
9909 
9910 /*:987*//*989:*/
9911 #line 8933 "./marpa.w"
9912 
ur_node_stack_reset(URS stack)9913 static inline void ur_node_stack_reset(URS stack){
9914 stack->t_top= stack->t_base;
9915 }
9916 
9917 /*:989*//*991:*/
9918 #line 8940 "./marpa.w"
9919 
ur_node_stack_destroy(URS stack)9920 static inline void ur_node_stack_destroy(URS stack){
9921 MARPA_OFF_DEBUG2("ur_node_stack_destroy %s",G_STRLOC);
9922 if(stack->t_base)obstack_free(&stack->t_obs,NULL);
9923 stack->t_base= NULL;
9924 MARPA_OFF_DEBUG2("ur_node_stack_destroy %s",G_STRLOC);
9925 }
9926 
9927 /*:991*//*993:*/
9928 #line 8950 "./marpa.w"
9929 
ur_node_new(URS stack,UR prev)9930 static inline UR ur_node_new(URS stack,UR prev){
9931 UR new_ur_node;
9932 new_ur_node= obstack_alloc(&stack->t_obs,sizeof(new_ur_node[0]));
9933 LV_Next_UR_of_UR(new_ur_node)= 0;
9934 LV_Prev_UR_of_UR(new_ur_node)= prev;
9935 return new_ur_node;
9936 }
9937 
9938 /*:993*//*995:*/
9939 #line 8961 "./marpa.w"
9940 
9941 static inline void
ur_node_push(URS stack,EIM earley_item,AEX aex)9942 ur_node_push(URS stack,EIM earley_item,AEX aex)
9943 {
9944 UR top= stack->t_top;
9945 UR new_top= Next_UR_of_UR(top);
9946 LV_EIM_of_UR(top)= earley_item;
9947 LV_AEX_of_UR(top)= aex;
9948 if(!new_top)
9949 {
9950 new_top= ur_node_new(stack,top);
9951 LV_Next_UR_of_UR(top)= new_top;
9952 }
9953 stack->t_top= new_top;
9954 }
9955 
9956 /*:995*//*997:*/
9957 #line 8979 "./marpa.w"
9958 
9959 static inline UR
ur_node_pop(URS stack)9960 ur_node_pop(URS stack)
9961 {
9962 UR new_top= Prev_UR_of_UR(stack->t_top);
9963 if(!new_top)return NULL;
9964 stack->t_top= new_top;
9965 return new_top;
9966 }
9967 
9968 /*:997*//*1002:*/
9969 #line 9080 "./marpa.w"
9970 
psia_test_and_set(struct obstack * obs,struct s_bocage_setup_per_es * per_es_data,EIM earley_item,AEX ahfa_element_ix)9971 static inline gint psia_test_and_set(
9972 struct obstack*obs,
9973 struct s_bocage_setup_per_es*per_es_data,
9974 EIM earley_item,
9975 AEX ahfa_element_ix)
9976 {
9977 const gint aim_count_of_item= AIM_Count_of_EIM(earley_item);
9978 const Marpa_Earley_Set_ID set_ordinal= ES_Ord_of_EIM(earley_item);
9979 OR**nodes_by_item= per_es_data[set_ordinal].t_aexes_by_item;
9980 const gint item_ordinal= Ord_of_EIM(earley_item);
9981 OR*nodes_by_aex= nodes_by_item[item_ordinal];
9982 MARPA_ASSERT(ahfa_element_ix<aim_count_of_item)
9983 if(!nodes_by_aex){
9984 AEX aex;
9985 nodes_by_aex= nodes_by_item[item_ordinal]=
9986 obstack_alloc(obs,aim_count_of_item*sizeof(OR));
9987 for(aex= 0;aex<aim_count_of_item;aex++){
9988 nodes_by_aex[aex]= NULL;
9989 }
9990 }
9991 if(!nodes_by_aex[ahfa_element_ix]){
9992 nodes_by_aex[ahfa_element_ix]= dummy_or_node;
9993 return 0;
9994 }
9995 return 1;
9996 }
9997 
9998 /*:1002*//*1039:*/
9999 #line 9679 "./marpa.w"
10000 
lim_base_data_get(LIM leo_item,EIM * p_base)10001 static inline AEX lim_base_data_get(LIM leo_item,EIM*p_base)
10002 {
10003 const SYMID postdot= Postdot_SYMID_of_LIM(leo_item);
10004 const EIM base= Base_EIM_of_LIM(leo_item);
10005 const TRANS transition= TRANS_of_EIM_by_SYMID(base,postdot);
10006 *p_base= base;
10007 return Leo_Base_AEX_of_TRANS(transition);
10008 }
10009 
10010 /*:1039*//*1041:*/
10011 #line 9693 "./marpa.w"
10012 
base_aim_of_lim(LIM leo_item)10013 static inline AIM base_aim_of_lim(LIM leo_item)
10014 {
10015 EIM base;
10016 const AEX base_aex= lim_base_data_get(leo_item,&base);
10017 return AIM_of_EIM_by_AEX(base,base_aex);
10018 }
10019 
10020 /*:1041*//*1048:*/
10021 #line 9814 "./marpa.w"
10022 
10023 static inline
draft_and_node_new(struct obstack * obs,OR predecessor,OR cause)10024 DAND draft_and_node_new(struct obstack*obs,OR predecessor,OR cause)
10025 {
10026 DAND draft_and_node= obstack_alloc(obs,sizeof(DAND_Object));
10027 Predecessor_OR_of_DAND(draft_and_node)= predecessor;
10028 Cause_OR_of_DAND(draft_and_node)= cause;
10029 MARPA_ASSERT(cause);
10030 return draft_and_node;
10031 }
10032 
10033 /*:1048*//*1051:*/
10034 #line 9840 "./marpa.w"
10035 
10036 static inline
draft_and_node_add(struct obstack * obs,OR parent,OR predecessor,OR cause)10037 void draft_and_node_add(struct obstack*obs,OR parent,OR predecessor,OR cause)
10038 {
10039 MARPA_ASSERT(Position_of_OR(parent)<=1||predecessor)
10040 const DAND new= draft_and_node_new(obs,predecessor,cause);
10041 Next_DAND_of_DAND(new)= DANDs_of_OR(parent);
10042 DANDs_of_OR(parent)= new;
10043 }
10044 
10045 /*:1051*//*1079:*/
10046 #line 10278 "./marpa.w"
10047 
marpa_and_node_count(struct marpa_r * r)10048 gint marpa_and_node_count(struct marpa_r*r)
10049 {
10050 BOC b= B_of_R(r);
10051 /*1357:*/
10052 #line 13088 "./marpa.w"
10053 const int failure_indicator= -2;
10054 
10055 /*:1357*/
10056 #line 10282 "./marpa.w"
10057 
10058 /*1371:*/
10059 #line 13178 "./marpa.w"
10060 
10061 if(Phase_of_R(r)==error_phase){
10062 R_ERROR(r->t_fatal_error);
10063 return failure_indicator;
10064 }
10065 /*:1371*/
10066 #line 10283 "./marpa.w"
10067 
10068 if(!b){
10069 R_ERROR("no bocage");
10070 return failure_indicator;
10071 }
10072 return AND_Count_of_B(b);
10073 }
10074 
10075 /*:1079*//*1082:*/
10076 #line 10316 "./marpa.w"
10077 
marpa_and_node_parent(struct marpa_r * r,int and_node_id)10078 gint marpa_and_node_parent(struct marpa_r*r,int and_node_id)
10079 {
10080 AND and_node;
10081 /*1357:*/
10082 #line 13088 "./marpa.w"
10083 const int failure_indicator= -2;
10084 
10085 /*:1357*/
10086 #line 10320 "./marpa.w"
10087 
10088 /*1080:*/
10089 #line 10291 "./marpa.w"
10090 {
10091 BOC b= B_of_R(r);
10092 AND and_nodes;
10093 /*1371:*/
10094 #line 13178 "./marpa.w"
10095 
10096 if(Phase_of_R(r)==error_phase){
10097 R_ERROR(r->t_fatal_error);
10098 return failure_indicator;
10099 }
10100 /*:1371*/
10101 #line 10294 "./marpa.w"
10102 
10103 if(!b){
10104 R_ERROR("no bocage");
10105 return failure_indicator;
10106 }
10107 and_nodes= ANDs_of_B(b);
10108 if(!and_nodes){
10109 R_ERROR("no and nodes");
10110 return failure_indicator;
10111 }
10112 if(and_node_id<0){
10113 R_ERROR("bad and node id");
10114 return failure_indicator;
10115 }
10116 if(and_node_id>=AND_Count_of_B(b)){
10117 return-1;
10118 }
10119 and_node= and_nodes+and_node_id;
10120 }
10121 
10122 /*:1080*/
10123 #line 10321 "./marpa.w"
10124 
10125 return ID_of_OR(OR_of_AND(and_node));
10126 }
10127 
10128 /*:1082*//*1084:*/
10129 #line 10327 "./marpa.w"
10130 
marpa_and_node_predecessor(struct marpa_r * r,int and_node_id)10131 gint marpa_and_node_predecessor(struct marpa_r*r,int and_node_id)
10132 {
10133 AND and_node;
10134 /*1357:*/
10135 #line 13088 "./marpa.w"
10136 const int failure_indicator= -2;
10137 
10138 /*:1357*/
10139 #line 10331 "./marpa.w"
10140 
10141 /*1080:*/
10142 #line 10291 "./marpa.w"
10143 {
10144 BOC b= B_of_R(r);
10145 AND and_nodes;
10146 /*1371:*/
10147 #line 13178 "./marpa.w"
10148 
10149 if(Phase_of_R(r)==error_phase){
10150 R_ERROR(r->t_fatal_error);
10151 return failure_indicator;
10152 }
10153 /*:1371*/
10154 #line 10294 "./marpa.w"
10155 
10156 if(!b){
10157 R_ERROR("no bocage");
10158 return failure_indicator;
10159 }
10160 and_nodes= ANDs_of_B(b);
10161 if(!and_nodes){
10162 R_ERROR("no and nodes");
10163 return failure_indicator;
10164 }
10165 if(and_node_id<0){
10166 R_ERROR("bad and node id");
10167 return failure_indicator;
10168 }
10169 if(and_node_id>=AND_Count_of_B(b)){
10170 return-1;
10171 }
10172 and_node= and_nodes+and_node_id;
10173 }
10174 
10175 /*:1080*/
10176 #line 10332 "./marpa.w"
10177 
10178 {
10179 const OR predecessor_or= Predecessor_OR_of_AND(and_node);
10180 const ORID predecessor_or_id=
10181 predecessor_or?ID_of_OR(predecessor_or):-1;
10182 return predecessor_or_id;
10183 }
10184 }
10185 
10186 /*:1084*//*1086:*/
10187 #line 10343 "./marpa.w"
10188 
marpa_and_node_cause(struct marpa_r * r,int and_node_id)10189 gint marpa_and_node_cause(struct marpa_r*r,int and_node_id)
10190 {
10191 AND and_node;
10192 /*1357:*/
10193 #line 13088 "./marpa.w"
10194 const int failure_indicator= -2;
10195 
10196 /*:1357*/
10197 #line 10347 "./marpa.w"
10198 
10199 /*1080:*/
10200 #line 10291 "./marpa.w"
10201 {
10202 BOC b= B_of_R(r);
10203 AND and_nodes;
10204 /*1371:*/
10205 #line 13178 "./marpa.w"
10206 
10207 if(Phase_of_R(r)==error_phase){
10208 R_ERROR(r->t_fatal_error);
10209 return failure_indicator;
10210 }
10211 /*:1371*/
10212 #line 10294 "./marpa.w"
10213 
10214 if(!b){
10215 R_ERROR("no bocage");
10216 return failure_indicator;
10217 }
10218 and_nodes= ANDs_of_B(b);
10219 if(!and_nodes){
10220 R_ERROR("no and nodes");
10221 return failure_indicator;
10222 }
10223 if(and_node_id<0){
10224 R_ERROR("bad and node id");
10225 return failure_indicator;
10226 }
10227 if(and_node_id>=AND_Count_of_B(b)){
10228 return-1;
10229 }
10230 and_node= and_nodes+and_node_id;
10231 }
10232 
10233 /*:1080*/
10234 #line 10348 "./marpa.w"
10235 
10236 {
10237 const OR cause_or= Cause_OR_of_AND(and_node);
10238 const ORID cause_or_id=
10239 OR_is_Token(cause_or)?-1:ID_of_OR(cause_or);
10240 return cause_or_id;
10241 }
10242 }
10243 
10244 /*:1086*//*1088:*/
10245 #line 10359 "./marpa.w"
10246 
marpa_and_node_symbol(struct marpa_r * r,int and_node_id)10247 gint marpa_and_node_symbol(struct marpa_r*r,int and_node_id)
10248 {
10249 AND and_node;
10250 /*1357:*/
10251 #line 13088 "./marpa.w"
10252 const int failure_indicator= -2;
10253 
10254 /*:1357*/
10255 #line 10363 "./marpa.w"
10256 
10257 /*1080:*/
10258 #line 10291 "./marpa.w"
10259 {
10260 BOC b= B_of_R(r);
10261 AND and_nodes;
10262 /*1371:*/
10263 #line 13178 "./marpa.w"
10264 
10265 if(Phase_of_R(r)==error_phase){
10266 R_ERROR(r->t_fatal_error);
10267 return failure_indicator;
10268 }
10269 /*:1371*/
10270 #line 10294 "./marpa.w"
10271 
10272 if(!b){
10273 R_ERROR("no bocage");
10274 return failure_indicator;
10275 }
10276 and_nodes= ANDs_of_B(b);
10277 if(!and_nodes){
10278 R_ERROR("no and nodes");
10279 return failure_indicator;
10280 }
10281 if(and_node_id<0){
10282 R_ERROR("bad and node id");
10283 return failure_indicator;
10284 }
10285 if(and_node_id>=AND_Count_of_B(b)){
10286 return-1;
10287 }
10288 and_node= and_nodes+and_node_id;
10289 }
10290 
10291 /*:1080*/
10292 #line 10364 "./marpa.w"
10293 
10294 {
10295 const OR cause_or= Cause_OR_of_AND(and_node);
10296 const SYMID symbol_id=
10297 OR_is_Token(cause_or)?SYMID_of_OR(cause_or):-1;
10298 return symbol_id;
10299 }
10300 }
10301 
10302 /*:1088*//*1090:*/
10303 #line 10392 "./marpa.w"
10304 
marpa_and_node_token(struct marpa_r * r,Marpa_And_Node_ID and_node_id,gpointer * value_p)10305 Marpa_Symbol_ID marpa_and_node_token(struct marpa_r*r,
10306 Marpa_And_Node_ID and_node_id,gpointer*value_p)
10307 {
10308 AND and_node;
10309 /*1357:*/
10310 #line 13088 "./marpa.w"
10311 const int failure_indicator= -2;
10312 
10313 /*:1357*/
10314 #line 10397 "./marpa.w"
10315 
10316 /*1080:*/
10317 #line 10291 "./marpa.w"
10318 {
10319 BOC b= B_of_R(r);
10320 AND and_nodes;
10321 /*1371:*/
10322 #line 13178 "./marpa.w"
10323 
10324 if(Phase_of_R(r)==error_phase){
10325 R_ERROR(r->t_fatal_error);
10326 return failure_indicator;
10327 }
10328 /*:1371*/
10329 #line 10294 "./marpa.w"
10330 
10331 if(!b){
10332 R_ERROR("no bocage");
10333 return failure_indicator;
10334 }
10335 and_nodes= ANDs_of_B(b);
10336 if(!and_nodes){
10337 R_ERROR("no and nodes");
10338 return failure_indicator;
10339 }
10340 if(and_node_id<0){
10341 R_ERROR("bad and node id");
10342 return failure_indicator;
10343 }
10344 if(and_node_id>=AND_Count_of_B(b)){
10345 return-1;
10346 }
10347 and_node= and_nodes+and_node_id;
10348 }
10349 
10350 /*:1080*/
10351 #line 10398 "./marpa.w"
10352 
10353 return and_node_token(and_node,value_p);
10354 }
10355 /*:1090*//*1092:*/
10356 #line 10403 "./marpa.w"
10357 
and_node_token(AND and_node,gpointer * value_p)10358 SYMID and_node_token(AND and_node,gpointer*value_p)
10359 {
10360 const OR cause_or= Cause_OR_of_AND(and_node);
10361 if(OR_is_Token(cause_or))
10362 {
10363 const TOK token= TOK_of_OR(cause_or);
10364 if(value_p)
10365 *value_p= Value_of_TOK(token);
10366 return SYMID_of_TOK(token);
10367 }
10368 return-1;
10369 }
10370 
10371 /*:1092*//*1104:*/
10372 #line 10467 "./marpa.w"
10373 
marpa_bocage_new(struct marpa_r * r,Marpa_Rule_ID rule_id,Marpa_Earley_Set_ID ordinal)10374 gint marpa_bocage_new(struct marpa_r*r,Marpa_Rule_ID rule_id,Marpa_Earley_Set_ID ordinal){
10375 /*1357:*/
10376 #line 13088 "./marpa.w"
10377 const int failure_indicator= -2;
10378 
10379 /*:1357*/
10380 #line 10469 "./marpa.w"
10381 
10382 ORID top_or_node_id= failure_indicator;
10383 const gint no_parse= -1;
10384 /*1105:*/
10385 #line 10497 "./marpa.w"
10386 
10387 const GRAMMAR_Const g= G_of_R(r);
10388 const gint rule_count_of_g= RULE_Count_of_G(g);
10389 const gint symbol_count_of_g= SYM_Count_of_G(g);
10390 BOC b;
10391 ES end_of_parse_es;
10392 RULE completed_start_rule;
10393 EIM start_eim= NULL;
10394 AIM start_aim= NULL;
10395 AEX start_aex= -1;
10396 struct obstack bocage_setup_obs;
10397 gint total_earley_items_in_parse;
10398 gint or_node_estimate= 0;
10399 const gint earley_set_count_of_r= ES_Count_of_R(r);
10400 
10401 /*:1105*//*1108:*/
10402 #line 10520 "./marpa.w"
10403 
10404 struct s_bocage_setup_per_es*per_es_data= NULL;
10405 
10406 /*:1108*/
10407 #line 10472 "./marpa.w"
10408 
10409 r_update_earley_sets(r);
10410 /*1109:*/
10411 #line 10524 "./marpa.w"
10412 
10413 {
10414 EARLEME end_of_parse_earleme;
10415 /*1371:*/
10416 #line 13178 "./marpa.w"
10417 
10418 if(Phase_of_R(r)==error_phase){
10419 R_ERROR(r->t_fatal_error);
10420 return failure_indicator;
10421 }
10422 /*:1371*/
10423 #line 10527 "./marpa.w"
10424 
10425 if(B_of_R(r)){
10426 R_ERROR("bocage in use");
10427 return failure_indicator;
10428 }
10429 switch(Phase_of_R(r))
10430 {
10431 default:
10432 R_ERROR("recce not evaluation-ready");
10433 return failure_indicator;
10434 case input_phase:
10435 case evaluation_phase:
10436 break;
10437 }
10438 
10439 MARPA_OFF_DEBUG2("ordinal=%d",ordinal);
10440 if(ordinal==-1)
10441 {
10442 end_of_parse_es= Current_ES_of_R(r);
10443 }
10444 else
10445 {
10446 if(!ES_Ord_is_Valid(r,ordinal))
10447 {
10448 R_ERROR("invalid es ordinal");
10449 return failure_indicator;
10450 }
10451 end_of_parse_es= ES_of_R_by_Ord(r,ordinal);
10452 }
10453 
10454 if(!end_of_parse_es)
10455 return no_parse;
10456 ordinal= Ord_of_ES(end_of_parse_es);
10457 end_of_parse_earleme= Earleme_of_ES(end_of_parse_es);
10458 if(rule_id==-1){
10459 completed_start_rule=
10460 end_of_parse_earleme?g->t_proper_start_rule:g->t_null_start_rule;
10461 if(!completed_start_rule)
10462 return no_parse;
10463 }else{
10464 if(!RULEID_of_G_is_Valid(g,rule_id))
10465 {
10466 R_ERROR("invalid rule id");
10467 return failure_indicator;
10468 }
10469 completed_start_rule= RULE_by_ID(g,rule_id);
10470 }
10471 MARPA_OFF_DEBUG2("ordinal=%d",ordinal);
10472 }
10473 
10474 /*:1109*/
10475 #line 10475 "./marpa.w"
10476 
10477 b= B_of_R(r)= g_slice_new(BOC_Object);
10478 MARPA_DEBUG3("%s new bocage B_of_R=%p",G_STRLOC,B_of_R(r));
10479 /*1025:*/
10480 #line 9426 "./marpa.w"
10481 
10482 ORs_of_B(b)= NULL;
10483 OR_Count_of_B(b)= 0;
10484 ANDs_of_B(b)= NULL;
10485 AND_Count_of_B(b)= 0;
10486 
10487 /*:1025*//*1100:*/
10488 #line 10444 "./marpa.w"
10489 
10490 b->is_obstack_initialized= 1;
10491 obstack_init(&OBS_of_B(b));
10492 /*:1100*//*1166:*/
10493 #line 11243 "./marpa.w"
10494 
10495 MARPA_DEBUG3("%s rank_safe where b=%p",G_STRLOC,b);
10496 rank_safe(RANK_of_B(b));
10497 /*:1166*/
10498 #line 10478 "./marpa.w"
10499 
10500 /*1110:*/
10501 #line 10577 "./marpa.w"
10502 
10503 {
10504 if(ordinal==0){
10505 gint rule_length= Length_of_RULE(completed_start_rule);
10506 OR*or_nodes= ORs_of_B(b)= g_new(OR,1);
10507 AND and_nodes= ANDs_of_B(b)= g_new(AND_Object,1);
10508 OR or_node= or_nodes[0]= (OR)obstack_alloc(&OBS_of_B(b),sizeof(OR_Object));
10509 ORID null_or_node_id= 0;
10510 Top_ORID_of_B(b)= null_or_node_id;
10511 
10512 OR_Count_of_B(b)= 1;
10513 AND_Count_of_B(b)= 1;
10514 
10515 RULE_of_OR(or_node)= completed_start_rule;
10516 Position_of_OR(or_node)= rule_length;
10517 Origin_Ord_of_OR(or_node)= 0;
10518 ID_of_OR(or_node)= null_or_node_id;
10519 ES_Ord_of_OR(or_node)= 0;
10520 First_ANDID_of_OR(or_node)= 0;
10521 AND_Count_of_OR(or_node)= 1;
10522 
10523 OR_of_AND(and_nodes)= or_node;
10524 Predecessor_OR_of_AND(and_nodes)= NULL;
10525 Cause_OR_of_AND(and_nodes)=
10526 (OR)TOK_by_ID_of_R(r,RHS_ID_of_RULE(completed_start_rule,rule_length-1));
10527 
10528 return null_or_node_id;
10529 }
10530 }
10531 
10532 /*:1110*/
10533 #line 10479 "./marpa.w"
10534 
10535 /*1114:*/
10536 #line 10660 "./marpa.w"
10537 
10538 {
10539 gint eim_ix;
10540 EIM*const earley_items= EIMs_of_ES(end_of_parse_es);
10541 const RULEID sought_rule_id= ID_of_RULE(completed_start_rule);
10542 const gint earley_item_count= EIM_Count_of_ES(end_of_parse_es);
10543 for(eim_ix= 0;eim_ix<earley_item_count;eim_ix++){
10544 const EIM earley_item= earley_items[eim_ix];
10545 const AHFA ahfa_state= AHFA_of_EIM(earley_item);
10546 if(Origin_Earleme_of_EIM(earley_item)> 0)continue;
10547 if(!AHFA_is_Predicted(ahfa_state)){
10548 gint aex;
10549 AIM*const ahfa_items= AIMs_of_AHFA(ahfa_state);
10550 const gint ahfa_item_count= AIM_Count_of_AHFA(ahfa_state);
10551 for(aex= 0;aex<ahfa_item_count;aex++){
10552 const AIM ahfa_item= ahfa_items[aex];
10553 if(RULEID_of_AIM(ahfa_item)==sought_rule_id){
10554 start_aim= ahfa_item;
10555 start_eim= earley_item;
10556 start_aex= aex;
10557 break;
10558 }
10559 }
10560 }
10561 if(start_eim)break;
10562 }
10563 }
10564 
10565 /*:1114*/
10566 #line 10480 "./marpa.w"
10567 
10568 if(!start_eim)goto SOFT_ERROR;
10569 Phase_of_R(r)= evaluation_phase;
10570 obstack_init(&bocage_setup_obs);
10571 /*1111:*/
10572 #line 10608 "./marpa.w"
10573 
10574 {
10575 guint ix;
10576 guint earley_set_count= ES_Count_of_R(r);
10577 total_earley_items_in_parse= 0;
10578 per_es_data=
10579 obstack_alloc(&bocage_setup_obs,
10580 sizeof(struct s_bocage_setup_per_es)*earley_set_count);
10581 for(ix= 0;ix<earley_set_count;ix++)
10582 {
10583 const ES_Const earley_set= ES_of_R_by_Ord(r,ix);
10584 const guint item_count= EIM_Count_of_ES(earley_set);
10585 total_earley_items_in_parse+= item_count;
10586 {
10587 struct s_bocage_setup_per_es*per_es= per_es_data+ix;
10588 OR**const per_eim_eixes= per_es->t_aexes_by_item=
10589 obstack_alloc(&bocage_setup_obs,sizeof(OR*)*item_count);
10590 guint item_ordinal;
10591 per_es->t_or_psl= NULL;
10592 per_es->t_and_psl= NULL;
10593 for(item_ordinal= 0;item_ordinal<item_count;item_ordinal++)
10594 {
10595 per_eim_eixes[item_ordinal]= NULL;
10596 }
10597 }
10598 }
10599 }
10600 
10601 /*:1111*/
10602 #line 10484 "./marpa.w"
10603 
10604 /*998:*/
10605 #line 8993 "./marpa.w"
10606 
10607 {
10608 UR_Const ur_node;
10609 const URS ur_node_stack= URS_of_R(r);
10610 ur_node_stack_reset(ur_node_stack);
10611 {
10612 const EIM ur_earley_item= start_eim;
10613 const AIM ur_aim= start_aim;
10614 const AEX ur_aex= start_aex;
10615 /*1000:*/
10616 #line 9061 "./marpa.w"
10617 {
10618 if(!psia_test_and_set
10619 (&bocage_setup_obs,per_es_data,ur_earley_item,ur_aex))
10620 {
10621 ur_node_push(ur_node_stack,ur_earley_item,ur_aex);
10622 or_node_estimate+= 1+Null_Count_of_AIM(ur_aim);
10623 }
10624 }
10625 
10626 /*:1000*/
10627 #line 9002 "./marpa.w"
10628 
10629 }
10630 while((ur_node= ur_node_pop(ur_node_stack)))
10631 {
10632 const EIM_Const parent_earley_item= EIM_of_UR(ur_node);
10633 const AEX parent_aex= AEX_of_UR(ur_node);
10634 const AIM parent_aim= AIM_of_EIM_by_AEX(parent_earley_item,parent_aex);
10635 MARPA_ASSERT(parent_aim>=AIM_by_ID(1))
10636 const AIM predecessor_aim= parent_aim-1;
10637 
10638 
10639 guint source_type= Source_Type_of_EIM(parent_earley_item);
10640 MARPA_ASSERT(!EIM_is_Predicted(parent_earley_item))
10641 /*1003:*/
10642 #line 9108 "./marpa.w"
10643 
10644 {
10645 SRCL source_link= NULL;
10646 EIM predecessor_earley_item= NULL;
10647 switch(source_type)
10648 {
10649 case SOURCE_IS_TOKEN:
10650 predecessor_earley_item= Predecessor_of_EIM(parent_earley_item);
10651 break;
10652 case SOURCE_IS_AMBIGUOUS:
10653 source_link= First_Token_Link_of_EIM(parent_earley_item);
10654 if(source_link)
10655 {
10656 predecessor_earley_item= Predecessor_of_SRCL(source_link);
10657 source_link= Next_SRCL_of_SRCL(source_link);
10658 }
10659 }
10660 for(;;)
10661 {
10662 if(predecessor_earley_item)
10663 {
10664 if(EIM_is_Predicted(predecessor_earley_item)){
10665 Set_boolean_in_PSIA_for_initial_nulls(predecessor_earley_item,predecessor_aim);
10666 }else{
10667 const EIM ur_earley_item= predecessor_earley_item;
10668 const AEX ur_aex=
10669 AEX_of_EIM_by_AIM(predecessor_earley_item,predecessor_aim);
10670 const AIM ur_aim= predecessor_aim;
10671 /*1000:*/
10672 #line 9061 "./marpa.w"
10673 {
10674 if(!psia_test_and_set
10675 (&bocage_setup_obs,per_es_data,ur_earley_item,ur_aex))
10676 {
10677 ur_node_push(ur_node_stack,ur_earley_item,ur_aex);
10678 or_node_estimate+= 1+Null_Count_of_AIM(ur_aim);
10679 }
10680 }
10681 
10682 /*:1000*/
10683 #line 9136 "./marpa.w"
10684 
10685 }
10686 }
10687 if(!source_link)
10688 break;
10689 predecessor_earley_item= Predecessor_of_SRCL(source_link);
10690 source_link= Next_SRCL_of_SRCL(source_link);
10691 }
10692 }
10693 
10694 /*:1003*/
10695 #line 9015 "./marpa.w"
10696 
10697 /*1005:*/
10698 #line 9163 "./marpa.w"
10699 
10700 {
10701 SRCL source_link= NULL;
10702 EIM predecessor_earley_item= NULL;
10703 EIM cause_earley_item= NULL;
10704 const SYMID transition_symbol_id= Postdot_SYMID_of_AIM(predecessor_aim);
10705 switch(source_type)
10706 {
10707 case SOURCE_IS_COMPLETION:
10708 predecessor_earley_item= Predecessor_of_EIM(parent_earley_item);
10709 cause_earley_item= Cause_of_EIM(parent_earley_item);
10710 break;
10711 case SOURCE_IS_AMBIGUOUS:
10712 source_link= First_Completion_Link_of_EIM(parent_earley_item);
10713 if(source_link)
10714 {
10715 predecessor_earley_item= Predecessor_of_SRCL(source_link);
10716 cause_earley_item= Cause_of_SRCL(source_link);
10717 source_link= Next_SRCL_of_SRCL(source_link);
10718 }
10719 break;
10720 }
10721 while(cause_earley_item)
10722 {
10723 if(predecessor_earley_item)
10724 {
10725 if(EIM_is_Predicted(predecessor_earley_item))
10726 {
10727 Set_boolean_in_PSIA_for_initial_nulls(predecessor_earley_item,predecessor_aim);
10728 }
10729 else
10730 {
10731 const EIM ur_earley_item= predecessor_earley_item;
10732 const AEX ur_aex=
10733 AEX_of_EIM_by_AIM(predecessor_earley_item,predecessor_aim);
10734 const AIM ur_aim= predecessor_aim;
10735 /*1000:*/
10736 #line 9061 "./marpa.w"
10737 {
10738 if(!psia_test_and_set
10739 (&bocage_setup_obs,per_es_data,ur_earley_item,ur_aex))
10740 {
10741 ur_node_push(ur_node_stack,ur_earley_item,ur_aex);
10742 or_node_estimate+= 1+Null_Count_of_AIM(ur_aim);
10743 }
10744 }
10745 
10746 /*:1000*/
10747 #line 9199 "./marpa.w"
10748 
10749 }
10750 }
10751 {
10752 const TRANS cause_completion_data=
10753 TRANS_of_EIM_by_SYMID(cause_earley_item,transition_symbol_id);
10754 const gint aex_count= Completion_Count_of_TRANS(cause_completion_data);
10755 const AEX*const aexes= AEXs_of_TRANS(cause_completion_data);
10756 const EIM ur_earley_item= cause_earley_item;
10757 gint ix;
10758 for(ix= 0;ix<aex_count;ix++){
10759 const AEX ur_aex= aexes[ix];
10760 const AIM ur_aim= AIM_of_EIM_by_AEX(ur_earley_item,ur_aex);
10761 /*1000:*/
10762 #line 9061 "./marpa.w"
10763 {
10764 if(!psia_test_and_set
10765 (&bocage_setup_obs,per_es_data,ur_earley_item,ur_aex))
10766 {
10767 ur_node_push(ur_node_stack,ur_earley_item,ur_aex);
10768 or_node_estimate+= 1+Null_Count_of_AIM(ur_aim);
10769 }
10770 }
10771 
10772 /*:1000*/
10773 #line 9212 "./marpa.w"
10774 
10775 }
10776 }
10777 if(!source_link)break;
10778 predecessor_earley_item= Predecessor_of_SRCL(source_link);
10779 cause_earley_item= Cause_of_SRCL(source_link);
10780 source_link= Next_SRCL_of_SRCL(source_link);
10781 }
10782 }
10783 
10784 /*:1005*/
10785 #line 9016 "./marpa.w"
10786 
10787 /*1006:*/
10788 #line 9222 "./marpa.w"
10789 
10790 {
10791 SRCL source_link= NULL;
10792 EIM cause_earley_item= NULL;
10793 LIM leo_predecessor= NULL;
10794 switch(source_type)
10795 {
10796 case SOURCE_IS_LEO:
10797 leo_predecessor= Predecessor_of_EIM(parent_earley_item);
10798 cause_earley_item= Cause_of_EIM(parent_earley_item);
10799 break;
10800 case SOURCE_IS_AMBIGUOUS:
10801 source_link= First_Leo_SRCL_of_EIM(parent_earley_item);
10802 if(source_link)
10803 {
10804 leo_predecessor= Predecessor_of_SRCL(source_link);
10805 cause_earley_item= Cause_of_SRCL(source_link);
10806 source_link= Next_SRCL_of_SRCL(source_link);
10807 }
10808 break;
10809 }
10810 while(cause_earley_item)
10811 {
10812 const SYMID transition_symbol_id= Postdot_SYMID_of_LIM(leo_predecessor);
10813 const TRANS cause_completion_data=
10814 TRANS_of_EIM_by_SYMID(cause_earley_item,transition_symbol_id);
10815 const gint aex_count= Completion_Count_of_TRANS(cause_completion_data);
10816 const AEX*const aexes= AEXs_of_TRANS(cause_completion_data);
10817 gint ix;
10818 EIM ur_earley_item= cause_earley_item;
10819 for(ix= 0;ix<aex_count;ix++){
10820 const AEX ur_aex= aexes[ix];
10821 const AIM ur_aim= AIM_of_EIM_by_AEX(ur_earley_item,ur_aex);
10822 /*1000:*/
10823 #line 9061 "./marpa.w"
10824 {
10825 if(!psia_test_and_set
10826 (&bocage_setup_obs,per_es_data,ur_earley_item,ur_aex))
10827 {
10828 ur_node_push(ur_node_stack,ur_earley_item,ur_aex);
10829 or_node_estimate+= 1+Null_Count_of_AIM(ur_aim);
10830 }
10831 }
10832 
10833 /*:1000*/
10834 #line 9255 "./marpa.w"
10835 
10836 }
10837 while(leo_predecessor){
10838 SYMID postdot= Postdot_SYMID_of_LIM(leo_predecessor);
10839 EIM leo_base= Base_EIM_of_LIM(leo_predecessor);
10840 TRANS transition= TRANS_of_EIM_by_SYMID(leo_base,postdot);
10841 const AEX ur_aex= Leo_Base_AEX_of_TRANS(transition);
10842 const AIM ur_aim= AIM_of_EIM_by_AEX(leo_base,ur_aex);
10843 ur_earley_item= leo_base;
10844 
10845 
10846 or_node_estimate+= 1+Null_Count_of_AIM(ur_aim+1);
10847 if(EIM_is_Predicted(ur_earley_item))
10848 {
10849 Set_boolean_in_PSIA_for_initial_nulls(ur_earley_item,ur_aim);
10850 }else{
10851 /*1000:*/
10852 #line 9061 "./marpa.w"
10853 {
10854 if(!psia_test_and_set
10855 (&bocage_setup_obs,per_es_data,ur_earley_item,ur_aex))
10856 {
10857 ur_node_push(ur_node_stack,ur_earley_item,ur_aex);
10858 or_node_estimate+= 1+Null_Count_of_AIM(ur_aim);
10859 }
10860 }
10861 
10862 /*:1000*/
10863 #line 9271 "./marpa.w"
10864 
10865 }
10866 leo_predecessor= Predecessor_LIM_of_LIM(leo_predecessor);
10867 }
10868 if(!source_link)break;
10869 leo_predecessor= Predecessor_of_SRCL(source_link);
10870 cause_earley_item= Cause_of_SRCL(source_link);
10871 source_link= Next_SRCL_of_SRCL(source_link);
10872 }
10873 }
10874 
10875 /*:1006*/
10876 #line 9017 "./marpa.w"
10877 
10878 }
10879 /*999:*/
10880 #line 9029 "./marpa.w"
10881 {
10882 const ES first_earley_set= ES_of_R_by_Ord(r,0);
10883 OR**const nodes_by_item= per_es_data[0].t_aexes_by_item;
10884 const EIM*const eims_of_es= EIMs_of_ES(first_earley_set);
10885 const gint item_count= EIM_Count_of_ES(first_earley_set);
10886 gint item_ordinal;
10887 for(item_ordinal= 0;item_ordinal<item_count;item_ordinal++)
10888 {
10889 OR*const nodes_by_aex= nodes_by_item[item_ordinal];
10890 if(nodes_by_aex){
10891 const EIM earley_item= eims_of_es[item_ordinal];
10892 const Marpa_AHFA_State_ID ahfa_id= AHFAID_of_EIM(earley_item);
10893 
10894 if(ahfa_id)continue;
10895 {
10896 const gint aim_count_of_item= AIM_Count_of_EIM(earley_item);
10897 AEX aex;
10898 for(aex= 0;aex<aim_count_of_item;aex++){
10899 AIM ahfa_item= AIM_of_EIM_by_AEX(earley_item,aex);
10900 if(Position_of_AIM(ahfa_item)==0){
10901 
10902 
10903 nodes_by_aex[aex]= NULL;
10904 goto FINISHED_UNSET;
10905 }
10906 }
10907 }
10908 }
10909 }
10910 FINISHED_UNSET:;
10911 }
10912 
10913 /*:999*/
10914 #line 9019 "./marpa.w"
10915 
10916 }
10917 
10918 /*:998*/
10919 #line 10485 "./marpa.w"
10920 
10921 /*1027:*/
10922 #line 9449 "./marpa.w"
10923 
10924 {
10925 PSAR_Object or_per_es_arena;
10926 const PSAR or_psar= &or_per_es_arena;
10927 gint work_earley_set_ordinal;
10928 OR last_or_node= NULL;
10929 ORs_of_B(b)= g_new(OR,or_node_estimate);
10930 psar_init(or_psar,SYMI_Count_of_G(g));
10931 for(work_earley_set_ordinal= 0;
10932 work_earley_set_ordinal<earley_set_count_of_r;
10933 work_earley_set_ordinal++)
10934 {
10935 const ES_Const earley_set= ES_of_R_by_Ord(r,work_earley_set_ordinal);
10936 EIM*const eims_of_es= EIMs_of_ES(earley_set);
10937 const gint item_count= EIM_Count_of_ES(earley_set);
10938 PSL this_earley_set_psl;
10939 OR**const nodes_by_item= per_es_data[work_earley_set_ordinal].t_aexes_by_item;
10940 psar_dealloc(or_psar);
10941 #define PSL_ES_ORD work_earley_set_ordinal
10942 #define CLAIMED_PSL this_earley_set_psl
10943 /*1338:*/
10944 #line 12918 "./marpa.w"
10945 
10946 {
10947 PSL*psl_owner= &per_es_data[PSL_ES_ORD].t_or_psl;
10948 if(!*psl_owner)
10949 psl_claim(psl_owner,or_psar);
10950 (CLAIMED_PSL)= *psl_owner;
10951 }
10952 #undef PSL_ES_ORD
10953 #undef CLAIMED_PSL
10954 
10955 /*:1338*/
10956 #line 9469 "./marpa.w"
10957 
10958 /*1028:*/
10959 #line 9477 "./marpa.w"
10960 
10961 {
10962 gint item_ordinal;
10963 for(item_ordinal= 0;item_ordinal<item_count;item_ordinal++)
10964 {
10965 OR*const work_nodes_by_aex= nodes_by_item[item_ordinal];
10966 if(work_nodes_by_aex){
10967 const EIM work_earley_item= eims_of_es[item_ordinal];
10968 const gint work_ahfa_item_count= AIM_Count_of_EIM(work_earley_item);
10969 AEX work_aex;
10970 const gint work_origin_ordinal= Ord_of_ES(Origin_of_EIM(work_earley_item));
10971 for(work_aex= 0;work_aex<work_ahfa_item_count;work_aex++){
10972 if(!work_nodes_by_aex[work_aex])continue;
10973 /*1029:*/
10974 #line 9497 "./marpa.w"
10975 
10976 {
10977 AIM ahfa_item= AIM_of_EIM_by_AEX(work_earley_item,work_aex);
10978 SYMI ahfa_item_symbol_instance;
10979 OR psia_or_node= NULL;
10980 ahfa_item_symbol_instance= SYMI_of_AIM(ahfa_item);
10981 {
10982 PSL or_psl;
10983 #define PSL_ES_ORD work_origin_ordinal
10984 #define CLAIMED_PSL or_psl
10985 /*1338:*/
10986 #line 12918 "./marpa.w"
10987 
10988 {
10989 PSL*psl_owner= &per_es_data[PSL_ES_ORD].t_or_psl;
10990 if(!*psl_owner)
10991 psl_claim(psl_owner,or_psar);
10992 (CLAIMED_PSL)= *psl_owner;
10993 }
10994 #undef PSL_ES_ORD
10995 #undef CLAIMED_PSL
10996 
10997 /*:1338*/
10998 #line 9507 "./marpa.w"
10999 
11000 /*1031:*/
11001 #line 9523 "./marpa.w"
11002 
11003 {
11004 MARPA_OFF_DEBUG3("%s ahfa_item_symbol_instance = %d",G_STRLOC,ahfa_item_symbol_instance);
11005 if(ahfa_item_symbol_instance>=0)
11006 {
11007 OR or_node;
11008 MARPA_ASSERT(ahfa_item_symbol_instance<SYMI_Count_of_G(g))
11009 or_node= PSL_Datum(or_psl,ahfa_item_symbol_instance);
11010 if(!or_node||ES_Ord_of_OR(or_node)!=work_earley_set_ordinal)
11011 {
11012 const RULE rule= RULE_of_AIM(ahfa_item);
11013 /*1032:*/
11014 #line 9553 "./marpa.w"
11015 
11016 {
11017 const gint or_node_id= OR_Count_of_B(b)++;
11018 OR*or_nodes_of_b= ORs_of_B(b);
11019 last_or_node= (OR)obstack_alloc(&OBS_of_B(b),sizeof(OR_Object));
11020 ID_of_OR(last_or_node)= or_node_id;
11021 if(G_UNLIKELY(or_node_id>=or_node_estimate))
11022 {
11023 MARPA_ASSERT(0);
11024 or_node_estimate*= 2;
11025 ORs_of_B(b)= or_nodes_of_b=
11026 g_renew(OR,or_nodes_of_b,or_node_estimate);
11027 }
11028 or_nodes_of_b[or_node_id]= last_or_node;
11029 }
11030 
11031 
11032 /*:1032*/
11033 #line 9534 "./marpa.w"
11034 
11035 or_node= last_or_node;
11036 PSL_Datum(or_psl,ahfa_item_symbol_instance)= last_or_node;
11037 Origin_Ord_of_OR(or_node)= Origin_Ord_of_EIM(work_earley_item);
11038 ES_Ord_of_OR(or_node)= work_earley_set_ordinal;
11039 RULE_of_OR(or_node)= rule;
11040 Position_of_OR(or_node)=
11041 ahfa_item_symbol_instance-SYMI_of_RULE(rule)+1;
11042 DANDs_of_OR(or_node)= NULL;
11043 }
11044 psia_or_node= or_node;
11045 }
11046 }
11047 
11048 /*:1031*/
11049 #line 9508 "./marpa.w"
11050 
11051 /*1034:*/
11052 #line 9578 "./marpa.w"
11053 
11054 {
11055 const gint null_count= Null_Count_of_AIM(ahfa_item);
11056 if(null_count> 0)
11057 {
11058 const RULE rule= RULE_of_AIM(ahfa_item);
11059 const gint symbol_instance_of_rule= SYMI_of_RULE(rule);
11060 const gint first_null_symbol_instance=
11061 ahfa_item_symbol_instance<0?symbol_instance_of_rule:ahfa_item_symbol_instance+1;
11062 gint i;
11063 for(i= 0;i<null_count;i++)
11064 {
11065 const gint symbol_instance= first_null_symbol_instance+i;
11066 OR or_node= PSL_Datum(or_psl,symbol_instance);
11067 MARPA_OFF_DEBUG3("adding nulling token or-node EIM = %s aex=%d",
11068 eim_tag(work_earley_item),work_aex);
11069 if(!or_node||ES_Ord_of_OR(or_node)!=work_earley_set_ordinal){
11070 DAND draft_and_node;
11071 const gint rhs_ix= symbol_instance-SYMI_of_RULE(rule);
11072 const OR predecessor= rhs_ix?last_or_node:NULL;
11073 const OR cause= (OR)TOK_by_ID_of_R(r,RHS_ID_of_RULE(rule,rhs_ix));
11074 /*1032:*/
11075 #line 9553 "./marpa.w"
11076 
11077 {
11078 const gint or_node_id= OR_Count_of_B(b)++;
11079 OR*or_nodes_of_b= ORs_of_B(b);
11080 last_or_node= (OR)obstack_alloc(&OBS_of_B(b),sizeof(OR_Object));
11081 ID_of_OR(last_or_node)= or_node_id;
11082 if(G_UNLIKELY(or_node_id>=or_node_estimate))
11083 {
11084 MARPA_ASSERT(0);
11085 or_node_estimate*= 2;
11086 ORs_of_B(b)= or_nodes_of_b=
11087 g_renew(OR,or_nodes_of_b,or_node_estimate);
11088 }
11089 or_nodes_of_b[or_node_id]= last_or_node;
11090 }
11091 
11092 
11093 /*:1032*/
11094 #line 9599 "./marpa.w"
11095 
11096 or_node= PSL_Datum(or_psl,symbol_instance)= last_or_node;
11097 Origin_Ord_of_OR(or_node)= work_origin_ordinal;
11098 ES_Ord_of_OR(or_node)= work_earley_set_ordinal;
11099 RULE_of_OR(or_node)= rule;
11100 MARPA_OFF_DEBUG3("Added rule %p to or-node %p",RULE_of_OR(or_node),or_node);
11101 Position_of_OR(or_node)= rhs_ix+1;
11102 MARPA_ASSERT(Position_of_OR(or_node)<=1||predecessor);
11103 draft_and_node= DANDs_of_OR(or_node)=
11104 draft_and_node_new(&bocage_setup_obs,predecessor,
11105 cause);
11106 MARPA_OFF_DEBUG3("or = %p, setting DAND = %p",or_node,DANDs_of_OR(or_node));
11107 Next_DAND_of_DAND(draft_and_node)= NULL;
11108 }
11109 psia_or_node= or_node;
11110 }
11111 }
11112 }
11113 
11114 /*:1034*/
11115 #line 9509 "./marpa.w"
11116 
11117 }
11118 
11119 
11120 MARPA_ASSERT(psia_or_node)
11121 work_nodes_by_aex[work_aex]= psia_or_node;
11122 /*1035:*/
11123 #line 9619 "./marpa.w"
11124 {
11125 SRCL source_link= NULL;
11126 EIM cause_earley_item= NULL;
11127 LIM leo_predecessor= NULL;
11128 switch(Source_Type_of_EIM(work_earley_item))
11129 {
11130 case SOURCE_IS_LEO:
11131 leo_predecessor= Predecessor_of_EIM(work_earley_item);
11132 cause_earley_item= Cause_of_EIM(work_earley_item);
11133 break;
11134 case SOURCE_IS_AMBIGUOUS:
11135 source_link= First_Leo_SRCL_of_EIM(work_earley_item);
11136 if(source_link)
11137 {
11138 leo_predecessor= Predecessor_of_SRCL(source_link);
11139 cause_earley_item= Cause_of_SRCL(source_link);
11140 source_link= Next_SRCL_of_SRCL(source_link);
11141 }
11142 break;
11143 }
11144 if(leo_predecessor){
11145 for(;;){
11146 /*1037:*/
11147 #line 9659 "./marpa.w"
11148 
11149 {
11150 LIM this_leo_item= leo_predecessor;
11151 LIM previous_leo_item= this_leo_item;
11152 while((this_leo_item= Predecessor_LIM_of_LIM(this_leo_item)))
11153 {
11154 const gint ordinal_of_set_of_this_leo_item= Ord_of_ES(ES_of_LIM(this_leo_item));
11155 const AIM path_ahfa_item= Path_AIM_of_LIM(previous_leo_item);
11156 const RULE path_rule= RULE_of_AIM(path_ahfa_item);
11157 const gint symbol_instance_of_path_ahfa_item= SYMI_of_AIM(path_ahfa_item);
11158 /*1042:*/
11159 #line 9704 "./marpa.w"
11160 
11161 {
11162 {
11163 OR or_node;
11164 PSL leo_psl;
11165 #define PSL_ES_ORD ordinal_of_set_of_this_leo_item
11166 #define CLAIMED_PSL leo_psl
11167 /*1338:*/
11168 #line 12918 "./marpa.w"
11169 
11170 {
11171 PSL*psl_owner= &per_es_data[PSL_ES_ORD].t_or_psl;
11172 if(!*psl_owner)
11173 psl_claim(psl_owner,or_psar);
11174 (CLAIMED_PSL)= *psl_owner;
11175 }
11176 #undef PSL_ES_ORD
11177 #undef CLAIMED_PSL
11178 
11179 /*:1338*/
11180 #line 9711 "./marpa.w"
11181 
11182 or_node= PSL_Datum(leo_psl,symbol_instance_of_path_ahfa_item);
11183 if(!or_node||ES_Ord_of_OR(or_node)!=work_earley_set_ordinal)
11184 {
11185 /*1032:*/
11186 #line 9553 "./marpa.w"
11187 
11188 {
11189 const gint or_node_id= OR_Count_of_B(b)++;
11190 OR*or_nodes_of_b= ORs_of_B(b);
11191 last_or_node= (OR)obstack_alloc(&OBS_of_B(b),sizeof(OR_Object));
11192 ID_of_OR(last_or_node)= or_node_id;
11193 if(G_UNLIKELY(or_node_id>=or_node_estimate))
11194 {
11195 MARPA_ASSERT(0);
11196 or_node_estimate*= 2;
11197 ORs_of_B(b)= or_nodes_of_b=
11198 g_renew(OR,or_nodes_of_b,or_node_estimate);
11199 }
11200 or_nodes_of_b[or_node_id]= last_or_node;
11201 }
11202 
11203 
11204 /*:1032*/
11205 #line 9715 "./marpa.w"
11206 
11207 PSL_Datum(leo_psl,symbol_instance_of_path_ahfa_item)= or_node= last_or_node;
11208 Origin_Ord_of_OR(or_node)= ordinal_of_set_of_this_leo_item;
11209 ES_Ord_of_OR(or_node)= work_earley_set_ordinal;
11210 RULE_of_OR(or_node)= path_rule;
11211 Position_of_OR(or_node)=
11212 symbol_instance_of_path_ahfa_item-SYMI_of_RULE(path_rule)+1;
11213 MARPA_OFF_DEBUG3("Created or-node %s at %s",or_tag(or_node),G_STRLOC);
11214 DANDs_of_OR(or_node)= NULL;
11215 MARPA_OFF_DEBUG3("or = %p, setting DAND = %p",or_node,DANDs_of_OR(or_node));
11216 }
11217 }
11218 }
11219 
11220 /*:1042*/
11221 #line 9669 "./marpa.w"
11222 
11223 /*1043:*/
11224 #line 9733 "./marpa.w"
11225 
11226 {
11227 gint i;
11228 const gint null_count= Null_Count_of_AIM(path_ahfa_item);
11229 for(i= 1;i<=null_count;i++)
11230 {
11231 const gint symbol_instance= symbol_instance_of_path_ahfa_item+i;
11232 OR or_node= PSL_Datum(this_earley_set_psl,symbol_instance);
11233 MARPA_ASSERT(symbol_instance<SYMI_Count_of_G(g))
11234 if(!or_node||ES_Ord_of_OR(or_node)!=work_earley_set_ordinal)
11235 {
11236 DAND draft_and_node;
11237 const gint rhs_ix= symbol_instance-SYMI_of_RULE(path_rule);
11238 const OR predecessor= rhs_ix?last_or_node:NULL;
11239 const OR cause= (OR)TOK_by_ID_of_R(r,RHS_ID_of_RULE(path_rule,rhs_ix));
11240 MARPA_ASSERT(symbol_instance<Length_of_RULE(path_rule))
11241 MARPA_ASSERT(symbol_instance>=0)
11242 /*1032:*/
11243 #line 9553 "./marpa.w"
11244 
11245 {
11246 const gint or_node_id= OR_Count_of_B(b)++;
11247 OR*or_nodes_of_b= ORs_of_B(b);
11248 last_or_node= (OR)obstack_alloc(&OBS_of_B(b),sizeof(OR_Object));
11249 ID_of_OR(last_or_node)= or_node_id;
11250 if(G_UNLIKELY(or_node_id>=or_node_estimate))
11251 {
11252 MARPA_ASSERT(0);
11253 or_node_estimate*= 2;
11254 ORs_of_B(b)= or_nodes_of_b=
11255 g_renew(OR,or_nodes_of_b,or_node_estimate);
11256 }
11257 or_nodes_of_b[or_node_id]= last_or_node;
11258 }
11259 
11260 
11261 /*:1032*/
11262 #line 9750 "./marpa.w"
11263 
11264 PSL_Datum(this_earley_set_psl,symbol_instance)= or_node= last_or_node;
11265 Origin_Ord_of_OR(or_node)= ordinal_of_set_of_this_leo_item;
11266 ES_Ord_of_OR(or_node)= work_earley_set_ordinal;
11267 RULE_of_OR(or_node)= path_rule;
11268 Position_of_OR(or_node)= rhs_ix+1;
11269 MARPA_ASSERT(Position_of_OR(or_node)<=1||predecessor);
11270 DANDs_of_OR(or_node)= draft_and_node=
11271 draft_and_node_new(&bocage_setup_obs,predecessor,cause);
11272 MARPA_OFF_DEBUG3("or = %p, setting DAND = %p",or_node,
11273 DANDs_of_OR(or_node));
11274 Next_DAND_of_DAND(draft_and_node)= NULL;
11275 }
11276 MARPA_ASSERT(Position_of_OR(or_node)<=
11277 SYMI_of_RULE(path_rule)+Length_of_RULE(path_rule))
11278 MARPA_ASSERT(Position_of_OR(or_node)>=SYMI_of_RULE(path_rule))
11279 }
11280 }
11281 
11282 /*:1043*/
11283 #line 9670 "./marpa.w"
11284 
11285 previous_leo_item= this_leo_item;
11286 }
11287 }
11288 
11289 /*:1037*/
11290 #line 9641 "./marpa.w"
11291 
11292 if(!source_link)break;
11293 leo_predecessor= Predecessor_of_SRCL(source_link);
11294 cause_earley_item= Cause_of_SRCL(source_link);
11295 source_link= Next_SRCL_of_SRCL(source_link);
11296 }
11297 }
11298 }
11299 
11300 /*:1035*/
11301 #line 9515 "./marpa.w"
11302 
11303 }
11304 
11305 /*:1029*/
11306 #line 9491 "./marpa.w"
11307 
11308 }
11309 }
11310 }
11311 }
11312 
11313 /*:1028*/
11314 #line 9470 "./marpa.w"
11315 
11316 /*1052:*/
11317 #line 9850 "./marpa.w"
11318 
11319 {
11320 gint item_ordinal;
11321 for(item_ordinal= 0;item_ordinal<item_count;item_ordinal++)
11322 {
11323 OR*const nodes_by_aex= nodes_by_item[item_ordinal];
11324 if(nodes_by_aex){
11325 const EIM work_earley_item= eims_of_es[item_ordinal];
11326 const gint work_ahfa_item_count= AIM_Count_of_EIM(work_earley_item);
11327 const gint work_origin_ordinal= Ord_of_ES(Origin_of_EIM(work_earley_item));
11328 AEX work_aex;
11329 for(work_aex= 0;work_aex<work_ahfa_item_count;work_aex++){
11330 OR or_node= nodes_by_aex[work_aex];
11331 Move_OR_to_Proper_OR(or_node);
11332 if(or_node){
11333 /*1054:*/
11334 #line 9887 "./marpa.w"
11335 
11336 {
11337 guint work_source_type= Source_Type_of_EIM(work_earley_item);
11338 const AIM work_ahfa_item= AIM_of_EIM_by_AEX(work_earley_item,work_aex);
11339 MARPA_ASSERT(work_ahfa_item>=AIM_by_ID(1))
11340 const AIM work_predecessor_aim= work_ahfa_item-1;
11341 const gint work_symbol_instance= SYMI_of_AIM(work_ahfa_item);
11342 OR work_proper_or_node;
11343 Set_OR_from_Ord_and_SYMI(work_proper_or_node,work_origin_ordinal,
11344 work_symbol_instance);
11345 
11346 /*1055:*/
11347 #line 9903 "./marpa.w"
11348 {
11349 SRCL source_link= NULL;
11350 EIM cause_earley_item= NULL;
11351 LIM leo_predecessor= NULL;
11352 switch(Source_Type_of_EIM(work_earley_item))
11353 {
11354 case SOURCE_IS_LEO:
11355 leo_predecessor= Predecessor_of_EIM(work_earley_item);
11356 cause_earley_item= Cause_of_EIM(work_earley_item);
11357 break;
11358 case SOURCE_IS_AMBIGUOUS:
11359 source_link= First_Leo_SRCL_of_EIM(work_earley_item);
11360 if(source_link)
11361 {
11362 leo_predecessor= Predecessor_of_SRCL(source_link);
11363 cause_earley_item= Cause_of_SRCL(source_link);
11364 source_link= Next_SRCL_of_SRCL(source_link);
11365 }
11366 break;
11367 }
11368 if(leo_predecessor){
11369 for(;;){
11370 /*1056:*/
11371 #line 9935 "./marpa.w"
11372 
11373 {
11374 
11375 RULE path_rule= NULL;
11376 
11377 RULE previous_path_rule;
11378 LIM path_leo_item= leo_predecessor;
11379 LIM higher_path_leo_item= Predecessor_LIM_of_LIM(path_leo_item);
11380 
11381 
11382 OR dand_predecessor;
11383 OR path_or_node;
11384 EIM base_earley_item;
11385 AEX base_aex= lim_base_data_get(path_leo_item,&base_earley_item);
11386 Set_OR_from_EIM_and_AEX(dand_predecessor,base_earley_item,base_aex);
11387 /*1057:*/
11388 #line 9964 "./marpa.w"
11389 
11390 {
11391 if(higher_path_leo_item){
11392 /*1061:*/
11393 #line 10008 "./marpa.w"
11394 
11395 {
11396 gint symbol_instance;
11397 const gint origin_ordinal= Origin_Ord_of_EIM(base_earley_item);
11398 const AIM aim= AIM_of_EIM_by_AEX(base_earley_item,base_aex);
11399 path_rule= RULE_of_AIM(aim);
11400 symbol_instance= Last_Proper_SYMI_of_RULE(path_rule);
11401 Set_OR_from_Ord_and_SYMI(path_or_node,origin_ordinal,symbol_instance);
11402 }
11403 
11404 /*:1061*/
11405 #line 9967 "./marpa.w"
11406 
11407 }else{
11408 path_or_node= work_proper_or_node;
11409 }
11410 }
11411 
11412 /*:1057*/
11413 #line 9950 "./marpa.w"
11414 
11415 /*1059:*/
11416 #line 9978 "./marpa.w"
11417 
11418 {
11419 const SYMID transition_symbol_id= Postdot_SYMID_of_LIM(leo_predecessor);
11420 const TRANS cause_completion_data=
11421 TRANS_of_EIM_by_SYMID(cause_earley_item,transition_symbol_id);
11422 const gint aex_count= Completion_Count_of_TRANS(cause_completion_data);
11423 const AEX*const aexes= AEXs_of_TRANS(cause_completion_data);
11424 gint ix;
11425 for(ix= 0;ix<aex_count;ix++)
11426 {
11427 const AEX cause_aex= aexes[ix];
11428 OR dand_cause;
11429 Set_OR_from_EIM_and_AEX(dand_cause,cause_earley_item,cause_aex);
11430 draft_and_node_add(&bocage_setup_obs,path_or_node,
11431 dand_predecessor,dand_cause);
11432 }
11433 }
11434 
11435 /*:1059*/
11436 #line 9951 "./marpa.w"
11437 
11438 previous_path_rule= path_rule;
11439 while(higher_path_leo_item){
11440 path_leo_item= higher_path_leo_item;
11441 higher_path_leo_item= Predecessor_LIM_of_LIM(path_leo_item);
11442 base_aex= lim_base_data_get(path_leo_item,&base_earley_item);
11443 Set_OR_from_EIM_and_AEX(dand_predecessor,base_earley_item,base_aex);
11444 /*1057:*/
11445 #line 9964 "./marpa.w"
11446 
11447 {
11448 if(higher_path_leo_item){
11449 /*1061:*/
11450 #line 10008 "./marpa.w"
11451 
11452 {
11453 gint symbol_instance;
11454 const gint origin_ordinal= Origin_Ord_of_EIM(base_earley_item);
11455 const AIM aim= AIM_of_EIM_by_AEX(base_earley_item,base_aex);
11456 path_rule= RULE_of_AIM(aim);
11457 symbol_instance= Last_Proper_SYMI_of_RULE(path_rule);
11458 Set_OR_from_Ord_and_SYMI(path_or_node,origin_ordinal,symbol_instance);
11459 }
11460 
11461 /*:1061*/
11462 #line 9967 "./marpa.w"
11463 
11464 }else{
11465 path_or_node= work_proper_or_node;
11466 }
11467 }
11468 
11469 /*:1057*/
11470 #line 9958 "./marpa.w"
11471 
11472 /*1062:*/
11473 #line 10018 "./marpa.w"
11474 
11475 {
11476 OR dand_cause;
11477 const SYMI symbol_instance= SYMI_of_Completed_RULE(previous_path_rule);
11478 const gint origin_ordinal= Ord_of_ES(ES_of_LIM(path_leo_item));
11479 Set_OR_from_Ord_and_SYMI(dand_cause,origin_ordinal,symbol_instance);
11480 draft_and_node_add(&bocage_setup_obs,path_or_node,
11481 dand_predecessor,dand_cause);
11482 }
11483 
11484 /*:1062*/
11485 #line 9959 "./marpa.w"
11486 
11487 previous_path_rule= path_rule;
11488 }
11489 }
11490 
11491 /*:1056*/
11492 #line 9925 "./marpa.w"
11493 
11494 if(!source_link)break;
11495 leo_predecessor= Predecessor_of_SRCL(source_link);
11496 cause_earley_item= Cause_of_SRCL(source_link);
11497 source_link= Next_SRCL_of_SRCL(source_link);
11498 }
11499 }
11500 }
11501 
11502 /*:1055*/
11503 #line 9898 "./marpa.w"
11504 
11505 /*1063:*/
11506 #line 10028 "./marpa.w"
11507 
11508 {
11509 SRCL source_link= NULL;
11510 EIM predecessor_earley_item= NULL;
11511 TOK token= NULL;
11512 switch(work_source_type)
11513 {
11514 case SOURCE_IS_TOKEN:
11515 predecessor_earley_item= Predecessor_of_EIM(work_earley_item);
11516 token= TOK_of_EIM(work_earley_item);
11517 break;
11518 case SOURCE_IS_AMBIGUOUS:
11519 source_link= First_Token_Link_of_EIM(work_earley_item);
11520 if(source_link)
11521 {
11522 predecessor_earley_item= Predecessor_of_SRCL(source_link);
11523 token= TOK_of_SRCL(source_link);
11524 source_link= Next_SRCL_of_SRCL(source_link);
11525 }
11526 }
11527 while(token)
11528 {
11529 /*1064:*/
11530 #line 10058 "./marpa.w"
11531 
11532 {
11533 OR dand_predecessor;
11534 /*1065:*/
11535 #line 10066 "./marpa.w"
11536 
11537 {
11538 if(Position_of_AIM(work_predecessor_aim)<1){
11539 dand_predecessor= NULL;
11540 }else{
11541 const AEX predecessor_aex=
11542 AEX_of_EIM_by_AIM(predecessor_earley_item,work_predecessor_aim);
11543 Set_OR_from_EIM_and_AEX(dand_predecessor,predecessor_earley_item,predecessor_aex);
11544 }
11545 }
11546 
11547 /*:1065*/
11548 #line 10061 "./marpa.w"
11549 
11550 draft_and_node_add(&bocage_setup_obs,work_proper_or_node,
11551 dand_predecessor,(OR)token);
11552 }
11553 
11554 /*:1064*/
11555 #line 10050 "./marpa.w"
11556 
11557 if(!source_link)break;
11558 predecessor_earley_item= Predecessor_of_SRCL(source_link);
11559 token= TOK_of_SRCL(source_link);
11560 source_link= Next_SRCL_of_SRCL(source_link);
11561 }
11562 }
11563 
11564 /*:1063*/
11565 #line 9899 "./marpa.w"
11566 
11567 /*1066:*/
11568 #line 10077 "./marpa.w"
11569 
11570 {
11571 SRCL source_link= NULL;
11572 EIM predecessor_earley_item= NULL;
11573 EIM cause_earley_item= NULL;
11574 const SYMID transition_symbol_id= Postdot_SYMID_of_AIM(work_predecessor_aim);
11575 switch(work_source_type)
11576 {
11577 case SOURCE_IS_COMPLETION:
11578 predecessor_earley_item= Predecessor_of_EIM(work_earley_item);
11579 cause_earley_item= Cause_of_EIM(work_earley_item);
11580 break;
11581 case SOURCE_IS_AMBIGUOUS:
11582 source_link= First_Completion_Link_of_EIM(work_earley_item);
11583 if(source_link)
11584 {
11585 predecessor_earley_item= Predecessor_of_SRCL(source_link);
11586 cause_earley_item= Cause_of_SRCL(source_link);
11587 source_link= Next_SRCL_of_SRCL(source_link);
11588 }
11589 break;
11590 }
11591 while(cause_earley_item)
11592 {
11593 const TRANS cause_completion_data=
11594 TRANS_of_EIM_by_SYMID(cause_earley_item,transition_symbol_id);
11595 const gint aex_count= Completion_Count_of_TRANS(cause_completion_data);
11596 const AEX*const aexes= AEXs_of_TRANS(cause_completion_data);
11597 gint ix;
11598 for(ix= 0;ix<aex_count;ix++){
11599 const AEX cause_aex= aexes[ix];
11600 /*1067:*/
11601 #line 10117 "./marpa.w"
11602 
11603 {
11604 OR dand_predecessor;
11605 OR dand_cause;
11606 const gint middle_ordinal= Origin_Ord_of_EIM(cause_earley_item);
11607 const AIM cause_ahfa_item= AIM_of_EIM_by_AEX(cause_earley_item,cause_aex);
11608 const SYMI cause_symbol_instance=
11609 SYMI_of_Completed_RULE(RULE_of_AIM(cause_ahfa_item));
11610 /*1065:*/
11611 #line 10066 "./marpa.w"
11612 
11613 {
11614 if(Position_of_AIM(work_predecessor_aim)<1){
11615 dand_predecessor= NULL;
11616 }else{
11617 const AEX predecessor_aex=
11618 AEX_of_EIM_by_AIM(predecessor_earley_item,work_predecessor_aim);
11619 Set_OR_from_EIM_and_AEX(dand_predecessor,predecessor_earley_item,predecessor_aex);
11620 }
11621 }
11622 
11623 /*:1065*/
11624 #line 10125 "./marpa.w"
11625 
11626 Set_OR_from_Ord_and_SYMI(dand_cause,middle_ordinal,cause_symbol_instance);
11627 draft_and_node_add(&bocage_setup_obs,work_proper_or_node,
11628 dand_predecessor,dand_cause);
11629 }
11630 
11631 /*:1067*/
11632 #line 10108 "./marpa.w"
11633 
11634 }
11635 if(!source_link)break;
11636 predecessor_earley_item= Predecessor_of_SRCL(source_link);
11637 cause_earley_item= Cause_of_SRCL(source_link);
11638 source_link= Next_SRCL_of_SRCL(source_link);
11639 }
11640 }
11641 
11642 /*:1066*/
11643 #line 9900 "./marpa.w"
11644 
11645 }
11646 
11647 /*:1054*/
11648 #line 9865 "./marpa.w"
11649 
11650 }
11651 }
11652 }
11653 }
11654 }
11655 
11656 /*:1052*/
11657 #line 9471 "./marpa.w"
11658 
11659 }
11660 psar_destroy(or_psar);
11661 ORs_of_B(b)= g_renew(OR,ORs_of_B(b),OR_Count_of_B(b));
11662 }
11663 
11664 /*:1027*/
11665 #line 10486 "./marpa.w"
11666 
11667 /*1075:*/
11668 #line 10231 "./marpa.w"
11669 
11670 {
11671 gint unique_draft_and_node_count= 0;
11672 /*1068:*/
11673 #line 10131 "./marpa.w"
11674 
11675 {
11676 OR*const or_nodes_of_b= ORs_of_B(b);
11677 const gint or_node_count_of_b= OR_Count_of_B(b);
11678 PSAR_Object and_per_es_arena;
11679 const PSAR and_psar= &and_per_es_arena;
11680 gint or_node_id= 0;
11681 psar_init(and_psar,rule_count_of_g+symbol_count_of_g);
11682 while(or_node_id<or_node_count_of_b){
11683 const OR work_or_node= or_nodes_of_b[or_node_id];
11684 /*1070:*/
11685 #line 10163 "./marpa.w"
11686 
11687 {
11688 DAND dand= DANDs_of_OR(work_or_node);
11689 DAND next_dand= Next_DAND_of_DAND(dand);
11690 ORID work_or_node_id= ID_of_OR(work_or_node);
11691 
11692 if(next_dand)
11693 {
11694 gint origin_ordinal= Origin_Ord_of_OR(work_or_node);
11695 psar_dealloc(and_psar);
11696 while(dand)
11697 {
11698 OR psl_or_node;
11699 OR predecessor= Predecessor_OR_of_DAND(dand);
11700 WHEID wheid= WHEID_of_OR(Cause_OR_of_DAND(dand));
11701 const gint middle_ordinal=
11702 predecessor?ES_Ord_of_OR(predecessor):origin_ordinal;
11703 PSL and_psl;
11704 PSL*psl_owner= &per_es_data[middle_ordinal].t_and_psl;
11705 
11706 if(!*psl_owner)psl_claim(psl_owner,and_psar);
11707 and_psl= *psl_owner;
11708 psl_or_node= PSL_Datum(and_psl,wheid);
11709 if(psl_or_node&&ID_of_OR(psl_or_node)==work_or_node_id)
11710 {
11711 
11712 Cause_OR_of_DAND(dand)= NULL;
11713 }else{
11714 
11715 PSL_Datum(and_psl,wheid)= work_or_node;
11716 unique_draft_and_node_count++;
11717 }
11718 dand= Next_DAND_of_DAND(dand);
11719 }
11720 }else{
11721 unique_draft_and_node_count++;
11722 }
11723 }
11724 
11725 /*:1070*/
11726 #line 10141 "./marpa.w"
11727 
11728 or_node_id++;
11729 }
11730 psar_destroy(and_psar);
11731 }
11732 
11733 /*:1068*/
11734 #line 10234 "./marpa.w"
11735 
11736 /*1076:*/
11737 #line 10238 "./marpa.w"
11738 
11739 {
11740 const gint or_count_of_b= OR_Count_of_B(b);
11741 gint or_node_id;
11742 gint and_node_id= 0;
11743 const OR*ors_of_b= ORs_of_B(b);
11744 const AND ands_of_b= ANDs_of_B(b)=
11745 g_new(AND_Object,unique_draft_and_node_count);
11746 for(or_node_id= 0;or_node_id<or_count_of_b;or_node_id++)
11747 {
11748 gint and_count_of_parent_or= 0;
11749 const OR or_node= ors_of_b[or_node_id];
11750 DAND dand= DANDs_of_OR(or_node);
11751 First_ANDID_of_OR(or_node)= and_node_id;
11752 while(dand)
11753 {
11754 const OR cause_or_node= Cause_OR_of_DAND(dand);
11755 if(cause_or_node)
11756 {
11757 
11758 const AND and_node= ands_of_b+and_node_id;
11759 OR_of_AND(and_node)= or_node;
11760 Predecessor_OR_of_AND(and_node)=
11761 Predecessor_OR_of_DAND(dand);
11762 Cause_OR_of_AND(and_node)= cause_or_node;
11763 and_node_id++;
11764 and_count_of_parent_or++;
11765 }
11766 dand= Next_DAND_of_DAND(dand);
11767 }
11768 AND_Count_of_OR(or_node)= and_count_of_parent_or;
11769 }
11770 AND_Count_of_B(b)= and_node_id;
11771 MARPA_ASSERT(and_node_id==unique_draft_and_node_count);
11772 }
11773 
11774 /*:1076*/
11775 #line 10235 "./marpa.w"
11776 
11777 }
11778 
11779 /*:1075*/
11780 #line 10487 "./marpa.w"
11781 
11782 /*1115:*/
11783 #line 10688 "./marpa.w"
11784 {
11785 const ESID end_of_parse_ordinal= Ord_of_ES(end_of_parse_es);
11786 OR**const nodes_by_item= per_es_data[end_of_parse_ordinal].t_aexes_by_item;
11787 const gint start_earley_item_ordinal= Ord_of_EIM(start_eim);
11788 OR*const nodes_by_aex= nodes_by_item[start_earley_item_ordinal];
11789 const OR top_or_node= nodes_by_aex[start_aex];
11790 top_or_node_id= ID_of_OR(top_or_node);
11791 }
11792 
11793 /*:1115*/
11794 #line 10488 "./marpa.w"
11795 
11796 obstack_free(&bocage_setup_obs,NULL);
11797 Top_ORID_of_B(b)= top_or_node_id;
11798 return top_or_node_id;
11799 SOFT_ERROR:;
11800 /*1116:*/
11801 #line 10698 "./marpa.w"
11802 
11803 /*1026:*/
11804 #line 9432 "./marpa.w"
11805 
11806 {
11807 OR*or_nodes= ORs_of_B(b);
11808 AND and_nodes= ANDs_of_B(b);
11809 if(or_nodes)
11810 {
11811 g_free(or_nodes);
11812 ORs_of_B(b)= NULL;
11813 }
11814 if(and_nodes)
11815 {
11816 g_free(and_nodes);
11817 ANDs_of_B(b)= NULL;
11818 }
11819 }
11820 
11821 /*:1026*//*1169:*/
11822 #line 11256 "./marpa.w"
11823 
11824 rank_destroy(RANK_of_B(b));
11825 /*:1169*/
11826 #line 10699 "./marpa.w"
11827 ;
11828 /*1101:*/
11829 #line 10447 "./marpa.w"
11830 
11831 if(b->is_obstack_initialized){
11832 obstack_free(&OBS_of_B(b),NULL);
11833 b->is_obstack_initialized= 0;
11834 }
11835 
11836 /*:1101*/
11837 #line 10700 "./marpa.w"
11838 ;
11839 
11840 /*:1116*/
11841 #line 10493 "./marpa.w"
11842 ;
11843 return no_parse;
11844 }
11845 
11846 /*:1104*//*1119:*/
11847 #line 10710 "./marpa.w"
11848 
marpa_bocage_free(struct marpa_r * r)11849 gint marpa_bocage_free(struct marpa_r*r){
11850 /*1357:*/
11851 #line 13088 "./marpa.w"
11852 const int failure_indicator= -2;
11853 
11854 /*:1357*/
11855 #line 10712 "./marpa.w"
11856 
11857 /*1371:*/
11858 #line 13178 "./marpa.w"
11859 
11860 if(Phase_of_R(r)==error_phase){
11861 R_ERROR(r->t_fatal_error);
11862 return failure_indicator;
11863 }
11864 /*:1371*/
11865 #line 10713 "./marpa.w"
11866 
11867 if(Phase_of_R(r)==evaluation_phase){
11868 
11869 Phase_of_R(r)= input_phase;
11870 }
11871 bocage_destroy(r);
11872 return 1;
11873 }
11874 
11875 /*:1119*//*1121:*/
11876 #line 10724 "./marpa.w"
11877 
bocage_destroy(struct marpa_r * r)11878 static inline void bocage_destroy(struct marpa_r*r)
11879 {
11880 BOC b= B_of_R(r);
11881 MARPA_DEBUG3("%s B_of_R=%p",G_STRLOC,B_of_R(r));
11882 if(b){
11883 /*1116:*/
11884 #line 10698 "./marpa.w"
11885 
11886 /*1026:*/
11887 #line 9432 "./marpa.w"
11888 
11889 {
11890 OR*or_nodes= ORs_of_B(b);
11891 AND and_nodes= ANDs_of_B(b);
11892 if(or_nodes)
11893 {
11894 g_free(or_nodes);
11895 ORs_of_B(b)= NULL;
11896 }
11897 if(and_nodes)
11898 {
11899 g_free(and_nodes);
11900 ANDs_of_B(b)= NULL;
11901 }
11902 }
11903 
11904 /*:1026*//*1169:*/
11905 #line 11256 "./marpa.w"
11906 
11907 rank_destroy(RANK_of_B(b));
11908 /*:1169*/
11909 #line 10699 "./marpa.w"
11910 ;
11911 /*1101:*/
11912 #line 10447 "./marpa.w"
11913 
11914 if(b->is_obstack_initialized){
11915 obstack_free(&OBS_of_B(b),NULL);
11916 b->is_obstack_initialized= 0;
11917 }
11918 
11919 /*:1101*/
11920 #line 10700 "./marpa.w"
11921 ;
11922 
11923 /*:1116*/
11924 #line 10730 "./marpa.w"
11925 ;
11926 g_slice_free(BOC_Object,b);
11927 B_of_R(r)= NULL;
11928 }
11929 MARPA_DEBUG3("%s B_of_R=%p",G_STRLOC,B_of_R(r));
11930 }
11931 
11932 /*:1121*//*1125:*/
11933 #line 10767 "./marpa.w"
11934 
marpa_or_node_set(struct marpa_r * r,int or_node_id)11935 gint marpa_or_node_set(struct marpa_r*r,int or_node_id)
11936 {
11937 OR or_node;
11938 /*1357:*/
11939 #line 13088 "./marpa.w"
11940 const int failure_indicator= -2;
11941 
11942 /*:1357*/
11943 #line 10771 "./marpa.w"
11944 
11945 /*1123:*/
11946 #line 10740 "./marpa.w"
11947 {
11948 BOC b= B_of_R(r);
11949 OR*or_nodes;
11950 /*1371:*/
11951 #line 13178 "./marpa.w"
11952 
11953 if(Phase_of_R(r)==error_phase){
11954 R_ERROR(r->t_fatal_error);
11955 return failure_indicator;
11956 }
11957 /*:1371*/
11958 #line 10743 "./marpa.w"
11959 
11960 if(!b){
11961 R_ERROR("no bocage");
11962 return failure_indicator;
11963 }
11964 or_nodes= ORs_of_B(b);
11965 if(!or_nodes){
11966 R_ERROR("no or nodes");
11967 return failure_indicator;
11968 }
11969 if(or_node_id<0){
11970 R_ERROR("bad or node id");
11971 return failure_indicator;
11972 }
11973 if(or_node_id>=OR_Count_of_B(b)){
11974 return-1;
11975 }
11976 or_node= or_nodes[or_node_id];
11977 }
11978 
11979 /*:1123*/
11980 #line 10772 "./marpa.w"
11981 
11982 return ES_Ord_of_OR(or_node);
11983 }
11984 
11985 /*:1125*//*1127:*/
11986 #line 10778 "./marpa.w"
11987 
marpa_or_node_origin(struct marpa_r * r,int or_node_id)11988 gint marpa_or_node_origin(struct marpa_r*r,int or_node_id)
11989 {
11990 OR or_node;
11991 /*1357:*/
11992 #line 13088 "./marpa.w"
11993 const int failure_indicator= -2;
11994 
11995 /*:1357*/
11996 #line 10782 "./marpa.w"
11997 
11998 /*1123:*/
11999 #line 10740 "./marpa.w"
12000 {
12001 BOC b= B_of_R(r);
12002 OR*or_nodes;
12003 /*1371:*/
12004 #line 13178 "./marpa.w"
12005 
12006 if(Phase_of_R(r)==error_phase){
12007 R_ERROR(r->t_fatal_error);
12008 return failure_indicator;
12009 }
12010 /*:1371*/
12011 #line 10743 "./marpa.w"
12012 
12013 if(!b){
12014 R_ERROR("no bocage");
12015 return failure_indicator;
12016 }
12017 or_nodes= ORs_of_B(b);
12018 if(!or_nodes){
12019 R_ERROR("no or nodes");
12020 return failure_indicator;
12021 }
12022 if(or_node_id<0){
12023 R_ERROR("bad or node id");
12024 return failure_indicator;
12025 }
12026 if(or_node_id>=OR_Count_of_B(b)){
12027 return-1;
12028 }
12029 or_node= or_nodes[or_node_id];
12030 }
12031 
12032 /*:1123*/
12033 #line 10783 "./marpa.w"
12034 
12035 return Origin_Ord_of_OR(or_node);
12036 }
12037 
12038 /*:1127*//*1129:*/
12039 #line 10789 "./marpa.w"
12040 
marpa_or_node_rule(struct marpa_r * r,int or_node_id)12041 gint marpa_or_node_rule(struct marpa_r*r,int or_node_id)
12042 {
12043 OR or_node;
12044 /*1357:*/
12045 #line 13088 "./marpa.w"
12046 const int failure_indicator= -2;
12047 
12048 /*:1357*/
12049 #line 10793 "./marpa.w"
12050 
12051 /*1123:*/
12052 #line 10740 "./marpa.w"
12053 {
12054 BOC b= B_of_R(r);
12055 OR*or_nodes;
12056 /*1371:*/
12057 #line 13178 "./marpa.w"
12058 
12059 if(Phase_of_R(r)==error_phase){
12060 R_ERROR(r->t_fatal_error);
12061 return failure_indicator;
12062 }
12063 /*:1371*/
12064 #line 10743 "./marpa.w"
12065 
12066 if(!b){
12067 R_ERROR("no bocage");
12068 return failure_indicator;
12069 }
12070 or_nodes= ORs_of_B(b);
12071 if(!or_nodes){
12072 R_ERROR("no or nodes");
12073 return failure_indicator;
12074 }
12075 if(or_node_id<0){
12076 R_ERROR("bad or node id");
12077 return failure_indicator;
12078 }
12079 if(or_node_id>=OR_Count_of_B(b)){
12080 return-1;
12081 }
12082 or_node= or_nodes[or_node_id];
12083 }
12084 
12085 /*:1123*/
12086 #line 10794 "./marpa.w"
12087 
12088 return ID_of_RULE(RULE_of_OR(or_node));
12089 }
12090 
12091 /*:1129*//*1131:*/
12092 #line 10800 "./marpa.w"
12093 
marpa_or_node_position(struct marpa_r * r,int or_node_id)12094 gint marpa_or_node_position(struct marpa_r*r,int or_node_id)
12095 {
12096 OR or_node;
12097 /*1357:*/
12098 #line 13088 "./marpa.w"
12099 const int failure_indicator= -2;
12100 
12101 /*:1357*/
12102 #line 10804 "./marpa.w"
12103 
12104 /*1123:*/
12105 #line 10740 "./marpa.w"
12106 {
12107 BOC b= B_of_R(r);
12108 OR*or_nodes;
12109 /*1371:*/
12110 #line 13178 "./marpa.w"
12111 
12112 if(Phase_of_R(r)==error_phase){
12113 R_ERROR(r->t_fatal_error);
12114 return failure_indicator;
12115 }
12116 /*:1371*/
12117 #line 10743 "./marpa.w"
12118 
12119 if(!b){
12120 R_ERROR("no bocage");
12121 return failure_indicator;
12122 }
12123 or_nodes= ORs_of_B(b);
12124 if(!or_nodes){
12125 R_ERROR("no or nodes");
12126 return failure_indicator;
12127 }
12128 if(or_node_id<0){
12129 R_ERROR("bad or node id");
12130 return failure_indicator;
12131 }
12132 if(or_node_id>=OR_Count_of_B(b)){
12133 return-1;
12134 }
12135 or_node= or_nodes[or_node_id];
12136 }
12137 
12138 /*:1123*/
12139 #line 10805 "./marpa.w"
12140 
12141 return Position_of_OR(or_node);
12142 }
12143 
12144 /*:1131*//*1133:*/
12145 #line 10811 "./marpa.w"
12146 
marpa_or_node_first_and(struct marpa_r * r,int or_node_id)12147 gint marpa_or_node_first_and(struct marpa_r*r,int or_node_id)
12148 {
12149 OR or_node;
12150 /*1357:*/
12151 #line 13088 "./marpa.w"
12152 const int failure_indicator= -2;
12153 
12154 /*:1357*/
12155 #line 10815 "./marpa.w"
12156 
12157 /*1123:*/
12158 #line 10740 "./marpa.w"
12159 {
12160 BOC b= B_of_R(r);
12161 OR*or_nodes;
12162 /*1371:*/
12163 #line 13178 "./marpa.w"
12164 
12165 if(Phase_of_R(r)==error_phase){
12166 R_ERROR(r->t_fatal_error);
12167 return failure_indicator;
12168 }
12169 /*:1371*/
12170 #line 10743 "./marpa.w"
12171 
12172 if(!b){
12173 R_ERROR("no bocage");
12174 return failure_indicator;
12175 }
12176 or_nodes= ORs_of_B(b);
12177 if(!or_nodes){
12178 R_ERROR("no or nodes");
12179 return failure_indicator;
12180 }
12181 if(or_node_id<0){
12182 R_ERROR("bad or node id");
12183 return failure_indicator;
12184 }
12185 if(or_node_id>=OR_Count_of_B(b)){
12186 return-1;
12187 }
12188 or_node= or_nodes[or_node_id];
12189 }
12190 
12191 /*:1123*/
12192 #line 10816 "./marpa.w"
12193 
12194 return First_ANDID_of_OR(or_node);
12195 }
12196 
12197 /*:1133*//*1135:*/
12198 #line 10822 "./marpa.w"
12199 
marpa_or_node_last_and(struct marpa_r * r,int or_node_id)12200 gint marpa_or_node_last_and(struct marpa_r*r,int or_node_id)
12201 {
12202 OR or_node;
12203 /*1357:*/
12204 #line 13088 "./marpa.w"
12205 const int failure_indicator= -2;
12206 
12207 /*:1357*/
12208 #line 10826 "./marpa.w"
12209 
12210 /*1123:*/
12211 #line 10740 "./marpa.w"
12212 {
12213 BOC b= B_of_R(r);
12214 OR*or_nodes;
12215 /*1371:*/
12216 #line 13178 "./marpa.w"
12217 
12218 if(Phase_of_R(r)==error_phase){
12219 R_ERROR(r->t_fatal_error);
12220 return failure_indicator;
12221 }
12222 /*:1371*/
12223 #line 10743 "./marpa.w"
12224 
12225 if(!b){
12226 R_ERROR("no bocage");
12227 return failure_indicator;
12228 }
12229 or_nodes= ORs_of_B(b);
12230 if(!or_nodes){
12231 R_ERROR("no or nodes");
12232 return failure_indicator;
12233 }
12234 if(or_node_id<0){
12235 R_ERROR("bad or node id");
12236 return failure_indicator;
12237 }
12238 if(or_node_id>=OR_Count_of_B(b)){
12239 return-1;
12240 }
12241 or_node= or_nodes[or_node_id];
12242 }
12243 
12244 /*:1123*/
12245 #line 10827 "./marpa.w"
12246 
12247 return First_ANDID_of_OR(or_node)
12248 +AND_Count_of_OR(or_node)-1;
12249 }
12250 
12251 /*:1135*//*1137:*/
12252 #line 10834 "./marpa.w"
12253 
marpa_or_node_and_count(struct marpa_r * r,int or_node_id)12254 gint marpa_or_node_and_count(struct marpa_r*r,int or_node_id)
12255 {
12256 OR or_node;
12257 /*1357:*/
12258 #line 13088 "./marpa.w"
12259 const int failure_indicator= -2;
12260 
12261 /*:1357*/
12262 #line 10838 "./marpa.w"
12263 
12264 /*1123:*/
12265 #line 10740 "./marpa.w"
12266 {
12267 BOC b= B_of_R(r);
12268 OR*or_nodes;
12269 /*1371:*/
12270 #line 13178 "./marpa.w"
12271 
12272 if(Phase_of_R(r)==error_phase){
12273 R_ERROR(r->t_fatal_error);
12274 return failure_indicator;
12275 }
12276 /*:1371*/
12277 #line 10743 "./marpa.w"
12278 
12279 if(!b){
12280 R_ERROR("no bocage");
12281 return failure_indicator;
12282 }
12283 or_nodes= ORs_of_B(b);
12284 if(!or_nodes){
12285 R_ERROR("no or nodes");
12286 return failure_indicator;
12287 }
12288 if(or_node_id<0){
12289 R_ERROR("bad or node id");
12290 return failure_indicator;
12291 }
12292 if(or_node_id>=OR_Count_of_B(b)){
12293 return-1;
12294 }
12295 or_node= or_nodes[or_node_id];
12296 }
12297 
12298 /*:1123*/
12299 #line 10839 "./marpa.w"
12300 
12301 return AND_Count_of_OR(or_node);
12302 }
12303 
12304 /*:1137*//*1141:*/
12305 #line 10885 "./marpa.w"
12306 
tree_exhaust(TREE tree)12307 static inline void tree_exhaust(TREE tree)
12308 {
12309 if(FSTACK_IS_INITIALIZED(tree->t_fork_stack))
12310 {
12311 FSTACK_DESTROY(tree->t_fork_stack);
12312 FSTACK_SAFE(tree->t_fork_stack);
12313 }
12314 if(FSTACK_IS_INITIALIZED(tree->t_fork_worklist))
12315 {
12316 FSTACK_DESTROY(tree->t_fork_worklist);
12317 FSTACK_SAFE(tree->t_fork_worklist);
12318 }
12319 if(tree->t_and_node_in_use){
12320 bv_free(tree->t_and_node_in_use);
12321 tree->t_and_node_in_use= NULL;
12322 }
12323 }
12324 
12325 /*:1141*//*1143:*/
12326 #line 10906 "./marpa.w"
12327 
tree_safe(TREE tree)12328 static inline void tree_safe(TREE tree)
12329 {
12330 FSTACK_SAFE(tree->t_fork_stack);
12331 FSTACK_SAFE(tree->t_fork_worklist);
12332 tree->t_and_node_in_use= NULL;
12333 tree->t_parse_count= -1;
12334 val_safe(VAL_of_TREE(tree));
12335 }
12336 
12337 /*:1143*//*1145:*/
12338 #line 10921 "./marpa.w"
12339 
marpa_tree_new(struct marpa_r * r)12340 int marpa_tree_new(struct marpa_r*r)
12341 {
12342 BOC b;
12343 TREE tree;
12344 gint first_tree_of_series= 0;
12345 /*1357:*/
12346 #line 13088 "./marpa.w"
12347 const int failure_indicator= -2;
12348 
12349 /*:1357*/
12350 #line 10927 "./marpa.w"
12351 
12352 /*1371:*/
12353 #line 13178 "./marpa.w"
12354 
12355 if(Phase_of_R(r)==error_phase){
12356 R_ERROR(r->t_fatal_error);
12357 return failure_indicator;
12358 }
12359 /*:1371*/
12360 #line 10928 "./marpa.w"
12361 
12362 /*1156:*/
12363 #line 11150 "./marpa.w"
12364 
12365 {
12366 b= B_of_R(r);
12367 if(!b){
12368 R_ERROR("no bocage");
12369 return failure_indicator;
12370 }
12371 }
12372 
12373 /*:1156*/
12374 #line 10929 "./marpa.w"
12375 
12376 tree= TREE_of_RANK(RANK_of_B(b));
12377 if(TREE_is_Exhausted(tree)){
12378 return-1;
12379 }
12380 val_destroy(VAL_of_TREE(tree));
12381 if(!TREE_is_Initialized(tree))
12382 {
12383 first_tree_of_series= 1;
12384 /*1150:*/
12385 #line 10988 "./marpa.w"
12386 
12387 {
12388 ORID top_or_id= Top_ORID_of_B(b);
12389 OR top_or_node= OR_of_B_by_ID(b,top_or_id);
12390 FORK fork;
12391 gint choice;
12392 const gint and_count= AND_Count_of_B(b);
12393 tree->t_parse_count= 0;
12394 tree->t_and_node_in_use= bv_create((guint)and_count);
12395 FSTACK_INIT(tree->t_fork_stack,FORK_Object,and_count);
12396 FSTACK_INIT(tree->t_fork_worklist,gint,and_count);
12397 choice= or_node_next_choice(b,tree,top_or_node,0);
12398 
12399 
12400 if(choice<0)goto TREE_IS_EXHAUSTED;
12401 fork= FSTACK_PUSH(tree->t_fork_stack);
12402 OR_of_FORK(fork)= top_or_node;
12403 Choice_of_FORK(fork)= choice;
12404 Parent_of_FORK(fork)= -1;
12405 FORK_Cause_is_Ready(fork)= 0;
12406 FORK_is_Cause(fork)= 0;
12407 FORK_Predecessor_is_Ready(fork)= 0;
12408 FORK_is_Predecessor(fork)= 0;
12409 *(FSTACK_PUSH(tree->t_fork_worklist))= 0;
12410 }
12411 
12412 /*:1150*/
12413 #line 10940 "./marpa.w"
12414 
12415 }
12416 while(1){
12417 const AND ands_of_b= ANDs_of_B(b);
12418 if(!first_tree_of_series){
12419 /*1151:*/
12420 #line 11017 "./marpa.w"
12421 {
12422 while(1){
12423 FORK iteration_candidate= FSTACK_TOP(tree->t_fork_stack,FORK_Object);
12424 gint choice;
12425 if(!iteration_candidate)break;
12426 choice= Choice_of_FORK(iteration_candidate);
12427 MARPA_ASSERT(choice>=0);
12428 {
12429 OR or_node= OR_of_FORK(iteration_candidate);
12430 ANDID and_node_id= and_order_get(b,or_node,choice);
12431 tree_and_node_release(tree,and_node_id);
12432 choice= or_node_next_choice(b,tree,or_node,choice+1);
12433 }
12434 if(choice>=0){
12435 
12436 
12437 
12438 
12439 
12440 Choice_of_FORK(iteration_candidate)= choice;
12441 FORK_Cause_is_Ready(iteration_candidate)= 0;
12442 FORK_Predecessor_is_Ready(iteration_candidate)= 0;
12443 break;
12444 }
12445 {
12446 
12447 const gint parent_fork_ix= Parent_of_FORK(iteration_candidate);
12448 if(parent_fork_ix>=0){
12449 FORK parent_fork= FORK_of_TREE_by_IX(tree,parent_fork_ix);
12450 if(FORK_is_Cause(iteration_candidate)){
12451 FORK_Cause_is_Ready(parent_fork)= 0;
12452 }
12453 if(FORK_is_Predecessor(iteration_candidate)){
12454 FORK_Predecessor_is_Ready(parent_fork)= 0;
12455 }
12456 }
12457 
12458 
12459 FSTACK_POP(tree->t_fork_stack);
12460 }
12461 }
12462 {
12463 gint stack_length= FSTACK_LENGTH(tree->t_fork_stack);
12464 gint i;
12465 if(stack_length<=0)goto TREE_IS_EXHAUSTED;
12466 FSTACK_CLEAR(tree->t_fork_worklist);
12467 for(i= 0;i<stack_length;i++){
12468 *(FSTACK_PUSH(tree->t_fork_worklist))= i;
12469 }
12470 }
12471 }
12472 
12473 /*:1151*/
12474 #line 10945 "./marpa.w"
12475 
12476 }
12477 first_tree_of_series= 0;
12478 /*1152:*/
12479 #line 11069 "./marpa.w"
12480 {
12481 while(1){
12482 FORKID*p_work_fork_id;
12483 FORK work_fork;
12484 ANDID work_and_node_id;
12485 AND work_and_node;
12486 OR work_or_node;
12487 OR child_or_node= NULL;
12488 gint choice;
12489 gint child_is_cause= 0;
12490 gint child_is_predecessor= 0;
12491 p_work_fork_id= FSTACK_TOP(tree->t_fork_worklist,FORKID);
12492 if(!p_work_fork_id){
12493 goto TREE_IS_FINISHED;
12494 }
12495 work_fork= FORK_of_TREE_by_IX(tree,*p_work_fork_id);
12496 work_or_node= OR_of_FORK(work_fork);
12497 work_and_node_id= and_order_get(b,work_or_node,Choice_of_FORK(work_fork));
12498 work_and_node= ands_of_b+work_and_node_id;
12499 if(!FORK_Cause_is_Ready(work_fork)){
12500 child_or_node= Cause_OR_of_AND(work_and_node);
12501 if(child_or_node&&OR_is_Token(child_or_node))child_or_node= NULL;
12502 if(child_or_node){
12503 child_is_cause= 1;
12504 }else{
12505 FORK_Cause_is_Ready(work_fork)= 1;
12506 }
12507 }
12508 if(!child_or_node&&!FORK_Predecessor_is_Ready(work_fork)){
12509 child_or_node= Predecessor_OR_of_AND(work_and_node);
12510 if(child_or_node){
12511 child_is_predecessor= 1;
12512 }else{
12513 FORK_Predecessor_is_Ready(work_fork)= 1;
12514 }
12515 }
12516 if(!child_or_node){
12517 FSTACK_POP(tree->t_fork_worklist);
12518 goto NEXT_FORK_ON_WORKLIST;
12519 }
12520 choice= or_node_next_choice(b,tree,child_or_node,0);
12521 if(choice<0)goto NEXT_TREE;
12522 /*1155:*/
12523 #line 11132 "./marpa.w"
12524 
12525 {
12526 FORKID new_fork_id= FSTACK_LENGTH(tree->t_fork_stack);
12527 FORK new_fork= FSTACK_PUSH(tree->t_fork_stack);
12528 *(FSTACK_PUSH(tree->t_fork_worklist))= new_fork_id;
12529 Parent_of_FORK(new_fork)= *p_work_fork_id;
12530 Choice_of_FORK(new_fork)= choice;
12531 OR_of_FORK(new_fork)= child_or_node;
12532 FORK_Cause_is_Ready(new_fork)= 0;
12533 if((FORK_is_Cause(new_fork)= child_is_cause)){
12534 FORK_Cause_is_Ready(work_fork)= 1;
12535 }
12536 FORK_Predecessor_is_Ready(new_fork)= 0;
12537 if((FORK_is_Predecessor(new_fork)= child_is_predecessor)){
12538 FORK_Predecessor_is_Ready(work_fork)= 1;
12539 }
12540 }
12541 
12542 /*:1155*/
12543 #line 11111 "./marpa.w"
12544 ;
12545 NEXT_FORK_ON_WORKLIST:;
12546 }
12547 NEXT_TREE:;
12548 }
12549 
12550 /*:1152*/
12551 #line 10948 "./marpa.w"
12552 
12553 }
12554 TREE_IS_FINISHED:;
12555 tree->t_parse_count++;
12556 return FSTACK_LENGTH(tree->t_fork_stack);
12557 TREE_IS_EXHAUSTED:;
12558 tree_exhaust(tree);
12559 return-1;
12560 }
12561 
12562 /*:1145*//*1147:*/
12563 #line 10967 "./marpa.w"
12564 
tree_and_node_claim(TREE tree,ANDID and_node_id)12565 static inline void tree_and_node_claim(TREE tree,ANDID and_node_id)
12566 {
12567 bv_bit_set(tree->t_and_node_in_use,(guint)and_node_id);
12568 }
12569 /*:1147*//*1148:*/
12570 #line 10973 "./marpa.w"
12571 
tree_and_node_release(TREE tree,ANDID and_node_id)12572 static inline void tree_and_node_release(TREE tree,ANDID and_node_id)
12573 {
12574 bv_bit_clear(tree->t_and_node_in_use,(guint)and_node_id);
12575 }
12576 /*:1148*//*1149:*/
12577 #line 10981 "./marpa.w"
12578 
tree_and_node_try(TREE tree,ANDID and_node_id)12579 static inline gint tree_and_node_try(TREE tree,ANDID and_node_id)
12580 {
12581 return!bv_bit_test_and_set(tree->t_and_node_in_use,(guint)and_node_id);
12582 }
12583 
12584 /*:1149*//*1154:*/
12585 #line 11119 "./marpa.w"
12586 
or_node_next_choice(BOC b,TREE tree,OR or_node,gint start_choice)12587 static inline gint or_node_next_choice(BOC b,TREE tree,OR or_node,gint start_choice)
12588 {
12589 gint choice= start_choice;
12590 while(1){
12591 ANDID and_node_id= and_order_get(b,or_node,choice);
12592 if(and_node_id<0)return-1;
12593 if(tree_and_node_try(tree,and_node_id))return choice;
12594 choice++;
12595 }
12596 return-1;
12597 }
12598 
12599 /*:1154*//*1158:*/
12600 #line 11161 "./marpa.w"
12601 
tree_destroy(TREE tree)12602 static inline void tree_destroy(TREE tree)
12603 {
12604 tree_exhaust(tree);
12605 tree->t_parse_count= -1;
12606 MARPA_DEBUG4("%s tree=%p parse_count=%d",G_STRLOC,tree,tree->t_parse_count);
12607 }
12608 
12609 /*:1158*//*1160:*/
12610 #line 11173 "./marpa.w"
12611 
marpa_parse_count(struct marpa_r * r)12612 gint marpa_parse_count(struct marpa_r*r)
12613 {
12614 BOC b;
12615 TREE tree;
12616 /*1357:*/
12617 #line 13088 "./marpa.w"
12618 const int failure_indicator= -2;
12619 
12620 /*:1357*/
12621 #line 11178 "./marpa.w"
12622 
12623 /*1371:*/
12624 #line 13178 "./marpa.w"
12625 
12626 if(Phase_of_R(r)==error_phase){
12627 R_ERROR(r->t_fatal_error);
12628 return failure_indicator;
12629 }
12630 /*:1371*/
12631 #line 11179 "./marpa.w"
12632 
12633 b= B_of_R(r);
12634 if(!b){
12635 return-1;
12636 }
12637 tree= TREE_of_RANK(RANK_of_B(b));
12638 MARPA_DEBUG3("%s b=%p",G_STRLOC,b);
12639 MARPA_DEBUG4("%s tree=%p parse_count=%d",G_STRLOC,tree,tree->t_parse_count);
12640 return tree->t_parse_count;
12641 }
12642 
12643 /*:1160*//*1162:*/
12644 #line 11197 "./marpa.w"
12645 
marpa_tree_size(struct marpa_r * r)12646 gint marpa_tree_size(struct marpa_r*r)
12647 {
12648 /*1357:*/
12649 #line 13088 "./marpa.w"
12650 const int failure_indicator= -2;
12651 
12652 /*:1357*/
12653 #line 11200 "./marpa.w"
12654 
12655 BOC b= B_of_R(r);
12656 TREE tree;
12657 /*1371:*/
12658 #line 13178 "./marpa.w"
12659 
12660 if(Phase_of_R(r)==error_phase){
12661 R_ERROR(r->t_fatal_error);
12662 return failure_indicator;
12663 }
12664 /*:1371*/
12665 #line 11203 "./marpa.w"
12666 
12667 if(!b){
12668 R_ERROR("no bocage");
12669 return failure_indicator;
12670 }
12671 tree= TREE_of_RANK(RANK_of_B(b));
12672 if(!TREE_is_Initialized(tree)){
12673 R_ERROR("tree not initialized");
12674 return failure_indicator;
12675 }
12676 if(TREE_is_Exhausted(tree)){
12677 return-1;
12678 }
12679 return FSTACK_LENGTH(tree->t_fork_stack);
12680 }
12681 
12682 /*:1162*//*1168:*/
12683 #line 11248 "./marpa.w"
12684 
rank_safe(RANK rank)12685 static inline void rank_safe(RANK rank)
12686 {
12687 rank->t_and_node_in_use= NULL;
12688 rank->t_and_node_orderings= NULL;
12689 tree_safe(TREE_of_RANK(rank));
12690 }
12691 
12692 /*:1168*//*1171:*/
12693 #line 11261 "./marpa.w"
12694 
rank_freeze(RANK rank)12695 static inline void rank_freeze(RANK rank)
12696 {
12697 if(rank->t_and_node_in_use)
12698 {
12699 bv_free(rank->t_and_node_in_use);
12700 rank->t_and_node_in_use= NULL;
12701 }
12702 }
rank_destroy(RANK rank)12703 static inline void rank_destroy(RANK rank)
12704 {
12705 tree_destroy(TREE_of_RANK(rank));
12706 rank_freeze(rank);
12707 if(rank->t_and_node_orderings){
12708 rank->t_and_node_orderings= NULL;
12709 obstack_free(&OBS_of_RANK(rank),NULL);
12710 }
12711 }
12712 
12713 /*:1171*//*1176:*/
12714 #line 11337 "./marpa.w"
12715 
marpa_and_order_set(struct marpa_r * r,Marpa_Or_Node_ID or_node_id,Marpa_And_Node_ID * and_node_ids,gint length)12716 gint marpa_and_order_set(struct marpa_r*r,
12717 Marpa_Or_Node_ID or_node_id,
12718 Marpa_And_Node_ID*and_node_ids,
12719 gint length)
12720 {
12721 OR or_node;
12722 RANK rank;
12723 /*1357:*/
12724 #line 13088 "./marpa.w"
12725 const int failure_indicator= -2;
12726 
12727 /*:1357*/
12728 #line 11345 "./marpa.w"
12729 
12730 /*1123:*/
12731 #line 10740 "./marpa.w"
12732 {
12733 BOC b= B_of_R(r);
12734 OR*or_nodes;
12735 /*1371:*/
12736 #line 13178 "./marpa.w"
12737 
12738 if(Phase_of_R(r)==error_phase){
12739 R_ERROR(r->t_fatal_error);
12740 return failure_indicator;
12741 }
12742 /*:1371*/
12743 #line 10743 "./marpa.w"
12744 
12745 if(!b){
12746 R_ERROR("no bocage");
12747 return failure_indicator;
12748 }
12749 or_nodes= ORs_of_B(b);
12750 if(!or_nodes){
12751 R_ERROR("no or nodes");
12752 return failure_indicator;
12753 }
12754 if(or_node_id<0){
12755 R_ERROR("bad or node id");
12756 return failure_indicator;
12757 }
12758 if(or_node_id>=OR_Count_of_B(b)){
12759 return-1;
12760 }
12761 or_node= or_nodes[or_node_id];
12762 }
12763 
12764 /*:1123*/
12765 #line 11346 "./marpa.w"
12766 
12767 {BOC b= B_of_R(r);
12768 ANDID**and_node_orderings;
12769 Bit_Vector and_node_in_use;
12770 struct obstack*obs;
12771 ANDID first_and_node_id;
12772 ANDID and_count_of_or;
12773 if(!b){
12774 R_ERROR("no bocage");
12775 return failure_indicator;
12776 }
12777 rank= RANK_of_B(b);
12778 and_node_orderings= rank->t_and_node_orderings;
12779 and_node_in_use= rank->t_and_node_in_use;
12780 obs= &OBS_of_RANK(rank);
12781 if(and_node_orderings&&!and_node_in_use)
12782 {
12783 R_ERROR("ranker frozen");
12784 return failure_indicator;
12785 }
12786 if(!and_node_orderings)
12787 {
12788 gint and_id;
12789 const gint and_count_of_r= AND_Count_of_B(b);
12790 obstack_init(obs);
12791 rank->t_and_node_orderings=
12792 and_node_orderings=
12793 obstack_alloc(obs,sizeof(ANDID*)*and_count_of_r);
12794 for(and_id= 0;and_id<and_count_of_r;and_id++)
12795 {
12796 and_node_orderings[and_id]= (ANDID*)NULL;
12797 }
12798 rank->t_and_node_in_use=
12799 and_node_in_use= bv_create((guint)and_count_of_r);
12800 }
12801 first_and_node_id= First_ANDID_of_OR(or_node);
12802 and_count_of_or= AND_Count_of_OR(or_node);
12803 {
12804 gint and_ix;
12805 for(and_ix= 0;and_ix<length;and_ix++)
12806 {
12807 ANDID and_node_id= and_node_ids[and_ix];
12808 if(and_node_id<first_and_node_id||
12809 and_node_id-first_and_node_id>=and_count_of_or){
12810 R_ERROR("and node not in or node");
12811 return failure_indicator;
12812 }
12813 if(bv_bit_test(and_node_in_use,(guint)and_node_id))
12814 {
12815 R_ERROR("dup and node");
12816 return failure_indicator;
12817 }
12818 bv_bit_set(and_node_in_use,(guint)and_node_id);
12819 }
12820 }
12821 if(and_node_orderings[or_node_id]){
12822 R_ERROR("or node already ordered");
12823 return failure_indicator;
12824 }
12825 {
12826 ANDID*orderings= obstack_alloc(obs,sizeof(ANDID)*(length+1));
12827 gint i;
12828 and_node_orderings[or_node_id]= orderings;
12829 *orderings++= length;
12830 for(i= 0;i<length;i++)
12831 {
12832 *orderings++= and_node_ids[i];
12833 }
12834 }
12835 }
12836 return 1;
12837 }
12838 
12839 /*:1176*//*1180:*/
12840 #line 11424 "./marpa.w"
12841 
and_order_get(BOC b,OR or_node,gint ix)12842 static inline ANDID and_order_get(BOC b,OR or_node,gint ix)
12843 {
12844 RANK rank;
12845 ANDID**and_node_orderings;
12846 if(ix>=AND_Count_of_OR(or_node))
12847 {
12848 return-1;
12849 }
12850 rank= RANK_of_B(b);
12851 and_node_orderings= rank->t_and_node_orderings;
12852 if(and_node_orderings)
12853 {
12854 ORID or_node_id= ID_of_OR(or_node);
12855 ANDID*ordering= and_node_orderings[or_node_id];
12856 if(ordering)
12857 {
12858 gint length= ordering[0];
12859 if(ix>=length)
12860 return-1;
12861 return ordering[1+ix];
12862 }
12863 }
12864 return First_ANDID_of_OR(or_node)+ix;
12865 }
12866 
marpa_and_order_get(struct marpa_r * r,Marpa_Or_Node_ID or_node_id,gint ix)12867 Marpa_And_Node_ID marpa_and_order_get(struct marpa_r*r,Marpa_Or_Node_ID or_node_id,gint ix)
12868 {
12869 OR or_node;
12870 /*1357:*/
12871 #line 13088 "./marpa.w"
12872 const int failure_indicator= -2;
12873 
12874 /*:1357*/
12875 #line 11453 "./marpa.w"
12876 
12877 /*1123:*/
12878 #line 10740 "./marpa.w"
12879 {
12880 BOC b= B_of_R(r);
12881 OR*or_nodes;
12882 /*1371:*/
12883 #line 13178 "./marpa.w"
12884 
12885 if(Phase_of_R(r)==error_phase){
12886 R_ERROR(r->t_fatal_error);
12887 return failure_indicator;
12888 }
12889 /*:1371*/
12890 #line 10743 "./marpa.w"
12891 
12892 if(!b){
12893 R_ERROR("no bocage");
12894 return failure_indicator;
12895 }
12896 or_nodes= ORs_of_B(b);
12897 if(!or_nodes){
12898 R_ERROR("no or nodes");
12899 return failure_indicator;
12900 }
12901 if(or_node_id<0){
12902 R_ERROR("bad or node id");
12903 return failure_indicator;
12904 }
12905 if(or_node_id>=OR_Count_of_B(b)){
12906 return-1;
12907 }
12908 or_node= or_nodes[or_node_id];
12909 }
12910 
12911 /*:1123*/
12912 #line 11454 "./marpa.w"
12913 
12914 if(ix<0){
12915 R_ERROR("negative and ix");
12916 return failure_indicator;
12917 }
12918 {
12919 BOC b= B_of_R(r);
12920 if(!b)
12921 {
12922 R_ERROR("no bocage");
12923 return failure_indicator;
12924 }
12925 return and_order_get(b,or_node,ix);
12926 }
12927 }
12928 
12929 /*:1180*//*1188:*/
12930 #line 11544 "./marpa.w"
12931 
marpa_fork_or_node(struct marpa_r * r,int fork_id)12932 gint marpa_fork_or_node(struct marpa_r*r,int fork_id)
12933 {
12934 FORK fork;
12935 /*1357:*/
12936 #line 13088 "./marpa.w"
12937 const int failure_indicator= -2;
12938 
12939 /*:1357*/
12940 #line 11548 "./marpa.w"
12941 
12942 /*1186:*/
12943 #line 11512 "./marpa.w"
12944 {
12945 FORK base_fork;
12946 BOC b= B_of_R(r);
12947 TREE tree;
12948 /*1371:*/
12949 #line 13178 "./marpa.w"
12950 
12951 if(Phase_of_R(r)==error_phase){
12952 R_ERROR(r->t_fatal_error);
12953 return failure_indicator;
12954 }
12955 /*:1371*/
12956 #line 11516 "./marpa.w"
12957 
12958 if(!b){
12959 R_ERROR("no bocage");
12960 return failure_indicator;
12961 }
12962 tree= TREE_of_RANK(RANK_of_B(b));
12963 if(!TREE_is_Initialized(tree)){
12964 R_ERROR("tree not initialized");
12965 return failure_indicator;
12966 }
12967 if(TREE_is_Exhausted(tree)){
12968 R_ERROR("bocage iteration exhausted");
12969 return failure_indicator;
12970 }
12971 base_fork= FSTACK_BASE(tree->t_fork_stack,FORK_Object);
12972 if(fork_id<0){
12973 R_ERROR("bad fork id");
12974 return failure_indicator;
12975 }
12976 if(fork_id>=FSTACK_LENGTH(tree->t_fork_stack)){
12977 return-1;
12978 }
12979 fork= base_fork+fork_id;
12980 }
12981 
12982 /*:1186*/
12983 #line 11549 "./marpa.w"
12984 
12985 return ID_of_OR(OR_of_FORK(fork));
12986 }
12987 
12988 /*:1188*//*1190:*/
12989 #line 11556 "./marpa.w"
12990 
marpa_fork_choice(struct marpa_r * r,int fork_id)12991 gint marpa_fork_choice(struct marpa_r*r,int fork_id)
12992 {
12993 FORK fork;
12994 /*1357:*/
12995 #line 13088 "./marpa.w"
12996 const int failure_indicator= -2;
12997 
12998 /*:1357*/
12999 #line 11560 "./marpa.w"
13000 
13001 /*1186:*/
13002 #line 11512 "./marpa.w"
13003 {
13004 FORK base_fork;
13005 BOC b= B_of_R(r);
13006 TREE tree;
13007 /*1371:*/
13008 #line 13178 "./marpa.w"
13009 
13010 if(Phase_of_R(r)==error_phase){
13011 R_ERROR(r->t_fatal_error);
13012 return failure_indicator;
13013 }
13014 /*:1371*/
13015 #line 11516 "./marpa.w"
13016 
13017 if(!b){
13018 R_ERROR("no bocage");
13019 return failure_indicator;
13020 }
13021 tree= TREE_of_RANK(RANK_of_B(b));
13022 if(!TREE_is_Initialized(tree)){
13023 R_ERROR("tree not initialized");
13024 return failure_indicator;
13025 }
13026 if(TREE_is_Exhausted(tree)){
13027 R_ERROR("bocage iteration exhausted");
13028 return failure_indicator;
13029 }
13030 base_fork= FSTACK_BASE(tree->t_fork_stack,FORK_Object);
13031 if(fork_id<0){
13032 R_ERROR("bad fork id");
13033 return failure_indicator;
13034 }
13035 if(fork_id>=FSTACK_LENGTH(tree->t_fork_stack)){
13036 return-1;
13037 }
13038 fork= base_fork+fork_id;
13039 }
13040 
13041 /*:1186*/
13042 #line 11561 "./marpa.w"
13043 
13044 return Choice_of_FORK(fork);
13045 }
13046 
13047 /*:1190*//*1192:*/
13048 #line 11576 "./marpa.w"
13049 
marpa_fork_parent(struct marpa_r * r,int fork_id)13050 gint marpa_fork_parent(struct marpa_r*r,int fork_id)
13051 {
13052 FORK fork;
13053 /*1357:*/
13054 #line 13088 "./marpa.w"
13055 const int failure_indicator= -2;
13056 
13057 /*:1357*/
13058 #line 11580 "./marpa.w"
13059 
13060 /*1186:*/
13061 #line 11512 "./marpa.w"
13062 {
13063 FORK base_fork;
13064 BOC b= B_of_R(r);
13065 TREE tree;
13066 /*1371:*/
13067 #line 13178 "./marpa.w"
13068 
13069 if(Phase_of_R(r)==error_phase){
13070 R_ERROR(r->t_fatal_error);
13071 return failure_indicator;
13072 }
13073 /*:1371*/
13074 #line 11516 "./marpa.w"
13075 
13076 if(!b){
13077 R_ERROR("no bocage");
13078 return failure_indicator;
13079 }
13080 tree= TREE_of_RANK(RANK_of_B(b));
13081 if(!TREE_is_Initialized(tree)){
13082 R_ERROR("tree not initialized");
13083 return failure_indicator;
13084 }
13085 if(TREE_is_Exhausted(tree)){
13086 R_ERROR("bocage iteration exhausted");
13087 return failure_indicator;
13088 }
13089 base_fork= FSTACK_BASE(tree->t_fork_stack,FORK_Object);
13090 if(fork_id<0){
13091 R_ERROR("bad fork id");
13092 return failure_indicator;
13093 }
13094 if(fork_id>=FSTACK_LENGTH(tree->t_fork_stack)){
13095 return-1;
13096 }
13097 fork= base_fork+fork_id;
13098 }
13099 
13100 /*:1186*/
13101 #line 11581 "./marpa.w"
13102 
13103 return Parent_of_FORK(fork);
13104 }
13105 
13106 /*:1192*//*1194:*/
13107 #line 11588 "./marpa.w"
13108 
marpa_fork_cause_is_ready(struct marpa_r * r,int fork_id)13109 gint marpa_fork_cause_is_ready(struct marpa_r*r,int fork_id)
13110 {
13111 FORK fork;
13112 /*1357:*/
13113 #line 13088 "./marpa.w"
13114 const int failure_indicator= -2;
13115 
13116 /*:1357*/
13117 #line 11592 "./marpa.w"
13118 
13119 /*1186:*/
13120 #line 11512 "./marpa.w"
13121 {
13122 FORK base_fork;
13123 BOC b= B_of_R(r);
13124 TREE tree;
13125 /*1371:*/
13126 #line 13178 "./marpa.w"
13127 
13128 if(Phase_of_R(r)==error_phase){
13129 R_ERROR(r->t_fatal_error);
13130 return failure_indicator;
13131 }
13132 /*:1371*/
13133 #line 11516 "./marpa.w"
13134 
13135 if(!b){
13136 R_ERROR("no bocage");
13137 return failure_indicator;
13138 }
13139 tree= TREE_of_RANK(RANK_of_B(b));
13140 if(!TREE_is_Initialized(tree)){
13141 R_ERROR("tree not initialized");
13142 return failure_indicator;
13143 }
13144 if(TREE_is_Exhausted(tree)){
13145 R_ERROR("bocage iteration exhausted");
13146 return failure_indicator;
13147 }
13148 base_fork= FSTACK_BASE(tree->t_fork_stack,FORK_Object);
13149 if(fork_id<0){
13150 R_ERROR("bad fork id");
13151 return failure_indicator;
13152 }
13153 if(fork_id>=FSTACK_LENGTH(tree->t_fork_stack)){
13154 return-1;
13155 }
13156 fork= base_fork+fork_id;
13157 }
13158 
13159 /*:1186*/
13160 #line 11593 "./marpa.w"
13161 
13162 return FORK_Cause_is_Ready(fork);
13163 }
13164 
13165 /*:1194*//*1196:*/
13166 #line 11600 "./marpa.w"
13167 
marpa_fork_predecessor_is_ready(struct marpa_r * r,int fork_id)13168 gint marpa_fork_predecessor_is_ready(struct marpa_r*r,int fork_id)
13169 {
13170 FORK fork;
13171 /*1357:*/
13172 #line 13088 "./marpa.w"
13173 const int failure_indicator= -2;
13174 
13175 /*:1357*/
13176 #line 11604 "./marpa.w"
13177 
13178 /*1186:*/
13179 #line 11512 "./marpa.w"
13180 {
13181 FORK base_fork;
13182 BOC b= B_of_R(r);
13183 TREE tree;
13184 /*1371:*/
13185 #line 13178 "./marpa.w"
13186 
13187 if(Phase_of_R(r)==error_phase){
13188 R_ERROR(r->t_fatal_error);
13189 return failure_indicator;
13190 }
13191 /*:1371*/
13192 #line 11516 "./marpa.w"
13193 
13194 if(!b){
13195 R_ERROR("no bocage");
13196 return failure_indicator;
13197 }
13198 tree= TREE_of_RANK(RANK_of_B(b));
13199 if(!TREE_is_Initialized(tree)){
13200 R_ERROR("tree not initialized");
13201 return failure_indicator;
13202 }
13203 if(TREE_is_Exhausted(tree)){
13204 R_ERROR("bocage iteration exhausted");
13205 return failure_indicator;
13206 }
13207 base_fork= FSTACK_BASE(tree->t_fork_stack,FORK_Object);
13208 if(fork_id<0){
13209 R_ERROR("bad fork id");
13210 return failure_indicator;
13211 }
13212 if(fork_id>=FSTACK_LENGTH(tree->t_fork_stack)){
13213 return-1;
13214 }
13215 fork= base_fork+fork_id;
13216 }
13217 
13218 /*:1186*/
13219 #line 11605 "./marpa.w"
13220 
13221 return FORK_Predecessor_is_Ready(fork);
13222 }
13223 
13224 /*:1196*//*1198:*/
13225 #line 11612 "./marpa.w"
13226 
marpa_fork_is_cause(struct marpa_r * r,int fork_id)13227 gint marpa_fork_is_cause(struct marpa_r*r,int fork_id)
13228 {
13229 FORK fork;
13230 /*1357:*/
13231 #line 13088 "./marpa.w"
13232 const int failure_indicator= -2;
13233 
13234 /*:1357*/
13235 #line 11616 "./marpa.w"
13236 
13237 /*1186:*/
13238 #line 11512 "./marpa.w"
13239 {
13240 FORK base_fork;
13241 BOC b= B_of_R(r);
13242 TREE tree;
13243 /*1371:*/
13244 #line 13178 "./marpa.w"
13245 
13246 if(Phase_of_R(r)==error_phase){
13247 R_ERROR(r->t_fatal_error);
13248 return failure_indicator;
13249 }
13250 /*:1371*/
13251 #line 11516 "./marpa.w"
13252 
13253 if(!b){
13254 R_ERROR("no bocage");
13255 return failure_indicator;
13256 }
13257 tree= TREE_of_RANK(RANK_of_B(b));
13258 if(!TREE_is_Initialized(tree)){
13259 R_ERROR("tree not initialized");
13260 return failure_indicator;
13261 }
13262 if(TREE_is_Exhausted(tree)){
13263 R_ERROR("bocage iteration exhausted");
13264 return failure_indicator;
13265 }
13266 base_fork= FSTACK_BASE(tree->t_fork_stack,FORK_Object);
13267 if(fork_id<0){
13268 R_ERROR("bad fork id");
13269 return failure_indicator;
13270 }
13271 if(fork_id>=FSTACK_LENGTH(tree->t_fork_stack)){
13272 return-1;
13273 }
13274 fork= base_fork+fork_id;
13275 }
13276 
13277 /*:1186*/
13278 #line 11617 "./marpa.w"
13279 
13280 return FORK_is_Cause(fork);
13281 }
13282 
13283 /*:1198*//*1200:*/
13284 #line 11624 "./marpa.w"
13285 
marpa_fork_is_predecessor(struct marpa_r * r,int fork_id)13286 gint marpa_fork_is_predecessor(struct marpa_r*r,int fork_id)
13287 {
13288 FORK fork;
13289 /*1357:*/
13290 #line 13088 "./marpa.w"
13291 const int failure_indicator= -2;
13292 
13293 /*:1357*/
13294 #line 11628 "./marpa.w"
13295 
13296 /*1186:*/
13297 #line 11512 "./marpa.w"
13298 {
13299 FORK base_fork;
13300 BOC b= B_of_R(r);
13301 TREE tree;
13302 /*1371:*/
13303 #line 13178 "./marpa.w"
13304 
13305 if(Phase_of_R(r)==error_phase){
13306 R_ERROR(r->t_fatal_error);
13307 return failure_indicator;
13308 }
13309 /*:1371*/
13310 #line 11516 "./marpa.w"
13311 
13312 if(!b){
13313 R_ERROR("no bocage");
13314 return failure_indicator;
13315 }
13316 tree= TREE_of_RANK(RANK_of_B(b));
13317 if(!TREE_is_Initialized(tree)){
13318 R_ERROR("tree not initialized");
13319 return failure_indicator;
13320 }
13321 if(TREE_is_Exhausted(tree)){
13322 R_ERROR("bocage iteration exhausted");
13323 return failure_indicator;
13324 }
13325 base_fork= FSTACK_BASE(tree->t_fork_stack,FORK_Object);
13326 if(fork_id<0){
13327 R_ERROR("bad fork id");
13328 return failure_indicator;
13329 }
13330 if(fork_id>=FSTACK_LENGTH(tree->t_fork_stack)){
13331 return-1;
13332 }
13333 fork= base_fork+fork_id;
13334 }
13335 
13336 /*:1186*/
13337 #line 11629 "./marpa.w"
13338 
13339 return FORK_is_Predecessor(fork);
13340 }
13341 
13342 /*:1200*//*1207:*/
13343 #line 11697 "./marpa.w"
13344 
val_safe(VAL val)13345 static inline void val_safe(VAL val)
13346 {
13347 DSTACK_SAFE(val->t_virtual_stack);
13348 VAL_is_Active(val)= 0;
13349 VAL_is_Trace(val)= 0;
13350 TOS_of_VAL(val)= -1;
13351 FORK_of_VAL(val)= -1;
13352 }
13353 
13354 /*:1207*//*1211:*/
13355 #line 11748 "./marpa.w"
13356 
marpa_val_new(struct marpa_r * r)13357 int marpa_val_new(struct marpa_r*r)
13358 {
13359 BOC b;
13360 TREE tree;
13361 /*1357:*/
13362 #line 13088 "./marpa.w"
13363 const int failure_indicator= -2;
13364 
13365 /*:1357*/
13366 #line 11753 "./marpa.w"
13367 
13368 /*1371:*/
13369 #line 13178 "./marpa.w"
13370 
13371 if(Phase_of_R(r)==error_phase){
13372 R_ERROR(r->t_fatal_error);
13373 return failure_indicator;
13374 }
13375 /*:1371*/
13376 #line 11754 "./marpa.w"
13377 
13378 /*1156:*/
13379 #line 11150 "./marpa.w"
13380 
13381 {
13382 b= B_of_R(r);
13383 if(!b){
13384 R_ERROR("no bocage");
13385 return failure_indicator;
13386 }
13387 }
13388 
13389 /*:1156*/
13390 #line 11755 "./marpa.w"
13391 
13392 tree= TREE_of_RANK(RANK_of_B(b));
13393 if(TREE_is_Exhausted(tree)){
13394 return-1;
13395 }
13396 if(!TREE_is_Initialized(tree))
13397 {
13398 R_ERROR("tree not initialized");
13399 return failure_indicator;
13400 }
13401 {
13402 VAL val= VAL_of_TREE(tree);
13403 const gint minimum_stack_size= (8192/sizeof(gint));
13404 const gint initial_stack_size=
13405 MAX(Size_of_TREE(tree)/1024,minimum_stack_size);
13406 val_destroy(val);
13407 DSTACK_INIT(VStack_of_VAL(val),gint,initial_stack_size);
13408 VAL_is_Active(val)= 1;
13409 }
13410 return 1;
13411 }
13412 
13413 /*:1211*//*1213:*/
13414 #line 11779 "./marpa.w"
13415 
val_destroy(VAL val)13416 static inline void val_destroy(VAL val)
13417 {
13418 
13419 if(DSTACK_IS_INITIALIZED(val->t_virtual_stack))
13420 {
13421 DSTACK_DESTROY(val->t_virtual_stack);
13422 DSTACK_SAFE(val->t_virtual_stack);
13423 }
13424 val_safe(val);
13425 }
13426 
13427 /*:1213*//*1216:*/
13428 #line 11807 "./marpa.w"
13429 
marpa_val_trace(struct marpa_r * r,gint flag)13430 gint marpa_val_trace(struct marpa_r*r,gint flag)
13431 {
13432 BOC b;
13433 TREE tree;
13434 VAL val;
13435 /*1357:*/
13436 #line 13088 "./marpa.w"
13437 const int failure_indicator= -2;
13438 
13439 /*:1357*/
13440 #line 11813 "./marpa.w"
13441 
13442 /*1214:*/
13443 #line 11792 "./marpa.w"
13444 {
13445 /*1371:*/
13446 #line 13178 "./marpa.w"
13447 
13448 if(Phase_of_R(r)==error_phase){
13449 R_ERROR(r->t_fatal_error);
13450 return failure_indicator;
13451 }
13452 /*:1371*/
13453 #line 11793 "./marpa.w"
13454 
13455 b= B_of_R(r);
13456 if(!b){
13457 return failure_indicator;
13458 }
13459 tree= TREE_of_RANK(RANK_of_B(b));
13460 val= VAL_of_TREE(tree);
13461 if(!VAL_is_Active(val)){
13462 return failure_indicator;
13463 }
13464 }
13465 
13466 /*:1214*/
13467 #line 11814 "./marpa.w"
13468 
13469 VAL_is_Trace(val)= flag;
13470 return 1;
13471 }
13472 
13473 /*:1216*//*1218:*/
13474 #line 11821 "./marpa.w"
13475 
marpa_val_fork(struct marpa_r * r)13476 Marpa_Fork_ID marpa_val_fork(struct marpa_r*r)
13477 {
13478 BOC b;
13479 TREE tree;
13480 VAL val;
13481 /*1357:*/
13482 #line 13088 "./marpa.w"
13483 const int failure_indicator= -2;
13484 
13485 /*:1357*/
13486 #line 11827 "./marpa.w"
13487 
13488 /*1214:*/
13489 #line 11792 "./marpa.w"
13490 {
13491 /*1371:*/
13492 #line 13178 "./marpa.w"
13493 
13494 if(Phase_of_R(r)==error_phase){
13495 R_ERROR(r->t_fatal_error);
13496 return failure_indicator;
13497 }
13498 /*:1371*/
13499 #line 11793 "./marpa.w"
13500 
13501 b= B_of_R(r);
13502 if(!b){
13503 return failure_indicator;
13504 }
13505 tree= TREE_of_RANK(RANK_of_B(b));
13506 val= VAL_of_TREE(tree);
13507 if(!VAL_is_Active(val)){
13508 return failure_indicator;
13509 }
13510 }
13511 
13512 /*:1214*/
13513 #line 11828 "./marpa.w"
13514 
13515 return FORK_of_VAL(val);
13516 }
13517 
13518 /*:1218*//*1220:*/
13519 #line 11834 "./marpa.w"
13520 
marpa_val_event(struct marpa_r * r,Marpa_Event * event)13521 Marpa_Fork_ID marpa_val_event(struct marpa_r*r,Marpa_Event*event)
13522 {
13523 BOC b;
13524 TREE tree;
13525 VAL val;
13526 AND and_nodes;
13527 gint semantic_rule_id= -1;
13528 gint token_id= -1;
13529 gpointer token_value= NULL;
13530 gint arg_0= -1;
13531 gint arg_n= -1;
13532 FORKID fork_ix;
13533 gint continue_with_next_fork;
13534 
13535 
13536 /*1357:*/
13537 #line 13088 "./marpa.w"
13538 const int failure_indicator= -2;
13539 
13540 /*:1357*/
13541 #line 11850 "./marpa.w"
13542 
13543 /*1214:*/
13544 #line 11792 "./marpa.w"
13545 {
13546 /*1371:*/
13547 #line 13178 "./marpa.w"
13548 
13549 if(Phase_of_R(r)==error_phase){
13550 R_ERROR(r->t_fatal_error);
13551 return failure_indicator;
13552 }
13553 /*:1371*/
13554 #line 11793 "./marpa.w"
13555 
13556 b= B_of_R(r);
13557 if(!b){
13558 return failure_indicator;
13559 }
13560 tree= TREE_of_RANK(RANK_of_B(b));
13561 val= VAL_of_TREE(tree);
13562 if(!VAL_is_Active(val)){
13563 return failure_indicator;
13564 }
13565 }
13566 
13567 /*:1214*/
13568 #line 11851 "./marpa.w"
13569 
13570 and_nodes= ANDs_of_B(b);
13571 
13572 arg_0= arg_n= TOS_of_VAL(val);
13573 fork_ix= FORK_of_VAL(val);
13574 if(fork_ix<0){
13575 fork_ix= Size_of_TREE(tree);
13576 }
13577 continue_with_next_fork= !VAL_is_Trace(val);
13578 
13579 while(1){
13580 OR or;
13581 RULE fork_rule;
13582 fork_ix--;
13583 if(fork_ix<0)goto RETURN_SOFT_ERROR;
13584 {
13585 ANDID and_node_id;
13586 AND and_node;
13587 const FORK fork= FORK_of_TREE_by_IX(tree,fork_ix);
13588 const gint choice= Choice_of_FORK(fork);
13589 or= OR_of_FORK(fork);
13590 and_node_id= and_order_get(b,or,choice);
13591 and_node= and_nodes+and_node_id;
13592 token_id= and_node_token(and_node,&token_value);
13593 }
13594 if(token_id>=0){
13595 arg_0= ++arg_n;
13596 continue_with_next_fork= 0;
13597 }
13598 fork_rule= RULE_of_OR(or);
13599 if(Position_of_OR(or)==Length_of_RULE(fork_rule)){
13600 gint virtual_rhs= RULE_is_Virtual_RHS(fork_rule);
13601 gint virtual_lhs= RULE_is_Virtual_LHS(fork_rule);
13602 gint real_symbol_count;
13603 const DSTACK virtual_stack= &VStack_of_VAL(val);
13604 if(virtual_lhs){
13605 real_symbol_count= Real_SYM_Count_of_RULE(fork_rule);
13606 if(virtual_rhs){
13607 *(DSTACK_TOP(*virtual_stack,gint))+= real_symbol_count;
13608 }else{
13609 *DSTACK_PUSH(*virtual_stack,gint)= real_symbol_count;
13610 }
13611 goto NEXT_FORK;
13612 }
13613 if(virtual_rhs){
13614 real_symbol_count= Real_SYM_Count_of_RULE(fork_rule);
13615 real_symbol_count+= *DSTACK_POP(*virtual_stack,gint);
13616 }else{
13617 real_symbol_count= Length_of_RULE(fork_rule);
13618 }
13619 arg_0= arg_n-real_symbol_count+1;
13620 semantic_rule_id=
13621 fork_rule->t_is_semantic_equivalent?
13622 fork_rule->t_original:ID_of_RULE(fork_rule);
13623 continue_with_next_fork= 0;
13624 }
13625 NEXT_FORK:;
13626 if(!continue_with_next_fork)break;
13627 }
13628 
13629 /*1221:*/
13630 #line 11920 "./marpa.w"
13631 
13632 {
13633 SYMID_of_EVE(event)= token_id;
13634 Value_of_EVE(event)= token_value;
13635 RULEID_of_EVE(event)= semantic_rule_id;
13636 TOS_of_VAL(val)= Arg0_of_EVE(event)= arg_0;
13637 FORK_of_VAL(val)= fork_ix;
13638 ArgN_of_EVE(event)= arg_n;
13639 }
13640 
13641 /*:1221*/
13642 #line 11911 "./marpa.w"
13643 
13644 return FORK_of_VAL(val);
13645 
13646 RETURN_SOFT_ERROR:;
13647 /*1221:*/
13648 #line 11920 "./marpa.w"
13649 
13650 {
13651 SYMID_of_EVE(event)= token_id;
13652 Value_of_EVE(event)= token_value;
13653 RULEID_of_EVE(event)= semantic_rule_id;
13654 TOS_of_VAL(val)= Arg0_of_EVE(event)= arg_0;
13655 FORK_of_VAL(val)= fork_ix;
13656 ArgN_of_EVE(event)= arg_n;
13657 }
13658 
13659 /*:1221*/
13660 #line 11915 "./marpa.w"
13661 
13662 return-1;
13663 
13664 }
13665 
13666 /*:1220*//*1224:*/
13667 #line 11954 "./marpa.w"
13668 
bv_bits_to_size(guint bits)13669 static inline guint bv_bits_to_size(guint bits)
13670 {
13671 return(bits+bv_modmask)/bv_wordbits;
13672 }
13673 /*:1224*//*1226:*/
13674 #line 11962 "./marpa.w"
13675 
bv_bits_to_unused_mask(guint bits)13676 static inline guint bv_bits_to_unused_mask(guint bits)
13677 {
13678 guint mask= bits&bv_modmask;
13679 if(mask)mask= (guint)~(~0uL<<mask);else mask= (guint)~0uL;
13680 return(mask);
13681 }
13682 /*:1226*//*1229:*/
13683 #line 11980 "./marpa.w"
13684 
bv_create(guint bits)13685 static inline Bit_Vector bv_create(guint bits)
13686 {
13687 guint size= bv_bits_to_size(bits);
13688 guint bytes= (size+bv_hiddenwords)<<sizeof(guint);
13689 guint*addr= (Bit_Vector)g_malloc0((size_t)bytes);
13690 *addr++= bits;
13691 *addr++= size;
13692 *addr++= bv_bits_to_unused_mask(bits);
13693 return addr;
13694 }
13695 
13696 /*:1229*//*1231:*/
13697 #line 12000 "./marpa.w"
13698 
13699 static inline Bit_Vector
bv_obs_create(struct obstack * obs,guint bits)13700 bv_obs_create(struct obstack*obs,guint bits)
13701 {
13702 guint size= bv_bits_to_size(bits);
13703 guint bytes= (size+bv_hiddenwords)<<sizeof(guint);
13704 guint*addr= (Bit_Vector)obstack_alloc(obs,(size_t)bytes);
13705 *addr++= bits;
13706 *addr++= size;
13707 *addr++= bv_bits_to_unused_mask(bits);
13708 if(size> 0){
13709 Bit_Vector bv= addr;
13710 while(size--)*bv++= 0u;
13711 }
13712 return addr;
13713 }
13714 
13715 
13716 /*:1231*//*1232:*/
13717 #line 12021 "./marpa.w"
13718 
bv_shadow(Bit_Vector bv)13719 static inline Bit_Vector bv_shadow(Bit_Vector bv)
13720 {
13721 return bv_create(BV_BITS(bv));
13722 }
13723 /*:1232*//*1234:*/
13724 #line 12033 "./marpa.w"
13725 static inline
bv_copy(Bit_Vector bv_to,Bit_Vector bv_from)13726 Bit_Vector bv_copy(Bit_Vector bv_to,Bit_Vector bv_from)
13727 {
13728 guint*p_to= bv_to;
13729 const guint bits= BV_BITS(bv_to);
13730 if(bits> 0)
13731 {
13732 gint count= BV_SIZE(bv_to);
13733 while(count--)*p_to++= *bv_from++;
13734 }
13735 return(bv_to);
13736 }
13737 /*:1234*//*1236:*/
13738 #line 12053 "./marpa.w"
13739 static inline
bv_clone(Bit_Vector bv)13740 Bit_Vector bv_clone(Bit_Vector bv)
13741 {
13742 return bv_copy(bv_shadow(bv),bv);
13743 }
13744 /*:1236*//*1238:*/
13745 #line 12063 "./marpa.w"
13746 
bv_free(Bit_Vector vector)13747 static inline void bv_free(Bit_Vector vector){
13748 vector-= bv_hiddenwords;
13749 g_free(vector);
13750 }
13751 /*:1238*//*1240:*/
13752 #line 12072 "./marpa.w"
13753 
bv_bytes(Bit_Vector bv)13754 static inline gint bv_bytes(Bit_Vector bv){
13755 return(BV_SIZE(bv)+bv_hiddenwords)*sizeof(Bit_Vector_Word);
13756 }
13757 /*:1240*//*1242:*/
13758 #line 12080 "./marpa.w"
13759 
bv_fill(Bit_Vector bv)13760 static inline void bv_fill(Bit_Vector bv)
13761 {
13762 guint size= BV_SIZE(bv);
13763 if(size<=0)return;
13764 while(size--)*bv++= ~0u;
13765 --bv;
13766 *bv&= BV_MASK(bv);
13767 }
13768 /*:1242*//*1246:*/
13769 #line 12095 "./marpa.w"
13770 
bv_clear(Bit_Vector bv)13771 static inline void bv_clear(Bit_Vector bv)
13772 {
13773 guint size= BV_SIZE(bv);
13774 if(size<=0)return;
13775 while(size--)*bv++= 0u;
13776 }
13777 
13778 /*:1246*//*1248:*/
13779 #line 12111 "./marpa.w"
13780 
bv_over_clear(Bit_Vector bv,guint bit)13781 static inline void bv_over_clear(Bit_Vector bv,guint bit)
13782 {
13783 guint length= bit/bv_wordbits+1;
13784 while(length--)*bv++= 0u;
13785 }
13786 
13787 /*:1248*//*1250:*/
13788 #line 12119 "./marpa.w"
13789 
bv_bit_set(Bit_Vector vector,guint bit)13790 static inline void bv_bit_set(Bit_Vector vector,guint bit){
13791 *(vector+(bit/bv_wordbits))|= (bv_lsb<<(bit%bv_wordbits));
13792 }
13793 /*:1250*//*1252:*/
13794 #line 12127 "./marpa.w"
13795 
bv_bit_clear(Bit_Vector vector,guint bit)13796 static inline void bv_bit_clear(Bit_Vector vector,guint bit){
13797 *(vector+(bit/bv_wordbits))&= ~(bv_lsb<<(bit%bv_wordbits));
13798 }
13799 /*:1252*//*1254:*/
13800 #line 12135 "./marpa.w"
13801 
bv_bit_test(Bit_Vector vector,guint bit)13802 static inline gboolean bv_bit_test(Bit_Vector vector,guint bit){
13803 return(*(vector+(bit/bv_wordbits))&(bv_lsb<<(bit%bv_wordbits)))!=0u;
13804 }
13805 /*:1254*//*1258:*/
13806 #line 12146 "./marpa.w"
13807 
13808 static inline gboolean
bv_bit_test_and_set(Bit_Vector vector,guint bit)13809 bv_bit_test_and_set(Bit_Vector vector,guint bit)
13810 {
13811 Bit_Vector addr= vector+(bit/bv_wordbits);
13812 guint mask= bv_lsb<<(bit%bv_wordbits);
13813 if((*addr&mask)!=0u)
13814 return 1;
13815 *addr|= mask;
13816 return 0;
13817 }
13818 
13819 /*:1258*//*1260:*/
13820 #line 12160 "./marpa.w"
13821 
13822 static inline
bv_is_empty(Bit_Vector addr)13823 gboolean bv_is_empty(Bit_Vector addr)
13824 {
13825 guint size= BV_SIZE(addr);
13826 gboolean r= TRUE;
13827 if(size> 0){
13828 *(addr+size-1)&= BV_MASK(addr);
13829 while(r&&(size--> 0))r= (*addr++==0);
13830 }
13831 return(r);
13832 }
13833 /*:1260*//*1262:*/
13834 #line 12177 "./marpa.w"
13835 
bv_not(Bit_Vector X,Bit_Vector Y)13836 static inline void bv_not(Bit_Vector X,Bit_Vector Y)
13837 {
13838 guint size= BV_SIZE(X);
13839 guint mask= BV_MASK(X);
13840 while(size--> 0)*X++= ~*Y++;
13841 *(--X)&= mask;
13842 }
13843 /*:1262*//*1264:*/
13844 #line 12189 "./marpa.w"
13845 
bv_and(Bit_Vector X,Bit_Vector Y,Bit_Vector Z)13846 static inline void bv_and(Bit_Vector X,Bit_Vector Y,Bit_Vector Z)
13847 {
13848 guint size= BV_SIZE(X);
13849 guint mask= BV_MASK(X);
13850 while(size--> 0)*X++= *Y++&*Z++;
13851 *(--X)&= mask;
13852 }
13853 /*:1264*//*1266:*/
13854 #line 12201 "./marpa.w"
13855 
bv_or(Bit_Vector X,Bit_Vector Y,Bit_Vector Z)13856 static inline void bv_or(Bit_Vector X,Bit_Vector Y,Bit_Vector Z)
13857 {
13858 guint size= BV_SIZE(X);
13859 guint mask= BV_MASK(X);
13860 while(size--> 0)*X++= *Y++|*Z++;
13861 *(--X)&= mask;
13862 }
13863 /*:1266*//*1268:*/
13864 #line 12213 "./marpa.w"
13865 
bv_or_assign(Bit_Vector X,Bit_Vector Y)13866 static inline void bv_or_assign(Bit_Vector X,Bit_Vector Y)
13867 {
13868 guint size= BV_SIZE(X);
13869 guint mask= BV_MASK(X);
13870 while(size--> 0)*X++|= *Y++;
13871 *(--X)&= mask;
13872 }
13873 /*:1268*//*1270:*/
13874 #line 12225 "./marpa.w"
13875 
13876 static inline
bv_scan(Bit_Vector bv,guint start,guint * min,guint * max)13877 gboolean bv_scan(Bit_Vector bv,guint start,
13878 guint*min,guint*max)
13879 {
13880 guint size= BV_SIZE(bv);
13881 guint mask= BV_MASK(bv);
13882 guint offset;
13883 guint bitmask;
13884 guint value;
13885 gboolean empty;
13886 
13887 if(size==0)return FALSE;
13888 if(start>=BV_BITS(bv))return FALSE;
13889 *min= start;
13890 *max= start;
13891 offset= start/bv_wordbits;
13892 *(bv+size-1)&= mask;
13893 bv+= offset;
13894 size-= offset;
13895 bitmask= (guint)1<<(start&bv_modmask);
13896 mask= ~(bitmask|(bitmask-(guint)1));
13897 value= *bv++;
13898 if((value&bitmask)==0)
13899 {
13900 value&= mask;
13901 if(value==0)
13902 {
13903 offset++;
13904 empty= TRUE;
13905 while(empty&&(--size> 0))
13906 {
13907 if((value= *bv++))empty= FALSE;else offset++;
13908 }
13909 if(empty)return FALSE;
13910 }
13911 start= offset*bv_wordbits;
13912 bitmask= bv_lsb;
13913 mask= value;
13914 while(!(mask&bv_lsb))
13915 {
13916 bitmask<<= 1;
13917 mask>>= 1;
13918 start++;
13919 }
13920 mask= ~(bitmask|(bitmask-1));
13921 *min= start;
13922 *max= start;
13923 }
13924 value= ~value;
13925 value&= mask;
13926 if(value==0)
13927 {
13928 offset++;
13929 empty= TRUE;
13930 while(empty&&(--size> 0))
13931 {
13932 if((value= ~*bv++))empty= FALSE;else offset++;
13933 }
13934 if(empty)value= bv_lsb;
13935 }
13936 start= offset*bv_wordbits;
13937 while(!(value&bv_lsb))
13938 {
13939 value>>= 1;
13940 start++;
13941 }
13942 *max= --start;
13943 return TRUE;
13944 }
13945 /*:1270*//*1272:*/
13946 #line 12301 "./marpa.w"
13947 
13948 static inline guint
bv_count(Bit_Vector v)13949 bv_count(Bit_Vector v)
13950 {
13951 guint start,min,max;
13952 guint count= 0;
13953 for(start= 0;bv_scan(v,start,&min,&max);start= max+2)
13954 {
13955 count+= max-min+1;
13956 }
13957 return count;
13958 }
13959 /*:1272*//*1278:*/
13960 #line 12355 "./marpa.w"
13961 
13962 static void
rhs_closure(struct marpa_g * g,Bit_Vector bv)13963 rhs_closure(struct marpa_g*g,Bit_Vector bv)
13964 {
13965 guint min,max,start= 0;
13966 Marpa_Symbol_ID*top_of_stack= NULL;
13967 FSTACK_DECLARE(stack,Marpa_Symbol_ID)
13968 FSTACK_INIT(stack,Marpa_Symbol_ID,SYM_Count_of_G(g));
13969 while(bv_scan(bv,start,&min,&max))
13970 {
13971 guint symid;
13972 for(symid= min;symid<=max;symid++)
13973 {
13974 *(FSTACK_PUSH(stack))= symid;
13975 }
13976 start= max+2;
13977 }
13978 while((top_of_stack= FSTACK_POP(stack)))
13979 {
13980 guint rule_ix;
13981 GArray*rules= SYM_by_ID(*top_of_stack)->t_rhs;
13982 for(rule_ix= 0;rule_ix<rules->len;rule_ix++)
13983 {
13984 Marpa_Rule_ID rule_id=
13985 g_array_index(rules,Marpa_Rule_ID,rule_ix);
13986 RULE rule= RULE_by_ID(g,rule_id);
13987 guint rule_length;
13988 guint rh_ix;
13989 Marpa_Symbol_ID lhs_id= LHS_ID_of_RULE(rule);
13990 if(bv_bit_test(bv,(guint)lhs_id))
13991 goto NEXT_RULE;
13992 rule_length= Length_of_RULE(rule);
13993 for(rh_ix= 0;rh_ix<rule_length;rh_ix++)
13994 {
13995 if(!bv_bit_test(bv,(guint)RHS_ID_of_RULE(rule,rh_ix)))
13996 goto NEXT_RULE;
13997 }
13998 
13999 
14000 
14001 bv_bit_set(bv,(guint)lhs_id);
14002 *(FSTACK_PUSH(stack))= lhs_id;
14003 NEXT_RULE:;
14004 }
14005 }
14006 FSTACK_DESTROY(stack);
14007 }
14008 /*:1278*//*1283:*/
14009 #line 12434 "./marpa.w"
14010 
matrix_create(guint rows,guint columns)14011 static inline Bit_Matrix matrix_create(guint rows,guint columns)
14012 {
14013 guint bv_data_words= bv_bits_to_size(columns);
14014 guint row_bytes= (bv_data_words+bv_hiddenwords)*sizeof(Bit_Vector_Word);
14015 guint bv_mask= bv_bits_to_unused_mask(columns);
14016 Bit_Vector_Word*matrix_addr= g_malloc0((size_t)(row_bytes*rows));
14017 guint row;
14018 for(row= 0;row<rows;row++){
14019 guint row_start= row*(bv_data_words+bv_hiddenwords);
14020 matrix_addr[row_start]= columns;
14021 matrix_addr[row_start+1]= bv_data_words;
14022 matrix_addr[row_start+2]= bv_mask;
14023 }
14024 return matrix_addr;
14025 }
14026 /*:1283*//*1285:*/
14027 #line 12454 "./marpa.w"
14028 
matrix_free(Bit_Matrix matrix)14029 static inline void matrix_free(Bit_Matrix matrix){
14030 g_free(matrix);
14031 }
14032 /*:1285*//*1287:*/
14033 #line 12467 "./marpa.w"
14034 
matrix_columns(Bit_Matrix matrix)14035 static inline gint matrix_columns(Bit_Matrix matrix){
14036 Bit_Vector row0= matrix+bv_hiddenwords;
14037 return BV_BITS(row0);
14038 }
14039 /*:1287*//*1289:*/
14040 #line 12484 "./marpa.w"
14041 
matrix_row(Bit_Matrix matrix,guint row)14042 static inline Bit_Vector matrix_row(Bit_Matrix matrix,guint row){
14043 Bit_Vector row0= matrix+bv_hiddenwords;
14044 guint words_per_row= BV_SIZE(row0)+bv_hiddenwords;
14045 return row0+row*words_per_row;
14046 }
14047 /*:1289*//*1292:*/
14048 #line 12494 "./marpa.w"
14049 
matrix_bit_set(Bit_Matrix matrix,guint row,guint column)14050 static inline void matrix_bit_set(Bit_Matrix matrix,guint row,guint column){
14051 Bit_Vector vector= matrix_row(matrix,row);
14052 bv_bit_set(vector,column);
14053 }
14054 /*:1292*//*1295:*/
14055 #line 12503 "./marpa.w"
14056 
matrix_bit_clear(Bit_Matrix matrix,guint row,guint column)14057 static inline void matrix_bit_clear(Bit_Matrix matrix,guint row,guint column){
14058 Bit_Vector vector= matrix_row(matrix,row);
14059 bv_bit_clear(vector,column);
14060 }
14061 /*:1295*//*1298:*/
14062 #line 12512 "./marpa.w"
14063 
matrix_bit_test(Bit_Matrix matrix,guint row,guint column)14064 static inline gboolean matrix_bit_test(Bit_Matrix matrix,guint row,guint column){
14065 Bit_Vector vector= matrix_row(matrix,row);
14066 return bv_bit_test(vector,column);
14067 }
14068 /*:1298*//*1300:*/
14069 #line 12526 "./marpa.w"
14070 
transitive_closure(Bit_Matrix matrix)14071 static void transitive_closure(Bit_Matrix matrix)
14072 {
14073 struct transition{guint from,to;}*top_of_stack= NULL;
14074 guint size= matrix_columns(matrix);
14075 guint row;
14076 DSTACK_DECLARE(stack);
14077 DSTACK_INIT(stack,struct transition,1024);
14078 for(row= 0;row<size;row++){
14079 guint min,max,start;
14080 Bit_Vector row_vector= matrix_row(matrix,row);
14081 for(start= 0;bv_scan(row_vector,start,&min,&max);start= max+2){
14082 guint column;
14083 for(column= min;column<=max;column++){
14084 struct transition*t= DSTACK_PUSH(stack,struct transition);
14085 t->from= row;
14086 t->to= column;
14087 }}}
14088 while((top_of_stack= DSTACK_POP(stack,struct transition))){
14089 guint old_from= top_of_stack->from;
14090 guint old_to= top_of_stack->to;
14091 guint new_ix;
14092 for(new_ix= 0;new_ix<size;new_ix++){
14093 
14094 
14095 
14096 if(!matrix_bit_test(matrix,new_ix,old_to)&&
14097 matrix_bit_test(matrix,new_ix,old_from)){
14098 struct transition*t= (DSTACK_PUSH(stack,struct transition));
14099 matrix_bit_set(matrix,new_ix,old_to);
14100 t->from= new_ix;
14101 t->to= old_to;
14102 }
14103 if(!matrix_bit_test(matrix,old_from,new_ix)&&
14104 matrix_bit_test(matrix,old_to,new_ix)){
14105 struct transition*t= (DSTACK_PUSH(stack,struct transition));
14106 matrix_bit_set(matrix,old_from,new_ix);
14107 t->from= old_from;
14108 t->to= new_ix;
14109 }
14110 }
14111 }
14112 DSTACK_DESTROY(stack);
14113 }
14114 /*:1300*//*1310:*/
14115 #line 12670 "./marpa.w"
14116 
dstack_resize(struct s_dstack * this,gsize type_bytes)14117 static inline gpointer dstack_resize(struct s_dstack*this,gsize type_bytes){
14118 this->t_capacity*= 2;
14119 this->t_base= g_realloc(this->t_base,this->t_capacity*type_bytes);
14120 return this->t_base;
14121 }
14122 /*:1310*//*1327:*/
14123 #line 12813 "./marpa.w"
14124 
14125 static inline void
psar_init(const PSAR psar,gint length)14126 psar_init(const PSAR psar,gint length)
14127 {
14128 psar->t_psl_length= length;
14129 psar->t_first_psl= psar->t_first_free_psl= psl_new(psar);
14130 }
14131 /*:1327*//*1328:*/
14132 #line 12820 "./marpa.w"
14133 
psar_destroy(const PSAR psar)14134 static inline void psar_destroy(const PSAR psar)
14135 {
14136 PSL psl= psar->t_first_psl;
14137 MARPA_OFF_DEBUG3("%s psl=%p",G_STRLOC,psl);
14138 while(psl)
14139 {
14140 PSL next_psl= psl->t_next;
14141 PSL*owner= psl->t_owner;
14142 MARPA_OFF_DEBUG3("%s owner=%p",G_STRLOC,owner);
14143 if(owner)
14144 *owner= NULL;
14145 g_slice_free1(Sizeof_PSL(psar),psl);
14146 psl= next_psl;
14147 MARPA_OFF_DEBUG3("%s psl=%p",G_STRLOC,psl);
14148 }
14149 }
14150 /*:1328*//*1329:*/
14151 #line 12837 "./marpa.w"
14152 
psl_new(const PSAR psar)14153 static inline PSL psl_new(const PSAR psar){
14154 gint i;
14155 PSL new_psl= g_slice_alloc(Sizeof_PSL(psar));
14156 new_psl->t_next= NULL;
14157 new_psl->t_prev= NULL;
14158 new_psl->t_owner= NULL;
14159 for(i= 0;i<psar->t_psl_length;i++){
14160 PSL_Datum(new_psl,i)= NULL;
14161 }
14162 return new_psl;
14163 }
14164 /*:1329*//*1333:*/
14165 #line 12869 "./marpa.w"
14166 
psar_reset(const PSAR psar)14167 static inline void psar_reset(const PSAR psar){
14168 PSL psl= psar->t_first_psl;
14169 while(psl&&psl->t_owner){
14170 gint i;
14171 for(i= 0;i<psar->t_psl_length;i++){
14172 PSL_Datum(psl,i)= NULL;
14173 }
14174 psl= psl->t_next;
14175 }
14176 psar_dealloc(psar);
14177 }
14178 
14179 /*:1333*//*1335:*/
14180 #line 12888 "./marpa.w"
14181 
psar_dealloc(const PSAR psar)14182 static inline void psar_dealloc(const PSAR psar){
14183 PSL psl= psar->t_first_psl;
14184 while(psl){
14185 PSL*owner= psl->t_owner;
14186 if(!owner)break;
14187 (*owner)= NULL;
14188 psl->t_owner= NULL;
14189 psl= psl->t_next;
14190 }
14191 psar->t_first_free_psl= psar->t_first_psl;
14192 }
14193 
14194 /*:1335*//*1337:*/
14195 #line 12910 "./marpa.w"
14196 
psl_claim(PSL * const psl_owner,const PSAR psar)14197 static inline void psl_claim(
14198 PSL*const psl_owner,const PSAR psar){
14199 PSL new_psl= psl_alloc(psar);
14200 (*psl_owner)= new_psl;
14201 new_psl->t_owner= psl_owner;
14202 }
14203 
14204 /*:1337*//*1341:*/
14205 #line 12935 "./marpa.w"
14206 
psl_alloc(const PSAR psar)14207 static inline PSL psl_alloc(const PSAR psar){
14208 PSL free_psl= psar->t_first_free_psl;
14209 PSL next_psl= free_psl->t_next;
14210 if(!next_psl){
14211 next_psl= free_psl->t_next= psl_new(psar);
14212 next_psl->t_prev= free_psl;
14213 }
14214 psar->t_first_free_psl= next_psl;
14215 return free_psl;
14216 }
14217 
14218 /*:1341*//*1377:*/
14219 #line 13242 "./marpa.w"
14220 
r_error(struct marpa_r * r,Marpa_Message_ID message,guint flags)14221 static void r_error(struct marpa_r*r,Marpa_Message_ID message,guint flags){
14222 if(!(flags&CONTEXT_FLAG))r_context_clear(r);
14223 r->t_error= message;
14224 if(flags&FATAL_FLAG)r->t_fatal_error= r->t_error;
14225 r_message(r,message);
14226 }
14227 
14228 /*:1377*//*1385:*/
14229 #line 13316 "./marpa.w"
14230 
marpa_g_message_callback_set(struct marpa_g * g,Marpa_G_Message_Callback * cb)14231 void marpa_g_message_callback_set(struct marpa_g*g,Marpa_G_Message_Callback*cb)
14232 {g->t_message_callback= cb;}
marpa_g_message_callback_arg_set(struct marpa_g * g,gpointer cb_arg)14233 void marpa_g_message_callback_arg_set(struct marpa_g*g,gpointer cb_arg)
14234 {g->t_message_callback_arg= cb_arg;}
marpa_g_message_callback_arg(struct marpa_g * g)14235 gpointer marpa_g_message_callback_arg(struct marpa_g*g)
14236 {return g->t_message_callback_arg;}
14237 /*:1385*//*1387:*/
14238 #line 13333 "./marpa.w"
14239 
grammar_message(struct marpa_g * g,Marpa_Message_ID id)14240 static inline void grammar_message(struct marpa_g*g,Marpa_Message_ID id)
14241 {Marpa_G_Message_Callback*cb= g->t_message_callback;
14242 if(cb){(*cb)(g,id);}}
14243 /*:1387*//*1393:*/
14244 #line 13353 "./marpa.w"
14245 
marpa_r_message_callback_set(struct marpa_r * r,Marpa_R_Message_Callback * cb)14246 void marpa_r_message_callback_set(struct marpa_r*r,Marpa_R_Message_Callback*cb)
14247 {r->t_message_callback= cb;}
marpa_r_message_callback_arg_set(struct marpa_r * r,gpointer cb_arg)14248 void marpa_r_message_callback_arg_set(struct marpa_r*r,gpointer cb_arg)
14249 {r->t_message_callback_arg= cb_arg;}
marpa_r_message_callback_arg(struct marpa_r * r)14250 gpointer marpa_r_message_callback_arg(struct marpa_r*r)
14251 {return Message_Callback_Arg_of_R(r);}
14252 /*:1393*//*1395:*/
14253 #line 13364 "./marpa.w"
14254 
r_message(struct marpa_r * r,Marpa_Message_ID id)14255 static inline void r_message(struct marpa_r*r,Marpa_Message_ID id)
14256 {Marpa_R_Message_Callback*cb= Message_Callback_of_R(r);
14257 if(cb){(*cb)(r,id);}}
14258 /*:1395*//*1399:*/
14259 #line 13417 "./marpa.w"
14260 
14261 #if MARPA_DEBUG
14262 PRIVATE_NOT_INLINE gchar*
eim_tag_safe(gchar * buffer,EIM eim)14263 eim_tag_safe(gchar*buffer,EIM eim)
14264 {
14265 sprintf(buffer,"S%d@%d-%d",
14266 AHFAID_of_EIM(eim),Origin_Earleme_of_EIM(eim),
14267 Earleme_of_EIM(eim));
14268 return buffer;
14269 }
14270 
14271 static char DEBUG_eim_tag_buffer[1000];
14272 PRIVATE_NOT_INLINE gchar*
eim_tag(EIM eim)14273 eim_tag(EIM eim)
14274 {
14275 return eim_tag_safe(DEBUG_eim_tag_buffer,eim);
14276 }
14277 #endif
14278 
14279 /*:1399*//*1401:*/
14280 #line 13446 "./marpa.w"
14281 
14282 #if MARPA_DEBUG
14283 PRIVATE_NOT_INLINE gchar*
lim_tag_safe(gchar * buffer,LIM lim)14284 lim_tag_safe(gchar*buffer,LIM lim)
14285 {
14286 sprintf(buffer,"L%d@%d",
14287 Postdot_SYMID_of_LIM(lim),Earleme_of_LIM(lim));
14288 return buffer;
14289 }
14290 
14291 static char DEBUG_lim_tag_buffer[1000];
14292 PRIVATE_NOT_INLINE gchar*
lim_tag(LIM lim)14293 lim_tag(LIM lim)
14294 {
14295 return lim_tag_safe(DEBUG_lim_tag_buffer,lim);
14296 }
14297 #endif
14298 
14299 /*:1401*//*1403:*/
14300 #line 13475 "./marpa.w"
14301 
14302 #if MARPA_DEBUG
14303 PRIVATE_NOT_INLINE const gchar*
or_tag_safe(gchar * buffer,OR or)14304 or_tag_safe(gchar*buffer,OR or)
14305 {
14306 if(!or)return"NULL";
14307 if(OR_is_Token(or))return"TOKEN";
14308 if(Type_of_OR(or)==DUMMY_OR_NODE)return"DUMMY";
14309 sprintf(buffer,"R%d:%d@%d-%d",
14310 ID_of_RULE(RULE_of_OR(or)),Position_of_OR(or),
14311 Origin_Ord_of_OR(or),
14312 ES_Ord_of_OR(or));
14313 return buffer;
14314 }
14315 
14316 static char DEBUG_or_tag_buffer[1000];
14317 PRIVATE_NOT_INLINE const gchar*
or_tag(OR or)14318 or_tag(OR or)
14319 {
14320 return or_tag_safe(DEBUG_or_tag_buffer,or);
14321 }
14322 #endif
14323 
14324 /*:1403*//*1405:*/
14325 #line 13510 "./marpa.w"
14326 
14327 #if MARPA_DEBUG
14328 PRIVATE_NOT_INLINE const gchar*
aim_tag_safe(gchar * buffer,AIM aim)14329 aim_tag_safe(gchar*buffer,AIM aim)
14330 {
14331 if(!aim)return"NULL";
14332 const gint aim_position= Position_of_AIM(aim);
14333 if(aim_position>=0){
14334 sprintf(buffer,"R%d@%d",RULEID_of_AIM(aim),Position_of_AIM(aim));
14335 }else{
14336 sprintf(buffer,"R%d@end",RULEID_of_AIM(aim));
14337 }
14338 return buffer;
14339 }
14340 
14341 static char DEBUG_aim_tag_buffer[1000];
14342 PRIVATE_NOT_INLINE const gchar*
aim_tag(AIM aim)14343 aim_tag(AIM aim)
14344 {
14345 return aim_tag_safe(DEBUG_aim_tag_buffer,aim);
14346 }
14347 #endif
14348 
14349 
14350 /*:1405*/
14351 #line 13592 "./marpa.w"
14352 
14353 
14354 /*:1411*/
14355