/[bison]/bison/src/lex.c
ViewVC logotype

Diff of /bison/src/lex.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.37 by marc, Thu Aug 30 00:41:37 2001 UTC revision 1.38 by pascal, Thu Sep 20 18:32:20 2001 UTC
# Line 23  Line 23 
23  #include "files.h"  #include "files.h"
24  #include "getopt.h"             /* for optarg */  #include "getopt.h"             /* for optarg */
25  #include "symtab.h"  #include "symtab.h"
26    #include "options.h"
27  #include "lex.h"  #include "lex.h"
28  #include "xalloc.h"  #include "xalloc.h"
29  #include "complain.h"  #include "complain.h"
# Line 509  lex (void) Line 510  lex (void)
510      }      }
511  }  }
512    
513  /* the following table dictates the action taken for the various %  /* This function is a strcmp, which doesn't differentiate `-' and `_'
514     directives.  A set_flag value causes the named flag to be set.  A     chars.  */
    retval action returns the code.  */  
 struct percent_table_struct  
 {  
   const char *name;  
   void *set_flag;  
   int retval;  
 };  
515    
516  struct percent_table_struct percent_table[] =  static int
517    option_strcmp (const char *left, const char *right)
518  {  {
519    { "token",            NULL,                   tok_token },      const unsigned char *l, *r;
520    { "term",             NULL,                   tok_token },      int c;
   { "nterm",            NULL,                   tok_nterm },  
   { "type",             NULL,                   tok_type },  
   { "guard",            NULL,                   tok_guard },  
   { "union",            NULL,                   tok_union },  
   { "expect",           NULL,                   tok_expect },  
   { "thong",            NULL,                   tok_thong },  
   { "start",            NULL,                   tok_start },  
   { "left",             NULL,                   tok_left },  
   { "right",            NULL,                   tok_right },  
   { "nonassoc",         NULL,                   tok_nonassoc },  
   { "binary",           NULL,                   tok_nonassoc },  
   { "prec",             NULL,                   tok_prec },  
   { "locations",        &locations_flag,        tok_noop },     /* -l */  
   { "no_lines",         &no_lines_flag,         tok_noop },     /* -l */  
   { "raw",              NULL,                   tok_obsolete }, /* -r */  
   { "token_table",      &token_table_flag,      tok_noop },     /* -k */  
   { "yacc",             &yacc_flag,             tok_noop },     /* -y */  
   { "fixed_output_files",&yacc_flag,            tok_noop },     /* -y */  
   { "defines",          &defines_flag,          tok_noop },     /* -d */  
   { "no_parser",        &no_parser_flag,        tok_noop },     /* -n */  
 #if 0  
   /* For the time being, this is not enabled yet, while it's possible  
      though, since we use obstacks.  The only risk is with semantic  
      parsers which will output an `include' of an output file: be sure  
      that the naem included is indeed the name of the output file.  */  
   { "output_file",      &spec_outfile,          tok_setopt },   /* -o */  
   { "file_prefix",      &spec_file_prefix,      tok_setopt },   /* -b */  
   { "name_prefix",      &spec_name_prefix,      tok_setopt },   /* -p */  
 #endif  
   { "header_extension", NULL,                   tok_hdrext },  
   { "source_extension", NULL,                   tok_srcext },  
   { "define",           NULL,                   tok_define },  
   { "verbose",          &verbose_flag,          tok_noop },     /* -v */  
   { "debug",            &debug_flag,            tok_noop },     /* -t */  
   { "skeleton",         NULL,                   tok_skel },     /* -S */  
   { "semantic_parser",  &semantic_parser,       tok_noop },  
   { "pure_parser",      &pure_parser,           tok_noop },  
521    
522    { NULL, NULL, tok_illegal}      assert(left != NULL && right != NULL);    
523  };      l = (const unsigned char *)left;
524        r = (const unsigned char *)right;
525        while (((c = *l - *r++) == 0 && *l != '\0')
526               || ((*l == '-' || *l == '_') && (*r == '_' || *r == '-')))
527            l++;
528        return c;
529    }
530    
531  /* Parse a token which starts with %.  /* Parse a token which starts with %.
532     Assumes the % has already been read and discarded.  */     Assumes the % has already been read and discarded.  */
# Line 571  int Line 535  int
535  parse_percent_token (void)  parse_percent_token (void)
536  {  {
537    int c;    int c;
538    struct percent_table_struct *tx;    const struct option_table_struct *tx;
539    
540    c = getc (finput);    c = getc (finput);
541    
# Line 616  parse_percent_token (void) Line 580  parse_percent_token (void)
580    token_buffer = obstack_finish (&token_obstack);    token_buffer = obstack_finish (&token_obstack);
581    
582    /* table lookup % directive */    /* table lookup % directive */
583    for (tx = percent_table; tx->name; tx++)    for (tx = option_table; tx->name; tx++)
584      if (strcmp (token_buffer + 1, tx->name) == 0)      if ((tx->access == opt_percent || tx->access == opt_both)
585            && option_strcmp (token_buffer + 1, tx->name) == 0)
586        break;        break;
587    
588    if (tx->set_flag)    if (tx->set_flag)
# Line 626  parse_percent_token (void) Line 591  parse_percent_token (void)
591        return tok_noop;        return tok_noop;
592      }      }
593    
594    switch (tx->retval)    switch (tx->ret_val)
595      {      {
596      case tok_setopt:      case tok_setopt:
597        *((char **) (tx->set_flag)) = optarg;        *((char **) (tx->set_flag)) = optarg;
# Line 638  parse_percent_token (void) Line 603  parse_percent_token (void)
603        break;        break;
604      }      }
605    
606    return tx->retval;    return tx->ret_val;
607  }  }

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.38

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26