]> granicus.if.org Git - flex/commitdiff
Initial revision
authorVern Paxson <vern@ee.lbl.gov>
Wed, 24 May 1989 00:32:10 +0000 (00:32 +0000)
committerVern Paxson <vern@ee.lbl.gov>
Wed, 24 May 1989 00:32:10 +0000 (00:32 +0000)
flex.skl [new file with mode: 0644]

diff --git a/flex.skl b/flex.skl
new file mode 100644 (file)
index 0000000..5ac11d2
--- /dev/null
+++ b/flex.skl
@@ -0,0 +1,443 @@
+/* A lexical scanner generated by flex */
+
+/* scanner skeleton version:
+ * $Header$
+ */
+
+#include <stdio.h>
+
+#define FLEX_SCANNER
+
+/* returned upon end-of-file */
+#define YY_END_TOK 0
+
+/* amount of stuff to slurp up with each read */
+#define YY_READ_BUF_SIZE 8192
+
+#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of input buffer */
+
+/* number of characters one rule can match.  One less than YY_BUF_SIZE to make
+ * sure we never access beyond the end of an array
+ */
+#define YY_BUF_MAX (YY_BUF_SIZE - 1)
+
+/* copy whatever the last rule matched to the standard output */
+
+#define ECHO fputs( yytext, yyout )
+
+/* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#define YY_INPUT(buf,result,max_size) \
+       if ( (result = read( fileno(yyin), buf, max_size )) < 0 ) \
+           YY_FATAL_ERROR( "read() in flex scanner failed" );
+#define YY_NULL 0
+
+/* report a fatal error */
+#define YY_FATAL_ERROR(msg) \
+       { \
+       fputs( msg, stderr ); \
+       putc( '\n', stderr ); \
+       exit( 1 ); \
+       }
+
+/* default yywrap function - always treat EOF as an EOF */
+#define yywrap() 1
+
+/* enter a start condition.  This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way that old Unix-lex does it
+ */
+#define BEGIN yy_start = 1 +
+
+/* default declaration of generated scanner - a define so the user can
+ * easily add parameters
+ */
+#define YY_DECL int yylex()
+
+/* code executed at the end of each rule */
+#define YY_BREAK break;
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext
+ */
+#define YY_DO_BEFORE_ACTION \
+       yytext = yy_bp; \
+       yy_hold_char = *yy_cp; \
+       *yy_cp = '\0'; \
+       yy_c_buf_p = yy_cp;
+
+/* returns the length of the matched text */
+#define yyleng (yy_cp - yy_bp)
+
+#define EOB_ACT_RESTART_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+/* return all but the first 'n' matched characters back to the input stream */
+#define yyless(n) \
+       { \
+       *yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \
+       yy_c_buf_p = yy_cp = yy_bp + n; \
+       YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+       }
+
+#define unput(c) yyunput( c, yy_bp )
+
+#define YY_USER_ACTION
+
+%% section 1 code and the data tables for the DFA go here
+
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+
+/* these variables are all declared out here so that section 3 code can
+ * manipulate them
+ */
+static char *yy_c_buf_p;       /* points to current character in buffer */
+static int yy_init = 1;                /* whether we need to initialize */
+static int yy_start = 0;       /* start state number */
+
+/* true when we've seen an EOF for the current input file */
+static int yy_eof_has_been_seen;
+
+static int yy_n_chars;         /* number of characters read into yy_ch_buf */
+
+/* yy_ch_buf has to be 2 characters longer than YY_BUF_SIZE because we need
+ * to put in 2 end-of-buffer characters (this is explained where it is
+ * done) at the end of yy_ch_buf
+ */
+static char yy_ch_buf[YY_BUF_SIZE + 2];
+
+/* yy_hold_char holds the character lost when yytext is formed */
+static char yy_hold_char;
+char *yytext;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+static yy_state_type yy_get_previous_state();
+static int yy_get_next_buffer();
+
+static yyunput();
+static input();
+
+YY_DECL
+    {
+    register yy_state_type yy_current_state;
+    register char *yy_cp, *yy_bp;
+    register int yy_act;
+
+%% user's declarations go here
+
+    if ( yy_init )
+       {
+       if ( ! yy_start )
+           yy_start = 1;       /* first start state */
+
+       if ( ! yyin )
+           yyin = stdin;
+
+       if ( ! yyout )
+           yyout = stdout;
+
+new_file:
+       /* this is where we enter upon encountering an end-of-file and
+        * yywrap() indicating that we should continue processing
+        */
+
+       /* we put in the '\n' and start reading from [1] so that an
+        * initial match-at-newline will be true.
+        */
+
+       yy_ch_buf[0] = '\n';
+       yy_n_chars = 1;
+
+       /* we always need two end-of-buffer characters.  The first causes
+        * a transition to the end-of-buffer state.  The second causes
+        * a jam in that state.
+        */
+       yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+       yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+       yy_eof_has_been_seen = 0;
+
+       yytext = yy_c_buf_p = &yy_ch_buf[1];
+       yy_hold_char = *yy_c_buf_p;
+       yy_init = 0;
+       }
+
+    while ( 1 )                /* loops until end-of-file is reached */
+       {
+       yy_cp = yy_c_buf_p;
+
+       /* support of yytext */
+       *yy_cp = yy_hold_char;
+
+       /* yy_bp points to the position in yy_ch_buf of the start of the
+        * current run.
+        */
+       yy_bp = yy_cp;
+
+%% code to set up and find next match goes here
+
+       /* bogus while loop to let YY_BACK_TRACK and EOB_ACT_LAST_MATCH
+        * actions branch here without introducing an optimizer-daunting
+        * goto
+        */
+       while ( 1 )
+           {
+%% code to find the action number goes here
+
+           YY_DO_BEFORE_ACTION;
+           YY_USER_ACTION;
+
+#ifdef FLEX_DEBUG
+           fprintf( stderr, "--accepting rule #%d (\"%s\")\n",
+                    yy_act, yytext );
+#endif
+           switch ( yy_act )
+               {
+%% actions go here
+
+               case YY_END_OF_BUFFER:
+                   /* undo the effects of YY_DO_BEFORE_ACTION */
+                   *yy_cp = yy_hold_char;
+
+                   yytext = yy_bp;
+
+                   switch ( yy_get_next_buffer() )
+                       {
+                       case EOB_ACT_END_OF_FILE:
+                           {
+                           if ( yywrap() )
+                               {
+                               /* note: because we've taken care in
+                                * yy_get_next_buffer() to have set up yytext,
+                                * we can now set up yy_c_buf_p so that if some
+                                * total hoser (like flex itself) wants
+                                * to call the scanner after we return the
+                                * YY_NULL, it'll still work - another YY_NULL
+                                * will get returned.
+                                */
+                               yy_c_buf_p = yytext;
+                               return ( YY_NULL );
+                               }
+
+                           else
+                               goto new_file;
+                           }
+                           break;
+
+                       case EOB_ACT_RESTART_SCAN:
+                           yy_c_buf_p = yytext;
+                           yy_hold_char = *yy_c_buf_p;
+                           break;
+
+                       case EOB_ACT_LAST_MATCH:
+                           yy_c_buf_p = &yy_ch_buf[yy_n_chars];
+
+                           yy_current_state = yy_get_previous_state();
+
+                           yy_cp = yy_c_buf_p;
+                           yy_bp = yytext;
+                           continue; /* go to "YY_DO_BEFORE_ACTION" */
+                       }
+                   break;
+
+               default:
+                   printf( "action # %d\n", yy_act );
+                   YY_FATAL_ERROR( "fatal flex scanner internal error" );
+               }
+
+           break; /* exit bogus while loop */
+           }
+       }
+    }
+
+
+/* yy_get_next_buffer - try to read in new buffer
+ *
+ * synopsis
+ *     int yy_get_next_buffer();
+ *     
+ * returns a code representing an action
+ *     EOB_ACT_LAST_MATCH - 
+ *     EOB_ACT_RESTART_SCAN - restart the scanner
+ *     EOB_ACT_END_OF_FILE - end of file
+ */
+
+static int yy_get_next_buffer()
+
+    {
+    if ( yy_c_buf_p != &yy_ch_buf[yy_n_chars + 1] )
+       {
+       YY_FATAL_ERROR( "NULL in input" );
+       /*NOTREACHED*/
+       }
+
+    else
+       { /* try to read more data */
+       register char *dest = yy_ch_buf;
+       register char *source = yytext - 1; /* copy prev. char, too */
+       register int number_to_move, i;
+       int ret_val;
+       
+       /* first move last chars to start of buffer */
+       number_to_move = yy_c_buf_p - yytext;
+
+       for ( i = 0; i < number_to_move; ++i )
+           *(dest++) = *(source++);
+
+       if ( yy_eof_has_been_seen )
+           /* don't do the read, it's not guaranteed to return an EOF,
+            * just force an EOF
+            */
+           yy_n_chars = 0;
+
+       else
+           /* read in more data */
+           YY_INPUT( (&yy_ch_buf[number_to_move]), yy_n_chars,
+                     YY_BUF_SIZE - number_to_move - 1 );
+
+       if ( yy_n_chars == 0 )
+           {
+           if ( number_to_move == 1 )
+               ret_val = EOB_ACT_END_OF_FILE;
+           else
+               ret_val = EOB_ACT_LAST_MATCH;
+
+           yy_eof_has_been_seen = 1;
+           }
+
+       else
+           ret_val = EOB_ACT_RESTART_SCAN;
+
+       yy_n_chars += number_to_move;
+       yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+       yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+       /* yytext begins at the second character in
+        * yy_ch_buf; the first character is the one which
+        * preceded it before reading in the latest buffer;
+        * it needs to be kept around in case it's a
+        * newline, so yy_get_previous_state() will have
+        * with '^' rules active
+        */
+
+       yytext = &yy_ch_buf[1];
+
+       return ( ret_val );
+       }
+    }
+
+
+/* yy_get_previous_state - get the state just before the EOB char was reached
+ *
+ * synopsis
+ *     yy_state_type yy_get_previous_state();
+ */
+
+static yy_state_type yy_get_previous_state()
+
+    {
+    register yy_state_type yy_current_state;
+    register char *yy_cp;
+
+%% code to get the start state into yy_current_state goes here
+
+    for ( yy_cp = yytext; yy_cp < yy_c_buf_p; ++yy_cp )
+       {
+%% code to find the next state goes here
+       }
+
+    return ( yy_current_state );
+    }
+
+
+static yyunput( c, yy_bp )
+int c;
+register char *yy_bp;
+
+    {
+    register char *yy_cp = yy_c_buf_p;
+
+    *yy_cp = yy_hold_char; /* undo effects of setting up yytext */
+
+    if ( yy_cp < yy_ch_buf + 2 )
+       { /* need to shift things up to make room */
+       register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
+       register char *dest = &yy_ch_buf[YY_BUF_SIZE + 2];
+       register char *source = &yy_ch_buf[number_to_move];
+
+       while ( source > yy_ch_buf )
+           *--dest = *--source;
+
+       yy_cp += dest - source;
+       yy_bp += dest - source;
+
+       if ( yy_cp < yy_ch_buf + 2 )
+           YY_FATAL_ERROR( "flex scanner push-back overflow" );
+       }
+
+    if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
+       yy_cp[-2] = '\n';
+
+    *--yy_cp = c;
+
+    YY_DO_BEFORE_ACTION; /* set up yytext again */
+    }
+
+
+static int input()
+
+    {
+    int c;
+    char *yy_cp = yy_c_buf_p;
+
+    *yy_cp = yy_hold_char;
+
+    if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+       { /* need more input */
+       yytext = yy_c_buf_p;
+       ++yy_c_buf_p;
+
+       switch ( yy_get_next_buffer() )
+           {
+           /* this code, unfortunately, is somewhat redundant with
+            * that above
+            */
+           case EOB_ACT_END_OF_FILE:
+               {
+               if ( yywrap() )
+                   {
+                   yy_c_buf_p = yytext;
+                   return ( EOF );
+                   }
+
+               yy_ch_buf[0] = '\n';
+               yy_n_chars = 1;
+               yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+               yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+               yy_eof_has_been_seen = 0;
+               yytext = yy_c_buf_p = &yy_ch_buf[1];
+               yy_hold_char = *yy_c_buf_p;
+
+               return ( input() );
+               }
+               break;
+
+           case EOB_ACT_RESTART_SCAN:
+               yy_c_buf_p = yytext;
+               break;
+
+           case EOB_ACT_LAST_MATCH:
+               YY_FATAL_ERROR( "unexpected last match in input()" );
+           }
+       }
+
+    c = *yy_c_buf_p;
+    yy_hold_char = *++yy_c_buf_p;
+
+    return ( c );
+    }