home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 290_01 / fastskel.c < prev    next >
Text File  |  1990-05-14  |  11KB  |  427 lines

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