]> git.saurik.com Git - bison.git/blobdiff - src/lex.c
Add.
[bison.git] / src / lex.c
index deb6eb7af47374fd303b83ac865b2c7fdb059d4f..d43403ce9bd98f6dc76da4703ea17b3fb3b7218c 100644 (file)
--- a/src/lex.c
+++ b/src/lex.c
 static struct obstack token_obstack;
 const char *token_buffer = NULL;
 
-bucket *symval = NULL;
+symbol_t *symval = NULL;
 int numval;
 
 /* A token to be reread, see unlex and lex. */
 static token_t unlexed = tok_undef;
-static bucket *unlexed_symval = NULL;
+static symbol_t *unlexed_symval = NULL;
 static const char *unlexed_token_buffer = NULL;
 
 void
@@ -364,9 +364,13 @@ lex (void)
        obstack_1grow (&token_obstack, '\0');
        token_buffer = obstack_finish (&token_obstack);
        symval = getsym (token_buffer);
-       symval->class = token_sym;
-       if (symval->user_token_number == SUNDEF)
-         symval->user_token_number = code;
+       if (symval->number == NUMBER_UNDEFINED)
+         {
+           symval->number = ntokens++;
+           symval->class = token_sym;
+           if (symval->user_token_number == USER_NUMBER_UNDEFINED)
+             symval->user_token_number = code;
+         }
        return tok_identifier;
       }
 
@@ -388,7 +392,11 @@ lex (void)
        token_buffer = obstack_finish (&token_obstack);
 
        symval = getsym (token_buffer);
-       symval->class = token_sym;
+       if (symval->number == NUMBER_UNDEFINED)
+         {
+           symval->number = ntokens++;
+           symval->class = token_sym;
+         }
 
        return tok_identifier;
       }
@@ -476,49 +484,56 @@ option_strcmp (const char *left, const char *right)
 token_t
 parse_percent_token (void)
 {
-  const struct option_table_struct *tx = NULL;
+  const struct option_table_s *tx = NULL;
   const char *arg = NULL;
   /* Where the ARG was found in token_buffer. */
   size_t arg_offset = 0;
 
   int c = getc (finput);
+  obstack_1grow (&token_obstack, '%');
+  obstack_1grow (&token_obstack, c);
 
-  switch (c)
+  if (!isalpha (c))
     {
-    case '%':
-      return tok_two_percents;
+      obstack_1grow (&token_obstack, '\0');
+      token_buffer = obstack_finish (&token_obstack);
 
-    case '{':
-      return tok_percent_left_curly;
+      switch (c)
+       {
+       case '%':
+         return tok_two_percents;
 
-      /* FIXME: Who the heck are those 5 guys!?! `%<' = `%left'!!!
-        Let's ask for there removal.  */
-    case '<':
-      return tok_left;
+       case '{':
+         return tok_percent_left_curly;
 
-    case '>':
-      return tok_right;
+         /* The following guys are here for backward compatibility with
+            very ancient Yacc versions.  The paper of Johnson mentions
+            them (as ancient :).  */
+       case '<':
+         return tok_left;
 
-    case '2':
-      return tok_nonassoc;
+       case '>':
+         return tok_right;
 
-    case '0':
-      return tok_token;
+       case '2':
+         return tok_nonassoc;
 
-    case '=':
-      return tok_prec;
-    }
+       case '0':
+         return tok_token;
 
-  if (!isalpha (c))
-    return tok_illegal;
+       case '=':
+         return tok_prec;
 
-  obstack_1grow (&token_obstack, '%');
-  while (isalpha (c) || c == '_' || c == '-')
+       default:
+         return tok_illegal;
+       }
+    }
+
+  while (c = getc (finput), isalpha (c) || c == '_' || c == '-')
     {
       if (c == '_')
        c = '-';
       obstack_1grow (&token_obstack, c);
-      c = getc (finput);
     }
 
   /* %DIRECTIVE="ARG".  Separate into
@@ -563,15 +578,16 @@ parse_percent_token (void)
   switch (tx->ret_val)
     {
     case tok_stropt:
-      assert (tx->set_flag);
+      assert (tx->flag);
       if (arg)
        {
+         char **flag = (char **) tx->flag;
          /* Keep only the first assignment: command line options have
             already been processed, and we want them to have
             precedence.  Side effect: if this %-option is used
             several times, only the first is honored.  Bah.  */
-         if (!*((char **) (tx->set_flag)))
-           *((char **) (tx->set_flag)) = xstrdup (arg);
+         if (!*flag)
+           *flag = xstrdup (arg);
        }
       else
        fatal (_("`%s' requires an argument"), token_buffer);
@@ -579,8 +595,8 @@ parse_percent_token (void)
       break;
 
     case tok_intopt:
-      assert (tx->set_flag);
-      *((int *) (tx->set_flag)) = 1;
+      assert (tx->flag);
+      *((int *) (tx->flag)) = 1;
       return tok_noop;
       break;