home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 290_02 / skeleton.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-12  |  7.4 KB  |  347 lines

  1. /* A lexical scanner generated by flex */
  2.  
  3. #include "skeleton.h"
  4.  
  5. %% section 1 code and data tables for DFA go here
  6.  
  7. /* these declarations have to come after the section 1 code or lint gets
  8.  * confused about whether the variables are used
  9.  */
  10. FILE *yyin = stdin, *yyout = stdout;
  11.  
  12. /* these variables are all declared out here so that section 3 code can
  13.  * manipulate them
  14.  */
  15. static int yy_start, yy_b_buf_p, yy_c_buf_p, yy_e_buf_p;
  16. static int yy_saw_eof, yy_init = 1;
  17.  
  18. /* yy_ch_buf has to be 1 character longer than YY_BUF_SIZE, since when
  19.  * setting up yytext we can try to put a '\0' just past the end of the
  20.  * matched text
  21.  */
  22. static char yy_ch_buf[YY_BUF_SIZE + 1];
  23. static int yy_st_buf[YY_BUF_SIZE];
  24. static char yy_hold_char;
  25.  
  26. static char input( void) ;
  27. static void unput( char) ;
  28.  
  29. char *yytext;
  30. static int yyleng;
  31.  
  32. /*--------------------------------------------------------------------------*/
  33. /*------------------------- BEGIN LEXICAL ANALYZER -------------------------*/
  34. /*--------------------------------------------------------------------------*/
  35.  
  36. YY_DECL
  37.     {
  38.     int yy_n_chars, yy_lp, yy_iii, yy_buf_pos, yy_act;
  39. #ifdef FLEX_REJECT_ENABLED
  40.     int yy_full_match;
  41. #endif
  42.  
  43. %% user's declarations go here
  44.  
  45.     if ( yy_init )
  46.     {
  47.     YY_INIT;
  48.     yy_start = 1;
  49.     yy_init = 0;
  50.     }
  51.  
  52.     goto get_next_token;
  53.  
  54. do_action:
  55.  
  56. #ifdef FLEX_REJECT_ENABLED
  57.     /* remember matched text in case we back up due to trailing context */
  58.     yy_full_match = yy_c_buf_p;
  59. #endif
  60.  
  61.     for ( ; ; )
  62.     {
  63.     YY_DO_BEFORE_ACTION
  64.  
  65. #ifdef FLEX_DEBUG
  66.     fprintf( stderr, "--accepting rule #%d\n", yy_act );
  67. #endif
  68.     switch ( yy_act )
  69.         {
  70. %% actions go here
  71.  
  72. case YY_NEW_FILE:
  73. break; /* begin reading from new file */
  74.  
  75. case YY_END_TOK:
  76. return ( YY_END_TOK );
  77.  
  78. default:
  79. YY_FATAL_ERROR( "fatal flex scanner internal error" );
  80.         }
  81.  
  82. get_next_token:
  83.     {
  84.     register int yy_curst;
  85.     register char yy_sym;
  86.  
  87.     YY_DO_BEFORE_SCAN
  88.  
  89.     /* set up to begin running DFA */
  90.  
  91.     yy_curst = yy_start;
  92.  
  93.     if ( yy_ch_buf[yy_c_buf_p] == '\n' )
  94.         ++yy_curst;
  95.  
  96.     /* yy_b_buf_p points to the position in yy_ch_buf
  97.      * of the start of the current run.
  98.      */
  99.  
  100.     yy_b_buf_p = yy_c_buf_p + 1;
  101.  
  102.     do /* until the machine jams */
  103.         {
  104.         if ( yy_c_buf_p == yy_e_buf_p )
  105.         { /* need more input */
  106.         if ( yy_e_buf_p >= YY_BUF_LIM )
  107.             { /* not enough room to do another read */
  108.             /* see if we can make some room for more chars */
  109.  
  110.             yy_n_chars = yy_e_buf_p - yy_b_buf_p;
  111.  
  112.             if ( yy_n_chars >= 0 )
  113.             /* shift down buffer to make room */
  114.             for ( yy_iii = 0; yy_iii <= yy_n_chars; ++yy_iii )
  115.                 {
  116.                 yy_buf_pos = yy_b_buf_p + yy_iii;
  117.                 yy_ch_buf[yy_iii] = yy_ch_buf[yy_buf_pos];
  118.                 yy_st_buf[yy_iii] = yy_st_buf[yy_buf_pos];
  119.                 }
  120.  
  121.             yy_b_buf_p = 0;
  122.             yy_e_buf_p = yy_n_chars;
  123.  
  124.             if ( yy_e_buf_p >= YY_BUF_LIM )
  125.             YY_FATAL_ERROR( "flex input buffer overflowed" );
  126.  
  127.             yy_c_buf_p = yy_e_buf_p;
  128.             }
  129.  
  130.         else if ( yy_saw_eof )
  131.             {
  132. saweof:            if ( yy_b_buf_p > yy_e_buf_p )
  133.             {
  134.             if ( yywrap() )
  135.                 {
  136.                 yy_act = YY_END_TOK;
  137.                 goto do_action;
  138.                 }
  139.             
  140.             else
  141.                 {
  142.                 YY_INIT;
  143.                 yy_act = YY_NEW_FILE;
  144.                 goto do_action;
  145.                 }
  146.             }
  147.  
  148.             else /* do a jam to eat up more input */
  149.             {
  150. #ifndef FLEX_INTERACTIVE_SCANNER
  151.             /* we're going to decrement yy_c_buf_p upon doing
  152.              * the jam.  In this case, that's wrong, since
  153.              * it points to the last non-jam character.  So
  154.              * we increment it now to counter the decrement.
  155.              */
  156.             ++yy_c_buf_p;
  157. #endif
  158.             break;
  159.             }
  160.             }
  161.  
  162.         YY_INPUT( (yy_ch_buf + yy_c_buf_p + 1), yy_n_chars,
  163.               YY_MAX_LINE );
  164.  
  165.         if ( yy_n_chars == YY_NULL )
  166.             {
  167.             if ( yy_saw_eof )
  168.     YY_FATAL_ERROR( "flex scanner saw EOF twice - shouldn't happen" );
  169.             yy_saw_eof = 1;
  170.             goto saweof;
  171.             }
  172.  
  173.         yy_e_buf_p += yy_n_chars;
  174.         }
  175.  
  176.         ++yy_c_buf_p;
  177.  
  178. #ifdef FLEX_USE_ECS
  179.         yy_sym = e[yy_ch_buf[yy_c_buf_p]];
  180. #else
  181.         yy_sym = yy_ch_buf[yy_c_buf_p];
  182. #endif
  183.  
  184. #ifdef FLEX_FULL_TABLE
  185.         yy_curst = n[yy_curst][yy_sym];
  186.  
  187. #else /* get next state from compressed table */
  188.  
  189.         while ( c[b[yy_curst] + yy_sym] != yy_curst )
  190.         {
  191.         yy_curst = d[yy_curst];
  192.  
  193. #ifdef FLEX_USE_MECS
  194.         /* we've arrange it so that templates are never chained
  195.          * to one another.  This means we can afford make a
  196.          * very simple test to see if we need to convert to
  197.          * yy_sym's meta-equivalence class without worrying
  198.          * about erroneously looking up the meta-equivalence
  199.          * class twice
  200.          */
  201.  
  202.         if ( yy_curst >= YY_TEMPLATE )
  203.             yy_sym = m[yy_sym];
  204. #endif
  205.         }
  206.  
  207.         yy_curst = n[b[yy_curst] + yy_sym];
  208.  
  209. #endif
  210.  
  211.         yy_st_buf[yy_c_buf_p] = yy_curst;
  212.  
  213.         }
  214. #ifdef FLEX_INTERACTIVE_SCANNER
  215.     while ( b[yy_curst] != YY_JAM_BASE );
  216. #else
  217.     while ( yy_curst != YY_JAM );
  218.     --yy_c_buf_p; /* put back character we jammed on */
  219.  
  220. #endif
  221.  
  222.     if ( yy_c_buf_p >= yy_b_buf_p )
  223.         { /* we matched some text */
  224.         yy_curst = yy_st_buf[yy_c_buf_p];
  225.         yy_lp = l[yy_curst];
  226.  
  227. #ifdef FLEX_REJECT_ENABLED
  228. find_rule: /* we branch to this label when doing a REJECT */
  229. #endif
  230.  
  231.         for ( ; ; ) /* until we find what rule we matched */
  232.         {
  233. #ifdef FLEX_REJECT_ENABLED
  234.         if ( yy_lp && yy_lp < l[yy_curst + 1] )
  235.             {
  236.             yy_act = a[yy_lp];
  237.             goto do_action; /* "continue 2" */
  238.             }
  239. #else
  240.         if ( yy_lp )
  241.             {
  242.             yy_act = yy_lp;
  243.             goto do_action; /* "continue 2" */
  244.             }
  245. #endif
  246.  
  247.         if ( --yy_c_buf_p < yy_b_buf_p )
  248.             break;
  249.  
  250.         yy_curst = yy_st_buf[yy_c_buf_p];
  251.         yy_lp = l[yy_curst];
  252.         }
  253.         }
  254.  
  255.     YY_FATAL_ERROR( "no match in flex scanner - possible NULL in input" );
  256.     }
  257.     }
  258.  
  259.     /*NOTREACHED*/
  260.     }
  261.  
  262.  
  263. static  void unput( c )
  264. char c;
  265. {
  266.  register int i;
  267.  register int yy_buf_pos ;
  268.  
  269.     YY_DO_BEFORE_SCAN; /* undo effects of setting up yytext */
  270.  
  271.     if ( yy_c_buf_p == 0 )
  272.     {
  273.     yy_buf_pos = YY_BUF_MAX ;
  274.     for ( i = yy_e_buf_p; i >= yy_c_buf_p; --i )
  275.         {
  276.         yy_ch_buf[yy_buf_pos] = yy_ch_buf[i];
  277.         yy_st_buf[yy_buf_pos] = yy_st_buf[i];
  278.         --yy_buf_pos;
  279.         }
  280.  
  281.     yy_c_buf_p = YY_BUF_MAX - yy_e_buf_p;
  282.     yy_e_buf_p = YY_BUF_MAX;
  283.     }
  284.  
  285.     if ( yy_c_buf_p <= 0 )
  286.     YY_FATAL_ERROR( "flex scanner push-back overflow" );
  287.  
  288.     if ( yy_c_buf_p >= yy_b_buf_p && yy_ch_buf[yy_c_buf_p] == '\n' )
  289.     yy_ch_buf[yy_c_buf_p - 1] = '\n';
  290.  
  291.     yy_ch_buf[yy_c_buf_p--] =  c;
  292.  
  293.     YY_DO_BEFORE_ACTION; /* set up yytext again */
  294.  
  295.     }
  296.  
  297.  
  298. static char input( void)
  299. {
  300.     char c;
  301.  
  302.     YY_DO_BEFORE_SCAN
  303.  
  304.     if ( yy_c_buf_p == yy_e_buf_p )
  305.     { /* need more input */
  306.     int yy_n_chars;
  307.  
  308.     /* we can throw away the entire current buffer */
  309.     if ( yy_saw_eof )
  310.         {
  311.         if ( yywrap() )
  312.         return ( EOF );
  313.  
  314.         YY_INIT;
  315.         }
  316.  
  317.     yy_b_buf_p = 0;
  318.     YY_INPUT( yy_ch_buf, yy_n_chars, YY_MAX_LINE );
  319.  
  320.     if ( yy_n_chars == YY_NULL )
  321.     {
  322.         yy_saw_eof = 1;
  323.  
  324.         if ( yywrap() )
  325.         return ( EOF );
  326.  
  327.         YY_INIT;
  328.  
  329.         return ( input() );
  330.     }
  331.  
  332.     yy_c_buf_p = -1;
  333.     yy_e_buf_p = yy_n_chars - 1;
  334.     }
  335.  
  336.     c = (unsigned char) yy_ch_buf[++yy_c_buf_p];
  337.  
  338.     YY_DO_BEFORE_ACTION;
  339.  
  340.     return ( c );
  341.     }
  342.  
  343. /*--------------------------------------------------------------------------*/
  344. /*------------------------- END OF LEXICAL ANALYZER ------------------------*/
  345. /*--------------------------------------------------------------------------*/
  346.  
  347.