/[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.72.2.9 by akim, Tue Sep 25 18:35:04 2001 UTC revision 1.72.2.10 by akim, Fri Nov 2 14:02:31 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 821  parse_thong_decl (void) Line 821  parse_thong_decl (void)
821    token_t token;    token_t token;
822    struct bucket *symbol;    struct bucket *symbol;
823    char *typename = 0;    char *typename = 0;
824    int usrtoknum;    int usrtoknum = 0;
825    
826    token = lex ();               /* fetch typename or first token */    token = lex ();               /* fetch typename or first token */
827    if (token == tok_typename)    if (token == tok_typename)
# Line 852  parse_thong_decl (void) Line 852  parse_thong_decl (void)
852        usrtoknum = numval;        usrtoknum = numval;
853        token = lex ();           /* okay, did number, now get literal */        token = lex ();           /* okay, did number, now get literal */
854      }      }
   else  
     usrtoknum = 0;  
855    
856    /* process literal string token */    /* process literal string token */
857    
# Line 875  parse_thong_decl (void) Line 873  parse_thong_decl (void)
873  }  }
874    
875    
876  /*-----------------------------------------------------------------------------.  /*------------------------------------------------------------------.
877  | Parse a double quoted parameter. It was used for %{source,header}_extension. |  | Parse a double quoted parameter. It was used for                  |
878  | For the moment, It is not used since extension features have been removed.   |  | %{source,header}_extension.  For the moment, It is not used since |
879  `-----------------------------------------------------------------------------*/  | extension features have been removed.                             |
880    `------------------------------------------------------------------*/
881    
882  #if 0  #if 0
883    
# Line 1664  output_token_defines (struct obstack *oo Line 1663  output_token_defines (struct obstack *oo
1663    
1664    
1665  /*------------------------------------------------------------------.  /*------------------------------------------------------------------.
1666    | Set TOKEN_TRANSLATIONS.  Check that no two symbols share the same |
1667    | number.                                                           |
1668    `------------------------------------------------------------------*/
1669    
1670    static void
1671    token_translations_init (void)
1672    {
1673      bucket *bp = NULL;
1674      int i;
1675    
1676      token_translations = XCALLOC (short, max_user_token_number + 1);
1677    
1678      /* Initialize all entries for literal tokens to 2, the internal
1679         token number for $undefined., which represents all invalid
1680         inputs.  */
1681      for (i = 0; i <= max_user_token_number; i++)
1682        token_translations[i] = 2;
1683    
1684      for (bp = firstsymbol; bp; bp = bp->next)
1685        {
1686          /* Non-terminal? */
1687          if (bp->value >= ntokens)
1688            continue;
1689          /* A token string alias? */
1690          if (bp->user_token_number == SALIAS)
1691            continue;
1692          /* A token which translation has already been set? */
1693          if (token_translations[bp->user_token_number] != 2)
1694            complain (_("tokens %s and %s both assigned number %d"),
1695                      tags[token_translations[bp->user_token_number]],
1696                      bp->tag, bp->user_token_number);
1697          token_translations[bp->user_token_number] = bp->value;
1698        }
1699    }
1700    
1701    
1702    /*------------------------------------------------------------------.
1703  | Assign symbol numbers, and write definition of token names into   |  | Assign symbol numbers, and write definition of token names into   |
1704  | FDEFINES.  Set up vectors TAGS and SPREC of names and precedences |  | FDEFINES.  Set up vectors TAGS and SPREC of names and precedences |
1705  | of symbols.                                                       |  | of symbols.                                                       |
# Line 1674  packsymbols (void) Line 1710  packsymbols (void)
1710  {  {
1711    bucket *bp = NULL;    bucket *bp = NULL;
1712    int tokno = 1;    int tokno = 1;
   int i, j;  
1713    int last_user_token_number;    int last_user_token_number;
1714    static char DOLLAR[] = "$";    static char DOLLAR[] = "$";
1715    
   /* int lossage = 0; JF set but not used */  
   
1716    tags = XCALLOC (char *, nsyms + 1);    tags = XCALLOC (char *, nsyms + 1);
   tags[0] = DOLLAR;  
1717    user_toknums = XCALLOC (short, nsyms + 1);    user_toknums = XCALLOC (short, nsyms + 1);
   user_toknums[0] = 0;  
1718    
1719    sprec = XCALLOC (short, nsyms);    sprec = XCALLOC (short, nsyms);
1720    sassoc = XCALLOC (short, nsyms);    sassoc = XCALLOC (short, nsyms);
1721    
1722      /* The EOF token. */
1723      tags[0] = DOLLAR;
1724      user_toknums[0] = 0;
1725    
1726    max_user_token_number = 256;    max_user_token_number = 256;
1727    last_user_token_number = 256;    last_user_token_number = 256;
1728    
# Line 1740  packsymbols (void) Line 1775  packsymbols (void)
1775    
1776        if (bp->class == token_sym)        if (bp->class == token_sym)
1777          {          {
1778            if (!bp->user_token_number)            if (bp->user_token_number == 0)
1779              bp->user_token_number = ++last_user_token_number;              bp->user_token_number = ++last_user_token_number;
1780            if (bp->user_token_number > max_user_token_number)            if (bp->user_token_number > max_user_token_number)
1781              max_user_token_number = bp->user_token_number;              max_user_token_number = bp->user_token_number;
# Line 1752  packsymbols (void) Line 1787  packsymbols (void)
1787        sassoc[bp->value] = bp->assoc;        sassoc[bp->value] = bp->assoc;
1788      }      }
1789    
1790    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;  
     }  
1791    
1792    error_token_number = errtoken->value;    error_token_number = errtoken->value;
1793    
# Line 1800  packsymbols (void) Line 1816  packsymbols (void)
1816          }          }
1817    
1818        if (semantic_parser)        if (semantic_parser)
1819          for (i = ntokens; i < nsyms; i++)          {
1820            {            int i;
1821              /* don't make these for dummy nonterminals made by gensym.  */  
1822              if (*tags[i] != '@')            for (i = ntokens; i < nsyms; i++)
1823                 obstack_fgrow2 (&defines_obstack,              {
1824                                 "# define\tNT%s\t%d\n", tags[i], i);                /* don't make these for dummy nonterminals made by gensym.  */
1825            }                if (*tags[i] != '@')
1826                    obstack_fgrow2 (&defines_obstack,
1827                                    "# define\tNT%s\t%d\n", tags[i], i);
1828                }
1829  #if 0  #if 0
1830        /* `fdefines' is now a temporary file, so we need to copy its            /* `fdefines' is now a temporary file, so we need to copy its
1831           contents in `done', so we can't close it here.  */               contents in `done', so we can't close it here.  */
1832        fclose (fdefines);            fclose (fdefines);
1833        fdefines = NULL;            fdefines = NULL;
1834  #endif  #endif
1835            }
1836      }      }
1837  }  }
1838    

Legend:
Removed from v.1.72.2.9  
changed lines
  Added in v.1.72.2.10

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