]>
git.saurik.com Git - bison.git/blob - src/output.c
94ad42562745436d1850644e04e644a21f376bb9
   1 /* Output the generated parsing program for bison, 
   2    Copyright 1984, 1986, 1989, 1992, 2000, 2001 
   3    Free Software Foundation, Inc. 
   5    This file is part of Bison, the GNU Compiler Compiler. 
   7    Bison is free software; you can redistribute it and/or modify it 
   8    under the terms of the GNU General Public License as published by 
   9    the Free Software Foundation; either version 2, or (at your option) 
  12    Bison is distributed in the hope that it will be useful, but 
  13    WITHOUT ANY WARRANTY; without even the implied warranty of 
  14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
  15    General Public License for more details. 
  17    You should have received a copy of the GNU General Public License 
  18    along with Bison; see the file COPYING.  If not, write to the Free 
  19    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
  23 /* The parser tables consist of these tables.  Marked ones needed only 
  24    for the semantic parser.  Double marked are output only if switches 
  27    YYTRANSLATE = vector mapping yylex's token numbers into bison's 
  30    ++ YYTNAME = vector of string-names indexed by bison token number. 
  32    ++ YYTOKNUM = vector of yylex token numbers corresponding to 
  35    YYRLINE = vector of line-numbers of all rules.  For yydebug 
  38    YYRHS = vector of items of all rules.  This is exactly what RITEMS 
  39    contains.  For yydebug and for semantic parser. 
  41    YYPRHS[R] = index in YYRHS of first item for rule R. 
  43    YYR1[R] = symbol number of symbol that rule R derives. 
  45    YYR2[R] = number of symbols composing right hand side of rule R. 
  47    + YYSTOS[S] = the symbol number of the symbol that leads to state 
  50    YYDEFACT[S] = default rule to reduce with in state s, when YYTABLE 
  51    doesn't specify something else to do.  Zero means the default is an 
  54    YYDEFGOTO[I] = default state to go to after a reduction of a rule 
  55    that generates variable NTOKENS + I, except when YYTABLE specifies 
  58    YYPACT[S] = index in YYTABLE of the portion describing state S. 
  59    The lookahead token's type is used to index that portion to find 
  62    If the value in YYTABLE is positive, we shift the token and go to 
  65    If the value is negative, it is minus a rule number to reduce by. 
  67    If the value is zero, the default action from YYDEFACT[S] is used. 
  69    YYPGOTO[I] = the index in YYTABLE of the portion describing what to 
  70    do after reducing a rule that derives variable I + NTOKENS.  This 
  71    portion is indexed by the parser state number, S, as of before the 
  72    text for this nonterminal was read.  The value from YYTABLE is the 
  73    state to go to if the corresponding value in YYCHECK is S. 
  75    YYTABLE = a vector filled with portions for different uses, found 
  76    via YYPACT and YYPGOTO. 
  78    YYCHECK = a vector indexed in parallel with YYTABLE.  It indicates, 
  79    in a roundabout way, the bounds of the portion you are trying to 
  82    Suppose that the portion of yytable starts at index P and the index 
  83    to be examined within the portion is I.  Then if YYCHECK[P+I] != I, 
  84    I is outside the bounds of what is actually allocated, and the 
  85    default (from YYDEFACT or YYDEFGOTO) should be used.  Otherwise, 
  86    YYTABLE[P+I] should be used. 
  88    YYFINAL = the state number of the termination state.  YYFLAG = most 
  89    negative short int.  Used to flag ??  */ 
 101 #include "conflicts.h" 
 102 #include "muscle_tab.h" 
 107 static short **froms 
= NULL
; 
 108 static short **tos 
= NULL
; 
 109 static short *tally 
= NULL
; 
 110 static short *width 
= NULL
; 
 111 static short *actrow 
= NULL
; 
 112 static short *state_count 
= NULL
; 
 113 static short *order 
= NULL
; 
 114 static short *base 
= NULL
; 
 115 static short *pos 
= NULL
; 
 116 static short *table 
= NULL
; 
 117 static short *check 
= NULL
; 
 121 struct obstack muscle_obstack
; 
 122 static struct obstack format_obstack
