/[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 by akim, Wed Aug 15 08:40:19 2001 UTC revision 1.73 by ra, Tue Aug 21 19:47:13 2001 UTC
# Line 34  Line 34 
34  #include "output.h"  #include "output.h"
35  #include "reader.h"  #include "reader.h"
36  #include "conflicts.h"  #include "conflicts.h"
37    #include "macrotab.h"
38    
39  /* Number of slots allocated (but not necessarily used yet) in `rline'  */  /* Number of slots allocated (but not necessarily used yet) in `rline'  */
40  static int rline_allocated;  static int rline_allocated;
# Line 156  get_type_name (int n, symbol_list * rule Line 157  get_type_name (int n, symbol_list * rule
157  `------------------------------------------------------------*/  `------------------------------------------------------------*/
158    
159  static inline void  static inline void
160  copy_string (FILE *fin, struct obstack *oout, int match)  copy_string2 (FILE *fin, struct obstack *oout, int match, int store)
161  {  {
162    int c;    int c;
163    
164    obstack_1grow (oout, match);    if (store)
165        obstack_1grow (oout, match);
166    
167    c = getc (fin);    c = getc (fin);
168    
# Line 192  copy_string (FILE *fin, struct obstack * Line 194  copy_string (FILE *fin, struct obstack *
194        c = getc (fin);        c = getc (fin);
195      }      }
196    
197    obstack_1grow (oout, c);    if (store)
198        obstack_1grow (oout, c);
199    }
200    
201    /* FIXME. */
202    
203    static inline void
204    copy_string (FILE *fin, struct obstack *oout, int match)
205    {
206      copy_string2 (fin, oout, match, 1);
207  }  }
208    
209    /* FIXME. */
210    
211    static inline void
212    copy_identifier (FILE *fin, struct obstack *oout)
213    {
214      int c;
215    
216      while (isalnum (c = getc (fin)) || c == '_')
217        obstack_1grow (oout, c);
218    
219      ungetc (c, fin);
220    }
221    
222  /*-----------------------------------------------------------------.  /*-----------------------------------------------------------------.
223  | Dump the wannabee comment from IN to OUT1 and OUT2 (which can be |  | Dump the wannabee comment from IN to OUT1 and OUT2 (which can be |
# Line 403  copy_definition (void) Line 426  copy_definition (void)
426    /* -1 while reading a character if prev char was %. */    /* -1 while reading a character if prev char was %. */
427    int after_percent;    int after_percent;
428    
429    #if 0
430    if (!no_lines_flag)    if (!no_lines_flag)
431      obstack_fgrow2 (&attrs_obstack, "#line %d %s\n",      obstack_fgrow2 (&attrs_obstack, "#line %d %s\n",
432                      lineno, quotearg_style (c_quoting_style, infile));                      lineno, quotearg_style (c_quoting_style, infile));
433    #endif
434    
435    after_percent = 0;    after_percent = 0;
436    
# Line 874  parse_thong_decl (void) Line 899  parse_thong_decl (void)
899    nsyms--;    nsyms--;
900  }  }
901    
902    /* FIXME. */
903    
904    static void
905    parse_macro_decl (void)
906    {
907      int ch = ungetc (skip_white_space (), finput);
908      char* macro_key;
909      char* macro_value;
910      struct obstack macro_obstack;
911    
912      obstack_init (&macro_obstack);
913    
914      /* Read key. */
915      if (!isalpha (ch) && ch != '_')
916        {
917          complain (_("invalid %s declaration"), "%define");
918          skip_to_char ('%');
919          return;
920        }
921      copy_identifier (finput, &macro_obstack);
922      macro_key = obstack_finish (&macro_obstack);
923      
924      /* Read value. */
925      ch = skip_white_space ();
926      if (ch != '"')
927        {
928          ungetc (ch, finput);
929          if (ch != EOF)
930            {
931              complain (_("invalid %s declaration"), "%define");
932              skip_to_char ('%');
933              return;
934            }
935          else
936            fatal (_("Premature EOF after %s"), "\"");
937        }
938      copy_string (finput, &macro_obstack, '"');
939      macro_value = obstack_finish (&macro_obstack);
940    
941      obstack_free (&macro_obstack, 0);
942    
943      /* Store the (key, value) pair in the environment. */
944      macro_insert (macro_key, macro_value);
945    }
946    
947  /*------------------------------------------.  /*------------------------------------------.
948  | Parse what comes after %header_extension. |  | Parse what comes after %header_extension. |
949  `------------------------------------------*/  `------------------------------------------*/
# Line 981  read_declarations (void) Line 1051  read_declarations (void)
1051                parse_source_extension_decl ();                parse_source_extension_decl ();
1052                break;                break;
1053    
1054                case tok_define:
1055                  parse_macro_decl ();
1056                  break;
1057    
1058              case tok_noop:              case tok_noop:
1059                break;                break;
1060    
# Line 1564  readgram (void) Line 1638  readgram (void)
1638    if (nrules == 0)    if (nrules == 0)
1639      fatal (_("no rules in the input grammar"));      fatal (_("no rules in the input grammar"));
1640    
1641    #if 0 /* This code is in the skeleton now.  */
1642    /* JF put out same default YYSTYPE as YACC does */    /* JF put out same default YYSTYPE as YACC does */
1643    if (typed == 0    if (typed == 0
1644        && !value_components_used)        && !value_components_used)
# Line 1579  readgram (void) Line 1654  readgram (void)
1654  #  define YYSTYPE int\n\  #  define YYSTYPE int\n\
1655  # endif\n");  # endif\n");
1656      }      }
1657    #endif
1658    
1659    /* Report any undefined symbols and consider them nonterminals.  */    /* Report any undefined symbols and consider them nonterminals.  */
1660    
# Line 1641  output_token_defines (struct obstack *oo Line 1717  output_token_defines (struct obstack *oo
1717          obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value);          obstack_fgrow2 (oout, "# define\tT%s\t%d\n", symbol, bp->value);
1718      }      }
1719    
1720    obstack_1grow (oout, '\n');    /* obstack_1grow (oout, '\n'); */
1721  }  }
1722    
1723    
# Line 1763  packsymbols (void) Line 1839  packsymbols (void)
1839    
1840    error_token_number = errtoken->value;    error_token_number = errtoken->value;
1841    
1842    if (!no_parser_flag)    output_token_defines (&output_obstack);
1843      output_token_defines (&table_obstack);    obstack_1grow (&output_obstack, 0);
1844      macro_insert ("tokendef", obstack_finish (&output_obstack));
1845    
1846      /* if (!no_parser_flag)
1847         output_token_defines (&table_obstack); */
1848    
1849    if (startval->class == unknown_sym)    if (startval->class == unknown_sym)
1850      fatal (_("the start symbol %s is undefined"), startval->tag);      fatal (_("the start symbol %s is undefined"), startval->tag);
# Line 1913  reader (void) Line 1993  reader (void)
1993    
1994    /* Initialize the symbol table.  */    /* Initialize the symbol table.  */
1995    tabinit ();    tabinit ();
1996    
1997    /* Construct the error token */    /* Construct the error token */
1998    errtoken = getsym ("error");    errtoken = getsym ("error");
1999    errtoken->class = token_sym;    errtoken->class = token_sym;
2000    errtoken->user_token_number = 256;    /* Value specified by POSIX.  */    errtoken->user_token_number = 256;    /* Value specified by POSIX.  */
2001    
2002    /* Construct a token that represents all undefined literal tokens.    /* Construct a token that represents all undefined literal tokens.
2003       It is always token number 2.  */       It is always token number 2.  */
2004    undeftoken = getsym ("$undefined.");    undeftoken = getsym ("$undefined.");
# Line 1926  reader (void) Line 2008  reader (void)
2008    /* Read the declaration section.  Copy %{ ... %} groups to    /* Read the declaration section.  Copy %{ ... %} groups to
2009       TABLE_OBSTACK and FDEFINES file.  Also notice any %token, %left,       TABLE_OBSTACK and FDEFINES file.  Also notice any %token, %left,
2010       etc. found there.  */       etc. found there.  */
2011    obstack_1grow (&table_obstack, '\n');    /* obstack_1grow (&table_obstack, '\n'); */
   obstack_fgrow3 (&table_obstack, "\  
 /* %s, made from %s\n\  
    by GNU bison %s.  */\n\  
 \n",  
                   no_parser_flag ? "Bison-generated parse tables" : "A Bison parser",  
                   infile, VERSION);  
2012    
   obstack_sgrow (&table_obstack,  
                        "#define YYBISON 1  /* Identify Bison output.  */\n\n");  
2013    read_declarations ();    read_declarations ();
2014    /* Start writing the guard and action files, if they are needed.  */    /* Start writing the guard and action files, if they are needed.  */
2015    output_headers ();    /* output_headers (); */
2016    /* Read in the grammar, build grammar in list form.  Write out    /* Read in the grammar, build grammar in list form.  Write out
2017       guards and actions.  */       guards and actions.  */
2018    readgram ();    readgram ();
2019    /* Now we know whether we need the line-number stack.  If we do,    /* Now we know whether we need the line-number stack.  If we do,
2020       write its type into the .tab.h file.  */       write its type into the .tab.h file.  */
2021    if (defines_flag)    /* if (defines_flag)
2022      reader_output_yylsp (&defines_obstack);       reader_output_yylsp (&defines_obstack); */
2023    /* Write closing delimiters for actions and guards.  */    /* Write closing delimiters for actions and guards.  */
2024    output_trailers ();    /* output_trailers (); */
2025    if (locations_flag)    /* if (locations_flag)
2026      obstack_sgrow (&table_obstack, "#define YYLSP_NEEDED 1\n\n");       obstack_sgrow (&table_obstack, "#define YYLSP_NEEDED 1\n\n"); */
2027    /* Assign the symbols their symbol numbers.  Write #defines for the    /* Assign the symbols their symbol numbers.  Write #defines for the
2028       token symbols into FDEFINES if requested.  */       token symbols into FDEFINES if requested.  */
2029    packsymbols ();    packsymbols ();
# Line 1959  reader (void) Line 2033  reader (void)
2033       referred to by symbol number.  */       referred to by symbol number.  */
2034    free_symtab ();    free_symtab ();
2035  }  }
   
   
 /*------------------------------------------------------------------.  
 | Define YYLTYPE.  Cannot be in the skeleton since we might have to |  
 | output it in the headers if --defines is used.                    |  
 `------------------------------------------------------------------*/  
   
 void  
 reader_output_yylsp (struct obstack *oout)  
 {  
   if (locations_flag)  
     obstack_sgrow (oout, "\  
 \n\  
 #ifndef YYLTYPE\n\  
 typedef struct yyltype\n\  
 {\n\  
   int first_line;\n\  
   int first_column;\n\  
 \n\  
   int last_line;\n\  
   int last_column;\n\  
 } yyltype;\n\  
 \n\  
 # define YYLTYPE yyltype\n\  
 #endif\n\  
 \n");  
 }  

Legend:
Removed from v.1.72  
changed lines
  Added in v.1.73

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