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

Diff of /bison/src/output.c

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

revision 1.39 by akim, Mon Aug 13 14:51:15 2001 UTC revision 1.40 by ra, Tue Aug 21 19:47:13 2001 UTC
# Line 103  Line 103 
103  #include "lalr.h"  #include "lalr.h"
104  #include "reader.h"  #include "reader.h"
105  #include "conflicts.h"  #include "conflicts.h"
106    #include "macrotab.h"
107    
108  extern void berror PARAMS((const char *));  extern void berror PARAMS((const char *));
109    
   
   
110  static int nvectors;  static int nvectors;
111  static int nentries;  static int nentries;
112  static short **froms;  static short **froms;
# Line 124  static short *check; Line 123  static short *check;
123  static int lowzero;  static int lowzero;
124  static int high;  static int high;
125    
126    struct obstack macro_obstack;
127    struct obstack output_obstack;
128    
129    /* FIXME. */
130    
131  static inline void  static inline void
132  output_short_or_char_table (struct obstack *oout,  output_table_data (struct obstack* oout,
133                              const char *comment,                     short* table,
134                              const char *type,                     short first,
135                              const char *table_name,                     short begin,
136                              short *short_table,                     short end)
137                              short first_value,  {
138                              short begin, short end)    int i;
139  {    int j = 1;
140    int i, j;    
141      obstack_fgrow1 (oout, "%6d", first);
142    if (comment)    for (i = begin; i < end; ++i)
     obstack_fgrow1 (oout, "/* %s. */\n", comment);  
   
   obstack_fgrow3 (oout, "static const %s %s[] =\n{\n  %6d",  
                   type, table_name, first_value);  
   
   j = 1;  
   for (i = begin; i < end; i++)  
143      {      {
144        obstack_1grow (oout, ',');        obstack_1grow (oout, ',');
   
145        if (j >= 10)        if (j >= 10)
146          {          {
147            obstack_sgrow (oout, "\n  ");            obstack_sgrow (oout, "\n  ");
148            j = 1;            j = 1;
149          }          }
150        else        else
151          {          ++j;
152            j++;        obstack_fgrow1 (oout, "%6d", table[i]);
         }  
   
       obstack_fgrow1 (oout, "%6d", short_table[i]);  
153      }      }
154      obstack_1grow (oout, 0);
   obstack_sgrow (oout, "\n};\n");  
 }  
   
   
 static inline void  
 output_short_table (struct obstack *oout,  
                     const char *comment,  
                     const char *table_name,  
                     short *short_table,  
                     short first_value,  
                     short begin, short end)  
 {  
   output_short_or_char_table (oout, comment, "short", table_name, short_table,  
                               first_value, begin, end);  
155  }  }
156    
157    
 /*--------------------------------------------------------------.  
 | output_headers -- Output constant strings to the beginning of |  
 | certain files.                                                |  
 `--------------------------------------------------------------*/  
   
 /* Don't put the `%s' insides quotes, since it quotearg puts them. */  
   
 #define GUARDSTR        \  
 "\n\  
 #include %s\n\  
 extern int yyerror;\n\  
 extern int yycost;\n\  
 extern char * yymsg;\n\  
 extern YYSTYPE yyval;\n\  
 \n\  
 yyguard(n, yyvsp, yylsp)\n\  
 register int n;\n\  
 register YYSTYPE *yyvsp;\n\  
 register YYLTYPE *yylsp;\n\  
 {\n\  
   yyerror = 0;\n\  
   yycost = 0;\n\  
   yymsg = 0;\n\  
   switch (n)\n\  
     {"  
   
 #define ACTSTR          \  
 "\n\  
 #include %s\n\  
 extern YYSTYPE yyval;\n\  
 extern int yychar;\n\  
 \n\  
 yyaction(n, yyvsp, yylsp)\n\  
 register int n;\n\  
 register YYSTYPE *yyvsp;\n\  
 register YYLTYPE *yylsp;\n\  
 {\n\  
   switch (n)\n\  
     {"  
   
 #define ACTSTR_SIMPLE   "\n  switch (yyn) {\n"  
   
 void  
 output_headers (void)  
 {  
   char *attrsfile_quoted = 0;  
   
   if (semantic_parser)  
     {  
       /* FIXME: This is *buggy*.  ATTRSFILE is not computed yet, since  
          we are waiting for the full input file to have been read to  
          be sure of the output file name.  So basically, here, a SEGV  
          is guaranteed.  OTOH, currently semantic parsers are not  
          supported.  */  
       attrsfile_quoted = quotearg_style (c_quoting_style, attrsfile);  
       obstack_fgrow1 (&guard_obstack, GUARDSTR, attrsfile_quoted);  
     }  
   
   if (no_parser_flag)  
     return;  
   
   if (semantic_parser)  
     obstack_fgrow1 (&action_obstack, ACTSTR, attrsfile_quoted);  
   else  
     obstack_sgrow (&action_obstack, ACTSTR_SIMPLE);  
   
   /* Rename certain symbols if -p was specified.  */  
   if (spec_name_prefix)  
     {  
       obstack_fgrow1 (&table_obstack,  
                       "#define yyparse %sparse\n", spec_name_prefix);  
       obstack_fgrow1 (&table_obstack,  
                       "#define yylex %slex\n", spec_name_prefix);  
       obstack_fgrow1 (&table_obstack,  
                       "#define yyerror %serror\n", spec_name_prefix);  
       obstack_fgrow1 (&table_obstack,  
                       "#define yylval %slval\n", spec_name_prefix);  
       obstack_fgrow1 (&table_obstack,  
                       "#define yychar %schar\n", spec_name_prefix);  
       obstack_fgrow1 (&table_obstack,  
                       "#define yydebug %sdebug\n", spec_name_prefix);  
       obstack_fgrow1 (&table_obstack,  
                       "#define yynerrs %snerrs\n", spec_name_prefix);  
     }  
 }  
   
   
 /*-------------------------------------------------------.  
 | Output constant strings to the ends of certain files.  |  
 `-------------------------------------------------------*/  
   
 void  
 output_trailers (void)  
 {  
   if (semantic_parser)  
     obstack_sgrow (&guard_obstack, "\n    }\n}\n");  
   
   obstack_1grow (&action_obstack, '\n');  
   
   if (no_parser_flag)  
     return;  
   
   if (semantic_parser)  
     obstack_sgrow (&action_obstack, "    }\n");  
   
   obstack_sgrow (&action_obstack, "}\n");  
 }  
   
   
   
158  static void  static void
159  output_token_translations (void)  output_token_translations (void)
160  {  {
161    obstack_sgrow (&table_obstack, "\    output_table_data (&output_obstack, token_translations,
162  \n\                       0, 1, max_user_token_number + 1);
163  /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */\n");    macro_insert ("translate", obstack_finish (&output_obstack));
   
   if (translations)  
     {  
       obstack_fgrow2 (&table_obstack,  
       "#define YYTRANSLATE(x) ((unsigned)(x) <= %d ? yytranslate[x] : %d)\  
 \n\  
 \n",  
                max_user_token_number, nsyms);  
   
       output_short_or_char_table (&table_obstack,  
              "YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX",  
                     ntokens < 127 ? "char" : "short",  
                     "yytranslate", token_translations,  
                     0, 1, max_user_token_number + 1);  
     }  
   else  
     {  
       obstack_sgrow (&table_obstack,  
                            "\n#define YYTRANSLATE(x) (x)\n");  
     }  
164  }  }
165    
166    
167  static void  static void
168  output_gram (void)  output_gram (void)
169  {  {
170    /* With the ordinary parser,    output_table_data (&output_obstack, rrhs,
171       yyprhs and yyrhs are needed only for yydebug. */                       0, 1, nrules + 1);
172    /* With the no_parser option, all tables are generated */    macro_insert ("prhs", obstack_finish (&output_obstack));
173    if (!semantic_parser && !no_parser_flag)    
     obstack_sgrow (&table_obstack, "\n#if YYDEBUG != 0\n");  
   
   output_short_table (&table_obstack, NULL, "yyprhs", rrhs,  
                       0, 1, nrules + 1);  
   
174    {    {
175      size_t yyrhs_size = 1;      size_t yyrhs_size = 1;
176      short *yyrhs, *sp;      short *yyrhs, *sp;
# Line 341  output_gram (void) Line 183  output_gram (void)
183      for (sp = ritem + 1, i = 1; *sp; ++sp, ++i)      for (sp = ritem + 1, i = 1; *sp; ++sp, ++i)
184        yyrhs[i] = *sp > 0 ? *sp : 0;        yyrhs[i] = *sp > 0 ? *sp : 0;
185    
186      output_short_table (&table_obstack, NULL, "yyrhs", yyrhs,      output_table_data (&output_obstack, yyrhs,
187                          ritem[0], 1, yyrhs_size);                         ritem[0], 1, yyrhs_size);
188        macro_insert ("rhs", obstack_finish (&output_obstack));
189    
190      XFREE (yyrhs);      XFREE (yyrhs);
191    }    }
192    
193    if (!semantic_parser && !no_parser_flag)    /* if (!semantic_parser && !no_parser_flag)
194      obstack_sgrow (&table_obstack, "\n#endif\n");       obstack_sgrow (&table_obstack, "\n#endif\n"); */
195  }  }
196    
197    
198  static void  static void
199  output_stos (void)  output_stos (void)
200  {  {
201    output_short_table (&table_obstack, NULL, "yystos", accessing_symbol,    output_table_data (&output_obstack, accessing_symbol,
202                        0, 1, nstates);                       0, 1, nstates);
203      macro_insert ("stos", obstack_finish (&output_obstack));
204  }  }
205    
206    
# Line 366  output_rule_data (void) Line 211  output_rule_data (void)
211    int j;    int j;
212    short *short_tab = NULL;    short *short_tab = NULL;
213    
214    obstack_sgrow (&table_obstack, "\n\    output_table_data (&output_obstack, rline,
215  #if YYDEBUG != 0\n");                       0, 1, nrules + 1);
216      macro_insert ("rline", obstack_finish (&output_obstack));
   output_short_table (&table_obstack,  
            "YYRLINE[YYN] -- source line where rule number YYN was defined",  
                       "yyrline", rline,  
                       0, 1, nrules + 1);  
   
   obstack_sgrow (&table_obstack, "#endif\n\n");  
   
   if (token_table_flag || no_parser_flag)  
     {  
       obstack_fgrow1 (&table_obstack, "#define YYNTOKENS %d\n", ntokens);  
       obstack_fgrow1 (&table_obstack, "#define YYNNTS %d\n", nvars);  
       obstack_fgrow1 (&table_obstack, "#define YYNRULES %d\n", nrules);  
       obstack_fgrow1 (&table_obstack, "#define YYNSTATES %d\n", nstates);  
       obstack_fgrow1 (&table_obstack, "#define YYMAXUTOK %d\n\n",  
                       max_user_token_number);  
     }  
   
   /* Output the table of symbol names.  */  
   if (!token_table_flag && !no_parser_flag)  
     obstack_sgrow (&table_obstack,  
                          "\n#if YYDEBUG != 0 || defined YYERROR_VERBOSE\n\n");  
   obstack_sgrow (&table_obstack, "\  
 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */\n");  
   obstack_sgrow (&table_obstack,  
            "static const char *const yytname[] =\n{\n  ");  
217    
218    j = 0;    j = 0;
219    for (i = 0; i < nsyms; i++)    for (i = 0; i < nsyms; i++)
# Line 416  output_rule_data (void) Line 236  output_rule_data (void)
236    
237        if (j + strsize > 75)        if (j + strsize > 75)
238          {          {
239            obstack_sgrow (&table_obstack, "\n  ");            obstack_sgrow (&output_obstack, "\n  ");
240            j = 2;            j = 2;
241          }          }
242    
243        obstack_1grow (&table_obstack, '\"');        obstack_1grow (&output_obstack, '\"');
244        for (p = tags[i]; p && *p; p++)        for (p = tags[i]; p && *p; p++)
245          {          {
246            if (*p == '"' || *p == '\\')            if (*p == '"' || *p == '\\')
247              obstack_fgrow1 (&table_obstack, "\\%c", *p);              obstack_fgrow1 (&output_obstack, "\\%c", *p);
248            else if (*p == '\n')            else if (*p == '\n')
249              obstack_sgrow (&table_obstack, "\\n");              obstack_sgrow (&output_obstack, "\\n");
250            else if (*p == '\t')            else if (*p == '\t')
251              obstack_sgrow (&table_obstack, "\\t");              obstack_sgrow (&output_obstack, "\\t");
252            else if (*p == '\b')            else if (*p == '\b')
253              obstack_sgrow (&table_obstack, "\\b");              obstack_sgrow (&output_obstack, "\\b");
254            else if (*p < 040 || *p >= 0177)            else if (*p < 040 || *p >= 0177)
255              obstack_fgrow1 (&table_obstack, "\\%03o", *p);              obstack_fgrow1 (&output_obstack, "\\%03o", *p);
256            else            else
257              obstack_1grow (&table_obstack, *p);              obstack_1grow (&output_obstack, *p);
258          }          }
259    
260        obstack_sgrow (&table_obstack, "\", ");        obstack_sgrow (&output_obstack, "\", ");
261        j += strsize;        j += strsize;
262      }      }
263    /* add a NULL entry to list of tokens */    /* add a NULL entry to list of tokens */
264    obstack_sgrow (&table_obstack, "NULL\n};\n");    obstack_sgrow (&output_obstack, "NULL");
265    
266    if (!token_table_flag && !no_parser_flag)    /* Finish table and store. */
267      obstack_sgrow (&table_obstack, "#endif\n\n");    obstack_1grow (&output_obstack, 0);
268      macro_insert ("tname", obstack_finish (&output_obstack));
269    
270    /* Output YYTOKNUM. */    /* Output YYTOKNUM. */
271    if (token_table_flag)    output_table_data (&output_obstack, user_toknums,
272      {                       0, 1, ntokens + 1);
273        output_short_table (&table_obstack,    macro_insert ("toknum", obstack_finish (&output_obstack));
                   "YYTOKNUM[YYLEX] -- Index in YYTNAME corresponding to YYLEX",  
                           "yytoknum", user_toknums,  
                           0, 1, ntokens + 1);  
     }  
274    
275    /* Output YYR1. */    /* Output YYR1. */
276    output_short_table (&table_obstack,    output_table_data (&output_obstack, rlhs,
277                "YYR1[YYN] -- Symbol number of symbol that rule YYN derives",                       0, 1, nrules + 1);
278                        "yyr1", rlhs,    macro_insert ("r1", obstack_finish (&output_obstack));
                       0, 1, nrules + 1);  
279    XFREE (rlhs + 1);    XFREE (rlhs + 1);
280    
   obstack_1grow (&table_obstack, '\n');  
   
281    /* Output YYR2. */    /* Output YYR2. */
282    short_tab = XMALLOC (short, nrules + 1);    short_tab = XMALLOC (short, nrules + 1);
283    for (i = 1; i < nrules; i++)    for (i = 1; i < nrules; i++)
284      short_tab[i] = rrhs[i + 1] - rrhs[i] - 1;      short_tab[i] = rrhs[i + 1] - rrhs[i] - 1;
285    short_tab[nrules] = nitems - rrhs[nrules] - 1;    short_tab[nrules] = nitems - rrhs[nrules] - 1;
286    output_short_table (&table_obstack,    output_table_data (&output_obstack, short_tab,
287          "YYR2[YYN] -- Number of symbols composing right hand side of rule YYN",                       0, 1, nrules + 1);
288                        "yyr2", short_tab,    macro_insert ("r2", obstack_finish (&output_obstack));
                       0, 1, nrules + 1);  
   obstack_1grow (&table_obstack, '\n');  
   
289    XFREE (short_tab);    XFREE (short_tab);
290    
291    XFREE (rrhs + 1);    XFREE (rrhs + 1);
292  }  }
293    
   
 static void  
 output_defines (void)  
 {  
   obstack_fgrow1 (&table_obstack, "\n\n#define\tYYFINAL\t\t%d\n", final_state);  
   obstack_fgrow1 (&table_obstack, "#define\tYYFLAG\t\t%d\n", MINSHORT);  
   obstack_fgrow1 (&table_obstack, "#define\tYYNTBASE\t%d\n", ntokens);  
 }  
   
   
294  /*------------------------------------------------------------------.  /*------------------------------------------------------------------.
295  | Decide what to do for each type of token if seen as the lookahead |  | Decide what to do for each type of token if seen as the lookahead |
296  | token in specified state.  The value returned is used as the      |  | token in specified state.  The value returned is used as the      |
# Line 730  token_actions (void) Line 531  token_actions (void)
531        yydefact[i] = action_row (i);        yydefact[i] = action_row (i);
532        save_row (i);        save_row (i);
533      }      }
   XFREE (actrow);  
534    
535    output_short_table (&table_obstack,    output_table_data (&output_obstack, yydefact,
536    "YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE\n\                       yydefact[0], 1, nstates);
537     doesn't specify something else to do.  Zero means the default is an\n\    macro_insert ("defact", obstack_finish (&output_obstack));
538     error",    
539                        "yydefact", yydefact,    XFREE (actrow);
                       yydefact[0], 1, nstates);  
   obstack_1grow (&table_obstack, '\n');  
540    XFREE (yydefact);    XFREE (yydefact);
541  }  }
542    
# Line 865  static void Line 663  static void
663  goto_actions (void)  goto_actions (void)
664  {  {
665    int i;    int i;
   
666    short *yydefgoto = XMALLOC (short, nsyms - ntokens);    short *yydefgoto = XMALLOC (short, nsyms - ntokens);
   state_count = XCALLOC (short, nstates);  
667    
668      state_count = XCALLOC (short, nstates);
669    for (i = ntokens; i < nsyms; ++i)    for (i = ntokens; i < nsyms; ++i)
670      {      {
671        int default_state = default_goto (i);        int default_state = default_goto (i);
# Line 876  goto_actions (void) Line 673  goto_actions (void)
673        yydefgoto[i - ntokens] = default_state;        yydefgoto[i - ntokens] = default_state;
674      }      }
675    
676    output_short_table (&table_obstack, NULL, "yydefgoto", yydefgoto,    output_table_data (&output_obstack, yydefgoto,
677                        yydefgoto[0], 1, nsyms - ntokens);                       yydefgoto[0], 1, nsyms - ntokens);
678      macro_insert ("defgoto", obstack_finish (&output_obstack));
679    
680    XFREE (state_count);    XFREE (state_count);
681    XFREE (yydefgoto);    XFREE (yydefgoto);
# Line 1079  pack_table (void) Line 877  pack_table (void)
877  static void  static void
878  output_base (void)  output_base (void)
879  {  {
880    output_short_table (&table_obstack, NULL, "yypact", base,    /* Output pact. */
881                        base[0], 1, nstates);    output_table_data (&output_obstack, base,
882                         base[0], 1, nstates);
883    obstack_1grow (&table_obstack, '\n');    macro_insert ("pact", obstack_finish (&output_obstack));
884    
885    output_short_table (&table_obstack, NULL, "yypgoto", base,    /* Output pgoto. */
886                        base[nstates], nstates + 1, nvectors);    output_table_data (&output_obstack, base,
887                         base[nstates], nstates + 1, nvectors);
888      macro_insert ("pgoto", obstack_finish (&output_obstack));
889    
890    XFREE (base);    XFREE (base);
891  }  }
# Line 1094  output_base (void) Line 894  output_base (void)
894  static void  static void
895  output_table (void)  output_table (void)
896  {  {
897    obstack_fgrow1 (&table_obstack, "\n\n#define\tYYLAST\t\t%d\n\n\n", high);    output_table_data (&output_obstack, table,
898    output_short_table (&table_obstack, NULL, "yytable", table,                       table[0], 1, high + 1);
899                        table[0], 1, high + 1);    macro_insert ("table", obstack_finish (&output_obstack));
900    XFREE (table);    XFREE (table);
901  }  }
902    
# Line 1104  output_table (void) Line 904  output_table (void)
904  static void  static void
905  output_check (void)  output_check (void)
906  {  {
907    output_short_table (&table_obstack, NULL, "yycheck", check,    output_table_data (&output_obstack, check,
908                        check[0], 1, high + 1);                       check[0], 1, high + 1);
909      macro_insert ("check", obstack_finish (&output_obstack));
910    XFREE (check);    XFREE (check);
911  }  }
912    
# Line 1137  output_actions (void) Line 938  output_actions (void)
938    
939    sort_actions ();    sort_actions ();
940    pack_table ();    pack_table ();
941    obstack_1grow (&table_obstack, '\n');    /* FIXME: See if this is useful. */
942      /* obstack_1grow (&table_obstack, '\n'); */
943    output_base ();    output_base ();
944    output_table ();    output_table ();
945    obstack_1grow (&table_obstack, '\n');    /* FIXME: See if this is useful. */
946      /* obstack_1grow (&table_obstack, '\n'); */
947    output_check ();    output_check ();
948  }  }
949    
# Line 1156  output_parser (void) Line 959  output_parser (void)
959    size_t line;    size_t line;
960    int actions_dumped = 0;    int actions_dumped = 0;
961    
   if (pure_parser)  
     obstack_sgrow (&table_obstack, "#define YYPURE 1\n\n");  
   