; 
 124 int error_verbose 
= 0; 
 126 /* Returns the number of lines of S.  */ 
 128 get_lines_number (const char *s
) 
 133   for (i 
= 0; s
[i
]; ++i
) 
 144 output_table_data (struct obstack 
*oout
, 
 153   obstack_fgrow1 (oout
, "%6d", first
); 
 154   for (i 
= begin
; i 
< end
; ++i
) 
 156       obstack_1grow (oout
, ','); 
 159           obstack_sgrow (oout
, "\n  "); 
 164       obstack_fgrow1 (oout
, "%6d", table_data
[i
]); 
 166   obstack_1grow (oout
, 0); 
 171 output_token_translations (void) 
 173   output_table_data (&format_obstack
, token_translations
, 
 174                      0, 1, max_user_token_number 
+ 1); 
 175   muscle_insert ("translate", obstack_finish (&format_obstack
)); 
 176   XFREE (token_translations
); 
 185     short *values 
= XCALLOC (short, nrules 
+ 1); 
 186     for (i 
= 0; i 
< nrules 
+ 1; ++i
) 
 187       values
[i
] = rule_table
[i
].rhs
; 
 188     output_table_data (&format_obstack
, values
, 
 193   muscle_insert ("prhs", obstack_finish (&format_obstack
)); 
 199     yyrhs 
= XMALLOC (short, nritems
); 
 201     for (i 
= 1; i 
< nritems
; ++i
) 
 202       yyrhs
[i
] = ritem
[i
] >= 0 ? ritem
[i
] : -1; 
 204     output_table_data (&format_obstack
, yyrhs
, 
 205                        ritem
[0], 1, nritems
); 
 206     muscle_insert ("rhs", obstack_finish (&format_obstack
)); 
 212   if (!semantic_parser
) 
 213     obstack_sgrow (&table_obstack
, "\n#endif\n"); 
 222   short *values 
= (short *) alloca (sizeof (short) * nstates
); 
 223   for (i 
= 0; i 
< nstates
; ++i
) 
 224     values
[i
] = state_table
[i
]->accessing_symbol
; 
 225   output_table_data (&format_obstack
, values
, 
 227   muscle_insert ("stos", obstack_finish (&format_obstack
)); 
 232 output_rule_data (void) 
 236   short *short_tab 
= NULL
; 
 239     short *values 
= XCALLOC (short, nrules 
+ 1); 
 240     for (i 
= 0; i 
< nrules 
+ 1; ++i
) 
 241       values
[i
] = rule_table
[i
].line
; 
 242     output_table_data (&format_obstack
, values
, 
 244     muscle_insert ("rline", obstack_finish (&format_obstack
)); 
 250   for (i 
= 0; i 
< nsyms
; i
++) 
 252       /* Be sure not to use twice the same quotearg slot. */ 
 254         quotearg_n_style (1, c_quoting_style
, 
 255                           quotearg_style (escape_quoting_style
, tags
[i
])); 
 256       /* Width of the next token, including the two quotes, the coma 
 258       int strsize 
= strlen (cp
) + 2; 
 260       if (j 
+ strsize 
> 75) 
 262           obstack_sgrow (&format_obstack
, "\n  "); 
 266       obstack_sgrow (&format_obstack
, cp
); 
 267       obstack_sgrow (&format_obstack
, ", "); 
 270   /* add a NULL entry to list of tokens */ 
 271   obstack_sgrow (&format_obstack
, "NULL"); 
 273   /* Finish table and store. */ 
 274   obstack_1grow (&format_obstack
, 0); 
 275   muscle_insert ("tname", obstack_finish (&format_obstack
)); 
 277   /* Output YYTOKNUM. */ 
 278   output_table_data (&format_obstack
, user_toknums
, 
 280   muscle_insert ("toknum", obstack_finish (&format_obstack
)); 
 284     short *values 
= XCALLOC (short, nrules 
+ 1); 
 285     for (i 
= 0; i 
< nrules 
+ 1; ++i
) 
 286       values
[i
] = rule_table
[i
].lhs
; 
 287     output_table_data (&format_obstack
, values
, 
 289     muscle_insert ("r1", obstack_finish (&format_obstack
)); 
 294   short_tab 
= XMALLOC (short, nrules 
+ 1); 
 295   for (i 
= 1; i 
< nrules
; i
++) 
 296     short_tab
[i
] = rule_table
[i 
+ 1].rhs 
- rule_table
[i
].rhs 
- 1; 
 297   short_tab
[nrules
] =  nritems 
- rule_table
[nrules
].rhs 
- 1; 
 298   output_table_data (&format_obstack
, short_tab
, 
 300   muscle_insert ("r2", obstack_finish (&format_obstack
)); 
 304 /*------------------------------------------------------------------. 
 305 | Decide what to do for each type of token if seen as the lookahead | 
 306 | token in specified state.  The value returned is used as the      | 
 307 | default action (yydefact) for the state.  In addition, actrow is  | 
 308 | filled with what to do for each kind of token, index by symbol    | 
 309 | number, with zero meaning do the default action.  The value       | 
 310 | MINSHORT, a very negative number, means this situation is an      | 
 311 | error.  The parser recognizes this value specially.               | 
 313 | This is where conflicts are resolved.  The loop over lookahead    | 
 314 | rules considered lower-numbered rules last, and the last rule     | 
 315 | considered that likes a token gets to handle it.                  | 
 316 `------------------------------------------------------------------*/ 
 319 action_row (state_t 
*state
) 
 322   int default_rule 
= 0; 
 323   reductions 
*redp 
= state
->reductions
; 
 324   shifts 
*shiftp 
= state
->shifts
; 
 325   errs 
*errp 
= state
->errs
; 
 326   /* set nonzero to inhibit having any default reduction */ 
 329   for (i 
= 0; i 
< ntokens
; i
++) 
 332   if (redp
->nreds 
>= 1) 
 335       /* loop over all the rules available here which require 
 337       for (i 
= state
->nlookaheads 
- 1; i 
>= 0; --i
) 
 338         /* and find each token which the rule finds acceptable 
 340         for (j 
= 0; j 
< ntokens
; j
++) 
 341           /* and record this rule as the rule to use if that 
 343           if (BITISSET (LA (state
->lookaheadsp 
+ i
), j
)) 
 344             actrow
[j
] = -LAruleno
[state
->lookaheadsp 
+ i
]; 
 347   /* Now see which tokens are allowed for shifts in this state.  For 
 348      them, record the shift as the thing to do.  So shift is preferred 
 350   for (i 
= 0; i 
< shiftp
->nshifts
; i
++) 
 353       int shift_state 
= shiftp
->shifts
[i
]; 
 357       symbol 
= state_table
[shift_state
]->accessing_symbol
; 
 362       actrow
[symbol
] = shift_state
; 
 364       /* Do not use any default reduction if there is a shift for 
 366       if (symbol 
== error_token_number
) 
 370   /* See which tokens are an explicit error in this state (due to 
 371      %nonassoc).  For them, record MINSHORT as the action.  */ 
 372   for (i 
= 0; i 
< errp
->nerrs
; i
++) 
 374       int symbol 
= errp
->errs
[i
]; 
 375       actrow
[symbol
] = MINSHORT
; 
 378   /* Now find the most common reduction and make it the default action 
 381   if (redp
->nreds 
>= 1 && !nodefault
) 
 383       if (state
->consistent
) 
 384         default_rule 
= redp
->rules
[0]; 
 388           for (i 
= 0; i 
< state
->nlookaheads
; i
++) 
 391               int rule 
= -LAruleno
[state
->lookaheadsp 
+ i
]; 
 394               for (j 
= 0; j 
< ntokens
; j
++) 
 395                 if (actrow
[j
] == rule
) 
 405           /* actions which match the default are replaced with zero, 
 406              which means "use the default" */ 
 411               for (j 
= 0; j 
< ntokens
; j
++) 
 412                 if (actrow
[j
] == default_rule
) 
 415               default_rule 
= -default_rule
; 
 420   /* If have no default rule, the default is an error. 
 421      So replace any action which says "error" with "use default".  */ 
 423   if (default_rule 
== 0) 
 424     for (i 
= 0; i 
< ntokens
; i
++) 
 425       if (actrow
[i
] == MINSHORT
) 
 442   for (i 
= 0; i 
< ntokens
; i
++) 
 449   froms
[state
] = sp1 
= sp 
= XCALLOC (short, count
); 
 450   tos
[state
] = sp2 
= XCALLOC (short, count
); 
 452   for (i 
= 0; i 
< ntokens
; i
++) 
 459   tally
[state
] = count
; 
 460   width
[state
] = sp1
[-1] - sp
[0] + 1; 
 464 /*------------------------------------------------------------------. 
 465 | Figure out the actions for the specified state, indexed by        | 
 466 | lookahead token type.                                             | 
 468 | The YYDEFACT table is output now.  The detailed info is saved for | 
 469 | putting into YYTABLE later.                                       | 
 470 `------------------------------------------------------------------*/ 
 476   short *yydefact 
= XCALLOC (short, nstates
); 
 478   actrow 
= XCALLOC (short, ntokens
); 
 479   for (i 
= 0; i 
< nstates
; ++i
) 
 481       yydefact
[i
] = action_row (state_table
[i
]); 
 485   output_table_data (&format_obstack
, yydefact
, 
 486                      yydefact
[0], 1, nstates
); 
 487   muscle_insert ("defact", obstack_finish (&format_obstack
)); 
 494 /*-----------------------------. 
 495 | Output the actions to OOUT.  | 
 496 `-----------------------------*/ 
 499 actions_output (FILE *out
, size_t *line
) 
 502   for (rule 
= 1; rule 
< nrules 
+ 1; ++rule
) 
 503     if (rule_table
[rule
].action
) 
 505         fprintf (out
, "  case %d:\n", rule
); 
 508           fprintf (out
, muscle_find ("linef"), 
 509                    rule_table
[rule
].action_line
, 
 510                    quotearg_style (c_quoting_style
, 
 511                                    muscle_find ("filename"))); 
 512         /* As a Bison extension, add the ending semicolon.  Since some 
 513            Yacc don't do that, help people using bison as a Yacc 
 514            finding their missing semicolons.  */ 
 515         fprintf (out
, "{ %s%s }\n    break;\n\n", 
 516                  rule_table
[rule
].action
, 
 517                  yacc_flag 
? ";" : ""); 
 519         /* We always output 4 '\n' per action.  */ 
 521         /* Plus one if !no_lines_flag.  */ 
 524         /* Get the number of lines written by the user.  */ 
 525         *line 
+= get_lines_number (rule_table
[rule
].action
); 
 530 /*----------------------------. 
 531 | Output the guards to OOUT.  | 
 532 `----------------------------*/ 
 535 guards_output (FILE *out
, size_t *line
) 
 538   for (rule 
= 1; rule 
< nrules 
+ 1; ++rule
) 
 539     if (rule_table
[rule
].action
) 
 541         fprintf (out
, "  case %d:\n", rule
); 
 544           fprintf (out
, muscle_find ("linef"), 
 545                    rule_table
[rule
].guard_line
, 
 546                    quotearg_style (c_quoting_style
, 
 547                                    muscle_find ("filename"))); 
 548         fprintf (out
, "{ %s; }\n    break;\n\n", 
 549                  rule_table
[rule
].guard
); 
 551         /* We always output 4 '\n' per action.  */ 
 553         /* Plus one if !no_lines_flag.  */ 
 556         /* Get the number of lines written by the user.  */ 
 557         *line 
+= get_lines_number (rule_table
[rule
].guard
); 
 563 save_column (int symbol
, int default_state
) 
 570   int symno 
= symbol 
- ntokens 
+ nstates
; 
 572   short begin 
= goto_map
[symbol
]; 
 573   short end 
= goto_map
[symbol 
+ 1]; 
 576   for (i 
= begin
; i 
< end
; i
++) 
 577     if (to_state
[i
] != default_state
) 
 583   froms
[symno
] = sp1 
= sp 
= XCALLOC (short, count
); 
 584   tos
[symno
] = sp2 
= XCALLOC (short, count
); 
 586   for (i 
= begin
; i 
< end
; i
++) 
 587     if (to_state
[i
] != default_state
) 
 589         *sp1
++ = from_state
[i
]; 
 590         *sp2
++ = to_state
[i
]; 
 593   tally
[symno
] = count
; 
 594   width
[symno
] = sp1
[-1] - sp
[0] + 1; 
 598 default_goto (int symbol
) 
 601   int m 
= goto_map
[symbol
]; 
 602   int n 
= goto_map
[symbol 
+ 1]; 
 603   int default_state 
= -1; 
 609   for (i 
= 0; i 
< nstates
; i
++) 
 612   for (i 
= m
; i 
< n
; i
++) 
 613     state_count
[to_state
[i
]]++; 
 615   for (i 
= 0; i 
< nstates
; i
++) 
 616     if (state_count
[i
] > max
) 
 618         max 
= state_count
[i
]; 
 622   return default_state
; 
 626 /*-------------------------------------------------------------------. 
 627 | Figure out what to do after reducing with each rule, depending on  | 
 628 | the saved state from before the beginning of parsing the data that | 
 629 | matched this rule.                                                 | 
 631 | The YYDEFGOTO table is output now.  The detailed info is saved for | 
 632 | putting into YYTABLE later.                                        | 
 633 `-------------------------------------------------------------------*/ 
 639   short *yydefgoto 
= XMALLOC (short, nsyms 
- ntokens
); 
 641   state_count 
= XCALLOC (short, nstates
); 
 642   for (i 
= ntokens
; i 
< nsyms
; ++i
) 
 644       int default_state 
= default_goto (i
); 
 645       save_column (i
, default_state
); 
 646       yydefgoto
[i 
- ntokens
] = default_state
; 
 649   output_table_data (&format_obstack
, yydefgoto
, 
 650                      yydefgoto
[0], 1, nsyms 
- ntokens
); 
 651   muscle_insert ("defgoto", obstack_finish (&format_obstack
)); 
 658 /* The next few functions decide how to pack the actions and gotos 
 659    information into yytable. */ 
 666   order 
= XCALLOC (short, nvectors
); 
 669   for (i 
= 0; i 
< nvectors
; i
++) 
 675         int j 
= nentries 
- 1; 
 677         while (j 
>= 0 && (width
[order
[j
]] < w
)) 
 680         while (j 
>= 0 && (width
[order
[j
]] == w
) && (tally
[order
[j
]] < t
)) 
 683         for (k 
= nentries 
- 1; k 
> j
; k
--) 
 684           order
[k 
+ 1] = order
[k
]; 
 693 matching_state (int vector
) 
 695   int i 
= order
[vector
]; 
 706   for (prev 
= vector 
- 1; prev 
>= 0; prev
--) 
 712       if (width
[j
] != w 
|| tally
[j
] != t
) 
 715       for (k 
= 0; match 
&& k 
< t
; k
++) 
 716         if (tos
[j
][k
] != tos
[i
][k
] || froms
[j
][k
] != froms
[i
][k
]) 
 728 pack_vector (int vector
) 
 730   int i 
= order
[vector
]; 
 734   short *from 
= froms
[i
]; 
 739   for (j 
= lowzero 
- from
[0]; j 
< MAXTABLE
; j
++) 
 744       for (k 
= 0; ok 
&& k 
< t
; k
++) 
 748             fatal (_("maximum table size (%d) exceeded"), MAXTABLE
); 
 754       for (k 
= 0; ok 
&& k 
< vector
; k
++) 
 760           for (k 
= 0; k 
< t
; k
++) 
 764               check
[loc
] = from
[k
]; 
 767           while (table
[lowzero
] != 0) 
 776 #define pack_vector_succeeded 0 
 777   assert (pack_vector_succeeded
); 
 789   base 
= XCALLOC (short, nvectors
); 
 790   pos 
= XCALLOC (short, nentries
); 
 791   table 
= XCALLOC (short, MAXTABLE
); 
 792   check 
= XCALLOC (short, MAXTABLE
); 
 797   for (i 
= 0; i 
< nvectors
; i
++) 
 800   for (i 
= 0; i 
< MAXTABLE
; i
++) 
 803   for (i 
= 0; i 
< nentries
; i
++) 
 805       state 
= matching_state (i
); 
 808         place 
= pack_vector (i
); 
 813       base
[order
[i
]] = place
; 
 816   for (i 
= 0; i 
< nvectors
; i
++) 
 827 /* the following functions output yytable, yycheck 
 828    and the vectors whose elements index the portion starts */ 
 834   output_table_data (&format_obstack
, base
, 
 835                      base
[0], 1, nstates
); 
 836   muscle_insert ("pact", obstack_finish (&format_obstack
)); 
 839   output_table_data (&format_obstack
, base
, 
 840                      base
[nstates
], nstates 
+ 1, nvectors
); 
 841   muscle_insert ("pgoto", obstack_finish (&format_obstack
)); 
 850   output_table_data (&format_obstack
, table
, 
 851                      table
[0], 1, high 
+ 1); 
 852   muscle_insert ("table", obstack_finish (&format_obstack
)); 
 860   output_table_data (&format_obstack
, check
, 
 861                      check
[0], 1, high 
+ 1); 
 862   muscle_insert ("check", obstack_finish (&format_obstack
)); 
 866 /* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable 
 870 output_actions (void) 
 873   nvectors 
= nstates 
+ nvars
; 
 875   froms 
= XCALLOC (short *, nvectors
); 
 876   tos 
= XCALLOC (short *, nvectors
); 
 877   tally 
= XCALLOC (short, nvectors
); 
 878   width 
= XCALLOC (short, nvectors
); 
 885   XFREE (goto_map 
+ ntokens
); 
 897   for (i 
= 0; i 
< nstates
; ++i
) 
 899       free (state_table
[i
]->shifts
); 
 900       XFREE (state_table
[i
]->reductions
); 
 901       free (state_table
[i
]->errs
); 
 902       free (state_table
[i
]); 
 908 /*------------------------------------------------------------. 
 909 | Copy the parser code from SKEL_FILENAME into OOUT obstack.  | 
 910 | and do the muscle substitution.                             | 
 911 `------------------------------------------------------------*/ 
 914 output_parser (const char *skel_filename
, FILE *out
) 
 919   size_t skeleton_line
; 
 921   fskel 
= xfopen (skel_filename
, "r"); 
 923   /* New output code.  */ 
 939       else if ((c 
= getc (fskel
)) == '%') 
 941           /* Read the muscle.  */ 
 942           const char *muscle_key 
= 0; 
 943           const char *muscle_value 
= 0; 
 945           while (isalnum (c 
= getc (fskel
)) || c 
== '-') 
 946             obstack_1grow (&muscle_obstack
, c
); 
 947           obstack_1grow (&muscle_obstack
, 0); 
 949           /* Output the right value, or see if it's something special.  */ 
 950           muscle_key 
= obstack_finish (&muscle_obstack
); 
 951           muscle_value 
= muscle_find (muscle_key
); 
 952           if (!strcmp (muscle_key
, "actions")) 
 953             actions_output (out
, &output_line
); 
 954           else if (!strcmp (muscle_key
, "guards")) 
 955             guards_output (out
, &output_line
); 
 956           else if (!strcmp (muscle_key
, "line")) 
 957             fprintf (out
, "%d", output_line
); 
 958           else if (!strcmp (muscle_key
, "skeleton-line")) 
 959             fprintf (out
, "%d", skeleton_line
); 
 960           else if (muscle_value
) 
 962               fputs (muscle_value
, out
); 
 963               output_line 
+= get_lines_number (muscle_value
); 
 968               fputs (muscle_key
, out
); 
 979 /*----------------------------------------. 
 980 | Prepare the master parser to be output  | 
 981 `----------------------------------------*/ 
 984 output_master_parser (void) 
 986   FILE *parser 
= xfopen (parser_file_name
, "w"); 
 990         skeleton 
= skeleton_find ("BISON_HAIRY", BISON_HAIRY
); 
 992         skeleton 
= skeleton_find ("BISON_SIMPLE", BISON_SIMPLE
); 
 994   muscle_insert ("skeleton", skeleton
); 
 995   muscle_insert ("parser-file-name", parser_file_name
); 
 997   output_parser (skeleton
, parser
); 
1004 #define MUSCLE_INSERT_INT(Key, Value)                           \ 
1006   obstack_fgrow1 (&muscle_obstack, "%d", Value);                \ 
1007   obstack_1grow (&muscle_obstack, 0);                           \ 
1008   muscle_insert (Key, obstack_finish (&muscle_obstack));        \ 
1011 #define MUSCLE_INSERT_STRING(Key, Value)                        \ 
1013   obstack_sgrow (&muscle_obstack, Value);                       \ 
1014   obstack_1grow (&muscle_obstack, 0);                           \ 
1015   muscle_insert (Key, obstack_finish (&muscle_obstack));        \ 
1018 #define MUSCLE_INSERT_PREFIX(Key, Value)                                \ 
1020   obstack_fgrow2 (&muscle_obstack, "%s%s", spec_name_prefix, Value);    \ 
1021   obstack_1grow (&muscle_obstack, 0);                                   \ 
1022   muscle_insert (Key, obstack_finish (&muscle_obstack));                \ 
1028   MUSCLE_INSERT_INT ("last", high
); 
1029   MUSCLE_INSERT_INT ("flag", MINSHORT
); 
1030   MUSCLE_INSERT_INT ("pure", pure_parser
); 
1031   MUSCLE_INSERT_INT ("nsym", nsyms
); 
1032   MUSCLE_INSERT_INT ("debug", debug_flag
); 
1033   MUSCLE_INSERT_INT ("final", final_state
); 
1034   MUSCLE_INSERT_INT ("maxtok", max_user_token_number
); 
1035   MUSCLE_INSERT_INT ("error-verbose", error_verbose
); 
1036   MUSCLE_INSERT_STRING ("prefix", spec_name_prefix
); 
1038   MUSCLE_INSERT_INT ("nnts", nvars
); 
1039   MUSCLE_INSERT_INT ("nrules", nrules
); 
1040   MUSCLE_INSERT_INT ("nstates", nstates
); 
1041   MUSCLE_INSERT_INT ("ntokens", ntokens
); 
1043   MUSCLE_INSERT_INT ("locations-flag", locations_flag
); 
1047 /*-------------------------. 
1048 | Output the header file.  | 
1049 `-------------------------*/ 
1052 header_output (void) 
1054   FILE *out 
= xfopen (spec_defines_file
, "w"); 
1055   char *macro_name 
= compute_header_macro (); 
1057   fprintf (out
, "#ifndef %s\n", macro_name
); 
1058   fprintf (out
, "# define %s\n\n", macro_name
); 
1060   fputs (muscle_find ("tokendef"), out
); 
1065 # define YYSTYPE yystype\n\ 
1067                     muscle_find ("stype")); 
1070     fprintf (out
, "\nextern YYSTYPE %slval;\n", 
1072   if (semantic_parser
) 
1076       for (i 
= ntokens
; i 
< nsyms
; i
++) 
1077         /* don't make these for dummy nonterminals made by gensym.  */ 
1078         if (*tags
[i
] != '@') 
1079           fprintf (out
, "# define NT%s\t%d\n", tags
[i
], i
); 
1082   fprintf (out
, "\n#endif /* not %s */\n", macro_name
); 
1088 /*----------------------------------------------------------. 
1089 | Output the parsing tables and the parser code to ftable.  | 
1090 `----------------------------------------------------------*/ 
1095   obstack_init (&format_obstack
); 
1097   output_token_translations (); 
1101   if (semantic_parser
) 
1103   output_rule_data (); 
1104   XFREE (user_toknums
); 
1108   /* Copy definitions in directive.  */ 
1109   obstack_1grow (&attrs_obstack
, 0); 
1110   muscle_insert ("prologue", obstack_finish (&attrs_obstack
)); 
1112   /* Output the parser. */ 
1113   output_master_parser (); 
1114   /* Output the header if needed. */ 
1118   free (rule_table 
+ 1); 
1119   obstack_free (&muscle_obstack
, NULL
); 
1120   obstack_free (&format_obstack
, NULL
); 
1121   obstack_free (&action_obstack
, NULL
); 
1122   obstack_free (&attrs_obstack
, NULL
);