/usr.bin/lex/gen.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 1629 lines · 1089 code · 329 blank · 211 comment · 189 complexity · 40df6a8a931d08b24e1ca0b6abd2e948 MD5 · raw file

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