home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d156 / flex.lha / Flex / Flex2 / flex.fastskel < prev    next >
Text File  |  1988-10-02  |  9KB  |  403 lines

  1. /* A lexical scanner generated by flex */
  2.  
  3. #define FLEX_FAST_SKEL
  4.  
  5. #include "fastskeldef.h"
  6.  
  7. %% section 1 code and the definition of YY_TRANS_OFFSET_TYPE, if needed, go here
  8.  
  9. #ifndef FLEX_FULL_TABLE
  10.     /* struct for yy_transition */
  11.     struct yy_trans_info
  12.     {
  13.     /* v is a verify for a transition. */
  14.     short v;
  15.  
  16.     /* In cases where its sister v *is* a "yes, there is a transition",
  17.          * n is* the offset (in records) to the next state.  In most cases
  18.          * where there is no transition, the value of n is irrelevant.  If n
  19.          * is the -1th  record of a state, though, then n is the action
  20.      * number for that state
  21.      */
  22.     YY_TRANS_OFFSET_TYPE n;
  23.     };
  24. #endif
  25.  
  26. %% data tables for DFA go here
  27.  
  28. /* these declarations have to come after the section 1 code or lint gets
  29.  * confused about whether the variables are used
  30.  */
  31. FILE *yyin = stdin, *yyout = stdout;
  32.  
  33. /* these variables are all declared out here so that section 3 code can
  34.  * manipulate them
  35.  */
  36. static char *yy_c_buf_p;    /* points to current character in buffer */
  37. static char *yy_b_buf_p;    /* points to start of current scan */
  38. static int yy_init = 1;    /* whether we need to initialize */
  39. static int yy_start;    /* start state number */
  40.  
  41. /* true when we've seen an EOF for the current input file */
  42. static int yy_eof_has_been_seen;
  43.  
  44. static int yy_n_chars;        /* number of characters read into yy_ch_buf */
  45.  
  46. /* yy_ch_buf has to be 2 characters longer than YY_BUF_SIZE because we need
  47.  * to put in 2 end-of-buffer characters (this is explained where it is
  48.  * done) at the end of yy_ch_buf
  49.  */
  50. static char yy_ch_buf[YY_BUF_SIZE + 2];
  51.  
  52. /* yy_hold_char holds the character lost when yytext is formed */
  53. static char yy_hold_char;
  54. char *yytext;
  55. static int yyleng;    /* length of yytext */
  56.  
  57. static YY_CS_TYPE yy_last_accepting_state;
  58. static char *yy_last_accepting_cpos;
  59.  
  60. static YY_CS_TYPE yy_get_previous_state();
  61. static int yy_get_next_buffer();
  62.  
  63. #define FLEX_USES_BACKTRACKING
  64.  
  65. #ifdef FLEX_USES_BACKTRACKING
  66. #    ifdef FLEX_FULL_TABLE
  67. #    define YY_BACKTRACKING_ACTION \
  68.         if ( l[yy_current_state] ) \
  69.             { \
  70.             yy_last_accepting_state = yy_current_state; \
  71.             yy_last_accepting_cpos = yy_c_buf_p; \
  72.             }
  73. #    else
  74. #    define YY_BACKTRACKING_ACTION \
  75.         if ( yy_current_state[-1].n ) \
  76.             { \
  77.             yy_last_accepting_state = yy_current_state; \
  78.             yy_last_accepting_cpos = yy_c_buf_p; \
  79.             }
  80. #    endif
  81. #else
  82. #    define YY_BACKTRACKING_ACTION
  83. #endif
  84.  
  85. YY_DECL
  86.     {
  87.     register YY_CS_TYPE yy_current_state;
  88.     register int yy_c;
  89.     register struct yy_trans_info *yy_trans_info;
  90.     register int yy_act;
  91.  
  92. %% user's declarations go here
  93.  
  94.     if ( yy_init )
  95.     {
  96.     yy_start = 1;    /* first start state */
  97.  
  98. new_file:
  99.     /* this is where we enter upon encountering and end-of-file and
  100.      * yywrap() indicating that we should continue processing
  101.      */
  102.  
  103.     /* we put in the '\n' and start reading from [1] so that an
  104.      * initial match-at-newline will be true.
  105.      */
  106.  
  107.     yy_ch_buf[0] = '\n';
  108.     yy_n_chars = 1;
  109.  
  110.     /* we always need two end-of-buffer characters.  The first causes
  111.      * a transition to the end-of-buffer state.  The second causes
  112.      * a jam in that state.
  113.      */
  114.     yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  115.     yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  116.  
  117.     yy_eof_has_been_seen = 0;
  118.  
  119.     YY_FAST_INIT;
  120.     yy_init = 0;
  121.     }
  122.  
  123.     while ( 1 )        /* loops until end-of-file is reached */
  124.     {
  125.     /* support of yytext and yyleng */
  126.     YY_DO_BEFORE_SCAN;
  127.  
  128.     /* yy_b_buf_p points to the position in yy_ch_buf of the start of the
  129.      * current run.
  130.      */
  131.     yy_b_buf_p = yy_c_buf_p;
  132.  
  133.         YY_FIND_START_STATE( yy_current_state );
  134.  
  135.         YY_FIND_NEXT_MATCH;
  136.  
  137.     YY_DO_BEFORE_ACTION;
  138.  
  139. /* we need this label to process the very last action (right before the end of
  140.  * the file)
  141.  */
  142. do_action:
  143.     YY_FIND_ACTION( yy_act );
  144.  
  145. #ifdef FLEX_DEBUG
  146.     fprintf( stderr, "--accepting rule #%d\n", yy_act );
  147. #endif
  148.     switch ( yy_act )
  149.         {
  150. %% actions go here
  151.  
  152.         case YY_BACK_TRACK:
  153.         YY_DO_BEFORE_SCAN; /* undo the effects of YY_DO_BEFORE_ACTION */
  154.         yy_c_buf_p = yy_last_accepting_cpos + 1;
  155.         yy_current_state = yy_last_accepting_state;
  156.         YY_DO_BEFORE_ACTION;
  157.         goto do_action;
  158.  
  159.         case YY_NEW_FILE:
  160.         break; /* begin reading from new file */
  161.  
  162.         case YY_DO_DEFAULT:
  163.         /* we have to eat up one character and recompute yytext and
  164.          * yyleng
  165.          */
  166.         YY_DO_BEFORE_SCAN; /* undo the effects of YY_DO_BEFORE_ACTION */
  167.         ++yy_c_buf_p;
  168.         YY_DO_BEFORE_ACTION;
  169.         YY_DEFAULT_ACTION;
  170.         break;
  171.  
  172.         case YY_END_OF_BUFFER:
  173.         YY_DO_BEFORE_SCAN; /* undo the effects of YY_DO_BEFORE_ACTION */
  174.  
  175.         switch ( yy_get_next_buffer() )
  176.             {
  177.             case EOB_ACT_END_OF_FILE:
  178.             {
  179.             if ( yywrap() )
  180.                 {
  181.                 /* note: because we've taken care in
  182.                  * yy_get_next_buffer() to have set up yy_b_buf_p,
  183.                  * we can now set up yy_c_buf_p so that if some
  184.                  * total hoser (like flex itself) wants
  185.                  * to call the scanner after we return the
  186.                  * YY_NULL, it'll still work - another YY_NULL
  187.                   * will get returned.
  188.                  */
  189.                 yy_c_buf_p = yy_b_buf_p;
  190.                 return ( YY_NULL );
  191.                 }
  192.  
  193.             else
  194.                 goto new_file;
  195.             }
  196.             break;
  197.  
  198.             case EOB_ACT_RESTART_SCAN:
  199.             yy_c_buf_p = yy_b_buf_p;
  200.  
  201.             YY_DO_BEFORE_RESTART;
  202.             break;
  203.  
  204.             case EOB_ACT_LAST_MATCH:
  205.             yy_c_buf_p = &yy_ch_buf[yy_n_chars];
  206.  
  207.             yy_current_state = yy_get_previous_state();
  208.  
  209.             YY_DO_BEFORE_ACTION;
  210.  
  211.             goto do_action;
  212.             }
  213.         break;
  214.  
  215.         default:
  216.         printf( "action # %d\n", yy_act );
  217.         YY_FATAL_ERROR( "fatal flex scanner internal error" );
  218.         }
  219.     }
  220.     }
  221.  
  222.  
  223. /* yy_get_next_buffer - try to read in new buffer
  224.  *
  225.  * synopsis
  226.  *     int yy_get_next_buffer();
  227.  *     
  228.  * returns a code representing an action
  229.  *     EOB_ACT_LAST_MATCH - 
  230.  *     EOB_ACT_RESTART_SCAN - restart the scanner
  231.  *     EOB_ACT_END_OF_FILE - end of file
  232.  */
  233.  
  234. static int yy_get_next_buffer()
  235.  
  236.     {
  237.     if ( yy_c_buf_p != &yy_ch_buf[yy_n_chars + 1] )
  238.     {
  239.     YY_FATAL_ERROR( "NULL in input" );
  240.     /*NOTREACHED*/
  241.     }
  242.  
  243.     else
  244.     { /* try to read more data */
  245.     register char *dest = yy_ch_buf;
  246.     register char *source = yy_b_buf_p - 1; /* copy prev. char, too */
  247.     register int number_to_move, i;
  248.     int ret_val;
  249.     
  250.     /* first move last chars to start of buffer */
  251.     number_to_move = yy_c_buf_p - yy_b_buf_p;
  252.  
  253.     for ( i = 0; i < number_to_move; ++i )
  254.         *(dest++) = *(source++);
  255.  
  256.     if ( yy_eof_has_been_seen )
  257.         /* don't do the read, it's not guaranteed to return an EOF,
  258.          * just force an EOF
  259.          */
  260.         yy_n_chars = 0;
  261.  
  262.     else
  263.         /* read in more data */
  264.         YY_INPUT( (&yy_ch_buf[number_to_move]), yy_n_chars,
  265.               YY_BUF_SIZE - number_to_move - 1 );
  266.  
  267.     if ( yy_n_chars == 0 )
  268.         {
  269.         if ( number_to_move == 1 )
  270.         ret_val = EOB_ACT_END_OF_FILE;
  271.         else
  272.         ret_val = EOB_ACT_LAST_MATCH;
  273.  
  274.         yy_eof_has_been_seen = 1;
  275.         }
  276.  
  277.     else
  278.         ret_val = EOB_ACT_RESTART_SCAN;
  279.  
  280.     yy_n_chars += number_to_move;
  281.     yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  282.     yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  283.  
  284.     /* yy_b_buf_p begins at the second character in
  285.      * yy_ch_buf; the first character is the one which
  286.      * preceded it before reading in the latest buffer;
  287.      * it needs to be kept around in case it's a
  288.      * newline, so yy_get_previous_state() will have
  289.      * with '^' rules active
  290.      */
  291.  
  292.     yy_b_buf_p = &yy_ch_buf[1];
  293.  
  294.     return ( ret_val );
  295.     }
  296.     }
  297.  
  298.  
  299. /* yy_get_previous_state - get the state just before the eob char was reached
  300.  *
  301.  * synopsis
  302.  *     YY_CS_TYPE yy_get_previous_state();
  303.  */
  304.  
  305. static YY_CS_TYPE yy_get_previous_state()
  306.  
  307.     {
  308.     register YY_CS_TYPE yy_cur_state;
  309.     register char *yy_temp_char_ptr;
  310.  
  311.     YY_FIND_START_STATE( yy_cur_state );
  312.  
  313.     for ( yy_temp_char_ptr = yy_b_buf_p; yy_temp_char_ptr < yy_c_buf_p; )
  314.     YY_GET_NEXT_STATE;
  315.  
  316.     return ( yy_cur_state );
  317.     }
  318.  
  319.  
  320. static unput( c )
  321. int c;
  322.  
  323.     {
  324.     YY_DO_BEFORE_SCAN; /* undo effects of setting up yytext */
  325.  
  326.     if ( yy_c_buf_p < yy_ch_buf + 2 )
  327.     { /* need to shift things up to make room */
  328.     register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
  329.     register char *dest = &yy_ch_buf[YY_BUF_SIZE + 2];
  330.     register char *source = &yy_ch_buf[number_to_move];
  331.  
  332.     while ( source > yy_ch_buf )
  333.         *--dest = *--source;
  334.  
  335.     yy_c_buf_p += dest - source;
  336.     yy_b_buf_p += dest - source;
  337.  
  338.     if ( yy_c_buf_p < yy_ch_buf + 2 )
  339.         YY_FATAL_ERROR( "flex scanner push-back overflow" );
  340.     }
  341.  
  342.     if ( yy_c_buf_p > yy_b_buf_p && yy_c_buf_p[-1] == '\n' )
  343.     yy_c_buf_p[-2] = '\n';
  344.  
  345.     *--yy_c_buf_p = c;
  346.  
  347.     YY_DO_BEFORE_ACTION; /* set up yytext again */
  348.     }
  349.  
  350.  
  351. static int input()
  352.  
  353.     {
  354.     int c;
  355.  
  356.     YY_DO_BEFORE_SCAN;
  357.  
  358.     if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
  359.     { /* need more input */
  360.     yy_b_buf_p = yy_c_buf_p;
  361.     ++yy_c_buf_p;
  362.  
  363.     switch ( yy_get_next_buffer() )
  364.         {
  365.         /* this code, unfortunately, is somewhat redundant with
  366.          * that above
  367.          */
  368.         case EOB_ACT_END_OF_FILE:
  369.         {
  370.         if ( yywrap() )
  371.             {
  372.             yy_c_buf_p = yy_b_buf_p;
  373.             return ( EOF );
  374.             }
  375.  
  376.         yy_ch_buf[0] = '\n';
  377.         yy_n_chars = 1;
  378.         yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  379.         yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  380.         yy_eof_has_been_seen = 0;
  381.  
  382.         YY_FAST_INIT;
  383.  
  384.         return ( input() );
  385.         }
  386.         break;
  387.  
  388.         case EOB_ACT_RESTART_SCAN:
  389.         yy_c_buf_p = yy_b_buf_p;
  390.         break;
  391.  
  392.         case EOB_ACT_LAST_MATCH:
  393.         YY_FATAL_ERROR( "unexpected last match in input()" );
  394.         }
  395.     }
  396.  
  397.     c = *yy_c_buf_p++;
  398.  
  399.     YY_DO_BEFORE_RESTART;
  400.  
  401.     return ( c );
  402.     }
  403.