gen.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  1. /* gen - actual generation (writing) of flex scanners */
  2. /*-
  3. * Copyright (c) 1990 The Regents of the University of California.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * Vern Paxson.
  8. *
  9. * The United States Government has rights in this work pursuant
  10. * to contract no. DE-AC03-76SF00098 between the United States
  11. * Department of Energy and the University of California.
  12. *
  13. * Redistribution and use in source and binary forms with or without
  14. * modification are permitted provided that: (1) source distributions retain
  15. * this entire copyright notice and comment, and (2) distributions including
  16. * binaries display the following acknowledgement: ``This product includes
  17. * software developed by the University of California, Berkeley and its
  18. * contributors'' in the documentation or other materials provided with the
  19. * distribution and in all advertising materials mentioning features or use
  20. * of this software. Neither the name of the University nor the names of
  21. * its contributors may be used to endorse or promote products derived from
  22. * this software without specific prior written permission.
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  26. */
  27. /* $Header: /opt/vlysenkov/CVSROOT/arcadia/contrib/tools/flex-old/gen.c,v 1.2 2007-11-30 02:28:15 pg Exp $ */
  28. #include "flexdef.h"
  29. /* declare functions that have forward references */
  30. void gen_next_state PROTO((int));
  31. void genecs PROTO((void));
  32. void indent_put2s PROTO((char [], char []));
  33. void indent_puts PROTO((char []));
  34. static int indent_level = 0; /* each level is 8 spaces */
  35. #define indent_up() (++indent_level)
  36. #define indent_down() (--indent_level)
  37. #define set_indent(indent_val) indent_level = indent_val
  38. /* Almost everything is done in terms of arrays starting at 1, so provide
  39. * a null entry for the zero element of all C arrays. (The exception
  40. * to this is that the fast table representation generally uses the
  41. * 0 elements of its arrays, too.)
  42. */
  43. static char C_int_decl[] = "static yyconst int %s[%d] =\n { 0,\n";
  44. static char C_short_decl[] = "static yyconst short int %s[%d] =\n { 0,\n";
  45. static char C_long_decl[] = "static yyconst long int %s[%d] =\n { 0,\n";
  46. static char C_state_decl[] =
  47. "static yyconst yy_state_type %s[%d] =\n { 0,\n";
  48. /* Indent to the current level. */
  49. void do_indent()
  50. {
  51. int i = indent_level * 8;
  52. while ( i >= 8 )
  53. {
  54. outc( '\t' );
  55. i -= 8;
  56. }
  57. while ( i > 0 )
  58. {
  59. outc( ' ' );
  60. --i;
  61. }
  62. }
  63. /* Generate the code to keep backing-up information. */
  64. void gen_backing_up()
  65. {
  66. if ( reject || num_backing_up == 0 )
  67. return;
  68. if ( fullspd )
  69. indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
  70. else
  71. indent_puts( "if ( yy_accept[yy_current_state] )" );
  72. indent_up();
  73. indent_puts( "{" );
  74. indent_puts( "yy_last_accepting_state = yy_current_state;" );
  75. indent_puts( "yy_last_accepting_cpos = yy_cp;" );
  76. indent_puts( "}" );
  77. indent_down();
  78. }
  79. /* Generate the code to perform the backing up. */
  80. void gen_bu_action()
  81. {
  82. if ( reject || num_backing_up == 0 )
  83. return;
  84. set_indent( 3 );
  85. indent_puts( "case 0: /* must back up */" );
  86. indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
  87. indent_puts( "*yy_cp = yy_hold_char;" );
  88. if ( fullspd || fulltbl )
  89. indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
  90. else
  91. /* Backing-up info for compressed tables is taken \after/
  92. * yy_cp has been incremented for the next state.
  93. */
  94. indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  95. indent_puts( "yy_current_state = yy_last_accepting_state;" );
  96. indent_puts( "goto yy_find_action;" );
  97. outc( '\n' );
  98. set_indent( 0 );
  99. }
  100. /* genctbl - generates full speed compressed transition table */
  101. void genctbl()
  102. {
  103. int i;
  104. int end_of_buffer_action = num_rules + 1;
  105. /* Table of verify for transition and offset to next state. */
  106. out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n",
  107. tblend + numecs + 1 );
  108. outn( " {" );
  109. /* We want the transition to be represented as the offset to the
  110. * next state, not the actual state number, which is what it currently
  111. * is. The offset is base[nxt[i]] - (base of current state)]. That's
  112. * just the difference between the starting points of the two involved
  113. * states (to - from).
  114. *
  115. * First, though, we need to find some way to put in our end-of-buffer
  116. * flags and states. We do this by making a state with absolutely no
  117. * transitions. We put it at the end of the table.
  118. */
  119. /* We need to have room in nxt/chk for two more slots: One for the
  120. * action and one for the end-of-buffer transition. We now *assume*
  121. * that we're guaranteed the only character we'll try to index this
  122. * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
  123. * there's room for jam entries for other characters.
  124. */
  125. while ( tblend + 2 >= current_max_xpairs )
  126. expand_nxt_chk();
  127. while ( lastdfa + 1 >= current_max_dfas )
  128. increase_max_dfas();
  129. base[lastdfa + 1] = tblend + 2;
  130. nxt[tblend + 1] = end_of_buffer_action;
  131. chk[tblend + 1] = numecs + 1;
  132. chk[tblend + 2] = 1; /* anything but EOB */
  133. /* So that "make test" won't show arb. differences. */
  134. nxt[tblend + 2] = 0;
  135. /* Make sure every state has an end-of-buffer transition and an
  136. * action #.
  137. */
  138. for ( i = 0; i <= lastdfa; ++i )
  139. {
  140. int anum = dfaacc[i].dfaacc_state;
  141. int offset = base[i];
  142. chk[offset] = EOB_POSITION;
  143. chk[offset - 1] = ACTION_POSITION;
  144. nxt[offset - 1] = anum; /* action number */
  145. }
  146. for ( i = 0; i <= tblend; ++i )
  147. {
  148. if ( chk[i] == EOB_POSITION )
  149. transition_struct_out( 0, base[lastdfa + 1] - i );
  150. else if ( chk[i] == ACTION_POSITION )
  151. transition_struct_out( 0, nxt[i] );
  152. else if ( chk[i] > numecs || chk[i] == 0 )
  153. transition_struct_out( 0, 0 ); /* unused slot */
  154. else /* verify, transition */
  155. transition_struct_out( chk[i],
  156. base[nxt[i]] - (i - chk[i]) );
  157. }
  158. /* Here's the final, end-of-buffer state. */
  159. transition_struct_out( chk[tblend + 1], nxt[tblend + 1] );
  160. transition_struct_out( chk[tblend + 2], nxt[tblend + 2] );
  161. outn( " };\n" );
  162. /* Table of pointers to start states. */
  163. out_dec(
  164. "static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n",
  165. lastsc * 2 + 1 );
  166. outn( " {" ); /* } so vi doesn't get confused */
  167. for ( i = 0; i <= lastsc * 2; ++i )
  168. out_dec( " &yy_transition[%d],\n", base[i] );
  169. dataend();
  170. if ( useecs )
  171. genecs();
  172. }
  173. /* Generate equivalence-class tables. */
  174. void genecs()
  175. {
  176. int i, j;
  177. int numrows;
  178. out_str_dec( C_int_decl, "yy_ec", csize );
  179. for ( i = 1; i < csize; ++i )
  180. {
  181. if ( caseins && (i >= 'A') && (i <= 'Z') )
  182. ecgroup[i] = ecgroup[clower( i )];
  183. ecgroup[i] = ABS( ecgroup[i] );
  184. mkdata( ecgroup[i] );
  185. }
  186. dataend();
  187. if ( trace )
  188. {
  189. fputs( _( "\n\nEquivalence Classes:\n\n" ), stderr );
  190. numrows = csize / 8;
  191. for ( j = 0; j < numrows; ++j )
  192. {
  193. for ( i = j; i < csize; i = i + numrows )
  194. {
  195. fprintf( stderr, "%4s = %-2d",
  196. readable_form( i ), ecgroup[i] );
  197. putc( ' ', stderr );
  198. }
  199. putc( '\n', stderr );
  200. }
  201. }
  202. }
  203. /* Generate the code to find the action number. */
  204. void gen_find_action()
  205. {
  206. if ( fullspd )
  207. indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
  208. else if ( fulltbl )
  209. indent_puts( "yy_act = yy_accept[yy_current_state];" );
  210. else if ( reject )
  211. {
  212. indent_puts( "yy_current_state = *--yy_state_ptr;" );
  213. indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  214. outn(
  215. "find_rule: Y_DECLARE_UNUSED; /* we branch to this label when backing up */" );
  216. indent_puts(
  217. "for ( ; ; ) /* until we find what rule we matched */" );
  218. indent_up();
  219. indent_puts( "{" );
  220. indent_puts(
  221. "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
  222. indent_up();
  223. indent_puts( "{" );
  224. indent_puts( "yy_act = yy_acclist[yy_lp];" );
  225. if ( variable_trailing_context_rules )
  226. {
  227. indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
  228. indent_puts( " yy_looking_for_trail_begin )" );
  229. indent_up();
  230. indent_puts( "{" );
  231. indent_puts(
  232. "if ( yy_act == yy_looking_for_trail_begin )" );
  233. indent_up();
  234. indent_puts( "{" );
  235. indent_puts( "yy_looking_for_trail_begin = 0;" );
  236. indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
  237. indent_puts( "break;" );
  238. indent_puts( "}" );
  239. indent_down();
  240. indent_puts( "}" );
  241. indent_down();
  242. indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
  243. indent_up();
  244. indent_puts( "{" );
  245. indent_puts(
  246. "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
  247. indent_puts(
  248. "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
  249. if ( real_reject )
  250. {
  251. /* Remember matched text in case we back up
  252. * due to REJECT.
  253. */
  254. indent_puts( "yy_full_match = yy_cp;" );
  255. indent_puts( "yy_full_state = yy_state_ptr;" );
  256. indent_puts( "yy_full_lp = yy_lp;" );
  257. }
  258. indent_puts( "}" );
  259. indent_down();
  260. indent_puts( "else" );
  261. indent_up();
  262. indent_puts( "{" );
  263. indent_puts( "yy_full_match = yy_cp;" );
  264. indent_puts( "yy_full_state = yy_state_ptr;" );
  265. indent_puts( "yy_full_lp = yy_lp;" );
  266. indent_puts( "break;" );
  267. indent_puts( "}" );
  268. indent_down();
  269. indent_puts( "++yy_lp;" );
  270. indent_puts( "goto find_rule;" );
  271. }
  272. else
  273. {
  274. /* Remember matched text in case we back up due to
  275. * trailing context plus REJECT.
  276. */
  277. indent_up();
  278. indent_puts( "{" );
  279. indent_puts( "yy_full_match = yy_cp;" );
  280. indent_puts( "break;" );
  281. indent_puts( "}" );
  282. indent_down();
  283. }
  284. indent_puts( "}" );
  285. indent_down();
  286. indent_puts( "--yy_cp;" );
  287. /* We could consolidate the following two lines with those at
  288. * the beginning, but at the cost of complaints that we're
  289. * branching inside a loop.
  290. */
  291. indent_puts( "yy_current_state = *--yy_state_ptr;" );
  292. indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  293. indent_puts( "}" );
  294. indent_down();
  295. }
  296. else
  297. { /* compressed */
  298. indent_puts( "yy_act = yy_accept[yy_current_state];" );
  299. if ( interactive && ! reject )
  300. {
  301. /* Do the guaranteed-needed backing up to figure out
  302. * the match.
  303. */
  304. indent_puts( "if ( yy_act == 0 )" );
  305. indent_up();
  306. indent_puts( "{ /* have to back up */" );
  307. indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  308. indent_puts(
  309. "yy_current_state = yy_last_accepting_state;" );
  310. indent_puts( "yy_act = yy_accept[yy_current_state];" );
  311. indent_puts( "}" );
  312. indent_down();
  313. }
  314. }
  315. }
  316. /* genftbl - generate full transition table */
  317. void genftbl()
  318. {
  319. int i;
  320. int end_of_buffer_action = num_rules + 1;
  321. out_str_dec( long_align ? C_long_decl : C_short_decl,
  322. "yy_accept", lastdfa + 1 );
  323. dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  324. for ( i = 1; i <= lastdfa; ++i )
  325. {
  326. int anum = dfaacc[i].dfaacc_state;
  327. mkdata( anum );
  328. if ( trace && anum )
  329. fprintf( stderr, _( "state # %d accepts: [%d]\n" ),
  330. i, anum );
  331. }
  332. dataend();
  333. if ( useecs )
  334. genecs();
  335. /* Don't have to dump the actual full table entries - they were
  336. * created on-the-fly.
  337. */
  338. }
  339. /* Generate the code to find the next compressed-table state. */
  340. void gen_next_compressed_state( char_map )
  341. char *char_map;
  342. {
  343. indent_put2s( "YY_CHAR yy_c = %s;", char_map );
  344. /* Save the backing-up info \before/ computing the next state
  345. * because we always compute one more state than needed - we
  346. * always proceed until we reach a jam state
  347. */
  348. gen_backing_up();
  349. indent_puts(
  350. "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
  351. indent_up();
  352. indent_puts( "{" );
  353. indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" );
  354. if ( usemecs )
  355. {
  356. /* We've arrange it so that templates are never chained
  357. * to one another. This means we can afford to make a
  358. * very simple test to see if we need to convert to
  359. * yy_c's meta-equivalence class without worrying
  360. * about erroneously looking up the meta-equivalence
  361. * class twice
  362. */
  363. do_indent();
  364. /* lastdfa + 2 is the beginning of the templates */
  365. out_dec( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
  366. indent_up();
  367. indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
  368. indent_down();
  369. }
  370. indent_puts( "}" );
  371. indent_down();
  372. indent_puts(
  373. "yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" );
  374. }
  375. /* Generate the code to find the next match. */
  376. void gen_next_match()
  377. {
  378. /* NOTE - changes in here should be reflected in gen_next_state() and
  379. * gen_NUL_trans().
  380. */
  381. char *char_map = useecs ?
  382. "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
  383. "YY_SC_TO_UI(*yy_cp)";
  384. char *char_map_2 = useecs ?
  385. "yy_ec[YY_SC_TO_UI(*++yy_cp)]" :
  386. "YY_SC_TO_UI(*++yy_cp)";
  387. if ( fulltbl )
  388. {
  389. indent_put2s(
  390. "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
  391. char_map );
  392. indent_up();
  393. if ( num_backing_up > 0 )
  394. {
  395. indent_puts( "{" ); /* } for vi */
  396. gen_backing_up();
  397. outc( '\n' );
  398. }
  399. indent_puts( "++yy_cp;" );
  400. if ( num_backing_up > 0 )
  401. /* { for vi */
  402. indent_puts( "}" );
  403. indent_down();
  404. outc( '\n' );
  405. indent_puts( "yy_current_state = -yy_current_state;" );
  406. }
  407. else if ( fullspd )
  408. {
  409. indent_puts( "{" ); /* } for vi */
  410. indent_puts(
  411. "yyconst struct yy_trans_info *yy_trans_info;\n" );
  412. indent_puts( "YY_CHAR yy_c;\n" );
  413. indent_put2s( "for ( yy_c = %s;", char_map );
  414. indent_puts(
  415. " (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" );
  416. indent_puts( "yy_verify == yy_c;" );
  417. indent_put2s( " yy_c = %s )", char_map_2 );
  418. indent_up();
  419. if ( num_backing_up > 0 )
  420. indent_puts( "{" ); /* } for vi */
  421. indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  422. if ( num_backing_up > 0 )
  423. {
  424. outc( '\n' );
  425. gen_backing_up(); /* { for vi */
  426. indent_puts( "}" );
  427. }
  428. indent_down(); /* { for vi */
  429. indent_puts( "}" );
  430. }
  431. else
  432. { /* compressed */
  433. indent_puts( "do" );
  434. indent_up();
  435. indent_puts( "{" ); /* } for vi */
  436. gen_next_state( false );
  437. indent_puts( "++yy_cp;" );
  438. /* { for vi */
  439. indent_puts( "}" );
  440. indent_down();
  441. do_indent();
  442. if ( interactive )
  443. out_dec( "while ( yy_base[yy_current_state] != %d );\n",
  444. jambase );
  445. else
  446. out_dec( "while ( yy_current_state != %d );\n",
  447. jamstate );
  448. if ( ! reject && ! interactive )
  449. {
  450. /* Do the guaranteed-needed backing up to figure out
  451. * the match.
  452. */
  453. indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  454. indent_puts(
  455. "yy_current_state = yy_last_accepting_state;" );
  456. }
  457. }
  458. }
  459. /* Generate the code to find the next state. */
  460. void gen_next_state( worry_about_NULs )
  461. int worry_about_NULs;
  462. { /* NOTE - changes in here should be reflected in gen_next_match() */
  463. char char_map[256];
  464. if ( worry_about_NULs && ! nultrans )
  465. {
  466. if ( useecs )
  467. (void) sprintf( char_map,
  468. "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
  469. NUL_ec );
  470. else
  471. (void) sprintf( char_map,
  472. "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec );
  473. }
  474. else
  475. strcpy( char_map, useecs ?
  476. "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)" );
  477. if ( worry_about_NULs && nultrans )
  478. {
  479. if ( ! fulltbl && ! fullspd )
  480. /* Compressed tables back up *before* they match. */
  481. gen_backing_up();
  482. indent_puts( "if ( *yy_cp )" );
  483. indent_up();
  484. indent_puts( "{" ); /* } for vi */
  485. }
  486. if ( fulltbl )
  487. indent_put2s(
  488. "yy_current_state = yy_nxt[yy_current_state][%s];",
  489. char_map );
  490. else if ( fullspd )
  491. indent_put2s(
  492. "yy_current_state += yy_current_state[%s].yy_nxt;",
  493. char_map );
  494. else
  495. gen_next_compressed_state( char_map );
  496. if ( worry_about_NULs && nultrans )
  497. {
  498. /* { for vi */
  499. indent_puts( "}" );
  500. indent_down();
  501. indent_puts( "else" );
  502. indent_up();
  503. indent_puts(
  504. "yy_current_state = yy_NUL_trans[yy_current_state];" );
  505. indent_down();
  506. }
  507. if ( fullspd || fulltbl )
  508. gen_backing_up();
  509. if ( reject )
  510. indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  511. }
  512. /* Generate the code to make a NUL transition. */
  513. void gen_NUL_trans()
  514. { /* NOTE - changes in here should be reflected in gen_next_match() */
  515. /* Only generate a definition for "yy_cp" if we'll generate code
  516. * that uses it. Otherwise lint and the like complain.
  517. */
  518. int need_backing_up = (num_backing_up > 0 && ! reject);
  519. if ( need_backing_up && (! nultrans || fullspd || fulltbl) )
  520. /* We're going to need yy_cp lying around for the call
  521. * below to gen_backing_up().
  522. */
  523. indent_puts( "char *yy_cp = yy_c_buf_p;" );
  524. outc( '\n' );
  525. if ( nultrans )
  526. {
  527. indent_puts(
  528. "yy_current_state = yy_NUL_trans[yy_current_state];" );
  529. indent_puts( "yy_is_jam = (yy_current_state == 0);" );
  530. }
  531. else if ( fulltbl )
  532. {
  533. do_indent();
  534. out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
  535. NUL_ec );
  536. indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
  537. }
  538. else if ( fullspd )
  539. {
  540. do_indent();
  541. out_dec( "int yy_c = %d;\n", NUL_ec );
  542. indent_puts(
  543. "yyconst struct yy_trans_info *yy_trans_info;\n" );
  544. indent_puts(
  545. "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" );
  546. indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  547. indent_puts(
  548. "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
  549. }
  550. else
  551. {
  552. char NUL_ec_str[20];
  553. (void) sprintf( NUL_ec_str, "%d", NUL_ec );
  554. gen_next_compressed_state( NUL_ec_str );
  555. do_indent();
  556. out_dec( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
  557. if ( reject )
  558. {
  559. /* Only stack this state if it's a transition we
  560. * actually make. If we stack it on a jam, then
  561. * the state stack and yy_c_buf_p get out of sync.
  562. */
  563. indent_puts( "if ( ! yy_is_jam )" );
  564. indent_up();
  565. indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  566. indent_down();
  567. }
  568. }
  569. /* If we've entered an accepting state, back up; note that
  570. * compressed tables have *already* done such backing up, so
  571. * we needn't bother with it again.
  572. */
  573. if ( need_backing_up && (fullspd || fulltbl) )
  574. {
  575. outc( '\n' );
  576. indent_puts( "if ( ! yy_is_jam )" );
  577. indent_up();
  578. indent_puts( "{" );
  579. gen_backing_up();
  580. indent_puts( "}" );
  581. indent_down();
  582. }
  583. }
  584. /* Generate the code to find the start state. */
  585. void gen_start_state()
  586. {
  587. if ( fullspd )
  588. {
  589. if ( bol_needed )
  590. {
  591. indent_puts(
  592. "yy_current_state = yy_start_state_list[yy_start + YY_AT_BOL()];" );
  593. }
  594. else
  595. indent_puts(
  596. "yy_current_state = yy_start_state_list[yy_start];" );
  597. }
  598. else
  599. {
  600. indent_puts( "yy_current_state = yy_start;" );
  601. if ( bol_needed )
  602. indent_puts( "yy_current_state += YY_AT_BOL();" );
  603. if ( reject )
  604. {
  605. /* Set up for storing up states. */
  606. indent_puts( "yy_state_ptr = yy_state_buf;" );
  607. indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  608. }
  609. }
  610. }
  611. /* gentabs - generate data statements for the transition tables */
  612. void gentabs()
  613. {
  614. int i, j, k, *accset, nacc, *acc_array, total_states;
  615. int end_of_buffer_action = num_rules + 1;
  616. acc_array = allocate_integer_array( current_max_dfas );
  617. nummt = 0;
  618. /* The compressed table format jams by entering the "jam state",
  619. * losing information about the previous state in the process.
  620. * In order to recover the previous state, we effectively need
  621. * to keep backing-up information.
  622. */
  623. ++num_backing_up;
  624. if ( reject )
  625. {
  626. /* Write out accepting list and pointer list.
  627. *
  628. * First we generate the "yy_acclist" array. In the process,
  629. * we compute the indices that will go into the "yy_accept"
  630. * array, and save the indices in the dfaacc array.
  631. */
  632. int EOB_accepting_list[2];
  633. /* Set up accepting structures for the End Of Buffer state. */
  634. EOB_accepting_list[0] = 0;
  635. EOB_accepting_list[1] = end_of_buffer_action;
  636. accsiz[end_of_buffer_state] = 1;
  637. dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
  638. out_str_dec( long_align ? C_long_decl : C_short_decl,
  639. "yy_acclist", MAX( numas, 1 ) + 1 );
  640. j = 1; /* index into "yy_acclist" array */
  641. for ( i = 1; i <= lastdfa; ++i )
  642. {
  643. acc_array[i] = j;
  644. if ( accsiz[i] != 0 )
  645. {
  646. accset = dfaacc[i].dfaacc_set;
  647. nacc = accsiz[i];
  648. if ( trace )
  649. fprintf( stderr,
  650. _( "state # %d accepts: " ),
  651. i );
  652. for ( k = 1; k <= nacc; ++k )
  653. {
  654. int accnum = accset[k];
  655. ++j;
  656. if ( variable_trailing_context_rules &&
  657. ! (accnum & YY_TRAILING_HEAD_MASK) &&
  658. accnum > 0 && accnum <= num_rules &&
  659. rule_type[accnum] == RULE_VARIABLE )
  660. {
  661. /* Special hack to flag
  662. * accepting number as part
  663. * of trailing context rule.
  664. */
  665. accnum |= YY_TRAILING_MASK;
  666. }
  667. mkdata( accnum );
  668. if ( trace )
  669. {
  670. fprintf( stderr, "[%d]",
  671. accset[k] );
  672. if ( k < nacc )
  673. fputs( ", ", stderr );
  674. else
  675. putc( '\n', stderr );
  676. }
  677. }
  678. }
  679. }
  680. /* add accepting number for the "jam" state */
  681. acc_array[i] = j;
  682. dataend();
  683. }
  684. else
  685. {
  686. dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  687. for ( i = 1; i <= lastdfa; ++i )
  688. acc_array[i] = dfaacc[i].dfaacc_state;
  689. /* add accepting number for jam state */
  690. acc_array[i] = 0;
  691. }
  692. /* Spit out "yy_accept" array. If we're doing "reject", it'll be
  693. * pointers into the "yy_acclist" array. Otherwise it's actual
  694. * accepting numbers. In either case, we just dump the numbers.
  695. */
  696. /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
  697. * beginning at 0 and for "jam" state.
  698. */
  699. k = lastdfa + 2;
  700. if ( reject )
  701. /* We put a "cap" on the table associating lists of accepting
  702. * numbers with state numbers. This is needed because we tell
  703. * where the end of an accepting list is by looking at where
  704. * the list for the next state starts.
  705. */
  706. ++k;
  707. out_str_dec( long_align ? C_long_decl : C_short_decl, "yy_accept", k );
  708. for ( i = 1; i <= lastdfa; ++i )
  709. {
  710. mkdata( acc_array[i] );
  711. if ( ! reject && trace && acc_array[i] )
  712. fprintf( stderr, _( "state # %d accepts: [%d]\n" ),
  713. i, acc_array[i] );
  714. }
  715. /* Add entry for "jam" state. */
  716. mkdata( acc_array[i] );
  717. if ( reject )
  718. /* Add "cap" for the list. */
  719. mkdata( acc_array[i] );
  720. dataend();
  721. if ( useecs )
  722. genecs();
  723. if ( usemecs )
  724. {
  725. /* Write out meta-equivalence classes (used to index
  726. * templates with).
  727. */
  728. if ( trace )
  729. fputs( _( "\n\nMeta-Equivalence Classes:\n" ),
  730. stderr );
  731. out_str_dec( C_int_decl, "yy_meta", numecs + 1 );
  732. for ( i = 1; i <= numecs; ++i )
  733. {
  734. if ( trace )
  735. fprintf( stderr, "%d = %d\n",
  736. i, ABS( tecbck[i] ) );
  737. mkdata( ABS( tecbck[i] ) );
  738. }
  739. dataend();
  740. }
  741. total_states = lastdfa + numtemps;
  742. out_str_dec( (tblend >= MAX_SHORT || long_align) ?
  743. C_long_decl : C_short_decl,
  744. "yy_base", total_states + 1 );
  745. for ( i = 1; i <= lastdfa; ++i )
  746. {
  747. int d = def[i];
  748. if ( base[i] == JAMSTATE )
  749. base[i] = jambase;
  750. if ( d == JAMSTATE )
  751. def[i] = jamstate;
  752. else if ( d < 0 )
  753. {
  754. /* Template reference. */
  755. ++tmpuses;
  756. def[i] = lastdfa - d + 1;
  757. }
  758. mkdata( base[i] );
  759. }
  760. /* Generate jam state's base index. */
  761. mkdata( base[i] );
  762. for ( ++i /* skip jam state */; i <= total_states; ++i )
  763. {
  764. mkdata( base[i] );
  765. def[i] = jamstate;
  766. }
  767. dataend();
  768. out_str_dec( (total_states >= MAX_SHORT || long_align) ?
  769. C_long_decl : C_short_decl,
  770. "yy_def", total_states + 1 );
  771. for ( i = 1; i <= total_states; ++i )
  772. mkdata( def[i] );
  773. dataend();
  774. out_str_dec( (total_states >= MAX_SHORT || long_align) ?
  775. C_long_decl : C_short_decl,
  776. "yy_nxt", tblend + 1 );
  777. for ( i = 1; i <= tblend; ++i )
  778. {
  779. /* Note, the order of the following test is important.
  780. * If chk[i] is 0, then nxt[i] is undefined.
  781. */
  782. if ( chk[i] == 0 || nxt[i] == 0 )
  783. nxt[i] = jamstate; /* new state is the JAM state */
  784. mkdata( nxt[i] );
  785. }
  786. dataend();
  787. out_str_dec( (total_states >= MAX_SHORT || long_align) ?
  788. C_long_decl : C_short_decl,
  789. "yy_chk", tblend + 1 );
  790. for ( i = 1; i <= tblend; ++i )
  791. {
  792. if ( chk[i] == 0 )
  793. ++nummt;
  794. mkdata( chk[i] );
  795. }
  796. dataend();
  797. }
  798. /* Write out a formatted string (with a secondary string argument) at the
  799. * current indentation level, adding a final newline.
  800. */
  801. void indent_put2s( fmt, arg )
  802. char fmt[], arg[];
  803. {
  804. do_indent();
  805. out_str( fmt, arg );
  806. outn( "" );
  807. }
  808. /* Write out a string at the current indentation level, adding a final
  809. * newline.
  810. */
  811. void indent_puts( str )
  812. char str[];
  813. {
  814. do_indent();
  815. outn( str );
  816. }
  817. /* make_tables - generate transition tables and finishes generating output file
  818. */
  819. void make_tables()
  820. {
  821. int i;
  822. int did_eof_rule = false;
  823. skelout();
  824. /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
  825. * being used.
  826. */
  827. set_indent( 1 );
  828. if ( yymore_used && ! yytext_is_array )
  829. {
  830. indent_puts( "yytext_ptr -= yy_more_len; \\" );
  831. indent_puts( "yyleng = (int) (yy_cp - yytext_ptr); \\" );
  832. }
  833. else
  834. indent_puts( "yyleng = (int) (yy_cp - yy_bp); \\" );
  835. /* Now also deal with copying yytext_ptr to yytext if needed. */
  836. skelout();
  837. if ( yytext_is_array )
  838. {
  839. if ( yymore_used )
  840. indent_puts(
  841. "if ( yyleng + yy_more_offset >= YYLMAX ) \\" );
  842. else
  843. indent_puts( "if ( yyleng >= YYLMAX ) \\" );
  844. indent_up();
  845. indent_puts(
  846. "YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );
  847. indent_down();
  848. if ( yymore_used )
  849. {
  850. indent_puts(
  851. "yy_flex_strncpy( &yytext[yy_more_offset], yytext_ptr, yyleng + 1 ); \\" );
  852. indent_puts( "yyleng += yy_more_offset; \\" );
  853. indent_puts(
  854. "yy_prev_more_offset = yy_more_offset; \\" );
  855. indent_puts( "yy_more_offset = 0; \\" );
  856. }
  857. else
  858. {
  859. indent_puts(
  860. "yy_flex_strncpy( yytext, yytext_ptr, yyleng + 1 ); \\" );
  861. }
  862. }
  863. set_indent( 0 );
  864. skelout();
  865. out_dec( "#define YY_NUM_RULES %d\n", num_rules );
  866. out_dec( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
  867. if ( fullspd )
  868. {
  869. /* Need to define the transet type as a size large
  870. * enough to hold the biggest offset.
  871. */
  872. int total_table_size = tblend + numecs + 1;
  873. char *trans_offset_type =
  874. (total_table_size >= MAX_SHORT || long_align) ?
  875. "long" : "short";
  876. set_indent( 0 );
  877. indent_puts( "struct yy_trans_info" );
  878. indent_up();
  879. indent_puts( "{" ); /* } for vi */
  880. if ( long_align )
  881. indent_puts( "long yy_verify;" );
  882. else
  883. indent_puts( "short yy_verify;" );
  884. /* In cases where its sister yy_verify *is* a "yes, there is
  885. * a transition", yy_nxt is the offset (in records) to the
  886. * next state. In most cases where there is no transition,
  887. * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
  888. * record of a state, though, then yy_nxt is the action number
  889. * for that state.
  890. */
  891. indent_put2s( "%s yy_nxt;", trans_offset_type );
  892. indent_puts( "};" );
  893. indent_down();
  894. }
  895. if ( fullspd )
  896. genctbl();
  897. else if ( fulltbl )
  898. genftbl();
  899. else
  900. gentabs();
  901. /* Definitions for backing up. We don't need them if REJECT
  902. * is being used because then we use an alternative backin-up
  903. * technique instead.
  904. */
  905. if ( num_backing_up > 0 && ! reject )
  906. {
  907. if ( ! C_plus_plus )
  908. {
  909. indent_puts(
  910. "static yy_state_type yy_last_accepting_state;" );
  911. indent_puts(
  912. "static char *yy_last_accepting_cpos;\n" );
  913. }
  914. }
  915. if ( nultrans )
  916. {
  917. out_str_dec( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
  918. for ( i = 1; i <= lastdfa; ++i )
  919. {
  920. if ( fullspd )
  921. out_dec( " &yy_transition[%d],\n", base[i] );
  922. else
  923. mkdata( nultrans[i] );
  924. }
  925. dataend();
  926. }
  927. if ( ddebug )
  928. { /* Spit out table mapping rules to line numbers. */
  929. if ( ! C_plus_plus )
  930. {
  931. indent_puts( "extern int yy_flex_debug;" );
  932. indent_puts( "int yy_flex_debug = 1;\n" );
  933. }
  934. out_str_dec( long_align ? C_long_decl : C_short_decl,
  935. "yy_rule_linenum", num_rules );
  936. for ( i = 1; i < num_rules; ++i )
  937. mkdata( rule_linenum[i] );
  938. dataend();
  939. }
  940. if ( reject )
  941. {
  942. /* Declare state buffer variables. */
  943. if ( ! C_plus_plus )
  944. {
  945. outn(
  946. "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
  947. outn( "static char *yy_full_match;" );
  948. outn( "static int yy_lp;" );
  949. }
  950. if ( variable_trailing_context_rules )
  951. {
  952. if ( ! C_plus_plus )
  953. {
  954. outn(
  955. "static int yy_looking_for_trail_begin = 0;" );
  956. outn( "static int yy_full_lp;" );
  957. outn( "static int *yy_full_state;" );
  958. }
  959. out_hex( "#define YY_TRAILING_MASK 0x%x\n",
  960. (unsigned int) YY_TRAILING_MASK );
  961. out_hex( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
  962. (unsigned int) YY_TRAILING_HEAD_MASK );
  963. }
  964. outn( "#define REJECT \\" );
  965. outn( "{ \\" ); /* } for vi */
  966. outn(
  967. "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
  968. outn(
  969. "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
  970. if ( variable_trailing_context_rules )
  971. {
  972. outn(
  973. "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
  974. outn(
  975. "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
  976. outn(
  977. "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
  978. }
  979. outn( "++yy_lp; \\" );
  980. outn( "goto find_rule; \\" );
  981. /* { for vi */
  982. outn( "}" );
  983. }
  984. else
  985. {
  986. outn(
  987. "/* The intent behind this definition is that it'll catch" );
  988. outn( " * any uses of REJECT which flex missed." );
  989. outn( " */" );
  990. outn( "#define REJECT reject_used_but_not_detected" );
  991. }
  992. if ( yymore_used )
  993. {
  994. if ( ! C_plus_plus )
  995. {
  996. if ( yytext_is_array )
  997. {
  998. indent_puts( "static int yy_more_offset = 0;" );
  999. indent_puts(
  1000. "static int yy_prev_more_offset = 0;" );
  1001. }
  1002. else
  1003. {
  1004. indent_puts( "static int yy_more_flag = 0;" );
  1005. indent_puts( "static int yy_more_len = 0;" );
  1006. }
  1007. }
  1008. if ( yytext_is_array )
  1009. {
  1010. indent_puts(
  1011. "#define yymore() (yy_more_offset = yy_flex_strlen( yytext ))" );
  1012. indent_puts( "#define YY_NEED_STRLEN" );
  1013. indent_puts( "#define YY_MORE_ADJ 0" );
  1014. indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" );
  1015. indent_up();
  1016. indent_puts( "{ \\" );
  1017. indent_puts( "yy_more_offset = yy_prev_more_offset; \\" );
  1018. indent_puts( "yyleng -= yy_more_offset; \\" );
  1019. indent_puts( "}" );
  1020. indent_down();
  1021. }
  1022. else
  1023. {
  1024. indent_puts( "#define yymore() (yy_more_flag = 1)" );
  1025. indent_puts( "#define YY_MORE_ADJ yy_more_len" );
  1026. indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
  1027. }
  1028. }
  1029. else
  1030. {
  1031. indent_puts( "#define yymore() yymore_used_but_not_detected" );
  1032. indent_puts( "#define YY_MORE_ADJ 0" );
  1033. indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
  1034. }
  1035. if ( ! C_plus_plus )
  1036. {
  1037. if ( yytext_is_array )
  1038. {
  1039. outn( "#ifndef YYLMAX" );
  1040. outn( "#define YYLMAX 8192" );
  1041. outn( "#endif\n" );
  1042. outn( "char yytext[YYLMAX];" );
  1043. outn( "char *yytext_ptr;" );
  1044. }
  1045. else
  1046. outn( "char *yytext;" );
  1047. }
  1048. out( &action_array[defs1_offset] );
  1049. line_directive_out( stdout, 0 );
  1050. skelout();
  1051. if ( ! C_plus_plus )
  1052. {
  1053. if ( use_read )
  1054. {
  1055. outn( "\terrno=0; \\" );
  1056. outn(
  1057. "\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" );
  1058. outn( "\t{ \\" );
  1059. outn( "\t\tif( errno != EINTR) \\" );
  1060. outn( "\t\t{ \\" );
  1061. outn(
  1062. "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );
  1063. outn( "\t\t\tbreak; \\" );
  1064. outn( "\t\t} \\" );
  1065. outn( "\t\terrno=0; \\" );
  1066. outn( "\t\tclearerr(yyin); \\" );
  1067. outn( "\t}" );
  1068. }
  1069. else
  1070. {
  1071. outn(
  1072. "\tif ( yy_current_buffer->yy_is_interactive ) \\" );
  1073. outn( "\t\t{ \\" );
  1074. outn( "\t\tint c = '*', n; \\" );
  1075. outn( "\t\tfor ( n = 0; n < max_size && \\" );
  1076. outn( "\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" );
  1077. outn( "\t\t\tbuf[n] = (char) c; \\" );
  1078. outn( "\t\tif ( c == '\\n' ) \\" );
  1079. outn( "\t\t\tbuf[n++] = (char) c; \\" );
  1080. outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" );
  1081. outn(
  1082. "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );
  1083. outn( "\t\tresult = n; \\" );
  1084. outn( "\t\t} \\" );
  1085. outn( "\telse \\" );
  1086. outn( "\t\t{ \\" );
  1087. outn( "\t\terrno=0; \\" );
  1088. outn(
  1089. "\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\" );
  1090. outn( "\t\t\t{ \\" );
  1091. outn( "\t\t\tif( errno != EINTR) \\" );
  1092. outn( "\t\t\t\t{ \\" );
  1093. outn(
  1094. "\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );
  1095. outn( "\t\t\t\tbreak; \\" );
  1096. outn( "\t\t\t\t} \\" );
  1097. outn( "\t\t\terrno=0; \\" );
  1098. outn( "\t\t\tclearerr(yyin); \\" );
  1099. outn( "\t\t\t} \\" );
  1100. outn( "\t\t}" );
  1101. }
  1102. }
  1103. skelout();
  1104. indent_puts( "#define YY_RULE_SETUP \\" );
  1105. indent_up();
  1106. if ( bol_needed )
  1107. {
  1108. indent_puts( "if ( yyleng > 0 ) \\" );
  1109. indent_up();
  1110. indent_puts( "yy_current_buffer->yy_at_bol = \\" );
  1111. indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" );
  1112. indent_down();
  1113. }
  1114. indent_puts( "YY_USER_ACTION" );
  1115. indent_down();
  1116. skelout();
  1117. /* Copy prolog to output file. */
  1118. out( &action_array[prolog_offset] );
  1119. line_directive_out( stdout, 0 );
  1120. skelout();
  1121. set_indent( 2 );
  1122. if ( yymore_used && ! yytext_is_array )
  1123. {
  1124. indent_puts( "yy_more_len = 0;" );
  1125. indent_puts( "if ( yy_more_flag )" );
  1126. indent_up();
  1127. indent_puts( "{" );
  1128. indent_puts( "yy_more_len = yy_c_buf_p - yytext_ptr;" );
  1129. indent_puts( "yy_more_flag = 0;" );
  1130. indent_puts( "}" );
  1131. indent_down();
  1132. }
  1133. skelout();
  1134. gen_start_state();
  1135. /* Note, don't use any indentation. */
  1136. outn( "yy_match:" );
  1137. gen_next_match();
  1138. skelout();
  1139. set_indent( 2 );
  1140. gen_find_action();
  1141. skelout();
  1142. if ( do_yylineno )
  1143. {
  1144. indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );
  1145. indent_up();
  1146. indent_puts( "{" );
  1147. indent_puts( "int yyl;" );
  1148. indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" );
  1149. indent_up();
  1150. indent_puts( "if ( yytext[yyl] == '\\n' )" );
  1151. indent_up();
  1152. indent_puts( "++yylineno;" );
  1153. indent_down();
  1154. indent_down();
  1155. indent_puts( "}" );
  1156. indent_down();
  1157. }
  1158. skelout();
  1159. if ( ddebug )
  1160. {
  1161. indent_puts( "if ( yy_flex_debug )" );
  1162. indent_up();
  1163. indent_puts( "{" );
  1164. indent_puts( "if ( yy_act == 0 )" );
  1165. indent_up();
  1166. indent_puts( C_plus_plus ?
  1167. "cerr << \"--scanner backing up\\n\";" :
  1168. "fprintf( stderr, \"--scanner backing up\\n\" );" );
  1169. indent_down();
  1170. do_indent();
  1171. out_dec( "else if ( yy_act < %d )\n", num_rules );
  1172. indent_up();
  1173. if ( C_plus_plus )
  1174. {
  1175. indent_puts(
  1176. "cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<" );
  1177. indent_puts(
  1178. " \"(\\\"\" << yytext << \"\\\")\\n\";" );
  1179. }
  1180. else
  1181. {
  1182. indent_puts(
  1183. (long_align ?
  1184. "fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",":
  1185. "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\","));
  1186. indent_puts(
  1187. " yy_rule_linenum[yy_act], yytext );" );
  1188. }
  1189. indent_down();
  1190. do_indent();
  1191. out_dec( "else if ( yy_act == %d )\n", num_rules );
  1192. indent_up();
  1193. if ( C_plus_plus )
  1194. {
  1195. indent_puts(
  1196. "cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";" );
  1197. }
  1198. else
  1199. {
  1200. indent_puts(
  1201. "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
  1202. indent_puts( " yytext );" );
  1203. }
  1204. indent_down();
  1205. do_indent();
  1206. out_dec( "else if ( yy_act == %d )\n", num_rules + 1 );
  1207. indent_up();
  1208. indent_puts( C_plus_plus ?
  1209. "cerr << \"--(end of buffer or a NUL)\\n\";" :
  1210. "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
  1211. indent_down();
  1212. do_indent();
  1213. outn( "else" );
  1214. indent_up();
  1215. if ( C_plus_plus )
  1216. {
  1217. indent_puts(
  1218. "cerr << \"--EOF (start condition \" << YY_START << \")\\n\";" );
  1219. }
  1220. else
  1221. {
  1222. indent_puts(
  1223. "fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" );
  1224. }
  1225. indent_down();
  1226. indent_puts( "}" );
  1227. indent_down();
  1228. }
  1229. /* Copy actions to output file. */
  1230. skelout();
  1231. indent_up();
  1232. gen_bu_action();
  1233. out( &action_array[action_offset] );
  1234. line_directive_out( stdout, 0 );
  1235. /* generate cases for any missing EOF rules */
  1236. for ( i = 1; i <= lastsc; ++i )
  1237. if ( ! sceof[i] )
  1238. {
  1239. do_indent();
  1240. out_str( "case YY_STATE_EOF(%s):\n", scname[i] );
  1241. did_eof_rule = true;
  1242. }
  1243. if ( did_eof_rule )
  1244. {
  1245. indent_up();
  1246. indent_puts( "yyterminate();" );
  1247. indent_down();
  1248. }
  1249. /* Generate code for handling NUL's, if needed. */
  1250. /* First, deal with backing up and setting up yy_cp if the scanner
  1251. * finds that it should JAM on the NUL.
  1252. */
  1253. skelout();
  1254. set_indent( 4 );
  1255. if ( fullspd || fulltbl )
  1256. indent_puts( "yy_cp = yy_c_buf_p;" );
  1257. else
  1258. { /* compressed table */
  1259. if ( ! reject && ! interactive )
  1260. {
  1261. /* Do the guaranteed-needed backing up to figure
  1262. * out the match.
  1263. */
  1264. indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  1265. indent_puts(
  1266. "yy_current_state = yy_last_accepting_state;" );
  1267. }
  1268. else
  1269. /* Still need to initialize yy_cp, though
  1270. * yy_current_state was set up by
  1271. * yy_get_previous_state().
  1272. */
  1273. indent_puts( "yy_cp = yy_c_buf_p;" );
  1274. }
  1275. /* Generate code for yy_get_previous_state(). */
  1276. set_indent( 1 );
  1277. skelout();
  1278. gen_start_state();
  1279. set_indent( 2 );
  1280. skelout();
  1281. gen_next_state( true );
  1282. set_indent( 1 );
  1283. skelout();
  1284. gen_NUL_trans();
  1285. skelout();
  1286. if ( do_yylineno )
  1287. { /* update yylineno inside of unput() */
  1288. indent_puts( "if ( c == '\\n' )" );
  1289. indent_up();
  1290. indent_puts( "--yylineno;" );
  1291. indent_down();
  1292. }
  1293. skelout();
  1294. /* Update BOL and yylineno inside of input(). */
  1295. if ( bol_needed )
  1296. {
  1297. indent_puts( "yy_current_buffer->yy_at_bol = (c == '\\n');" );
  1298. if ( do_yylineno )
  1299. {
  1300. indent_puts( "if ( yy_current_buffer->yy_at_bol )" );
  1301. indent_up();
  1302. indent_puts( "++yylineno;" );
  1303. indent_down();
  1304. }
  1305. }
  1306. else if ( do_yylineno )
  1307. {
  1308. indent_puts( "if ( c == '\\n' )" );
  1309. indent_up();
  1310. indent_puts( "++yylineno;" );
  1311. indent_down();
  1312. }
  1313. skelout();
  1314. /* Copy remainder of input to output. */
  1315. line_directive_out( stdout, 1 );
  1316. if ( sectnum == 3 )
  1317. (void) flexscan(); /* copy remainder of input to output */
  1318. }