962    /* Loop over lines in the standard parser file.  */    /* Loop over lines in the standard parser file.  */
963    if (!skeleton)    if (!skeleton)
964      {      {
# Line 1169  output_parser (void) Line 969  output_parser (void)
969      }      }
970    fskel = xfopen (skeleton, "r");    fskel = xfopen (skeleton, "r");
971    
972    /* Set LINE to 2, not 1: `#line LINENUM' -- Here LINENUM is a    /* New output code. */
973       decimal integer constant.  This specifies that the line number of    line = 1;
974       the *following* line of input, in its original source file, was    c = getc (fskel);
975       LINENUM.  */    while (c != EOF)
   line = 2;  
   
   while (1)  
976      {      {
977        enum line_type_e        if (c != '%')
978          {          {
979            regular_line,            if (c == '\n')
980            sync_line,    /* #line. */              ++line;
981            actions_line  /* %% actions. */            obstack_1grow (&table_obstack, c);
982          };            c = getc (fskel);
       enum line_type_e line_type = regular_line;  
   
       c = getc (fskel);  
   
       /* Is this line special? */  
       if (c == '#')  
         {  
           /* See if it's a `#line' line. */  
           if ((c = getc (fskel)) == 'l')  
             if ((c = getc (fskel)) == 'i')  
               if ((c = getc (fskel)) == 'n')  
                 if ((c = getc (fskel)) == 'e')  
                   line_type = sync_line;  
                 else  
                   obstack_sgrow (&table_obstack, "#lin");  
               else  
                 obstack_sgrow (&table_obstack, "#li");  
             else  
               obstack_sgrow (&table_obstack, "#l");  
           else  
             obstack_sgrow (&table_obstack, "#");  
983          }          }
984        else if (c == '%')        else if ((c = getc (fskel)) == '%')
985          {          {
986            /* See if it's a `%% actions' line. */            /* Read the macro. */
987            if ((c = getc (fskel)) == '%')            char* macro_key = 0;
988              if ((c = getc (fskel)) == ' ')            char* macro_value = 0;
989                if ((c = getc (fskel)) == 'a')            while (isalnum (c = getc (fskel)) || c == '_')
990                  if ((c = getc (fskel)) == 'c')              obstack_1grow (&macro_obstack, c);
991                    if ((c = getc (fskel)) == 't')            obstack_1grow (&macro_obstack, 0);
992                      if ((c = getc (fskel)) == 'i')  
993                        if ((c = getc (fskel)) == 'o')            /* Output the right value, or see if it's something special. */
994                          if ((c = getc (fskel)) == 'n')            macro_key = obstack_finish (&macro_obstack);
995                            if ((c = getc (fskel)) == 's')            macro_value = macro_find (macro_key);
996                              line_type = actions_line;            if (macro_value)
997                            else              obstack_sgrow (&table_obstack, macro_value);
998                              obstack_sgrow (&table_obstack, "%% action");            else if (!strcmp (macro_key, "line"))
999                          else              obstack_fgrow1 (&table_obstack, "%d", line + 1);
1000                            obstack_sgrow (&table_obstack, "%% actio");            else if (!strcmp (macro_key, "action"))
1001                        else              {
1002                          obstack_sgrow (&table_obstack, "%% acti");                size_t size = obstack_object_size (&action_obstack);
1003                      else                obstack_grow (&table_obstack,
1004                        obstack_sgrow (&table_obstack, "%% act");                              obstack_finish (&action_obstack), size);
1005                    else              }
                     obstack_sgrow (&table_obstack, "%% ac");  
                 else  
                   obstack_sgrow (&table_obstack, "%% a");  
               else  
                 obstack_sgrow (&table_obstack, "%% ");  
             else  
               obstack_sgrow (&table_obstack, "%%");  
1006            else            else
1007              obstack_sgrow (&table_obstack, "%");              {
1008          }                obstack_sgrow (&table_obstack, "%%");
1009                  obstack_sgrow (&table_obstack, macro_key);
1010        switch (line_type)              }
         {  
         case sync_line:  
           if (!no_lines_flag)  
             obstack_fgrow2 (&table_obstack, "#line %d %s\n",  
                             line, quotearg_style (c_quoting_style, skeleton));  
   
           /* Skip the end of line. */  
           for (; c != '\n' && c != EOF; c = getc (fskel))  
             /* nothing */;  
           break;  
   
         case actions_line:  
           {  
             size_t size = obstack_object_size (&action_obstack);  
   
             actions_dumped++;  
             assert (actions_dumped == 1);  
             obstack_grow (&table_obstack,  
                           obstack_finish (&action_obstack),  
                           size);  
           }  
   
           /* Skip the end of line. */  
           for (; c != '\n' && c != EOF; c = getc (fskel))  
             /* nothing */;  
           break;  
   
         case regular_line:  
           for (; c != '\n' && c != EOF; c = getc (fskel))  
             obstack_1grow (&table_obstack, c);  
1011          }          }
   
       if (c == EOF)  
         break;  
       obstack_1grow (&table_obstack, c);  
       line++;  
1012      }      }
1013    assert (actions_dumped == 1);  
1014      /* End. */
1015    xfclose (fskel);    xfclose (fskel);
1016  }  }
1017    
# Line 1285  output_program (void) Line 1020  output_program (void)
1020  {  {
1021    int c;    int c;
1022    
   if (!no_lines_flag)  
     obstack_fgrow2 (&table_obstack, "#line %d %s\n",  
                     lineno, quotearg_style (c_quoting_style, infile));  
   
1023    while ((c = getc (finput)) != EOF)    while ((c = getc (finput)) != EOF)
1024      obstack_1grow (&table_obstack, c);      obstack_1grow (&table_obstack, c);
1025  }  }
# Line 1308  free_itemsets (void) Line 1039  free_itemsets (void)
1039      }      }
1040  }  }
1041    
1042    /* FIXME. */
1043    
1044    #define MACRO_INSERT_INT(Key, Value)                    \
1045    {                                                       \
1046      obstack_fgrow1 (&macro_obstack, "%d", Value);         \
1047      obstack_1grow (&macro_obstack, 0);                    \
1048      macro_insert (Key, obstack_finish (&macro_obstack));  \
1049    }
1050    
1051    #define MACRO_INSERT_STRING(Key, Value)                 \
1052    {                                                       \
1053      obstack_sgrow (&macro_obstack, Value);                \
1054      obstack_1grow (&macro_obstack, 0);                    \
1055      macro_insert (Key, obstack_finish (&macro_obstack));  \
1056    }
1057    
1058    #define MACRO_INSERT_PREFIX(Key, Value)                                 \
1059    {                                                                       \
1060      obstack_fgrow2 (&macro_obstack, "%s%s", spec_name_prefix, Value);     \
1061      obstack_1grow (&macro_obstack, 0);                                    \
1062      macro_insert (Key, obstack_finish (&macro_obstack));                  \
1063    }
1064    
1065    static void
1066    prepare (void)
1067    {
1068      MACRO_INSERT_INT ("last", high);
1069      MACRO_INSERT_INT ("flag", MINSHORT);
1070      MACRO_INSERT_INT ("pure", pure_parser);
1071      MACRO_INSERT_INT ("nsym", nsyms);
1072      MACRO_INSERT_INT ("debug", debug_flag);
1073      MACRO_INSERT_INT ("final", final_state);
1074      MACRO_INSERT_INT ("maxtok", max_user_token_number);
1075      MACRO_INSERT_INT ("ntbase", ntokens);
1076      MACRO_INSERT_INT ("verbose", 0);
1077    
1078      MACRO_INSERT_STRING ("filename", infile);
1079    
1080      MACRO_INSERT_INT ("nnts", nvars);
1081      MACRO_INSERT_INT ("nrules", nrules);
1082      MACRO_INSERT_INT ("nstates", nstates);
1083      MACRO_INSERT_INT ("ntokens", ntokens);
1084    
1085      if (spec_name_prefix)
1086        {
1087          MACRO_INSERT_PREFIX ("yylex", "lex");
1088          MACRO_INSERT_PREFIX ("yychar", "char");
1089          MACRO_INSERT_PREFIX ("yylval", "lval");
1090          MACRO_INSERT_PREFIX ("yydebug", "debug");
1091          MACRO_INSERT_PREFIX ("yyerror", "error");
1092          MACRO_INSERT_PREFIX ("yynerrs", "nerrs");
1093          MACRO_INSERT_PREFIX ("yyparse", "parse");
1094        }
1095    }
1096    
1097  /*----------------------------------------------------------.  /*----------------------------------------------------------.
1098  | Output the parsing tables and the parser code to ftable.  |  | Output the parsing tables and the parser code to ftable.  |
# Line 1316  free_itemsets (void) Line 1101  free_itemsets (void)
1101  void  void
1102  output (void)  output (void)
1103  {  {
1104    /* output_token_defines(ftable);      / * JF put out token defines FIRST */    obstack_init (&macro_obstack);
1105      obstack_init (&output_obstack);
1106    
1107    #if 0
1108    /* If using a simple parser the definition of YYSTYPE are put into    /* If using a simple parser the definition of YYSTYPE are put into
1109       TABLE_OBSTACK.  */       TABLE_OBSTACK.  */
1110    if (!semantic_parser)    if (!semantic_parser)
# Line 1325  output (void) Line 1112  output (void)
1112        size_t size = obstack_object_size (&attrs_obstack);        size_t size = obstack_object_size (&attrs_obstack);
1113        obstack_grow (&table_obstack, obstack_finish (&attrs_obstack), size);        obstack_grow (&table_obstack, obstack_finish (&attrs_obstack), size);
1114      }      }
1115    reader_output_yylsp (&table_obstack);  #endif
   if (debug_flag)  
     obstack_sgrow (&table_obstack, "\  
 #ifndef YYDEBUG\n\  
 # define YYDEBUG 1\n\  
 #endif\n\  
 \n");  
   
   if (semantic_parser)  
     obstack_fgrow1 (&table_obstack, "#include %s\n",  
                     quotearg_style (c_quoting_style, attrsfile));  
   
   if (!no_parser_flag)  
     obstack_sgrow (&table_obstack, "#include <stdio.h>\n\n");  
   
   /* Make "const" do nothing if not in ANSI C.  */  
   obstack_sgrow (&table_obstack, "\  
 #ifndef __cplusplus\n\  
 # ifndef __STDC__\n\  
 #  define const\n\  
 # endif\n\  
 #endif\n\  
 \n");  
1116    
1117      /* reader_output_yylsp (&table_obstack); */
1118    free_itemsets ();    free_itemsets ();
1119    output_defines ();  
1120    output_token_translations ();    output_token_translations ();
 /*   if (semantic_parser) */  
   /* This is now unconditional because debugging printouts can use it.  */  
1121    output_gram ();    output_gram ();
1122    
1123    XFREE (ritem);    XFREE (ritem);
1124    if (semantic_parser)    if (semantic_parser)
1125      output_stos ();      output_stos ();
1126    output_rule_data ();    output_rule_data ();
1127    output_actions ();    output_actions ();
1128    if (!no_parser_flag)  
1129      output_parser ();    /* if (!no_parser_flag) */
1130      prepare ();
1131      output_parser ();
1132    output_program ();    output_program ();
1133    
1134      obstack_free (&macro_obstack, 0);
1135      obstack_free (&output_obstack, 0);
1136  }  }

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40

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