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

Diff of /bison/src/reader.c

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

revision 1.91 by akim, Thu Oct 4 15:07:32 2001 UTC revision 1.92 by akim, Fri Nov 2 14:04:54 2001 UTC
# Line 1  Line 1 
1  /* Input parser for bison  /* Input parser for bison
2     Copyright 1984, 1986, 1989, 1992, 1998, 2000     Copyright 1984, 1986, 1989, 1992, 1998, 2000, 2001
3     Free Software Foundation, Inc.     Free Software Foundation, Inc.
4    
5     This file is part of Bison, the GNU Compiler Compiler.     This file is part of Bison, the GNU Compiler Compiler.
# Line 852  parse_thong_decl (void) Line 852  parse_thong_decl (void)
852    token_t token;    token_t token;
853    struct bucket *symbol;    struct bucket *symbol;
854    char *typename = 0;    char *typename = 0;
855    int usrtoknum;    int usrtoknum = 0;
856    
857    token = lex ();               /* fetch typename or first token */    token = lex ();               /* fetch typename or first token */
858    if (token == tok_typename)    if (token == tok_typename)
# Line 883  parse_thong_decl (void) Line 883  parse_thong_decl (void)
883        usrtoknum = numval;        usrtoknum = numval;
884        token = lex ();           /* okay, did number, now get literal */        token = lex ();           /* okay, did number, now get literal */
885      }      }
   else  
     usrtoknum = 0;  
886    
887    /* process literal string token */    /* process literal string token */
888    
# Line 1700  output_token_defines (struct obstack *oo Line 1698  output_token_defines (struct obstack *oo
1698    
1699    
1700  /*------------------------------------------------------------------.  /*------------------------------------------------------------------.
1701    | Set TOKEN_TRANSLATIONS.  Check that no two symbols share the same |
1702    | number.                                                           |
1703    `------------------------------------------------------------------*/
1704    
1705    static void
1706    token_translations_init (void)
1707    {
1708      bucket *bp = NULL;
1709      int i;
1710    
1711      token_translations = XCALLOC (short, max_user_token_number + 1);
1712    
1713      /* Initialize all entries for literal tokens to 2, the internal
1714         token number for $undefined., which represents all invalid
1715         inputs.  */
1716      for (i = 0; i <= max_user_token_number; i++)
1717        token_translations[i] = 2;
1718    
1719      for (bp = firstsymbol; bp; bp = bp->next)
1720        {
1721          /* Non-terminal? */
1722          if (bp->value >= ntokens)
1723            continue;
1724          /* A token string alias? */
1725          if (bp->user_token_number == SALIAS)
1726            continue;
1727          /* A token which translation has already been set? */
1728          if (token_translations[bp->user_token_number] != 2)
1729            complain (_("tokens %s and %s both assigned number %d"),
1730                      tags[token_translations[bp->user_token_number]],
1731                      bp->tag, bp->user_token_number);
1732          token_translations[bp->user_token_number] = bp->value;
1733        }
1734    }
1735    
1736    
1737    /*------------------------------------------------------------------.
1738  | Assign symbol numbers, and write definition of token names into   |  | Assign symbol numbers, and write definition of token names into   |
1739  | FDEFINES.  Set up vectors TAGS and SPREC of names and precedences |  | FDEFINES.  Set up vectors TAGS and SPREC of names and precedences |
1740  | of symbols.                                                       |  | of symbols.                                                       |
# Line 1710  packsymbols (void) Line 1745  packsymbols (void)
1745  {  {
1746    bucket *bp = NULL;    bucket *bp = NULL;
1747    int tokno = 1;    int tokno = 1;
   int i, j;  
1748    int last_user_token_number;    int last_user_token_number;
1749    static char DOLLAR[] = "$";    static char DOLLAR[] = "$";
1750    
1751    tags = XCALLOC (char *, nsyms + 1);    tags = XCALLOC (char *, nsyms + 1);
   tags[0] = DOLLAR;  
1752    user_toknums = XCALLOC (short, nsyms + 1);    user_toknums = XCALLOC (short, nsyms + 1);
   user_toknums[0] = 0;  
1753    
1754    sprec = XCALLOC (short, nsyms);    sprec = XCALLOC (short, nsyms);
1755    sassoc = XCALLOC (short, nsyms);    sassoc = XCALLOC (short, nsyms);
1756    
1757      /* The EOF token. */
1758      tags[0] = DOLLAR;
1759      user_toknums[0] = 0;
1760    
1761    max_user_token_number = 256;    max_user_token_number = 256;
1762    last_user_token_number = 256;    last_user_token_number = 256;
1763    
# Line 1774  packsymbols (void) Line 1810  packsymbols (void)
1810    
1811        if (bp->class == token_sym)        if (bp->class == token_sym)
1812          {          {
1813            if (!bp->user_token_number)            if (bp->user_token_number == 0)
1814              bp->user_token_number = ++last_user_token_number;              bp->user_token_number = ++last_user_token_number;
1815            if (bp->user_token_number > max_user_token_number)            if (bp->user_token_number > max_user_token_number)
1816              max_user_token_number = bp->user_token_number;              max_user_token_number = bp->user_token_number;
# Line 1786  packsymbols (void) Line 1822  packsymbols (void)
1822        sassoc[bp->value] = bp->assoc;        sassoc[bp->value] = bp->assoc;
1823      }      }
1824    
1825    token_translations = XCALLOC (short, max_user_token_number + 1);    token_translations_init ();
   
   /* initialize all entries for literal tokens to 2, the internal  
      token number for $undefined., which represents all invalid  
      inputs.  */  
   for (j = 0; j <= max_user_token_number; j++)  
     token_translations[j] = 2;  
   
   for (bp = firstsymbol; bp; bp = bp->next)  
     {  
       if (bp->value >= ntokens)  
         continue;               /* non-terminal */  
       if (bp->user_token_number == SALIAS)  
         continue;  
       if (token_translations[bp->user_token_number] != 2)  
         complain (_("tokens %s and %s both assigned number %d"),  
                   tags[token_translations[bp->user_token_number]],  
                   bp->tag, bp->user_token_number);  
       token_translations[bp->user_token_number] = bp->value;  
     }  
1826    
1827    error_token_number = errtoken->value;    error_token_number = errtoken->value;
1828    
# Line 1845  packsymbols (void) Line 1862  packsymbols (void)
1862          }          }
1863    
1864        if (semantic_parser)        if (semantic_parser)
1865          for (i = ntokens; i < nsyms; i++)          {
1866            {            int i;
1867              /* don't make these for dummy nonterminals made by gensym.  */  
1868              if (*tags[i] != '@')            for (i = ntokens; i < nsyms; i++)
1869                 obstack_fgrow2 (&defines_obstack,              {
1870                                 "# define\tNT%s\t%d\n", tags[i], i);                /* don't make these for dummy nonterminals made by gensym.  */
1871            }                if (*tags[i] != '@')
1872                    obstack_fgrow2 (&defines_obstack,
1873                                    "# define\tNT%s\t%d\n", tags[i], i);
1874                }
1875  #if 0  #if 0
1876        /* `fdefines' is now a temporary file, so we need to copy its            /* `fdefines' is now a temporary file, so we need to copy its
1877           contents in `done', so we can't close it here.  */               contents in `done', so we can't close it here.  */
1878        fclose (fdefines);            fclose (fdefines);
1879        fdefines = NULL;            fdefines = NULL;
1880  #endif  #endif
1881            }
1882      }      }
1883  }  }
1884    

Legend:
Removed from v.1.91  
changed lines
  Added in v.1.92

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