1*0a6a1f1dSLionel Sambuc /* $NetBSD: gen.c,v 1.11 2014/10/30 18:44:05 christos Exp $ */
2357f1050SThomas Veerman
3357f1050SThomas Veerman /* gen - actual generation (writing) of flex scanners */
4357f1050SThomas Veerman
5357f1050SThomas Veerman /* Copyright (c) 1990 The Regents of the University of California. */
6357f1050SThomas Veerman /* All rights reserved. */
7357f1050SThomas Veerman
8357f1050SThomas Veerman /* This code is derived from software contributed to Berkeley by */
9357f1050SThomas Veerman /* Vern Paxson. */
10357f1050SThomas Veerman
11357f1050SThomas Veerman /* The United States Government has rights in this work pursuant */
12357f1050SThomas Veerman /* to contract no. DE-AC03-76SF00098 between the United States */
13357f1050SThomas Veerman /* Department of Energy and the University of California. */
14357f1050SThomas Veerman
15357f1050SThomas Veerman /* This file is part of flex. */
16357f1050SThomas Veerman
17357f1050SThomas Veerman /* Redistribution and use in source and binary forms, with or without */
18357f1050SThomas Veerman /* modification, are permitted provided that the following conditions */
19357f1050SThomas Veerman /* are met: */
20357f1050SThomas Veerman
21357f1050SThomas Veerman /* 1. Redistributions of source code must retain the above copyright */
22357f1050SThomas Veerman /* notice, this list of conditions and the following disclaimer. */
23357f1050SThomas Veerman /* 2. Redistributions in binary form must reproduce the above copyright */
24357f1050SThomas Veerman /* notice, this list of conditions and the following disclaimer in the */
25357f1050SThomas Veerman /* documentation and/or other materials provided with the distribution. */
26357f1050SThomas Veerman
27357f1050SThomas Veerman /* Neither the name of the University nor the names of its contributors */
28357f1050SThomas Veerman /* may be used to endorse or promote products derived from this software */
29357f1050SThomas Veerman /* without specific prior written permission. */
30357f1050SThomas Veerman
31357f1050SThomas Veerman /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
32357f1050SThomas Veerman /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
33357f1050SThomas Veerman /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
34357f1050SThomas Veerman /* PURPOSE. */
35357f1050SThomas Veerman #include "flexdef.h"
36*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: gen.c,v 1.11 2014/10/30 18:44:05 christos Exp $");
37*0a6a1f1dSLionel Sambuc
38357f1050SThomas Veerman #include "tables.h"
39357f1050SThomas Veerman
40357f1050SThomas Veerman
41357f1050SThomas Veerman /* declare functions that have forward references */
42357f1050SThomas Veerman
43357f1050SThomas Veerman void gen_next_state PROTO ((int));
44357f1050SThomas Veerman void genecs PROTO ((void));
45357f1050SThomas Veerman void indent_put2s PROTO ((const char *, const char *));
46357f1050SThomas Veerman void indent_puts PROTO ((const char *));
47357f1050SThomas Veerman
48357f1050SThomas Veerman
49357f1050SThomas Veerman static int indent_level = 0; /* each level is 8 spaces */
50357f1050SThomas Veerman
51357f1050SThomas Veerman #define indent_up() (++indent_level)
52357f1050SThomas Veerman #define indent_down() (--indent_level)
53357f1050SThomas Veerman #define set_indent(indent_val) indent_level = indent_val
54357f1050SThomas Veerman
55357f1050SThomas Veerman /* Almost everything is done in terms of arrays starting at 1, so provide
56357f1050SThomas Veerman * a null entry for the zero element of all C arrays. (The exception
57357f1050SThomas Veerman * to this is that the fast table representation generally uses the
58357f1050SThomas Veerman * 0 elements of its arrays, too.)
59357f1050SThomas Veerman */
60357f1050SThomas Veerman
get_int16_decl(void)61357f1050SThomas Veerman static const char *get_int16_decl (void)
62357f1050SThomas Veerman {
63357f1050SThomas Veerman return (gentables)
64357f1050SThomas Veerman ? "static yyconst flex_int16_t %s[%d] =\n { 0,\n"
65357f1050SThomas Veerman : "static yyconst flex_int16_t * %s = 0;\n";
66357f1050SThomas Veerman }
67357f1050SThomas Veerman
68357f1050SThomas Veerman
get_int32_decl(void)69357f1050SThomas Veerman static const char *get_int32_decl (void)
70357f1050SThomas Veerman {
71357f1050SThomas Veerman return (gentables)
72357f1050SThomas Veerman ? "static yyconst flex_int32_t %s[%d] =\n { 0,\n"
73357f1050SThomas Veerman : "static yyconst flex_int32_t * %s = 0;\n";
74357f1050SThomas Veerman }
75357f1050SThomas Veerman
get_uint16_decl(void)76*0a6a1f1dSLionel Sambuc static const char *get_uint16_decl (void)
77*0a6a1f1dSLionel Sambuc {
78*0a6a1f1dSLionel Sambuc return (gentables)
79*0a6a1f1dSLionel Sambuc ? "static yyconst flex_uint16_t %s[%d] =\n { 0,\n"
80*0a6a1f1dSLionel Sambuc : "static yyconst flex_uint16_t * %s = 0;\n";
81*0a6a1f1dSLionel Sambuc }
82*0a6a1f1dSLionel Sambuc
get_uint32_decl(void)83*0a6a1f1dSLionel Sambuc static const char *get_uint32_decl (void)
84*0a6a1f1dSLionel Sambuc {
85*0a6a1f1dSLionel Sambuc return (gentables)
86*0a6a1f1dSLionel Sambuc ? "static yyconst flex_uint32_t %s[%d] =\n { 0,\n"
87*0a6a1f1dSLionel Sambuc : "static yyconst flex_uint32_t * %s = 0;\n";
88*0a6a1f1dSLionel Sambuc }
89*0a6a1f1dSLionel Sambuc
get_yy_char_decl(void)90*0a6a1f1dSLionel Sambuc static const char *get_yy_char_decl (void)
91*0a6a1f1dSLionel Sambuc {
92*0a6a1f1dSLionel Sambuc return (gentables)
93*0a6a1f1dSLionel Sambuc ? "static yyconst YY_CHAR %s[%d] =\n { 0,\n"
94*0a6a1f1dSLionel Sambuc : "static yyconst YY_CHAR * %s = 0;\n";
95*0a6a1f1dSLionel Sambuc }
get_state_decl(void)96357f1050SThomas Veerman static const char *get_state_decl (void)
97357f1050SThomas Veerman {
98357f1050SThomas Veerman return (gentables)
99357f1050SThomas Veerman ? "static yyconst yy_state_type %s[%d] =\n { 0,\n"
100357f1050SThomas Veerman : "static yyconst yy_state_type * %s = 0;\n";
101357f1050SThomas Veerman }
102357f1050SThomas Veerman
103357f1050SThomas Veerman /* Indent to the current level. */
104357f1050SThomas Veerman
do_indent()105357f1050SThomas Veerman void do_indent ()
106357f1050SThomas Veerman {
107357f1050SThomas Veerman register int i = indent_level * 8;
108357f1050SThomas Veerman
109357f1050SThomas Veerman while (i >= 8) {
110357f1050SThomas Veerman outc ('\t');
111357f1050SThomas Veerman i -= 8;
112357f1050SThomas Veerman }
113357f1050SThomas Veerman
114357f1050SThomas Veerman while (i > 0) {
115357f1050SThomas Veerman outc (' ');
116357f1050SThomas Veerman --i;
117357f1050SThomas Veerman }
118357f1050SThomas Veerman }
119357f1050SThomas Veerman
120357f1050SThomas Veerman
121357f1050SThomas Veerman /** Make the table for possible eol matches.
122357f1050SThomas Veerman * @return the newly allocated rule_can_match_eol table
123357f1050SThomas Veerman */
mkeoltbl(void)124357f1050SThomas Veerman static struct yytbl_data *mkeoltbl (void)
125357f1050SThomas Veerman {
126357f1050SThomas Veerman int i;
127357f1050SThomas Veerman flex_int8_t *tdata = 0;
128357f1050SThomas Veerman struct yytbl_data *tbl;
129357f1050SThomas Veerman
130357f1050SThomas Veerman tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data));
131357f1050SThomas Veerman yytbl_data_init (tbl, YYTD_ID_RULE_CAN_MATCH_EOL);
132357f1050SThomas Veerman tbl->td_flags = YYTD_DATA8;
133357f1050SThomas Veerman tbl->td_lolen = num_rules + 1;
134357f1050SThomas Veerman tbl->td_data = tdata =
135357f1050SThomas Veerman (flex_int8_t *) calloc (tbl->td_lolen, sizeof (flex_int8_t));
136357f1050SThomas Veerman
137357f1050SThomas Veerman for (i = 1; i <= num_rules; i++)
138357f1050SThomas Veerman tdata[i] = rule_has_nl[i] ? 1 : 0;
139357f1050SThomas Veerman
140357f1050SThomas Veerman buf_prints (&yydmap_buf,
141357f1050SThomas Veerman "\t{YYTD_ID_RULE_CAN_MATCH_EOL, (void**)&yy_rule_can_match_eol, sizeof(%s)},\n",
142357f1050SThomas Veerman "flex_int32_t");
143357f1050SThomas Veerman return tbl;
144357f1050SThomas Veerman }
145357f1050SThomas Veerman
146357f1050SThomas Veerman /* Generate the table for possible eol matches. */
geneoltbl(void)147357f1050SThomas Veerman static void geneoltbl (void)
148357f1050SThomas Veerman {
149357f1050SThomas Veerman int i;
150357f1050SThomas Veerman
151357f1050SThomas Veerman outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
152357f1050SThomas Veerman outn ("/* Table of booleans, true if rule could match eol. */");
153357f1050SThomas Veerman out_str_dec (get_int32_decl (), "yy_rule_can_match_eol",
154357f1050SThomas Veerman num_rules + 1);
155357f1050SThomas Veerman
156357f1050SThomas Veerman if (gentables) {
157357f1050SThomas Veerman for (i = 1; i <= num_rules; i++) {
158357f1050SThomas Veerman out_dec ("%d, ", rule_has_nl[i] ? 1 : 0);
159357f1050SThomas Veerman /* format nicely, 20 numbers per line. */
160357f1050SThomas Veerman if ((i % 20) == 19)
161357f1050SThomas Veerman out ("\n ");
162357f1050SThomas Veerman }
163357f1050SThomas Veerman out (" };\n");
164357f1050SThomas Veerman }
165357f1050SThomas Veerman outn ("]])");
166357f1050SThomas Veerman }
167357f1050SThomas Veerman
168357f1050SThomas Veerman
169357f1050SThomas Veerman /* Generate the code to keep backing-up information. */
170357f1050SThomas Veerman
gen_backing_up()171357f1050SThomas Veerman void gen_backing_up ()
172357f1050SThomas Veerman {
173357f1050SThomas Veerman if (reject || num_backing_up == 0)
174357f1050SThomas Veerman return;
175357f1050SThomas Veerman
176357f1050SThomas Veerman if (fullspd)
177357f1050SThomas Veerman indent_puts ("if ( yy_current_state[-1].yy_nxt )");
178357f1050SThomas Veerman else
179357f1050SThomas Veerman indent_puts ("if ( yy_accept[yy_current_state] )");
180357f1050SThomas Veerman
181357f1050SThomas Veerman indent_up ();
182357f1050SThomas Veerman indent_puts ("{");
183357f1050SThomas Veerman indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;");
184357f1050SThomas Veerman indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;");
185357f1050SThomas Veerman indent_puts ("}");
186357f1050SThomas Veerman indent_down ();
187357f1050SThomas Veerman }
188357f1050SThomas Veerman
189357f1050SThomas Veerman
190357f1050SThomas Veerman /* Generate the code to perform the backing up. */
191357f1050SThomas Veerman
gen_bu_action()192357f1050SThomas Veerman void gen_bu_action ()
193357f1050SThomas Veerman {
194357f1050SThomas Veerman if (reject || num_backing_up == 0)
195357f1050SThomas Veerman return;
196357f1050SThomas Veerman
197357f1050SThomas Veerman set_indent (3);
198357f1050SThomas Veerman
199357f1050SThomas Veerman indent_puts ("case 0: /* must back up */");
200357f1050SThomas Veerman indent_puts ("/* undo the effects of YY_DO_BEFORE_ACTION */");
201357f1050SThomas Veerman indent_puts ("*yy_cp = YY_G(yy_hold_char);");
202357f1050SThomas Veerman
203357f1050SThomas Veerman if (fullspd || fulltbl)
204357f1050SThomas Veerman indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos) + 1;");
205357f1050SThomas Veerman else
206357f1050SThomas Veerman /* Backing-up info for compressed tables is taken \after/
207357f1050SThomas Veerman * yy_cp has been incremented for the next state.
208357f1050SThomas Veerman */
209357f1050SThomas Veerman indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos);");
210357f1050SThomas Veerman
211357f1050SThomas Veerman indent_puts ("yy_current_state = YY_G(yy_last_accepting_state);");
212357f1050SThomas Veerman indent_puts ("goto yy_find_action;");
213357f1050SThomas Veerman outc ('\n');
214357f1050SThomas Veerman
215357f1050SThomas Veerman set_indent (0);
216357f1050SThomas Veerman }
217357f1050SThomas Veerman
218357f1050SThomas Veerman /** mkctbl - make full speed compressed transition table
219357f1050SThomas Veerman * This is an array of structs; each struct a pair of integers.
220357f1050SThomas Veerman * You should call mkssltbl() immediately after this.
221357f1050SThomas Veerman * Then, I think, mkecstbl(). Arrrg.
222357f1050SThomas Veerman * @return the newly allocated trans table
223357f1050SThomas Veerman */
224357f1050SThomas Veerman
mkctbl(void)225357f1050SThomas Veerman static struct yytbl_data *mkctbl (void)
226357f1050SThomas Veerman {
227357f1050SThomas Veerman register int i;
228357f1050SThomas Veerman struct yytbl_data *tbl = 0;
229357f1050SThomas Veerman flex_int32_t *tdata = 0, curr = 0;
230357f1050SThomas Veerman int end_of_buffer_action = num_rules + 1;
231357f1050SThomas Veerman
232357f1050SThomas Veerman buf_prints (&yydmap_buf,
233357f1050SThomas Veerman "\t{YYTD_ID_TRANSITION, (void**)&yy_transition, sizeof(%s)},\n",
234357f1050SThomas Veerman ((tblend + numecs + 1) >= INT16_MAX
235357f1050SThomas Veerman || long_align) ? "flex_int32_t" : "flex_int16_t");
236357f1050SThomas Veerman
237357f1050SThomas Veerman tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data));
238357f1050SThomas Veerman yytbl_data_init (tbl, YYTD_ID_TRANSITION);
239357f1050SThomas Veerman tbl->td_flags = YYTD_DATA32 | YYTD_STRUCT;
240357f1050SThomas Veerman tbl->td_hilen = 0;
241357f1050SThomas Veerman tbl->td_lolen = tblend + numecs + 1; /* number of structs */
242357f1050SThomas Veerman
243357f1050SThomas Veerman tbl->td_data = tdata =
244357f1050SThomas Veerman (flex_int32_t *) calloc (tbl->td_lolen * 2, sizeof (flex_int32_t));
245357f1050SThomas Veerman
246357f1050SThomas Veerman /* We want the transition to be represented as the offset to the
247357f1050SThomas Veerman * next state, not the actual state number, which is what it currently
248357f1050SThomas Veerman * is. The offset is base[nxt[i]] - (base of current state)]. That's
249357f1050SThomas Veerman * just the difference between the starting points of the two involved
250357f1050SThomas Veerman * states (to - from).
251357f1050SThomas Veerman *
252357f1050SThomas Veerman * First, though, we need to find some way to put in our end-of-buffer
253357f1050SThomas Veerman * flags and states. We do this by making a state with absolutely no
254357f1050SThomas Veerman * transitions. We put it at the end of the table.
255357f1050SThomas Veerman */
256357f1050SThomas Veerman
257357f1050SThomas Veerman /* We need to have room in nxt/chk for two more slots: One for the
258357f1050SThomas Veerman * action and one for the end-of-buffer transition. We now *assume*
259357f1050SThomas Veerman * that we're guaranteed the only character we'll try to index this
260357f1050SThomas Veerman * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
261357f1050SThomas Veerman * there's room for jam entries for other characters.
262357f1050SThomas Veerman */
263357f1050SThomas Veerman
264357f1050SThomas Veerman while (tblend + 2 >= current_max_xpairs)
265357f1050SThomas Veerman expand_nxt_chk ();
266357f1050SThomas Veerman
267357f1050SThomas Veerman while (lastdfa + 1 >= current_max_dfas)
268357f1050SThomas Veerman increase_max_dfas ();
269357f1050SThomas Veerman
270357f1050SThomas Veerman base[lastdfa + 1] = tblend + 2;
271357f1050SThomas Veerman nxt[tblend + 1] = end_of_buffer_action;
272357f1050SThomas Veerman chk[tblend + 1] = numecs + 1;
273357f1050SThomas Veerman chk[tblend + 2] = 1; /* anything but EOB */
274357f1050SThomas Veerman
275357f1050SThomas Veerman /* So that "make test" won't show arb. differences. */
276357f1050SThomas Veerman nxt[tblend + 2] = 0;
277357f1050SThomas Veerman
278357f1050SThomas Veerman /* Make sure every state has an end-of-buffer transition and an
279357f1050SThomas Veerman * action #.
280357f1050SThomas Veerman */
281357f1050SThomas Veerman for (i = 0; i <= lastdfa; ++i) {
282357f1050SThomas Veerman int anum = dfaacc[i].dfaacc_state;
283357f1050SThomas Veerman int offset = base[i];
284357f1050SThomas Veerman
285357f1050SThomas Veerman chk[offset] = EOB_POSITION;
286357f1050SThomas Veerman chk[offset - 1] = ACTION_POSITION;
287357f1050SThomas Veerman nxt[offset - 1] = anum; /* action number */
288357f1050SThomas Veerman }
289357f1050SThomas Veerman
290357f1050SThomas Veerman for (i = 0; i <= tblend; ++i) {
291357f1050SThomas Veerman if (chk[i] == EOB_POSITION) {
292357f1050SThomas Veerman tdata[curr++] = 0;
293357f1050SThomas Veerman tdata[curr++] = base[lastdfa + 1] - i;
294357f1050SThomas Veerman }
295357f1050SThomas Veerman
296357f1050SThomas Veerman else if (chk[i] == ACTION_POSITION) {
297357f1050SThomas Veerman tdata[curr++] = 0;
298357f1050SThomas Veerman tdata[curr++] = nxt[i];
299357f1050SThomas Veerman }
300357f1050SThomas Veerman
301357f1050SThomas Veerman else if (chk[i] > numecs || chk[i] == 0) {
302357f1050SThomas Veerman tdata[curr++] = 0;
303357f1050SThomas Veerman tdata[curr++] = 0;
304357f1050SThomas Veerman }
305357f1050SThomas Veerman else { /* verify, transition */
306357f1050SThomas Veerman
307357f1050SThomas Veerman tdata[curr++] = chk[i];
308357f1050SThomas Veerman tdata[curr++] = base[nxt[i]] - (i - chk[i]);
309357f1050SThomas Veerman }
310357f1050SThomas Veerman }
311357f1050SThomas Veerman
312357f1050SThomas Veerman
313357f1050SThomas Veerman /* Here's the final, end-of-buffer state. */
314357f1050SThomas Veerman tdata[curr++] = chk[tblend + 1];
315357f1050SThomas Veerman tdata[curr++] = nxt[tblend + 1];
316357f1050SThomas Veerman
317357f1050SThomas Veerman tdata[curr++] = chk[tblend + 2];
318357f1050SThomas Veerman tdata[curr++] = nxt[tblend + 2];
319357f1050SThomas Veerman
320357f1050SThomas Veerman return tbl;
321357f1050SThomas Veerman }
322357f1050SThomas Veerman
323357f1050SThomas Veerman
324357f1050SThomas Veerman /** Make start_state_list table.
325357f1050SThomas Veerman * @return the newly allocated start_state_list table
326357f1050SThomas Veerman */
mkssltbl(void)327357f1050SThomas Veerman static struct yytbl_data *mkssltbl (void)
328357f1050SThomas Veerman {
329357f1050SThomas Veerman struct yytbl_data *tbl = 0;
330357f1050SThomas Veerman flex_int32_t *tdata = 0;
331357f1050SThomas Veerman flex_int32_t i;
332357f1050SThomas Veerman
333357f1050SThomas Veerman tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data));
334357f1050SThomas Veerman yytbl_data_init (tbl, YYTD_ID_START_STATE_LIST);
335357f1050SThomas Veerman tbl->td_flags = YYTD_DATA32 | YYTD_PTRANS;
336357f1050SThomas Veerman tbl->td_hilen = 0;
337357f1050SThomas Veerman tbl->td_lolen = lastsc * 2 + 1;
338357f1050SThomas Veerman
339357f1050SThomas Veerman tbl->td_data = tdata =
340357f1050SThomas Veerman (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t));
341357f1050SThomas Veerman
342357f1050SThomas Veerman for (i = 0; i <= lastsc * 2; ++i)
343357f1050SThomas Veerman tdata[i] = base[i];
344357f1050SThomas Veerman
345357f1050SThomas Veerman buf_prints (&yydmap_buf,
346357f1050SThomas Veerman "\t{YYTD_ID_START_STATE_LIST, (void**)&yy_start_state_list, sizeof(%s)},\n",
347357f1050SThomas Veerman "struct yy_trans_info*");
348357f1050SThomas Veerman
349357f1050SThomas Veerman return tbl;
350357f1050SThomas Veerman }
351357f1050SThomas Veerman
352357f1050SThomas Veerman
353357f1050SThomas Veerman
354357f1050SThomas Veerman /* genctbl - generates full speed compressed transition table */
355357f1050SThomas Veerman
genctbl()356357f1050SThomas Veerman void genctbl ()
357357f1050SThomas Veerman {
358357f1050SThomas Veerman register int i;
359357f1050SThomas Veerman int end_of_buffer_action = num_rules + 1;
360357f1050SThomas Veerman
361357f1050SThomas Veerman /* Table of verify for transition and offset to next state. */
362357f1050SThomas Veerman if (gentables)
363357f1050SThomas Veerman out_dec ("static yyconst struct yy_trans_info yy_transition[%d] =\n {\n", tblend + numecs + 1);
364357f1050SThomas Veerman else
365357f1050SThomas Veerman outn ("static yyconst struct yy_trans_info *yy_transition = 0;");
366357f1050SThomas Veerman
367357f1050SThomas Veerman /* We want the transition to be represented as the offset to the
368357f1050SThomas Veerman * next state, not the actual state number, which is what it currently
369357f1050SThomas Veerman * is. The offset is base[nxt[i]] - (base of current state)]. That's
370357f1050SThomas Veerman * just the difference between the starting points of the two involved
371357f1050SThomas Veerman * states (to - from).
372357f1050SThomas Veerman *
373357f1050SThomas Veerman * First, though, we need to find some way to put in our end-of-buffer
374357f1050SThomas Veerman * flags and states. We do this by making a state with absolutely no
375357f1050SThomas Veerman * transitions. We put it at the end of the table.
376357f1050SThomas Veerman */
377357f1050SThomas Veerman
378357f1050SThomas Veerman /* We need to have room in nxt/chk for two more slots: One for the
379357f1050SThomas Veerman * action and one for the end-of-buffer transition. We now *assume*
380357f1050SThomas Veerman * that we're guaranteed the only character we'll try to index this
381357f1050SThomas Veerman * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
382357f1050SThomas Veerman * there's room for jam entries for other characters.
383357f1050SThomas Veerman */
384357f1050SThomas Veerman
385357f1050SThomas Veerman while (tblend + 2 >= current_max_xpairs)
386357f1050SThomas Veerman expand_nxt_chk ();
387357f1050SThomas Veerman
388357f1050SThomas Veerman while (lastdfa + 1 >= current_max_dfas)
389357f1050SThomas Veerman increase_max_dfas ();
390357f1050SThomas Veerman
391357f1050SThomas Veerman base[lastdfa + 1] = tblend + 2;
392357f1050SThomas Veerman nxt[tblend + 1] = end_of_buffer_action;
393357f1050SThomas Veerman chk[tblend + 1] = numecs + 1;
394357f1050SThomas Veerman chk[tblend + 2] = 1; /* anything but EOB */
395357f1050SThomas Veerman
396357f1050SThomas Veerman /* So that "make test" won't show arb. differences. */
397357f1050SThomas Veerman nxt[tblend + 2] = 0;
398357f1050SThomas Veerman
399357f1050SThomas Veerman /* Make sure every state has an end-of-buffer transition and an
400357f1050SThomas Veerman * action #.
401357f1050SThomas Veerman */
402357f1050SThomas Veerman for (i = 0; i <= lastdfa; ++i) {
403357f1050SThomas Veerman int anum = dfaacc[i].dfaacc_state;
404357f1050SThomas Veerman int offset = base[i];
405357f1050SThomas Veerman
406357f1050SThomas Veerman chk[offset] = EOB_POSITION;
407357f1050SThomas Veerman chk[offset - 1] = ACTION_POSITION;
408357f1050SThomas Veerman nxt[offset - 1] = anum; /* action number */
409357f1050SThomas Veerman }
410357f1050SThomas Veerman
411357f1050SThomas Veerman for (i = 0; i <= tblend; ++i) {
412357f1050SThomas Veerman if (chk[i] == EOB_POSITION)
413357f1050SThomas Veerman transition_struct_out (0, base[lastdfa + 1] - i);
414357f1050SThomas Veerman
415357f1050SThomas Veerman else if (chk[i] == ACTION_POSITION)
416357f1050SThomas Veerman transition_struct_out (0, nxt[i]);
417357f1050SThomas Veerman
418357f1050SThomas Veerman else if (chk[i] > numecs || chk[i] == 0)
419357f1050SThomas Veerman transition_struct_out (0, 0); /* unused slot */
420357f1050SThomas Veerman
421357f1050SThomas Veerman else /* verify, transition */
422357f1050SThomas Veerman transition_struct_out (chk[i],
423357f1050SThomas Veerman base[nxt[i]] - (i -
424357f1050SThomas Veerman chk[i]));
425357f1050SThomas Veerman }
426357f1050SThomas Veerman
427357f1050SThomas Veerman
428357f1050SThomas Veerman /* Here's the final, end-of-buffer state. */
429357f1050SThomas Veerman transition_struct_out (chk[tblend + 1], nxt[tblend + 1]);
430357f1050SThomas Veerman transition_struct_out (chk[tblend + 2], nxt[tblend + 2]);
431357f1050SThomas Veerman
432357f1050SThomas Veerman if (gentables)
433357f1050SThomas Veerman outn (" };\n");
434357f1050SThomas Veerman
435357f1050SThomas Veerman /* Table of pointers to start states. */
436357f1050SThomas Veerman if (gentables)
437357f1050SThomas Veerman out_dec ("static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc * 2 + 1);
438357f1050SThomas Veerman else
439357f1050SThomas Veerman outn ("static yyconst struct yy_trans_info **yy_start_state_list =0;");
440357f1050SThomas Veerman
441357f1050SThomas Veerman if (gentables) {
442357f1050SThomas Veerman outn (" {");
443357f1050SThomas Veerman
444357f1050SThomas Veerman for (i = 0; i <= lastsc * 2; ++i)
445357f1050SThomas Veerman out_dec (" &yy_transition[%d],\n", base[i]);
446357f1050SThomas Veerman
447357f1050SThomas Veerman dataend ();
448357f1050SThomas Veerman }
449357f1050SThomas Veerman
450357f1050SThomas Veerman if (useecs)
451357f1050SThomas Veerman genecs ();
452357f1050SThomas Veerman }
453357f1050SThomas Veerman
454357f1050SThomas Veerman
455357f1050SThomas Veerman /* mkecstbl - Make equivalence-class tables. */
mkecstbl(void)456357f1050SThomas Veerman static struct yytbl_data *mkecstbl (void)
457357f1050SThomas Veerman {
458357f1050SThomas Veerman register int i;
459357f1050SThomas Veerman struct yytbl_data *tbl = 0;
460357f1050SThomas Veerman flex_int32_t *tdata = 0;
461357f1050SThomas Veerman
462357f1050SThomas Veerman tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data));
463357f1050SThomas Veerman yytbl_data_init (tbl, YYTD_ID_EC);
464357f1050SThomas Veerman tbl->td_flags |= YYTD_DATA32;
465357f1050SThomas Veerman tbl->td_hilen = 0;
466357f1050SThomas Veerman tbl->td_lolen = csize;
467357f1050SThomas Veerman
468357f1050SThomas Veerman tbl->td_data = tdata =
469357f1050SThomas Veerman (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t));
470357f1050SThomas Veerman
471357f1050SThomas Veerman for (i = 1; i < csize; ++i) {
472357f1050SThomas Veerman ecgroup[i] = ABS (ecgroup[i]);
473357f1050SThomas Veerman tdata[i] = ecgroup[i];
474357f1050SThomas Veerman }
475357f1050SThomas Veerman
476357f1050SThomas Veerman buf_prints (&yydmap_buf,
477357f1050SThomas Veerman "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n",
478*0a6a1f1dSLionel Sambuc "YY_CHAR");
479357f1050SThomas Veerman
480357f1050SThomas Veerman return tbl;
481357f1050SThomas Veerman }
482357f1050SThomas Veerman
483357f1050SThomas Veerman /* Generate equivalence-class tables. */
484357f1050SThomas Veerman
genecs()485357f1050SThomas Veerman void genecs ()
486357f1050SThomas Veerman {
487357f1050SThomas Veerman register int i, j;
488357f1050SThomas Veerman int numrows;
489357f1050SThomas Veerman
490*0a6a1f1dSLionel Sambuc out_str_dec (get_yy_char_decl (), "yy_ec", csize);
491357f1050SThomas Veerman
492357f1050SThomas Veerman for (i = 1; i < csize; ++i) {
493357f1050SThomas Veerman ecgroup[i] = ABS (ecgroup[i]);
494357f1050SThomas Veerman mkdata (ecgroup[i]);
495357f1050SThomas Veerman }
496357f1050SThomas Veerman
497357f1050SThomas Veerman dataend ();
498357f1050SThomas Veerman
499357f1050SThomas Veerman if (trace) {
500357f1050SThomas Veerman fputs (_("\n\nEquivalence Classes:\n\n"), stderr);
501357f1050SThomas Veerman
502357f1050SThomas Veerman numrows = csize / 8;
503357f1050SThomas Veerman
504357f1050SThomas Veerman for (j = 0; j < numrows; ++j) {
505357f1050SThomas Veerman for (i = j; i < csize; i = i + numrows) {
506357f1050SThomas Veerman fprintf (stderr, "%4s = %-2d",
507357f1050SThomas Veerman readable_form (i), ecgroup[i]);
508357f1050SThomas Veerman
509357f1050SThomas Veerman putc (' ', stderr);
510357f1050SThomas Veerman }
511357f1050SThomas Veerman
512357f1050SThomas Veerman putc ('\n', stderr);
513357f1050SThomas Veerman }
514357f1050SThomas Veerman }
515357f1050SThomas Veerman }
516357f1050SThomas Veerman
517357f1050SThomas Veerman
518357f1050SThomas Veerman /* Generate the code to find the action number. */
519357f1050SThomas Veerman
gen_find_action()520357f1050SThomas Veerman void gen_find_action ()
521357f1050SThomas Veerman {
522357f1050SThomas Veerman if (fullspd)
523357f1050SThomas Veerman indent_puts ("yy_act = yy_current_state[-1].yy_nxt;");
524357f1050SThomas Veerman
525357f1050SThomas Veerman else if (fulltbl)
526357f1050SThomas Veerman indent_puts ("yy_act = yy_accept[yy_current_state];");
527357f1050SThomas Veerman
528357f1050SThomas Veerman else if (reject) {
529357f1050SThomas Veerman indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
530357f1050SThomas Veerman indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
531357f1050SThomas Veerman
532357f1050SThomas Veerman if (!variable_trailing_context_rules)
533357f1050SThomas Veerman outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
534357f1050SThomas Veerman outn ("find_rule: /* we branch to this label when backing up */");
535357f1050SThomas Veerman if (!variable_trailing_context_rules)
536357f1050SThomas Veerman outn ("]])\n");
537357f1050SThomas Veerman
538357f1050SThomas Veerman indent_puts
539357f1050SThomas Veerman ("for ( ; ; ) /* until we find what rule we matched */");
540357f1050SThomas Veerman
541357f1050SThomas Veerman indent_up ();
542357f1050SThomas Veerman
543357f1050SThomas Veerman indent_puts ("{");
544357f1050SThomas Veerman
545357f1050SThomas Veerman indent_puts
546357f1050SThomas Veerman ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )");
547357f1050SThomas Veerman indent_up ();
548357f1050SThomas Veerman indent_puts ("{");
549357f1050SThomas Veerman indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];");
550357f1050SThomas Veerman
551357f1050SThomas Veerman if (variable_trailing_context_rules) {
552357f1050SThomas Veerman indent_puts
553357f1050SThomas Veerman ("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
554357f1050SThomas Veerman indent_puts (" YY_G(yy_looking_for_trail_begin) )");
555357f1050SThomas Veerman indent_up ();
556357f1050SThomas Veerman indent_puts ("{");
557357f1050SThomas Veerman
558357f1050SThomas Veerman indent_puts
559357f1050SThomas Veerman ("if ( yy_act == YY_G(yy_looking_for_trail_begin) )");
560357f1050SThomas Veerman indent_up ();
561357f1050SThomas Veerman indent_puts ("{");
562357f1050SThomas Veerman indent_puts ("YY_G(yy_looking_for_trail_begin) = 0;");
563357f1050SThomas Veerman indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
564357f1050SThomas Veerman indent_puts ("break;");
565357f1050SThomas Veerman indent_puts ("}");
566357f1050SThomas Veerman indent_down ();
567357f1050SThomas Veerman
568357f1050SThomas Veerman indent_puts ("}");
569357f1050SThomas Veerman indent_down ();
570357f1050SThomas Veerman
571357f1050SThomas Veerman indent_puts
572357f1050SThomas Veerman ("else if ( yy_act & YY_TRAILING_MASK )");
573357f1050SThomas Veerman indent_up ();
574357f1050SThomas Veerman indent_puts ("{");
575357f1050SThomas Veerman indent_puts
576357f1050SThomas Veerman ("YY_G(yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK;");
577357f1050SThomas Veerman indent_puts
578357f1050SThomas Veerman ("YY_G(yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK;");
579357f1050SThomas Veerman
580357f1050SThomas Veerman if (real_reject) {
581357f1050SThomas Veerman /* Remember matched text in case we back up
582357f1050SThomas Veerman * due to REJECT.
583357f1050SThomas Veerman */
584357f1050SThomas Veerman indent_puts
585357f1050SThomas Veerman ("YY_G(yy_full_match) = yy_cp;");
586357f1050SThomas Veerman indent_puts
587357f1050SThomas Veerman ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
588357f1050SThomas Veerman indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
589357f1050SThomas Veerman }
590357f1050SThomas Veerman
591357f1050SThomas Veerman indent_puts ("}");
592357f1050SThomas Veerman indent_down ();
593357f1050SThomas Veerman
594357f1050SThomas Veerman indent_puts ("else");
595357f1050SThomas Veerman indent_up ();
596357f1050SThomas Veerman indent_puts ("{");
597357f1050SThomas Veerman indent_puts ("YY_G(yy_full_match) = yy_cp;");
598357f1050SThomas Veerman indent_puts
599357f1050SThomas Veerman ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
600357f1050SThomas Veerman indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
601357f1050SThomas Veerman indent_puts ("break;");
602357f1050SThomas Veerman indent_puts ("}");
603357f1050SThomas Veerman indent_down ();
604357f1050SThomas Veerman
605357f1050SThomas Veerman indent_puts ("++YY_G(yy_lp);");
606357f1050SThomas Veerman indent_puts ("goto find_rule;");
607357f1050SThomas Veerman }
608357f1050SThomas Veerman
609357f1050SThomas Veerman else {
610357f1050SThomas Veerman /* Remember matched text in case we back up due to
611357f1050SThomas Veerman * trailing context plus REJECT.
612357f1050SThomas Veerman */
613357f1050SThomas Veerman indent_up ();
614357f1050SThomas Veerman indent_puts ("{");
615357f1050SThomas Veerman indent_puts ("YY_G(yy_full_match) = yy_cp;");
616357f1050SThomas Veerman indent_puts ("break;");
617357f1050SThomas Veerman indent_puts ("}");
618357f1050SThomas Veerman indent_down ();
619357f1050SThomas Veerman }
620357f1050SThomas Veerman
621357f1050SThomas Veerman indent_puts ("}");
622357f1050SThomas Veerman indent_down ();
623357f1050SThomas Veerman
624357f1050SThomas Veerman indent_puts ("--yy_cp;");
625357f1050SThomas Veerman
626357f1050SThomas Veerman /* We could consolidate the following two lines with those at
627357f1050SThomas Veerman * the beginning, but at the cost of complaints that we're
628357f1050SThomas Veerman * branching inside a loop.
629357f1050SThomas Veerman */
630357f1050SThomas Veerman indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
631357f1050SThomas Veerman indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
632357f1050SThomas Veerman
633357f1050SThomas Veerman indent_puts ("}");
634357f1050SThomas Veerman
635357f1050SThomas Veerman indent_down ();
636357f1050SThomas Veerman }
637357f1050SThomas Veerman
638357f1050SThomas Veerman else { /* compressed */
639357f1050SThomas Veerman indent_puts ("yy_act = yy_accept[yy_current_state];");
640357f1050SThomas Veerman
641357f1050SThomas Veerman if (interactive && !reject) {
642357f1050SThomas Veerman /* Do the guaranteed-needed backing up to figure out
643357f1050SThomas Veerman * the match.
644357f1050SThomas Veerman */
645357f1050SThomas Veerman indent_puts ("if ( yy_act == 0 )");
646357f1050SThomas Veerman indent_up ();
647357f1050SThomas Veerman indent_puts ("{ /* have to back up */");
648357f1050SThomas Veerman indent_puts
649357f1050SThomas Veerman ("yy_cp = YY_G(yy_last_accepting_cpos);");
650357f1050SThomas Veerman indent_puts
651357f1050SThomas Veerman ("yy_current_state = YY_G(yy_last_accepting_state);");
652357f1050SThomas Veerman indent_puts
653357f1050SThomas Veerman ("yy_act = yy_accept[yy_current_state];");
654357f1050SThomas Veerman indent_puts ("}");
655357f1050SThomas Veerman indent_down ();
656357f1050SThomas Veerman }
657357f1050SThomas Veerman }
658357f1050SThomas Veerman }
659357f1050SThomas Veerman
660357f1050SThomas Veerman /* mkftbl - make the full table and return the struct .
661357f1050SThomas Veerman * you should call mkecstbl() after this.
662357f1050SThomas Veerman */
663357f1050SThomas Veerman
mkftbl(void)664357f1050SThomas Veerman struct yytbl_data *mkftbl (void)
665357f1050SThomas Veerman {
666357f1050SThomas Veerman register int i;
667357f1050SThomas Veerman int end_of_buffer_action = num_rules + 1;
668357f1050SThomas Veerman struct yytbl_data *tbl;
669357f1050SThomas Veerman flex_int32_t *tdata = 0;
670357f1050SThomas Veerman
671357f1050SThomas Veerman tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data));
672357f1050SThomas Veerman yytbl_data_init (tbl, YYTD_ID_ACCEPT);
673357f1050SThomas Veerman tbl->td_flags |= YYTD_DATA32;
674357f1050SThomas Veerman tbl->td_hilen = 0; /* it's a one-dimensional array */
675357f1050SThomas Veerman tbl->td_lolen = lastdfa + 1;
676357f1050SThomas Veerman
677357f1050SThomas Veerman tbl->td_data = tdata =
678357f1050SThomas Veerman (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t));
679357f1050SThomas Veerman
680357f1050SThomas Veerman dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
681357f1050SThomas Veerman
682357f1050SThomas Veerman for (i = 1; i <= lastdfa; ++i) {
683357f1050SThomas Veerman register int anum = dfaacc[i].dfaacc_state;
684357f1050SThomas Veerman
685357f1050SThomas Veerman tdata[i] = anum;
686357f1050SThomas Veerman
687357f1050SThomas Veerman if (trace && anum)
688357f1050SThomas Veerman fprintf (stderr, _("state # %d accepts: [%d]\n"),
689357f1050SThomas Veerman i, anum);
690357f1050SThomas Veerman }
691357f1050SThomas Veerman
692357f1050SThomas Veerman buf_prints (&yydmap_buf,
693357f1050SThomas Veerman "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
694357f1050SThomas Veerman long_align ? "flex_int32_t" : "flex_int16_t");
695357f1050SThomas Veerman return tbl;
696357f1050SThomas Veerman }
697357f1050SThomas Veerman
698357f1050SThomas Veerman
699357f1050SThomas Veerman /* genftbl - generate full transition table */
700357f1050SThomas Veerman
genftbl()701357f1050SThomas Veerman void genftbl ()
702357f1050SThomas Veerman {
703357f1050SThomas Veerman register int i;
704357f1050SThomas Veerman int end_of_buffer_action = num_rules + 1;
705357f1050SThomas Veerman
706357f1050SThomas Veerman out_str_dec (long_align ? get_int32_decl () : get_int16_decl (),
707357f1050SThomas Veerman "yy_accept", lastdfa + 1);
708357f1050SThomas Veerman
709357f1050SThomas Veerman dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
710357f1050SThomas Veerman
711357f1050SThomas Veerman for (i = 1; i <= lastdfa; ++i) {
712357f1050SThomas Veerman register int anum = dfaacc[i].dfaacc_state;
713357f1050SThomas Veerman
714357f1050SThomas Veerman mkdata (anum);
715357f1050SThomas Veerman
716357f1050SThomas Veerman if (trace && anum)
717357f1050SThomas Veerman fprintf (stderr, _("state # %d accepts: [%d]\n"),
718357f1050SThomas Veerman i, anum);
719357f1050SThomas Veerman }
720357f1050SThomas Veerman
721357f1050SThomas Veerman dataend ();
722357f1050SThomas Veerman
723357f1050SThomas Veerman if (useecs)
724357f1050SThomas Veerman genecs ();
725357f1050SThomas Veerman
726357f1050SThomas Veerman /* Don't have to dump the actual full table entries - they were
727357f1050SThomas Veerman * created on-the-fly.
728357f1050SThomas Veerman */
729357f1050SThomas Veerman }
730357f1050SThomas Veerman
731357f1050SThomas Veerman
732357f1050SThomas Veerman /* Generate the code to find the next compressed-table state. */
733357f1050SThomas Veerman
gen_next_compressed_state(char_map)734357f1050SThomas Veerman void gen_next_compressed_state (char_map)
735357f1050SThomas Veerman char *char_map;
736357f1050SThomas Veerman {
737357f1050SThomas Veerman indent_put2s ("register YY_CHAR yy_c = %s;", char_map);
738357f1050SThomas Veerman
739357f1050SThomas Veerman /* Save the backing-up info \before/ computing the next state
740357f1050SThomas Veerman * because we always compute one more state than needed - we
741357f1050SThomas Veerman * always proceed until we reach a jam state
742357f1050SThomas Veerman */
743357f1050SThomas Veerman gen_backing_up ();
744357f1050SThomas Veerman
745357f1050SThomas Veerman indent_puts
746357f1050SThomas Veerman ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )");
747357f1050SThomas Veerman indent_up ();
748357f1050SThomas Veerman indent_puts ("{");
749357f1050SThomas Veerman indent_puts ("yy_current_state = (int) yy_def[yy_current_state];");
750357f1050SThomas Veerman
751357f1050SThomas Veerman if (usemecs) {
752357f1050SThomas Veerman /* We've arrange it so that templates are never chained
753357f1050SThomas Veerman * to one another. This means we can afford to make a
754357f1050SThomas Veerman * very simple test to see if we need to convert to
755357f1050SThomas Veerman * yy_c's meta-equivalence class without worrying
756357f1050SThomas Veerman * about erroneously looking up the meta-equivalence
757357f1050SThomas Veerman * class twice
758357f1050SThomas Veerman */
759357f1050SThomas Veerman do_indent ();
760357f1050SThomas Veerman
761357f1050SThomas Veerman /* lastdfa + 2 is the beginning of the templates */
762357f1050SThomas Veerman out_dec ("if ( yy_current_state >= %d )\n", lastdfa + 2);
763357f1050SThomas Veerman
764357f1050SThomas Veerman indent_up ();
765357f1050SThomas Veerman indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];");
766357f1050SThomas Veerman indent_down ();
767357f1050SThomas Veerman }
768357f1050SThomas Veerman
769357f1050SThomas Veerman indent_puts ("}");
770357f1050SThomas Veerman indent_down ();
771357f1050SThomas Veerman
772357f1050SThomas Veerman indent_puts
773357f1050SThomas Veerman ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];");
774357f1050SThomas Veerman }
775357f1050SThomas Veerman
776357f1050SThomas Veerman
777357f1050SThomas Veerman /* Generate the code to find the next match. */
778357f1050SThomas Veerman
gen_next_match()779357f1050SThomas Veerman void gen_next_match ()
780357f1050SThomas Veerman {
781357f1050SThomas Veerman /* NOTE - changes in here should be reflected in gen_next_state() and
782357f1050SThomas Veerman * gen_NUL_trans().
783357f1050SThomas Veerman */
784357f1050SThomas Veerman char *char_map = useecs ?
785357f1050SThomas Veerman "yy_ec[YY_SC_TO_UI(*yy_cp)] " : "YY_SC_TO_UI(*yy_cp)";
786357f1050SThomas Veerman
787357f1050SThomas Veerman char *char_map_2 = useecs ?
788357f1050SThomas Veerman "yy_ec[YY_SC_TO_UI(*++yy_cp)] " : "YY_SC_TO_UI(*++yy_cp)";
789357f1050SThomas Veerman
790357f1050SThomas Veerman if (fulltbl) {
791357f1050SThomas Veerman if (gentables)
792357f1050SThomas Veerman indent_put2s
793357f1050SThomas Veerman ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )",
794357f1050SThomas Veerman char_map);
795357f1050SThomas Veerman else
796357f1050SThomas Veerman indent_put2s
797357f1050SThomas Veerman ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )",
798357f1050SThomas Veerman char_map);
799357f1050SThomas Veerman
800357f1050SThomas Veerman indent_up ();
801357f1050SThomas Veerman
802357f1050SThomas Veerman if (num_backing_up > 0) {
803357f1050SThomas Veerman indent_puts ("{");
804357f1050SThomas Veerman gen_backing_up ();
805357f1050SThomas Veerman outc ('\n');
806357f1050SThomas Veerman }
807357f1050SThomas Veerman
808357f1050SThomas Veerman indent_puts ("++yy_cp;");
809357f1050SThomas Veerman
810357f1050SThomas Veerman if (num_backing_up > 0)
811357f1050SThomas Veerman
812357f1050SThomas Veerman indent_puts ("}");
813357f1050SThomas Veerman
814357f1050SThomas Veerman indent_down ();
815357f1050SThomas Veerman
816357f1050SThomas Veerman outc ('\n');
817357f1050SThomas Veerman indent_puts ("yy_current_state = -yy_current_state;");
818357f1050SThomas Veerman }
819357f1050SThomas Veerman
820357f1050SThomas Veerman else if (fullspd) {
821357f1050SThomas Veerman indent_puts ("{");
822357f1050SThomas Veerman indent_puts
823357f1050SThomas Veerman ("register yyconst struct yy_trans_info *yy_trans_info;\n");
824357f1050SThomas Veerman indent_puts ("register YY_CHAR yy_c;\n");
825357f1050SThomas Veerman indent_put2s ("for ( yy_c = %s;", char_map);
826357f1050SThomas Veerman indent_puts
827357f1050SThomas Veerman (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->");
828357f1050SThomas Veerman indent_puts ("yy_verify == yy_c;");
829357f1050SThomas Veerman indent_put2s (" yy_c = %s )", char_map_2);
830357f1050SThomas Veerman
831357f1050SThomas Veerman indent_up ();
832357f1050SThomas Veerman
833357f1050SThomas Veerman if (num_backing_up > 0)
834357f1050SThomas Veerman indent_puts ("{");
835357f1050SThomas Veerman
836357f1050SThomas Veerman indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
837357f1050SThomas Veerman
838357f1050SThomas Veerman if (num_backing_up > 0) {
839357f1050SThomas Veerman outc ('\n');
840357f1050SThomas Veerman gen_backing_up ();
841357f1050SThomas Veerman indent_puts ("}");
842357f1050SThomas Veerman }
843357f1050SThomas Veerman
844357f1050SThomas Veerman indent_down ();
845357f1050SThomas Veerman indent_puts ("}");
846357f1050SThomas Veerman }
847357f1050SThomas Veerman
848357f1050SThomas Veerman else { /* compressed */
849357f1050SThomas Veerman indent_puts ("do");
850357f1050SThomas Veerman
851357f1050SThomas Veerman indent_up ();
852357f1050SThomas Veerman indent_puts ("{");
853357f1050SThomas Veerman
854357f1050SThomas Veerman gen_next_state (false);
855357f1050SThomas Veerman
856357f1050SThomas Veerman indent_puts ("++yy_cp;");
857357f1050SThomas Veerman
858357f1050SThomas Veerman
859357f1050SThomas Veerman indent_puts ("}");
860357f1050SThomas Veerman indent_down ();
861357f1050SThomas Veerman
862357f1050SThomas Veerman do_indent ();
863357f1050SThomas Veerman
864357f1050SThomas Veerman if (interactive)
865357f1050SThomas Veerman out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase);
866357f1050SThomas Veerman else
867357f1050SThomas Veerman out_dec ("while ( yy_current_state != %d );\n",
868357f1050SThomas Veerman jamstate);
869357f1050SThomas Veerman
870357f1050SThomas Veerman if (!reject && !interactive) {
871357f1050SThomas Veerman /* Do the guaranteed-needed backing up to figure out
872357f1050SThomas Veerman * the match.
873357f1050SThomas Veerman */
874357f1050SThomas Veerman indent_puts
875357f1050SThomas Veerman ("yy_cp = YY_G(yy_last_accepting_cpos);");
876357f1050SThomas Veerman indent_puts
877357f1050SThomas Veerman ("yy_current_state = YY_G(yy_last_accepting_state);");
878357f1050SThomas Veerman }
879357f1050SThomas Veerman }
880357f1050SThomas Veerman }
881357f1050SThomas Veerman
882357f1050SThomas Veerman
883357f1050SThomas Veerman /* Generate the code to find the next state. */
884357f1050SThomas Veerman
gen_next_state(worry_about_NULs)885357f1050SThomas Veerman void gen_next_state (worry_about_NULs)
886357f1050SThomas Veerman int worry_about_NULs;
887357f1050SThomas Veerman { /* NOTE - changes in here should be reflected in gen_next_match() */
888357f1050SThomas Veerman char char_map[256];
889357f1050SThomas Veerman
890357f1050SThomas Veerman if (worry_about_NULs && !nultrans) {
891357f1050SThomas Veerman if (useecs)
892357f1050SThomas Veerman snprintf (char_map, sizeof(char_map),
893357f1050SThomas Veerman "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
894357f1050SThomas Veerman NUL_ec);
895357f1050SThomas Veerman else
896357f1050SThomas Veerman snprintf (char_map, sizeof(char_map),
897357f1050SThomas Veerman "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)",
898357f1050SThomas Veerman NUL_ec);
899357f1050SThomas Veerman }
900357f1050SThomas Veerman
901357f1050SThomas Veerman else
902357f1050SThomas Veerman strcpy (char_map, useecs ?
903357f1050SThomas Veerman "yy_ec[YY_SC_TO_UI(*yy_cp)] " :
904357f1050SThomas Veerman "YY_SC_TO_UI(*yy_cp)");
905357f1050SThomas Veerman
906357f1050SThomas Veerman if (worry_about_NULs && nultrans) {
907357f1050SThomas Veerman if (!fulltbl && !fullspd)
908357f1050SThomas Veerman /* Compressed tables back up *before* they match. */
909357f1050SThomas Veerman gen_backing_up ();
910357f1050SThomas Veerman
911357f1050SThomas Veerman indent_puts ("if ( *yy_cp )");
912357f1050SThomas Veerman indent_up ();
913357f1050SThomas Veerman indent_puts ("{");
914357f1050SThomas Veerman }
915357f1050SThomas Veerman
916357f1050SThomas Veerman if (fulltbl) {
917357f1050SThomas Veerman if (gentables)
918357f1050SThomas Veerman indent_put2s
919357f1050SThomas Veerman ("yy_current_state = yy_nxt[yy_current_state][%s];",
920357f1050SThomas Veerman char_map);
921357f1050SThomas Veerman else
922357f1050SThomas Veerman indent_put2s
923357f1050SThomas Veerman ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];",
924357f1050SThomas Veerman char_map);
925357f1050SThomas Veerman }
926357f1050SThomas Veerman
927357f1050SThomas Veerman else if (fullspd)
928357f1050SThomas Veerman indent_put2s
929357f1050SThomas Veerman ("yy_current_state += yy_current_state[%s].yy_nxt;",
930357f1050SThomas Veerman char_map);
931357f1050SThomas Veerman
932357f1050SThomas Veerman else
933357f1050SThomas Veerman gen_next_compressed_state (char_map);
934357f1050SThomas Veerman
935357f1050SThomas Veerman if (worry_about_NULs && nultrans) {
936357f1050SThomas Veerman
937357f1050SThomas Veerman indent_puts ("}");
938357f1050SThomas Veerman indent_down ();
939357f1050SThomas Veerman indent_puts ("else");
940357f1050SThomas Veerman indent_up ();
941357f1050SThomas Veerman indent_puts
942357f1050SThomas Veerman ("yy_current_state = yy_NUL_trans[yy_current_state];");
943357f1050SThomas Veerman indent_down ();
944357f1050SThomas Veerman }
945357f1050SThomas Veerman
946357f1050SThomas Veerman if (fullspd || fulltbl)
947357f1050SThomas Veerman gen_backing_up ();
948357f1050SThomas Veerman
949357f1050SThomas Veerman if (reject)
950357f1050SThomas Veerman indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;");
951357f1050SThomas Veerman }
952357f1050SThomas Veerman
953357f1050SThomas Veerman
954357f1050SThomas Veerman /* Generate the code to make a NUL transition. */
955357f1050SThomas Veerman
gen_NUL_trans()956357f1050SThomas Veerman void gen_NUL_trans ()
957357f1050SThomas Veerman { /* NOTE - changes in here should be reflected in gen_next_match() */
958357f1050SThomas Veerman /* Only generate a definition for "yy_cp" if we'll generate code
959357f1050SThomas Veerman * that uses it. Otherwise lint and the like complain.
960357f1050SThomas Veerman */
961357f1050SThomas Veerman int need_backing_up = (num_backing_up > 0 && !reject);
962357f1050SThomas Veerman
963357f1050SThomas Veerman if (need_backing_up && (!nultrans || fullspd || fulltbl))
964357f1050SThomas Veerman /* We're going to need yy_cp lying around for the call
965357f1050SThomas Veerman * below to gen_backing_up().
966357f1050SThomas Veerman */
967357f1050SThomas Veerman indent_puts ("register char *yy_cp = YY_G(yy_c_buf_p);");
968357f1050SThomas Veerman
969357f1050SThomas Veerman outc ('\n');
970357f1050SThomas Veerman
971357f1050SThomas Veerman if (nultrans) {
972357f1050SThomas Veerman indent_puts
973357f1050SThomas Veerman ("yy_current_state = yy_NUL_trans[yy_current_state];");
974357f1050SThomas Veerman indent_puts ("yy_is_jam = (yy_current_state == 0);");
975357f1050SThomas Veerman }
976357f1050SThomas Veerman
977357f1050SThomas Veerman else if (fulltbl) {
978357f1050SThomas Veerman do_indent ();
979357f1050SThomas Veerman if (gentables)
980357f1050SThomas Veerman out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec);
981357f1050SThomas Veerman else
982357f1050SThomas Veerman out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec);
983357f1050SThomas Veerman indent_puts ("yy_is_jam = (yy_current_state <= 0);");
984357f1050SThomas Veerman }
985357f1050SThomas Veerman
986357f1050SThomas Veerman else if (fullspd) {
987357f1050SThomas Veerman do_indent ();
988357f1050SThomas Veerman out_dec ("register int yy_c = %d;\n", NUL_ec);
989357f1050SThomas Veerman
990357f1050SThomas Veerman indent_puts
991357f1050SThomas Veerman ("register yyconst struct yy_trans_info *yy_trans_info;\n");
992357f1050SThomas Veerman indent_puts
993357f1050SThomas Veerman ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];");
994357f1050SThomas Veerman indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
995357f1050SThomas Veerman
996357f1050SThomas Veerman indent_puts
997357f1050SThomas Veerman ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);");
998357f1050SThomas Veerman }
999357f1050SThomas Veerman
1000357f1050SThomas Veerman else {
1001357f1050SThomas Veerman char NUL_ec_str[20];
1002357f1050SThomas Veerman
1003357f1050SThomas Veerman snprintf (NUL_ec_str, sizeof(NUL_ec_str), "%d", NUL_ec);
1004357f1050SThomas Veerman gen_next_compressed_state (NUL_ec_str);
1005357f1050SThomas Veerman
1006357f1050SThomas Veerman do_indent ();
1007357f1050SThomas Veerman out_dec ("yy_is_jam = (yy_current_state == %d);\n",
1008357f1050SThomas Veerman jamstate);
1009357f1050SThomas Veerman
1010357f1050SThomas Veerman if (reject) {
1011357f1050SThomas Veerman /* Only stack this state if it's a transition we
1012357f1050SThomas Veerman * actually make. If we stack it on a jam, then
1013357f1050SThomas Veerman * the state stack and yy_c_buf_p get out of sync.
1014357f1050SThomas Veerman */
1015357f1050SThomas Veerman indent_puts ("if ( ! yy_is_jam )");
1016357f1050SThomas Veerman indent_up ();
1017357f1050SThomas Veerman indent_puts
1018357f1050SThomas Veerman ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1019357f1050SThomas Veerman indent_down ();
1020357f1050SThomas Veerman }
1021357f1050SThomas Veerman }
1022357f1050SThomas Veerman
1023357f1050SThomas Veerman /* If we've entered an accepting state, back up; note that
1024357f1050SThomas Veerman * compressed tables have *already* done such backing up, so
1025357f1050SThomas Veerman * we needn't bother with it again.
1026357f1050SThomas Veerman */
1027357f1050SThomas Veerman if (need_backing_up && (fullspd || fulltbl)) {
1028357f1050SThomas Veerman outc ('\n');
1029357f1050SThomas Veerman indent_puts ("if ( ! yy_is_jam )");
1030357f1050SThomas Veerman indent_up ();
1031357f1050SThomas Veerman indent_puts ("{");
1032357f1050SThomas Veerman gen_backing_up ();
1033357f1050SThomas Veerman indent_puts ("}");
1034357f1050SThomas Veerman indent_down ();
1035357f1050SThomas Veerman }
1036357f1050SThomas Veerman }
1037357f1050SThomas Veerman
1038357f1050SThomas Veerman
1039357f1050SThomas Veerman /* Generate the code to find the start state. */
1040357f1050SThomas Veerman
gen_start_state()1041357f1050SThomas Veerman void gen_start_state ()
1042357f1050SThomas Veerman {
1043357f1050SThomas Veerman if (fullspd) {
1044357f1050SThomas Veerman if (bol_needed) {
1045357f1050SThomas Veerman indent_puts
1046357f1050SThomas Veerman ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];");
1047357f1050SThomas Veerman }
1048357f1050SThomas Veerman else
1049357f1050SThomas Veerman indent_puts
1050357f1050SThomas Veerman ("yy_current_state = yy_start_state_list[YY_G(yy_start)];");
1051357f1050SThomas Veerman }
1052357f1050SThomas Veerman
1053357f1050SThomas Veerman else {
1054357f1050SThomas Veerman indent_puts ("yy_current_state = YY_G(yy_start);");
1055357f1050SThomas Veerman
1056357f1050SThomas Veerman if (bol_needed)
1057357f1050SThomas Veerman indent_puts ("yy_current_state += YY_AT_BOL();");
1058357f1050SThomas Veerman
1059357f1050SThomas Veerman if (reject) {
1060357f1050SThomas Veerman /* Set up for storing up states. */
1061357f1050SThomas Veerman outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1062357f1050SThomas Veerman indent_puts
1063357f1050SThomas Veerman ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);");
1064357f1050SThomas Veerman indent_puts
1065357f1050SThomas Veerman ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1066357f1050SThomas Veerman outn ("]])");
1067357f1050SThomas Veerman }
1068357f1050SThomas Veerman }
1069357f1050SThomas Veerman }
1070357f1050SThomas Veerman
1071357f1050SThomas Veerman
1072357f1050SThomas Veerman /* gentabs - generate data statements for the transition tables */
1073357f1050SThomas Veerman
gentabs()1074357f1050SThomas Veerman void gentabs ()
1075357f1050SThomas Veerman {
1076357f1050SThomas Veerman int i, j, k, *accset, nacc, *acc_array, total_states;
1077357f1050SThomas Veerman int end_of_buffer_action = num_rules + 1;
1078357f1050SThomas Veerman struct yytbl_data *yyacc_tbl = 0, *yymeta_tbl = 0, *yybase_tbl = 0,
1079357f1050SThomas Veerman *yydef_tbl = 0, *yynxt_tbl = 0, *yychk_tbl = 0, *yyacclist_tbl=0;
1080357f1050SThomas Veerman flex_int32_t *yyacc_data = 0, *yybase_data = 0, *yydef_data = 0,
1081357f1050SThomas Veerman *yynxt_data = 0, *yychk_data = 0, *yyacclist_data=0;
1082357f1050SThomas Veerman flex_int32_t yybase_curr = 0, yyacclist_curr=0,yyacc_curr=0;
1083357f1050SThomas Veerman
1084357f1050SThomas Veerman acc_array = allocate_integer_array (current_max_dfas);
1085357f1050SThomas Veerman nummt = 0;
1086357f1050SThomas Veerman
1087357f1050SThomas Veerman /* The compressed table format jams by entering the "jam state",
1088357f1050SThomas Veerman * losing information about the previous state in the process.
1089357f1050SThomas Veerman * In order to recover the previous state, we effectively need
1090357f1050SThomas Veerman * to keep backing-up information.
1091357f1050SThomas Veerman */
1092357f1050SThomas Veerman ++num_backing_up;
1093357f1050SThomas Veerman
1094357f1050SThomas Veerman if (reject) {
1095357f1050SThomas Veerman /* Write out accepting list and pointer list.
1096357f1050SThomas Veerman
1097357f1050SThomas Veerman * First we generate the "yy_acclist" array. In the process,
1098357f1050SThomas Veerman * we compute the indices that will go into the "yy_accept"
1099357f1050SThomas Veerman * array, and save the indices in the dfaacc array.
1100357f1050SThomas Veerman */
1101357f1050SThomas Veerman int EOB_accepting_list[2];
1102357f1050SThomas Veerman
1103357f1050SThomas Veerman /* Set up accepting structures for the End Of Buffer state. */
1104357f1050SThomas Veerman EOB_accepting_list[0] = 0;
1105357f1050SThomas Veerman EOB_accepting_list[1] = end_of_buffer_action;
1106357f1050SThomas Veerman accsiz[end_of_buffer_state] = 1;
1107357f1050SThomas Veerman dfaacc[end_of_buffer_state].dfaacc_set =
1108357f1050SThomas Veerman EOB_accepting_list;
1109357f1050SThomas Veerman
1110357f1050SThomas Veerman out_str_dec (long_align ? get_int32_decl () :
1111357f1050SThomas Veerman get_int16_decl (), "yy_acclist", MAX (numas,
1112357f1050SThomas Veerman 1) + 1);
1113357f1050SThomas Veerman
1114357f1050SThomas Veerman buf_prints (&yydmap_buf,
1115357f1050SThomas Veerman "\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n",
1116357f1050SThomas Veerman long_align ? "flex_int32_t" : "flex_int16_t");
1117357f1050SThomas Veerman
1118357f1050SThomas Veerman yyacclist_tbl = (struct yytbl_data*)calloc(1,sizeof(struct yytbl_data));
1119357f1050SThomas Veerman yytbl_data_init (yyacclist_tbl, YYTD_ID_ACCLIST);
1120357f1050SThomas Veerman yyacclist_tbl->td_lolen = MAX(numas,1) + 1;
1121357f1050SThomas Veerman yyacclist_tbl->td_data = yyacclist_data =
1122357f1050SThomas Veerman (flex_int32_t *) calloc (yyacclist_tbl->td_lolen, sizeof (flex_int32_t));
1123357f1050SThomas Veerman yyacclist_curr = 1;
1124357f1050SThomas Veerman
1125357f1050SThomas Veerman j = 1; /* index into "yy_acclist" array */
1126357f1050SThomas Veerman
1127357f1050SThomas Veerman for (i = 1; i <= lastdfa; ++i) {
1128357f1050SThomas Veerman acc_array[i] = j;
1129357f1050SThomas Veerman
1130357f1050SThomas Veerman if (accsiz[i] != 0) {
1131357f1050SThomas Veerman accset = dfaacc[i].dfaacc_set;
1132357f1050SThomas Veerman nacc = accsiz[i];
1133357f1050SThomas Veerman
1134357f1050SThomas Veerman if (trace)
1135357f1050SThomas Veerman fprintf (stderr,
1136357f1050SThomas Veerman _("state # %d accepts: "),
1137357f1050SThomas Veerman i);
1138357f1050SThomas Veerman
1139357f1050SThomas Veerman for (k = 1; k <= nacc; ++k) {
1140357f1050SThomas Veerman int accnum = accset[k];
1141357f1050SThomas Veerman
1142357f1050SThomas Veerman ++j;
1143357f1050SThomas Veerman
1144357f1050SThomas Veerman if (variable_trailing_context_rules
1145357f1050SThomas Veerman && !(accnum &
1146357f1050SThomas Veerman YY_TRAILING_HEAD_MASK)
1147357f1050SThomas Veerman && accnum > 0
1148357f1050SThomas Veerman && accnum <= num_rules
1149357f1050SThomas Veerman && rule_type[accnum] ==
1150357f1050SThomas Veerman RULE_VARIABLE) {
1151357f1050SThomas Veerman /* Special hack to flag
1152357f1050SThomas Veerman * accepting number as part
1153357f1050SThomas Veerman * of trailing context rule.
1154357f1050SThomas Veerman */
1155357f1050SThomas Veerman accnum |= YY_TRAILING_MASK;
1156357f1050SThomas Veerman }
1157357f1050SThomas Veerman
1158357f1050SThomas Veerman mkdata (accnum);
1159357f1050SThomas Veerman yyacclist_data[yyacclist_curr++] = accnum;
1160357f1050SThomas Veerman
1161357f1050SThomas Veerman if (trace) {
1162357f1050SThomas Veerman fprintf (stderr, "[%d]",
1163357f1050SThomas Veerman accset[k]);
1164357f1050SThomas Veerman
1165357f1050SThomas Veerman if (k < nacc)
1166357f1050SThomas Veerman fputs (", ",
1167357f1050SThomas Veerman stderr);
1168357f1050SThomas Veerman else
1169357f1050SThomas Veerman putc ('\n',
1170357f1050SThomas Veerman stderr);
1171357f1050SThomas Veerman }
1172357f1050SThomas Veerman }
1173357f1050SThomas Veerman }
1174357f1050SThomas Veerman }
1175357f1050SThomas Veerman
1176357f1050SThomas Veerman /* add accepting number for the "jam" state */
1177357f1050SThomas Veerman acc_array[i] = j;
1178357f1050SThomas Veerman
1179357f1050SThomas Veerman dataend ();
1180357f1050SThomas Veerman if (tablesext) {
1181357f1050SThomas Veerman yytbl_data_compress (yyacclist_tbl);
1182357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, yyacclist_tbl) < 0)
1183357f1050SThomas Veerman flexerror (_("Could not write yyacclist_tbl"));
1184357f1050SThomas Veerman yytbl_data_destroy (yyacclist_tbl);
1185357f1050SThomas Veerman yyacclist_tbl = NULL;
1186357f1050SThomas Veerman }
1187357f1050SThomas Veerman }
1188357f1050SThomas Veerman
1189357f1050SThomas Veerman else {
1190357f1050SThomas Veerman dfaacc[end_of_buffer_state].dfaacc_state =
1191357f1050SThomas Veerman end_of_buffer_action;
1192357f1050SThomas Veerman
1193357f1050SThomas Veerman for (i = 1; i <= lastdfa; ++i)
1194357f1050SThomas Veerman acc_array[i] = dfaacc[i].dfaacc_state;
1195357f1050SThomas Veerman
1196357f1050SThomas Veerman /* add accepting number for jam state */
1197357f1050SThomas Veerman acc_array[i] = 0;
1198357f1050SThomas Veerman }
1199357f1050SThomas Veerman
1200357f1050SThomas Veerman /* Begin generating yy_accept */
1201357f1050SThomas Veerman
1202357f1050SThomas Veerman /* Spit out "yy_accept" array. If we're doing "reject", it'll be
1203357f1050SThomas Veerman * pointers into the "yy_acclist" array. Otherwise it's actual
1204357f1050SThomas Veerman * accepting numbers. In either case, we just dump the numbers.
1205357f1050SThomas Veerman */
1206357f1050SThomas Veerman
1207357f1050SThomas Veerman /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
1208357f1050SThomas Veerman * beginning at 0 and for "jam" state.
1209357f1050SThomas Veerman */
1210357f1050SThomas Veerman k = lastdfa + 2;
1211357f1050SThomas Veerman
1212357f1050SThomas Veerman if (reject)
1213357f1050SThomas Veerman /* We put a "cap" on the table associating lists of accepting
1214357f1050SThomas Veerman * numbers with state numbers. This is needed because we tell
1215357f1050SThomas Veerman * where the end of an accepting list is by looking at where
1216357f1050SThomas Veerman * the list for the next state starts.
1217357f1050SThomas Veerman */
1218357f1050SThomas Veerman ++k;
1219357f1050SThomas Veerman
1220357f1050SThomas Veerman out_str_dec (long_align ? get_int32_decl () : get_int16_decl (),
1221357f1050SThomas Veerman "yy_accept", k);
1222357f1050SThomas Veerman
1223357f1050SThomas Veerman buf_prints (&yydmap_buf,
1224357f1050SThomas Veerman "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
1225357f1050SThomas Veerman long_align ? "flex_int32_t" : "flex_int16_t");
1226357f1050SThomas Veerman
1227357f1050SThomas Veerman yyacc_tbl =
1228357f1050SThomas Veerman (struct yytbl_data *) calloc (1,
1229357f1050SThomas Veerman sizeof (struct yytbl_data));
1230357f1050SThomas Veerman yytbl_data_init (yyacc_tbl, YYTD_ID_ACCEPT);
1231357f1050SThomas Veerman yyacc_tbl->td_lolen = k;
1232357f1050SThomas Veerman yyacc_tbl->td_data = yyacc_data =
1233357f1050SThomas Veerman (flex_int32_t *) calloc (yyacc_tbl->td_lolen, sizeof (flex_int32_t));
1234357f1050SThomas Veerman yyacc_curr=1;
1235357f1050SThomas Veerman
1236357f1050SThomas Veerman for (i = 1; i <= lastdfa; ++i) {
1237357f1050SThomas Veerman mkdata (acc_array[i]);
1238357f1050SThomas Veerman yyacc_data[yyacc_curr++] = acc_array[i];
1239357f1050SThomas Veerman
1240357f1050SThomas Veerman if (!reject && trace && acc_array[i])
1241357f1050SThomas Veerman fprintf (stderr, _("state # %d accepts: [%d]\n"),
1242357f1050SThomas Veerman i, acc_array[i]);
1243357f1050SThomas Veerman }
1244357f1050SThomas Veerman
1245357f1050SThomas Veerman /* Add entry for "jam" state. */
1246357f1050SThomas Veerman mkdata (acc_array[i]);
1247357f1050SThomas Veerman yyacc_data[yyacc_curr++] = acc_array[i];
1248357f1050SThomas Veerman
1249357f1050SThomas Veerman if (reject) {
1250357f1050SThomas Veerman /* Add "cap" for the list. */
1251357f1050SThomas Veerman mkdata (acc_array[i]);
1252357f1050SThomas Veerman yyacc_data[yyacc_curr++] = acc_array[i];
1253357f1050SThomas Veerman }
1254357f1050SThomas Veerman
1255357f1050SThomas Veerman dataend ();
1256357f1050SThomas Veerman if (tablesext) {
1257357f1050SThomas Veerman yytbl_data_compress (yyacc_tbl);
1258357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, yyacc_tbl) < 0)
1259357f1050SThomas Veerman flexerror (_("Could not write yyacc_tbl"));
1260357f1050SThomas Veerman yytbl_data_destroy (yyacc_tbl);
1261357f1050SThomas Veerman yyacc_tbl = NULL;
1262357f1050SThomas Veerman }
1263357f1050SThomas Veerman /* End generating yy_accept */
1264357f1050SThomas Veerman
1265357f1050SThomas Veerman if (useecs) {
1266357f1050SThomas Veerman
1267357f1050SThomas Veerman genecs ();
1268357f1050SThomas Veerman if (tablesext) {
1269357f1050SThomas Veerman struct yytbl_data *tbl;
1270357f1050SThomas Veerman
1271357f1050SThomas Veerman tbl = mkecstbl ();
1272357f1050SThomas Veerman yytbl_data_compress (tbl);
1273357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1274357f1050SThomas Veerman flexerror (_("Could not write ecstbl"));
1275357f1050SThomas Veerman yytbl_data_destroy (tbl);
1276357f1050SThomas Veerman tbl = 0;
1277357f1050SThomas Veerman }
1278357f1050SThomas Veerman }
1279357f1050SThomas Veerman
1280357f1050SThomas Veerman if (usemecs) {
1281357f1050SThomas Veerman /* Begin generating yy_meta */
1282357f1050SThomas Veerman /* Write out meta-equivalence classes (used to index
1283357f1050SThomas Veerman * templates with).
1284357f1050SThomas Veerman */
1285357f1050SThomas Veerman flex_int32_t *yymecs_data = 0;
1286357f1050SThomas Veerman yymeta_tbl =
1287357f1050SThomas Veerman (struct yytbl_data *) calloc (1,
1288357f1050SThomas Veerman sizeof (struct
1289357f1050SThomas Veerman yytbl_data));
1290357f1050SThomas Veerman yytbl_data_init (yymeta_tbl, YYTD_ID_META);
1291357f1050SThomas Veerman yymeta_tbl->td_lolen = numecs + 1;
1292357f1050SThomas Veerman yymeta_tbl->td_data = yymecs_data =
1293357f1050SThomas Veerman (flex_int32_t *) calloc (yymeta_tbl->td_lolen,
1294357f1050SThomas Veerman sizeof (flex_int32_t));
1295357f1050SThomas Veerman
1296357f1050SThomas Veerman if (trace)
1297357f1050SThomas Veerman fputs (_("\n\nMeta-Equivalence Classes:\n"),
1298357f1050SThomas Veerman stderr);
1299357f1050SThomas Veerman
1300*0a6a1f1dSLionel Sambuc out_str_dec (get_yy_char_decl (), "yy_meta", numecs + 1);
1301357f1050SThomas Veerman buf_prints (&yydmap_buf,
1302357f1050SThomas Veerman "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
1303*0a6a1f1dSLionel Sambuc "YY_CHAR");
1304357f1050SThomas Veerman
1305357f1050SThomas Veerman for (i = 1; i <= numecs; ++i) {
1306357f1050SThomas Veerman if (trace)
1307357f1050SThomas Veerman fprintf (stderr, "%d = %d\n",
1308357f1050SThomas Veerman i, ABS (tecbck[i]));
1309357f1050SThomas Veerman
1310357f1050SThomas Veerman mkdata (ABS (tecbck[i]));
1311357f1050SThomas Veerman yymecs_data[i] = ABS (tecbck[i]);
1312357f1050SThomas Veerman }
1313357f1050SThomas Veerman
1314357f1050SThomas Veerman dataend ();
1315357f1050SThomas Veerman if (tablesext) {
1316357f1050SThomas Veerman yytbl_data_compress (yymeta_tbl);
1317357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, yymeta_tbl) < 0)
1318357f1050SThomas Veerman flexerror (_
1319357f1050SThomas Veerman ("Could not write yymeta_tbl"));
1320357f1050SThomas Veerman yytbl_data_destroy (yymeta_tbl);
1321357f1050SThomas Veerman yymeta_tbl = NULL;
1322357f1050SThomas Veerman }
1323357f1050SThomas Veerman /* End generating yy_meta */
1324357f1050SThomas Veerman }
1325357f1050SThomas Veerman
1326357f1050SThomas Veerman total_states = lastdfa + numtemps;
1327357f1050SThomas Veerman
1328357f1050SThomas Veerman /* Begin generating yy_base */
1329357f1050SThomas Veerman out_str_dec ((tblend >= INT16_MAX || long_align) ?
1330*0a6a1f1dSLionel Sambuc get_uint32_decl () : get_uint16_decl (),
1331357f1050SThomas Veerman "yy_base", total_states + 1);
1332357f1050SThomas Veerman
1333357f1050SThomas Veerman buf_prints (&yydmap_buf,
1334357f1050SThomas Veerman "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
1335357f1050SThomas Veerman (tblend >= INT16_MAX
1336*0a6a1f1dSLionel Sambuc || long_align) ? "flex_uint32_t" : "flex_uint16_t");
1337357f1050SThomas Veerman yybase_tbl =
1338357f1050SThomas Veerman (struct yytbl_data *) calloc (1,
1339357f1050SThomas Veerman sizeof (struct yytbl_data));
1340357f1050SThomas Veerman yytbl_data_init (yybase_tbl, YYTD_ID_BASE);
1341357f1050SThomas Veerman yybase_tbl->td_lolen = total_states + 1;
1342357f1050SThomas Veerman yybase_tbl->td_data = yybase_data =
1343357f1050SThomas Veerman (flex_int32_t *) calloc (yybase_tbl->td_lolen,
1344357f1050SThomas Veerman sizeof (flex_int32_t));
1345357f1050SThomas Veerman yybase_curr = 1;
1346357f1050SThomas Veerman
1347357f1050SThomas Veerman for (i = 1; i <= lastdfa; ++i) {
1348357f1050SThomas Veerman register int d = def[i];
1349357f1050SThomas Veerman
1350357f1050SThomas Veerman if (base[i] == JAMSTATE)
1351357f1050SThomas Veerman base[i] = jambase;
1352357f1050SThomas Veerman
1353357f1050SThomas Veerman if (d == JAMSTATE)
1354357f1050SThomas Veerman def[i] = jamstate;
1355357f1050SThomas Veerman
1356357f1050SThomas Veerman else if (d < 0) {
1357357f1050SThomas Veerman /* Template reference. */
1358357f1050SThomas Veerman ++tmpuses;
1359357f1050SThomas Veerman def[i] = lastdfa - d + 1;
1360357f1050SThomas Veerman }
1361357f1050SThomas Veerman
1362357f1050SThomas Veerman mkdata (base[i]);
1363357f1050SThomas Veerman yybase_data[yybase_curr++] = base[i];
1364357f1050SThomas Veerman }
1365357f1050SThomas Veerman
1366357f1050SThomas Veerman /* Generate jam state's base index. */
1367357f1050SThomas Veerman mkdata (base[i]);
1368357f1050SThomas Veerman yybase_data[yybase_curr++] = base[i];
1369357f1050SThomas Veerman
1370357f1050SThomas Veerman for (++i /* skip jam state */ ; i <= total_states; ++i) {
1371357f1050SThomas Veerman mkdata (base[i]);
1372357f1050SThomas Veerman yybase_data[yybase_curr++] = base[i];
1373357f1050SThomas Veerman def[i] = jamstate;
1374357f1050SThomas Veerman }
1375357f1050SThomas Veerman
1376357f1050SThomas Veerman dataend ();
1377357f1050SThomas Veerman if (tablesext) {
1378357f1050SThomas Veerman yytbl_data_compress (yybase_tbl);
1379357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, yybase_tbl) < 0)
1380357f1050SThomas Veerman flexerror (_("Could not write yybase_tbl"));
1381357f1050SThomas Veerman yytbl_data_destroy (yybase_tbl);
1382357f1050SThomas Veerman yybase_tbl = NULL;
1383357f1050SThomas Veerman }
1384357f1050SThomas Veerman /* End generating yy_base */
1385357f1050SThomas Veerman
1386357f1050SThomas Veerman
1387357f1050SThomas Veerman /* Begin generating yy_def */
1388357f1050SThomas Veerman out_str_dec ((total_states >= INT16_MAX || long_align) ?
1389357f1050SThomas Veerman get_int32_decl () : get_int16_decl (),
1390357f1050SThomas Veerman "yy_def", total_states + 1);
1391357f1050SThomas Veerman
1392357f1050SThomas Veerman buf_prints (&yydmap_buf,
1393357f1050SThomas Veerman "\t{YYTD_ID_DEF, (void**)&yy_def, sizeof(%s)},\n",
1394357f1050SThomas Veerman (total_states >= INT16_MAX
1395357f1050SThomas Veerman || long_align) ? "flex_int32_t" : "flex_int16_t");
1396357f1050SThomas Veerman
1397357f1050SThomas Veerman yydef_tbl =
1398357f1050SThomas Veerman (struct yytbl_data *) calloc (1,
1399357f1050SThomas Veerman sizeof (struct yytbl_data));
1400357f1050SThomas Veerman yytbl_data_init (yydef_tbl, YYTD_ID_DEF);
1401357f1050SThomas Veerman yydef_tbl->td_lolen = total_states + 1;
1402357f1050SThomas Veerman yydef_tbl->td_data = yydef_data =
1403357f1050SThomas Veerman (flex_int32_t *) calloc (yydef_tbl->td_lolen, sizeof (flex_int32_t));
1404357f1050SThomas Veerman
1405357f1050SThomas Veerman for (i = 1; i <= total_states; ++i) {
1406357f1050SThomas Veerman mkdata (def[i]);
1407357f1050SThomas Veerman yydef_data[i] = def[i];
1408357f1050SThomas Veerman }
1409357f1050SThomas Veerman
1410357f1050SThomas Veerman dataend ();
1411357f1050SThomas Veerman if (tablesext) {
1412357f1050SThomas Veerman yytbl_data_compress (yydef_tbl);
1413357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, yydef_tbl) < 0)
1414357f1050SThomas Veerman flexerror (_("Could not write yydef_tbl"));
1415357f1050SThomas Veerman yytbl_data_destroy (yydef_tbl);
1416357f1050SThomas Veerman yydef_tbl = NULL;
1417357f1050SThomas Veerman }
1418357f1050SThomas Veerman /* End generating yy_def */
1419357f1050SThomas Veerman
1420357f1050SThomas Veerman
1421357f1050SThomas Veerman /* Begin generating yy_nxt */
1422357f1050SThomas Veerman out_str_dec ((total_states >= INT16_MAX || long_align) ?
1423*0a6a1f1dSLionel Sambuc get_uint32_decl () : get_uint16_decl (), "yy_nxt",
1424357f1050SThomas Veerman tblend + 1);
1425357f1050SThomas Veerman
1426357f1050SThomas Veerman buf_prints (&yydmap_buf,
1427357f1050SThomas Veerman "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
1428357f1050SThomas Veerman (total_states >= INT16_MAX
1429*0a6a1f1dSLionel Sambuc || long_align) ? "flex_uint32_t" : "flex_uint16_t");
1430357f1050SThomas Veerman
1431357f1050SThomas Veerman yynxt_tbl =
1432357f1050SThomas Veerman (struct yytbl_data *) calloc (1,
1433357f1050SThomas Veerman sizeof (struct yytbl_data));
1434357f1050SThomas Veerman yytbl_data_init (yynxt_tbl, YYTD_ID_NXT);
1435357f1050SThomas Veerman yynxt_tbl->td_lolen = tblend + 1;
1436357f1050SThomas Veerman yynxt_tbl->td_data = yynxt_data =
1437357f1050SThomas Veerman (flex_int32_t *) calloc (yynxt_tbl->td_lolen, sizeof (flex_int32_t));
1438357f1050SThomas Veerman
1439357f1050SThomas Veerman for (i = 1; i <= tblend; ++i) {
1440357f1050SThomas Veerman /* Note, the order of the following test is important.
1441357f1050SThomas Veerman * If chk[i] is 0, then nxt[i] is undefined.
1442357f1050SThomas Veerman */
1443357f1050SThomas Veerman if (chk[i] == 0 || nxt[i] == 0)
1444357f1050SThomas Veerman nxt[i] = jamstate; /* new state is the JAM state */
1445357f1050SThomas Veerman
1446357f1050SThomas Veerman mkdata (nxt[i]);
1447357f1050SThomas Veerman yynxt_data[i] = nxt[i];
1448357f1050SThomas Veerman }
1449357f1050SThomas Veerman
1450357f1050SThomas Veerman dataend ();
1451357f1050SThomas Veerman if (tablesext) {
1452357f1050SThomas Veerman yytbl_data_compress (yynxt_tbl);
1453357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0)
1454357f1050SThomas Veerman flexerror (_("Could not write yynxt_tbl"));
1455357f1050SThomas Veerman yytbl_data_destroy (yynxt_tbl);
1456357f1050SThomas Veerman yynxt_tbl = NULL;
1457357f1050SThomas Veerman }
1458357f1050SThomas Veerman /* End generating yy_nxt */
1459357f1050SThomas Veerman
1460357f1050SThomas Veerman /* Begin generating yy_chk */
1461357f1050SThomas Veerman out_str_dec ((total_states >= INT16_MAX || long_align) ?
1462357f1050SThomas Veerman get_int32_decl () : get_int16_decl (), "yy_chk",
1463357f1050SThomas Veerman tblend + 1);
1464357f1050SThomas Veerman
1465357f1050SThomas Veerman buf_prints (&yydmap_buf,
1466357f1050SThomas Veerman "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n",
1467357f1050SThomas Veerman (total_states >= INT16_MAX
1468357f1050SThomas Veerman || long_align) ? "flex_int32_t" : "flex_int16_t");
1469357f1050SThomas Veerman
1470357f1050SThomas Veerman yychk_tbl =
1471357f1050SThomas Veerman (struct yytbl_data *) calloc (1,
1472357f1050SThomas Veerman sizeof (struct yytbl_data));
1473357f1050SThomas Veerman yytbl_data_init (yychk_tbl, YYTD_ID_CHK);
1474357f1050SThomas Veerman yychk_tbl->td_lolen = tblend + 1;
1475357f1050SThomas Veerman yychk_tbl->td_data = yychk_data =
1476357f1050SThomas Veerman (flex_int32_t *) calloc (yychk_tbl->td_lolen, sizeof (flex_int32_t));
1477357f1050SThomas Veerman
1478357f1050SThomas Veerman for (i = 1; i <= tblend; ++i) {
1479357f1050SThomas Veerman if (chk[i] == 0)
1480357f1050SThomas Veerman ++nummt;
1481357f1050SThomas Veerman
1482357f1050SThomas Veerman mkdata (chk[i]);
1483357f1050SThomas Veerman yychk_data[i] = chk[i];
1484357f1050SThomas Veerman }
1485357f1050SThomas Veerman
1486357f1050SThomas Veerman dataend ();
1487357f1050SThomas Veerman if (tablesext) {
1488357f1050SThomas Veerman yytbl_data_compress (yychk_tbl);
1489357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, yychk_tbl) < 0)
1490357f1050SThomas Veerman flexerror (_("Could not write yychk_tbl"));
1491357f1050SThomas Veerman yytbl_data_destroy (yychk_tbl);
1492357f1050SThomas Veerman yychk_tbl = NULL;
1493357f1050SThomas Veerman }
1494357f1050SThomas Veerman /* End generating yy_chk */
1495357f1050SThomas Veerman
1496357f1050SThomas Veerman flex_free ((void *) acc_array);
1497357f1050SThomas Veerman }
1498357f1050SThomas Veerman
1499357f1050SThomas Veerman
1500357f1050SThomas Veerman /* Write out a formatted string (with a secondary string argument) at the
1501357f1050SThomas Veerman * current indentation level, adding a final newline.
1502357f1050SThomas Veerman */
1503357f1050SThomas Veerman
indent_put2s(fmt,arg)1504357f1050SThomas Veerman void indent_put2s (fmt, arg)
1505357f1050SThomas Veerman const char *fmt, *arg;
1506357f1050SThomas Veerman {
1507357f1050SThomas Veerman do_indent ();
1508357f1050SThomas Veerman out_str (fmt, arg);
1509357f1050SThomas Veerman outn ("");
1510357f1050SThomas Veerman }
1511357f1050SThomas Veerman
1512357f1050SThomas Veerman
1513357f1050SThomas Veerman /* Write out a string at the current indentation level, adding a final
1514357f1050SThomas Veerman * newline.
1515357f1050SThomas Veerman */
1516357f1050SThomas Veerman
indent_puts(str)1517357f1050SThomas Veerman void indent_puts (str)
1518357f1050SThomas Veerman const char *str;
1519357f1050SThomas Veerman {
1520357f1050SThomas Veerman do_indent ();
1521357f1050SThomas Veerman outn (str);
1522357f1050SThomas Veerman }
1523357f1050SThomas Veerman
1524357f1050SThomas Veerman
1525357f1050SThomas Veerman /* make_tables - generate transition tables and finishes generating output file
1526357f1050SThomas Veerman */
1527357f1050SThomas Veerman
make_tables()1528357f1050SThomas Veerman void make_tables ()
1529357f1050SThomas Veerman {
1530357f1050SThomas Veerman register int i;
1531357f1050SThomas Veerman int did_eof_rule = false;
1532357f1050SThomas Veerman struct yytbl_data *yynultrans_tbl;
1533357f1050SThomas Veerman
1534357f1050SThomas Veerman
1535357f1050SThomas Veerman skelout (); /* %% [2.0] - break point in skel */
1536357f1050SThomas Veerman
1537357f1050SThomas Veerman /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1538357f1050SThomas Veerman * being used.
1539357f1050SThomas Veerman */
1540357f1050SThomas Veerman set_indent (1);
1541357f1050SThomas Veerman
1542357f1050SThomas Veerman if (yymore_used && !yytext_is_array) {
1543357f1050SThomas Veerman indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\");
1544357f1050SThomas Veerman indent_puts
1545357f1050SThomas Veerman ("yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\");
1546357f1050SThomas Veerman }
1547357f1050SThomas Veerman
1548357f1050SThomas Veerman else
1549357f1050SThomas Veerman indent_puts ("yyleng = (size_t) (yy_cp - yy_bp); \\");
1550357f1050SThomas Veerman
1551357f1050SThomas Veerman /* Now also deal with copying yytext_ptr to yytext if needed. */
1552357f1050SThomas Veerman skelout (); /* %% [3.0] - break point in skel */
1553357f1050SThomas Veerman if (yytext_is_array) {
1554357f1050SThomas Veerman if (yymore_used)
1555357f1050SThomas Veerman indent_puts
1556357f1050SThomas Veerman ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\");
1557357f1050SThomas Veerman else
1558357f1050SThomas Veerman indent_puts ("if ( yyleng >= YYLMAX ) \\");
1559357f1050SThomas Veerman
1560357f1050SThomas Veerman indent_up ();
1561357f1050SThomas Veerman indent_puts
1562357f1050SThomas Veerman ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\");
1563357f1050SThomas Veerman indent_down ();
1564357f1050SThomas Veerman
1565357f1050SThomas Veerman if (yymore_used) {
1566357f1050SThomas Veerman indent_puts
1567357f1050SThomas Veerman ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1568357f1050SThomas Veerman indent_puts ("yyleng += YY_G(yy_more_offset); \\");
1569357f1050SThomas Veerman indent_puts
1570357f1050SThomas Veerman ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\");
1571357f1050SThomas Veerman indent_puts ("YY_G(yy_more_offset) = 0; \\");
1572357f1050SThomas Veerman }
1573357f1050SThomas Veerman else {
1574357f1050SThomas Veerman indent_puts
1575357f1050SThomas Veerman ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1576357f1050SThomas Veerman }
1577357f1050SThomas Veerman }
1578357f1050SThomas Veerman
1579357f1050SThomas Veerman set_indent (0);
1580357f1050SThomas Veerman
1581357f1050SThomas Veerman skelout (); /* %% [4.0] - break point in skel */
1582357f1050SThomas Veerman
1583357f1050SThomas Veerman
1584357f1050SThomas Veerman /* This is where we REALLY begin generating the tables. */
1585357f1050SThomas Veerman
1586357f1050SThomas Veerman out_dec ("#define YY_NUM_RULES %d\n", num_rules);
1587357f1050SThomas Veerman out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules + 1);
1588357f1050SThomas Veerman
1589357f1050SThomas Veerman if (fullspd) {
1590357f1050SThomas Veerman /* Need to define the transet type as a size large
1591357f1050SThomas Veerman * enough to hold the biggest offset.
1592357f1050SThomas Veerman */
1593357f1050SThomas Veerman int total_table_size = tblend + numecs + 1;
1594357f1050SThomas Veerman char *trans_offset_type =
1595357f1050SThomas Veerman (total_table_size >= INT16_MAX || long_align) ?
1596357f1050SThomas Veerman "flex_int32_t" : "flex_int16_t";
1597357f1050SThomas Veerman
1598357f1050SThomas Veerman set_indent (0);
1599357f1050SThomas Veerman indent_puts ("struct yy_trans_info");
1600357f1050SThomas Veerman indent_up ();
1601357f1050SThomas Veerman indent_puts ("{");
1602357f1050SThomas Veerman
1603357f1050SThomas Veerman /* We require that yy_verify and yy_nxt must be of the same size int. */
1604357f1050SThomas Veerman indent_put2s ("%s yy_verify;", trans_offset_type);
1605357f1050SThomas Veerman
1606357f1050SThomas Veerman /* In cases where its sister yy_verify *is* a "yes, there is
1607357f1050SThomas Veerman * a transition", yy_nxt is the offset (in records) to the
1608357f1050SThomas Veerman * next state. In most cases where there is no transition,
1609357f1050SThomas Veerman * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1610357f1050SThomas Veerman * record of a state, though, then yy_nxt is the action number
1611357f1050SThomas Veerman * for that state.
1612357f1050SThomas Veerman */
1613357f1050SThomas Veerman
1614357f1050SThomas Veerman indent_put2s ("%s yy_nxt;", trans_offset_type);
1615357f1050SThomas Veerman indent_puts ("};");
1616357f1050SThomas Veerman indent_down ();
1617357f1050SThomas Veerman }
1618357f1050SThomas Veerman else {
1619357f1050SThomas Veerman /* We generate a bogus 'struct yy_trans_info' data type
1620357f1050SThomas Veerman * so we can guarantee that it is always declared in the skel.
1621357f1050SThomas Veerman * This is so we can compile "sizeof(struct yy_trans_info)"
1622357f1050SThomas Veerman * in any scanner.
1623357f1050SThomas Veerman */
1624357f1050SThomas Veerman indent_puts
1625357f1050SThomas Veerman ("/* This struct is not used in this scanner,");
1626357f1050SThomas Veerman indent_puts (" but its presence is necessary. */");
1627357f1050SThomas Veerman indent_puts ("struct yy_trans_info");
1628357f1050SThomas Veerman indent_up ();
1629357f1050SThomas Veerman indent_puts ("{");
1630357f1050SThomas Veerman indent_puts ("flex_int32_t yy_verify;");
1631357f1050SThomas Veerman indent_puts ("flex_int32_t yy_nxt;");
1632357f1050SThomas Veerman indent_puts ("};");
1633357f1050SThomas Veerman indent_down ();
1634357f1050SThomas Veerman }
1635357f1050SThomas Veerman
1636357f1050SThomas Veerman if (fullspd) {
1637357f1050SThomas Veerman genctbl ();
1638357f1050SThomas Veerman if (tablesext) {
1639357f1050SThomas Veerman struct yytbl_data *tbl;
1640357f1050SThomas Veerman
1641357f1050SThomas Veerman tbl = mkctbl ();
1642357f1050SThomas Veerman yytbl_data_compress (tbl);
1643357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1644357f1050SThomas Veerman flexerror (_("Could not write ftbl"));
1645357f1050SThomas Veerman yytbl_data_destroy (tbl);
1646357f1050SThomas Veerman
1647357f1050SThomas Veerman tbl = mkssltbl ();
1648357f1050SThomas Veerman yytbl_data_compress (tbl);
1649357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1650357f1050SThomas Veerman flexerror (_("Could not write ssltbl"));
1651357f1050SThomas Veerman yytbl_data_destroy (tbl);
1652357f1050SThomas Veerman tbl = 0;
1653357f1050SThomas Veerman
1654357f1050SThomas Veerman if (useecs) {
1655357f1050SThomas Veerman tbl = mkecstbl ();
1656357f1050SThomas Veerman yytbl_data_compress (tbl);
1657357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1658357f1050SThomas Veerman flexerror (_
1659357f1050SThomas Veerman ("Could not write ecstbl"));
1660357f1050SThomas Veerman yytbl_data_destroy (tbl);
1661357f1050SThomas Veerman tbl = 0;
1662357f1050SThomas Veerman }
1663357f1050SThomas Veerman }
1664357f1050SThomas Veerman }
1665357f1050SThomas Veerman else if (fulltbl) {
1666357f1050SThomas Veerman genftbl ();
1667357f1050SThomas Veerman if (tablesext) {
1668357f1050SThomas Veerman struct yytbl_data *tbl;
1669357f1050SThomas Veerman
1670357f1050SThomas Veerman tbl = mkftbl ();
1671357f1050SThomas Veerman yytbl_data_compress (tbl);
1672357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1673357f1050SThomas Veerman flexerror (_("Could not write ftbl"));
1674357f1050SThomas Veerman yytbl_data_destroy (tbl);
1675357f1050SThomas Veerman tbl = 0;
1676357f1050SThomas Veerman
1677357f1050SThomas Veerman if (useecs) {
1678357f1050SThomas Veerman tbl = mkecstbl ();
1679357f1050SThomas Veerman yytbl_data_compress (tbl);
1680357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1681357f1050SThomas Veerman flexerror (_
1682357f1050SThomas Veerman ("Could not write ecstbl"));
1683357f1050SThomas Veerman yytbl_data_destroy (tbl);
1684357f1050SThomas Veerman tbl = 0;
1685357f1050SThomas Veerman }
1686357f1050SThomas Veerman }
1687357f1050SThomas Veerman }
1688357f1050SThomas Veerman else
1689357f1050SThomas Veerman gentabs ();
1690357f1050SThomas Veerman
1691357f1050SThomas Veerman if (do_yylineno) {
1692357f1050SThomas Veerman
1693357f1050SThomas Veerman geneoltbl ();
1694357f1050SThomas Veerman
1695357f1050SThomas Veerman if (tablesext) {
1696357f1050SThomas Veerman struct yytbl_data *tbl;
1697357f1050SThomas Veerman
1698357f1050SThomas Veerman tbl = mkeoltbl ();
1699357f1050SThomas Veerman yytbl_data_compress (tbl);
1700357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1701357f1050SThomas Veerman flexerror (_("Could not write eoltbl"));
1702357f1050SThomas Veerman yytbl_data_destroy (tbl);
1703357f1050SThomas Veerman tbl = 0;
1704357f1050SThomas Veerman }
1705357f1050SThomas Veerman }
1706357f1050SThomas Veerman
1707357f1050SThomas Veerman /* Definitions for backing up. We don't need them if REJECT
1708357f1050SThomas Veerman * is being used because then we use an alternative backin-up
1709357f1050SThomas Veerman * technique instead.
1710357f1050SThomas Veerman */
1711357f1050SThomas Veerman if (num_backing_up > 0 && !reject) {
1712357f1050SThomas Veerman if (!C_plus_plus && !reentrant) {
1713357f1050SThomas Veerman indent_puts
1714357f1050SThomas Veerman ("static yy_state_type yy_last_accepting_state;");
1715357f1050SThomas Veerman indent_puts
1716357f1050SThomas Veerman ("static char *yy_last_accepting_cpos;\n");
1717357f1050SThomas Veerman }
1718357f1050SThomas Veerman }
1719357f1050SThomas Veerman
1720357f1050SThomas Veerman if (nultrans) {
1721357f1050SThomas Veerman flex_int32_t *yynultrans_data = 0;
1722357f1050SThomas Veerman
1723357f1050SThomas Veerman /* Begin generating yy_NUL_trans */
1724357f1050SThomas Veerman out_str_dec (get_state_decl (), "yy_NUL_trans",
1725357f1050SThomas Veerman lastdfa + 1);
1726357f1050SThomas Veerman buf_prints (&yydmap_buf,
1727357f1050SThomas Veerman "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n",
1728357f1050SThomas Veerman (fullspd) ? "struct yy_trans_info*" :
1729357f1050SThomas Veerman "flex_int32_t");
1730357f1050SThomas Veerman
1731357f1050SThomas Veerman yynultrans_tbl =
1732357f1050SThomas Veerman (struct yytbl_data *) calloc (1,
1733357f1050SThomas Veerman sizeof (struct
1734357f1050SThomas Veerman yytbl_data));
1735357f1050SThomas Veerman yytbl_data_init (yynultrans_tbl, YYTD_ID_NUL_TRANS);
1736357f1050SThomas Veerman if (fullspd)
1737357f1050SThomas Veerman yynultrans_tbl->td_flags |= YYTD_PTRANS;
1738357f1050SThomas Veerman yynultrans_tbl->td_lolen = lastdfa + 1;
1739357f1050SThomas Veerman yynultrans_tbl->td_data = yynultrans_data =
1740357f1050SThomas Veerman (flex_int32_t *) calloc (yynultrans_tbl->td_lolen,
1741357f1050SThomas Veerman sizeof (flex_int32_t));
1742357f1050SThomas Veerman
1743357f1050SThomas Veerman for (i = 1; i <= lastdfa; ++i) {
1744357f1050SThomas Veerman if (fullspd) {
1745357f1050SThomas Veerman out_dec (" &yy_transition[%d],\n",
1746357f1050SThomas Veerman base[i]);
1747357f1050SThomas Veerman yynultrans_data[i] = base[i];
1748357f1050SThomas Veerman }
1749357f1050SThomas Veerman else {
1750357f1050SThomas Veerman mkdata (nultrans[i]);
1751357f1050SThomas Veerman yynultrans_data[i] = nultrans[i];
1752357f1050SThomas Veerman }
1753357f1050SThomas Veerman }
1754357f1050SThomas Veerman
1755357f1050SThomas Veerman dataend ();
1756357f1050SThomas Veerman if (tablesext) {
1757357f1050SThomas Veerman yytbl_data_compress (yynultrans_tbl);
1758357f1050SThomas Veerman if (yytbl_data_fwrite (&tableswr, yynultrans_tbl) <
1759357f1050SThomas Veerman 0)
1760357f1050SThomas Veerman flexerror (_
1761357f1050SThomas Veerman ("Could not write yynultrans_tbl"));
1762357f1050SThomas Veerman yytbl_data_destroy (yynultrans_tbl);
1763357f1050SThomas Veerman yynultrans_tbl = NULL;
1764357f1050SThomas Veerman }
1765357f1050SThomas Veerman /* End generating yy_NUL_trans */
1766357f1050SThomas Veerman }
1767357f1050SThomas Veerman
1768357f1050SThomas Veerman if (!C_plus_plus && !reentrant) {
1769357f1050SThomas Veerman indent_puts ("extern int yy_flex_debug;");
1770357f1050SThomas Veerman indent_put2s ("int yy_flex_debug = %s;\n",
1771357f1050SThomas Veerman ddebug ? "1" : "0");
1772357f1050SThomas Veerman }
1773357f1050SThomas Veerman
1774357f1050SThomas Veerman if (ddebug) { /* Spit out table mapping rules to line numbers. */
1775357f1050SThomas Veerman out_str_dec (long_align ? get_int32_decl () :
1776357f1050SThomas Veerman get_int16_decl (), "yy_rule_linenum",
1777357f1050SThomas Veerman num_rules);
1778357f1050SThomas Veerman for (i = 1; i < num_rules; ++i)
1779357f1050SThomas Veerman mkdata (rule_linenum[i]);
1780357f1050SThomas Veerman dataend ();
1781357f1050SThomas Veerman }
1782357f1050SThomas Veerman
1783357f1050SThomas Veerman if (reject) {
1784357f1050SThomas Veerman outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1785357f1050SThomas Veerman /* Declare state buffer variables. */
1786357f1050SThomas Veerman if (!C_plus_plus && !reentrant) {
1787357f1050SThomas Veerman outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
1788357f1050SThomas Veerman outn ("static char *yy_full_match;");
1789357f1050SThomas Veerman outn ("static int yy_lp;");
1790357f1050SThomas Veerman }
1791357f1050SThomas Veerman
1792357f1050SThomas Veerman if (variable_trailing_context_rules) {
1793357f1050SThomas Veerman if (!C_plus_plus && !reentrant) {
1794357f1050SThomas Veerman outn ("static int yy_looking_for_trail_begin = 0;");
1795357f1050SThomas Veerman outn ("static int yy_full_lp;");
1796357f1050SThomas Veerman outn ("static int *yy_full_state;");
1797357f1050SThomas Veerman }
1798357f1050SThomas Veerman
1799357f1050SThomas Veerman out_hex ("#define YY_TRAILING_MASK 0x%x\n",
1800357f1050SThomas Veerman (unsigned int) YY_TRAILING_MASK);
1801357f1050SThomas Veerman out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n",
1802357f1050SThomas Veerman (unsigned int) YY_TRAILING_HEAD_MASK);
1803357f1050SThomas Veerman }
1804357f1050SThomas Veerman
1805357f1050SThomas Veerman outn ("#define REJECT \\");
1806357f1050SThomas Veerman outn ("{ \\");
1807357f1050SThomas Veerman outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\");
1808357f1050SThomas Veerman outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
1809357f1050SThomas Veerman
1810357f1050SThomas Veerman if (variable_trailing_context_rules) {
1811357f1050SThomas Veerman outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\");
1812357f1050SThomas Veerman outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\");
1813357f1050SThomas Veerman outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
1814357f1050SThomas Veerman }
1815357f1050SThomas Veerman
1816357f1050SThomas Veerman outn ("++YY_G(yy_lp); \\");
1817357f1050SThomas Veerman outn ("goto find_rule; \\");
1818357f1050SThomas Veerman
1819357f1050SThomas Veerman outn ("}");
1820357f1050SThomas Veerman outn ("]])\n");
1821357f1050SThomas Veerman }
1822357f1050SThomas Veerman
1823357f1050SThomas Veerman else {
1824357f1050SThomas Veerman outn ("/* The intent behind this definition is that it'll catch");
1825357f1050SThomas Veerman outn (" * any uses of REJECT which flex missed.");
1826357f1050SThomas Veerman outn (" */");
1827357f1050SThomas Veerman outn ("#define REJECT reject_used_but_not_detected");
1828357f1050SThomas Veerman }
1829357f1050SThomas Veerman
1830357f1050SThomas Veerman if (yymore_used) {
1831357f1050SThomas Veerman if (!C_plus_plus) {
1832357f1050SThomas Veerman if (yytext_is_array) {
1833357f1050SThomas Veerman if (!reentrant){
1834357f1050SThomas Veerman indent_puts ("static int yy_more_offset = 0;");
1835357f1050SThomas Veerman indent_puts ("static int yy_prev_more_offset = 0;");
1836357f1050SThomas Veerman }
1837357f1050SThomas Veerman }
1838357f1050SThomas Veerman else if (!reentrant) {
1839357f1050SThomas Veerman indent_puts
1840357f1050SThomas Veerman ("static int yy_more_flag = 0;");
1841357f1050SThomas Veerman indent_puts
1842357f1050SThomas Veerman ("static int yy_more_len = 0;");
1843357f1050SThomas Veerman }
1844357f1050SThomas Veerman }
1845357f1050SThomas Veerman
1846357f1050SThomas Veerman if (yytext_is_array) {
1847357f1050SThomas Veerman indent_puts
1848357f1050SThomas Veerman ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))");
1849357f1050SThomas Veerman indent_puts ("#define YY_NEED_STRLEN");
1850357f1050SThomas Veerman indent_puts ("#define YY_MORE_ADJ 0");
1851357f1050SThomas Veerman indent_puts
1852357f1050SThomas Veerman ("#define YY_RESTORE_YY_MORE_OFFSET \\");
1853357f1050SThomas Veerman indent_up ();
1854357f1050SThomas Veerman indent_puts ("{ \\");
1855357f1050SThomas Veerman indent_puts
1856357f1050SThomas Veerman ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\");
1857357f1050SThomas Veerman indent_puts ("yyleng -= YY_G(yy_more_offset); \\");
1858357f1050SThomas Veerman indent_puts ("}");
1859357f1050SThomas Veerman indent_down ();
1860357f1050SThomas Veerman }
1861357f1050SThomas Veerman else {
1862357f1050SThomas Veerman indent_puts
1863357f1050SThomas Veerman ("#define yymore() (YY_G(yy_more_flag) = 1)");
1864357f1050SThomas Veerman indent_puts
1865357f1050SThomas Veerman ("#define YY_MORE_ADJ YY_G(yy_more_len)");
1866357f1050SThomas Veerman indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1867357f1050SThomas Veerman }
1868357f1050SThomas Veerman }
1869357f1050SThomas Veerman
1870357f1050SThomas Veerman else {
1871357f1050SThomas Veerman indent_puts
1872357f1050SThomas Veerman ("#define yymore() yymore_used_but_not_detected");
1873357f1050SThomas Veerman indent_puts ("#define YY_MORE_ADJ 0");
1874357f1050SThomas Veerman indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1875357f1050SThomas Veerman }
1876357f1050SThomas Veerman
1877357f1050SThomas Veerman if (!C_plus_plus) {
1878357f1050SThomas Veerman if (yytext_is_array) {
1879357f1050SThomas Veerman outn ("#ifndef YYLMAX");
1880357f1050SThomas Veerman outn ("#define YYLMAX 8192");
1881357f1050SThomas Veerman outn ("#endif\n");
1882357f1050SThomas Veerman if (!reentrant){
1883357f1050SThomas Veerman outn ("char yytext[YYLMAX];");
1884357f1050SThomas Veerman outn ("char *yytext_ptr;");
1885357f1050SThomas Veerman }
1886357f1050SThomas Veerman }
1887357f1050SThomas Veerman
1888357f1050SThomas Veerman else {
1889357f1050SThomas Veerman if(! reentrant)
1890357f1050SThomas Veerman outn ("char *yytext;");
1891357f1050SThomas Veerman }
1892357f1050SThomas Veerman }
1893357f1050SThomas Veerman
1894357f1050SThomas Veerman out (&action_array[defs1_offset]);
1895357f1050SThomas Veerman
1896357f1050SThomas Veerman line_directive_out (stdout, 0);
1897357f1050SThomas Veerman
1898357f1050SThomas Veerman skelout (); /* %% [5.0] - break point in skel */
1899357f1050SThomas Veerman
1900357f1050SThomas Veerman if (!C_plus_plus) {
1901357f1050SThomas Veerman if (use_read) {
1902357f1050SThomas Veerman outn ("\terrno=0; \\");
1903357f1050SThomas Veerman outn ("\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\");
1904357f1050SThomas Veerman outn ("\t{ \\");
1905357f1050SThomas Veerman outn ("\t\tif( errno != EINTR) \\");
1906357f1050SThomas Veerman outn ("\t\t{ \\");
1907357f1050SThomas Veerman outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1908357f1050SThomas Veerman outn ("\t\t\tbreak; \\");
1909357f1050SThomas Veerman outn ("\t\t} \\");
1910357f1050SThomas Veerman outn ("\t\terrno=0; \\");
1911357f1050SThomas Veerman outn ("\t\tclearerr(yyin); \\");
1912357f1050SThomas Veerman outn ("\t}\\");
1913357f1050SThomas Veerman }
1914357f1050SThomas Veerman
1915357f1050SThomas Veerman else {
1916357f1050SThomas Veerman outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\");
1917357f1050SThomas Veerman outn ("\t\t{ \\");
1918357f1050SThomas Veerman outn ("\t\tint c = '*'; \\");
1919357f1050SThomas Veerman outn ("\t\tsize_t n; \\");
1920357f1050SThomas Veerman outn ("\t\tfor ( n = 0; n < max_size && \\");
1921357f1050SThomas Veerman outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\");
1922357f1050SThomas Veerman outn ("\t\t\tbuf[n] = (char) c; \\");
1923357f1050SThomas Veerman outn ("\t\tif ( c == '\\n' ) \\");
1924357f1050SThomas Veerman outn ("\t\t\tbuf[n++] = (char) c; \\");
1925357f1050SThomas Veerman outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\");
1926357f1050SThomas Veerman outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1927357f1050SThomas Veerman outn ("\t\tresult = n; \\");
1928357f1050SThomas Veerman outn ("\t\t} \\");
1929357f1050SThomas Veerman outn ("\telse \\");
1930357f1050SThomas Veerman outn ("\t\t{ \\");
1931357f1050SThomas Veerman outn ("\t\terrno=0; \\");
1932357f1050SThomas Veerman outn ("\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\");
1933357f1050SThomas Veerman outn ("\t\t\t{ \\");
1934357f1050SThomas Veerman outn ("\t\t\tif( errno != EINTR) \\");
1935357f1050SThomas Veerman outn ("\t\t\t\t{ \\");
1936357f1050SThomas Veerman outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1937357f1050SThomas Veerman outn ("\t\t\t\tbreak; \\");
1938357f1050SThomas Veerman outn ("\t\t\t\t} \\");
1939357f1050SThomas Veerman outn ("\t\t\terrno=0; \\");
1940357f1050SThomas Veerman outn ("\t\t\tclearerr(yyin); \\");
1941357f1050SThomas Veerman outn ("\t\t\t} \\");
1942357f1050SThomas Veerman outn ("\t\t}\\");
1943357f1050SThomas Veerman }
1944357f1050SThomas Veerman }
1945357f1050SThomas Veerman
1946357f1050SThomas Veerman skelout (); /* %% [6.0] - break point in skel */
1947357f1050SThomas Veerman
1948357f1050SThomas Veerman indent_puts ("#define YY_RULE_SETUP \\");
1949357f1050SThomas Veerman indent_up ();
1950357f1050SThomas Veerman if (bol_needed) {
1951357f1050SThomas Veerman indent_puts ("if ( yyleng > 0 ) \\");
1952357f1050SThomas Veerman indent_up ();
1953357f1050SThomas Veerman indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\");
1954357f1050SThomas Veerman indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\");
1955357f1050SThomas Veerman indent_down ();
1956357f1050SThomas Veerman }
1957357f1050SThomas Veerman indent_puts ("YY_USER_ACTION");
1958357f1050SThomas Veerman indent_down ();
1959357f1050SThomas Veerman
1960357f1050SThomas Veerman skelout (); /* %% [7.0] - break point in skel */
1961357f1050SThomas Veerman
1962357f1050SThomas Veerman /* Copy prolog to output file. */
1963357f1050SThomas Veerman out (&action_array[prolog_offset]);
1964357f1050SThomas Veerman
1965357f1050SThomas Veerman line_directive_out (stdout, 0);
1966357f1050SThomas Veerman
1967357f1050SThomas Veerman skelout (); /* %% [8.0] - break point in skel */
1968357f1050SThomas Veerman
1969357f1050SThomas Veerman set_indent (2);
1970357f1050SThomas Veerman
1971357f1050SThomas Veerman if (yymore_used && !yytext_is_array) {
1972357f1050SThomas Veerman indent_puts ("YY_G(yy_more_len) = 0;");
1973357f1050SThomas Veerman indent_puts ("if ( YY_G(yy_more_flag) )");
1974357f1050SThomas Veerman indent_up ();
1975357f1050SThomas Veerman indent_puts ("{");
1976357f1050SThomas Veerman indent_puts
1977357f1050SThomas Veerman ("YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);");
1978357f1050SThomas Veerman indent_puts ("YY_G(yy_more_flag) = 0;");
1979357f1050SThomas Veerman indent_puts ("}");
1980357f1050SThomas Veerman indent_down ();
1981357f1050SThomas Veerman }
1982357f1050SThomas Veerman
1983357f1050SThomas Veerman skelout (); /* %% [9.0] - break point in skel */
1984357f1050SThomas Veerman
1985357f1050SThomas Veerman gen_start_state ();
1986357f1050SThomas Veerman
1987357f1050SThomas Veerman /* Note, don't use any indentation. */
1988357f1050SThomas Veerman outn ("yy_match:");
1989357f1050SThomas Veerman gen_next_match ();
1990357f1050SThomas Veerman
1991357f1050SThomas Veerman skelout (); /* %% [10.0] - break point in skel */
1992357f1050SThomas Veerman set_indent (2);
1993357f1050SThomas Veerman gen_find_action ();
1994357f1050SThomas Veerman
1995357f1050SThomas Veerman skelout (); /* %% [11.0] - break point in skel */
1996357f1050SThomas Veerman outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
1997357f1050SThomas Veerman indent_puts
1998357f1050SThomas Veerman ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )");
1999357f1050SThomas Veerman indent_up ();
2000357f1050SThomas Veerman indent_puts ("{");
200184d9c625SLionel Sambuc indent_puts ("yy_size_t yyl;");
2002357f1050SThomas Veerman do_indent ();
2003357f1050SThomas Veerman out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n",
2004357f1050SThomas Veerman yymore_used ? (yytext_is_array ? "YY_G(yy_prev_more_offset)" :
2005357f1050SThomas Veerman "YY_G(yy_more_len)") : "0");
2006357f1050SThomas Veerman indent_up ();
2007357f1050SThomas Veerman indent_puts ("if ( yytext[yyl] == '\\n' )");
2008357f1050SThomas Veerman indent_up ();
2009357f1050SThomas Veerman indent_puts ("M4_YY_INCR_LINENO();");
2010357f1050SThomas Veerman indent_down ();
2011357f1050SThomas Veerman indent_down ();
2012357f1050SThomas Veerman indent_puts ("}");
2013357f1050SThomas Veerman indent_down ();
2014357f1050SThomas Veerman outn ("]])");
2015357f1050SThomas Veerman
2016357f1050SThomas Veerman skelout (); /* %% [12.0] - break point in skel */
2017357f1050SThomas Veerman if (ddebug) {
2018357f1050SThomas Veerman indent_puts ("if ( yy_flex_debug )");
2019357f1050SThomas Veerman indent_up ();
2020357f1050SThomas Veerman
2021357f1050SThomas Veerman indent_puts ("{");
2022357f1050SThomas Veerman indent_puts ("if ( yy_act == 0 )");
2023357f1050SThomas Veerman indent_up ();
2024357f1050SThomas Veerman indent_puts (C_plus_plus ?
2025357f1050SThomas Veerman "std::cerr << \"--scanner backing up\\n\";" :
2026357f1050SThomas Veerman "fprintf( stderr, \"--scanner backing up\\n\" );");
2027357f1050SThomas Veerman indent_down ();
2028357f1050SThomas Veerman
2029357f1050SThomas Veerman do_indent ();
2030357f1050SThomas Veerman out_dec ("else if ( yy_act < %d )\n", num_rules);
2031357f1050SThomas Veerman indent_up ();
2032357f1050SThomas Veerman
2033357f1050SThomas Veerman if (C_plus_plus) {
2034357f1050SThomas Veerman indent_puts
2035357f1050SThomas Veerman ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<");
2036357f1050SThomas Veerman indent_puts
2037357f1050SThomas Veerman (" \"(\\\"\" << yytext << \"\\\")\\n\";");
2038357f1050SThomas Veerman }
2039357f1050SThomas Veerman else {
2040357f1050SThomas Veerman indent_puts
2041357f1050SThomas Veerman ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",");
2042357f1050SThomas Veerman
2043357f1050SThomas Veerman indent_puts
2044357f1050SThomas Veerman (" (long)yy_rule_linenum[yy_act], yytext );");
2045357f1050SThomas Veerman }
2046357f1050SThomas Veerman
2047357f1050SThomas Veerman indent_down ();
2048357f1050SThomas Veerman
2049357f1050SThomas Veerman do_indent ();
2050357f1050SThomas Veerman out_dec ("else if ( yy_act == %d )\n", num_rules);
2051357f1050SThomas Veerman indent_up ();
2052357f1050SThomas Veerman
2053357f1050SThomas Veerman if (C_plus_plus) {
2054357f1050SThomas Veerman indent_puts
2055357f1050SThomas Veerman ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";");
2056357f1050SThomas Veerman }
2057357f1050SThomas Veerman else {
2058357f1050SThomas Veerman indent_puts
2059357f1050SThomas Veerman ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\",");
2060357f1050SThomas Veerman indent_puts (" yytext );");
2061357f1050SThomas Veerman }
2062357f1050SThomas Veerman
2063357f1050SThomas Veerman indent_down ();
2064357f1050SThomas Veerman
2065357f1050SThomas Veerman do_indent ();
2066357f1050SThomas Veerman out_dec ("else if ( yy_act == %d )\n", num_rules + 1);
2067357f1050SThomas Veerman indent_up ();
2068357f1050SThomas Veerman
2069357f1050SThomas Veerman indent_puts (C_plus_plus ?
2070357f1050SThomas Veerman "std::cerr << \"--(end of buffer or a NUL)\\n\";" :
2071357f1050SThomas Veerman "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );");
2072357f1050SThomas Veerman
2073357f1050SThomas Veerman indent_down ();
2074357f1050SThomas Veerman
2075357f1050SThomas Veerman do_indent ();
2076357f1050SThomas Veerman outn ("else");
2077357f1050SThomas Veerman indent_up ();
2078357f1050SThomas Veerman
2079357f1050SThomas Veerman if (C_plus_plus) {
2080357f1050SThomas Veerman indent_puts
2081357f1050SThomas Veerman ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";");
2082357f1050SThomas Veerman }
2083357f1050SThomas Veerman else {
2084357f1050SThomas Veerman indent_puts
2085357f1050SThomas Veerman ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );");
2086357f1050SThomas Veerman }
2087357f1050SThomas Veerman
2088357f1050SThomas Veerman indent_down ();
2089357f1050SThomas Veerman
2090357f1050SThomas Veerman indent_puts ("}");
2091357f1050SThomas Veerman indent_down ();
2092357f1050SThomas Veerman }
2093357f1050SThomas Veerman
2094357f1050SThomas Veerman /* Copy actions to output file. */
2095357f1050SThomas Veerman skelout (); /* %% [13.0] - break point in skel */
2096357f1050SThomas Veerman indent_up ();
2097357f1050SThomas Veerman gen_bu_action ();
2098357f1050SThomas Veerman out (&action_array[action_offset]);
2099357f1050SThomas Veerman
2100357f1050SThomas Veerman line_directive_out (stdout, 0);
2101357f1050SThomas Veerman
2102357f1050SThomas Veerman /* generate cases for any missing EOF rules */
2103357f1050SThomas Veerman for (i = 1; i <= lastsc; ++i)
2104357f1050SThomas Veerman if (!sceof[i]) {
2105357f1050SThomas Veerman do_indent ();
2106357f1050SThomas Veerman out_str ("case YY_STATE_EOF(%s):\n", scname[i]);
2107357f1050SThomas Veerman did_eof_rule = true;
2108357f1050SThomas Veerman }
2109357f1050SThomas Veerman
2110357f1050SThomas Veerman if (did_eof_rule) {
2111357f1050SThomas Veerman indent_up ();
2112357f1050SThomas Veerman indent_puts ("yyterminate();");
2113357f1050SThomas Veerman indent_down ();
2114357f1050SThomas Veerman }
2115357f1050SThomas Veerman
2116357f1050SThomas Veerman
2117357f1050SThomas Veerman /* Generate code for handling NUL's, if needed. */
2118357f1050SThomas Veerman
2119357f1050SThomas Veerman /* First, deal with backing up and setting up yy_cp if the scanner
2120357f1050SThomas Veerman * finds that it should JAM on the NUL.
2121357f1050SThomas Veerman */
2122357f1050SThomas Veerman skelout (); /* %% [14.0] - break point in skel */
2123357f1050SThomas Veerman set_indent (4);
2124357f1050SThomas Veerman
2125357f1050SThomas Veerman if (fullspd || fulltbl)
2126357f1050SThomas Veerman indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2127357f1050SThomas Veerman
2128357f1050SThomas Veerman else { /* compressed table */
2129357f1050SThomas Veerman if (!reject && !interactive) {
2130357f1050SThomas Veerman /* Do the guaranteed-needed backing up to figure
2131357f1050SThomas Veerman * out the match.
2132357f1050SThomas Veerman */
2133357f1050SThomas Veerman indent_puts
2134357f1050SThomas Veerman ("yy_cp = YY_G(yy_last_accepting_cpos);");
2135357f1050SThomas Veerman indent_puts
2136357f1050SThomas Veerman ("yy_current_state = YY_G(yy_last_accepting_state);");
2137357f1050SThomas Veerman }
2138357f1050SThomas Veerman
2139357f1050SThomas Veerman else
2140357f1050SThomas Veerman /* Still need to initialize yy_cp, though
2141357f1050SThomas Veerman * yy_current_state was set up by
2142357f1050SThomas Veerman * yy_get_previous_state().
2143357f1050SThomas Veerman */
2144357f1050SThomas Veerman indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2145357f1050SThomas Veerman }
2146357f1050SThomas Veerman
2147357f1050SThomas Veerman
2148357f1050SThomas Veerman /* Generate code for yy_get_previous_state(). */
2149357f1050SThomas Veerman set_indent (1);
2150357f1050SThomas Veerman skelout (); /* %% [15.0] - break point in skel */
2151357f1050SThomas Veerman
2152357f1050SThomas Veerman gen_start_state ();
2153357f1050SThomas Veerman
2154357f1050SThomas Veerman set_indent (2);
2155357f1050SThomas Veerman skelout (); /* %% [16.0] - break point in skel */
2156357f1050SThomas Veerman gen_next_state (true);
2157357f1050SThomas Veerman
2158357f1050SThomas Veerman set_indent (1);
2159357f1050SThomas Veerman skelout (); /* %% [17.0] - break point in skel */
2160357f1050SThomas Veerman gen_NUL_trans ();
2161357f1050SThomas Veerman
2162357f1050SThomas Veerman skelout (); /* %% [18.0] - break point in skel */
2163357f1050SThomas Veerman skelout (); /* %% [19.0] - break point in skel */
2164357f1050SThomas Veerman /* Update BOL and yylineno inside of input(). */
2165357f1050SThomas Veerman if (bol_needed) {
2166357f1050SThomas Veerman indent_puts
2167357f1050SThomas Veerman ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');");
2168357f1050SThomas Veerman if (do_yylineno) {
2169357f1050SThomas Veerman indent_puts
2170357f1050SThomas Veerman ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )");
2171357f1050SThomas Veerman indent_up ();
2172357f1050SThomas Veerman indent_puts ("M4_YY_INCR_LINENO();");
2173357f1050SThomas Veerman indent_down ();
2174357f1050SThomas Veerman }
2175357f1050SThomas Veerman }
2176357f1050SThomas Veerman
2177357f1050SThomas Veerman else if (do_yylineno) {
2178357f1050SThomas Veerman indent_puts ("if ( c == '\\n' )");
2179357f1050SThomas Veerman indent_up ();
2180357f1050SThomas Veerman indent_puts ("M4_YY_INCR_LINENO();");
2181357f1050SThomas Veerman indent_down ();
2182357f1050SThomas Veerman }
2183357f1050SThomas Veerman
2184357f1050SThomas Veerman skelout ();
2185357f1050SThomas Veerman
2186357f1050SThomas Veerman /* Copy remainder of input to output. */
2187357f1050SThomas Veerman
2188357f1050SThomas Veerman line_directive_out (stdout, 1);
2189357f1050SThomas Veerman
2190357f1050SThomas Veerman if (sectnum == 3) {
2191357f1050SThomas Veerman OUT_BEGIN_CODE ();
2192357f1050SThomas Veerman (void) flexscan (); /* copy remainder of input to output */
2193357f1050SThomas Veerman OUT_END_CODE ();
2194357f1050SThomas Veerman }
2195357f1050SThomas Veerman }
2196