/[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.54 by pascal, Fri Aug 31 18:51:06 2001 UTC revision 1.55 by marc, Sun Sep 2 15:43:29 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"  #include "muscle_tab.h"
107    
108  extern void berror PARAMS((const char *));  extern void berror PARAMS((const char *));
109    
# Line 123  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;  struct obstack muscle_obstack;
127  struct obstack output_obstack;  struct obstack output_obstack;
128    
129  /* FIXME. */  /* FIXME. */
# Line 160  output_token_translations (void) Line 160  output_token_translations (void)
160  {  {
161    output_table_data (&output_obstack, token_translations,    output_table_data (&output_obstack, token_translations,
162                       0, 1, max_user_token_number + 1);                       0, 1, max_user_token_number + 1);
163    macro_insert ("translate", obstack_finish (&output_obstack));    muscle_insert ("translate", obstack_finish (&output_obstack));
164  }  }
165    
166    
# Line 169  output_gram (void) Line 169  output_gram (void)
169  {  {
170    output_table_data (&output_obstack, rrhs,    output_table_data (&output_obstack, rrhs,
171                       0, 1, nrules + 1);                       0, 1, nrules + 1);
172    macro_insert ("prhs", obstack_finish (&output_obstack));    muscle_insert ("prhs", obstack_finish (&output_obstack));
173        
174    {    {
175      size_t yyrhs_size = 1;      size_t yyrhs_size = 1;
# Line 185  output_gram (void) Line 185  output_gram (void)
185    
186      output_table_data (&output_obstack, 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));      muscle_insert ("rhs", obstack_finish (&output_obstack));
189    
190      XFREE (yyrhs);      XFREE (yyrhs);
191    }    }
# Line 202  output_stos (void) Line 202  output_stos (void)
202  {  {
203    output_table_data (&output_obstack, accessing_symbol,    output_table_data (&output_obstack, accessing_symbol,
204                       0, 1, nstates);                       0, 1, nstates);
205    macro_insert ("stos", obstack_finish (&output_obstack));    muscle_insert ("stos", obstack_finish (&output_obstack));
206  }  }
207    
208    
# Line 215  output_rule_data (void) Line 215  output_rule_data (void)
215    
216    output_table_data (&output_obstack, rline,    output_table_data (&output_obstack, rline,
217                       0, 1, nrules + 1);                       0, 1, nrules + 1);
218    macro_insert ("rline", obstack_finish (&output_obstack));    muscle_insert ("rline", obstack_finish (&output_obstack));
219    
220    j = 0;    j = 0;
221    for (i = 0; i < nsyms; i++)    for (i = 0; i < nsyms; i++)
# Line 267  output_rule_data (void) Line 267  output_rule_data (void)
267    
268    /* Finish table and store. */    /* Finish table and store. */
269    obstack_1grow (&output_obstack, 0);    obstack_1grow (&output_obstack, 0);
270    macro_insert ("tname", obstack_finish (&output_obstack));    muscle_insert ("tname", obstack_finish (&output_obstack));
271    
272    /* Output YYTOKNUM. */    /* Output YYTOKNUM. */
273    output_table_data (&output_obstack, user_toknums,    output_table_data (&output_obstack, user_toknums,
274                       0, 1, ntokens + 1);                       0, 1, ntokens + 1);
275    macro_insert ("toknum", obstack_finish (&output_obstack));    muscle_insert ("toknum", obstack_finish (&output_obstack));
276    
277    /* Output YYR1. */    /* Output YYR1. */
278    output_table_data (&output_obstack, rlhs,    output_table_data (&output_obstack, rlhs,
279                       0, 1, nrules + 1);                       0, 1, nrules + 1);
280    macro_insert ("r1", obstack_finish (&output_obstack));    muscle_insert ("r1", obstack_finish (&output_obstack));
281    XFREE (rlhs + 1);    XFREE (rlhs + 1);
282    
283    /* Output YYR2. */    /* Output YYR2. */
# Line 287  output_rule_data (void) Line 287  output_rule_data (void)
287    short_tab[nrules] = nitems - rrhs[nrules] - 1;    short_tab[nrules] = nitems - rrhs[nrules] - 1;
288    output_table_data (&output_obstack, short_tab,    output_table_data (&output_obstack, short_tab,
289                       0, 1, nrules + 1);                       0, 1, nrules + 1);
290    macro_insert ("r2", obstack_finish (&output_obstack));    muscle_insert ("r2", obstack_finish (&output_obstack));
291    XFREE (short_tab);    XFREE (short_tab);
292    
293    XFREE (rrhs + 1);    XFREE (rrhs + 1);
# Line 536  token_actions (void) Line 536  token_actions (void)
536    
537    output_table_data (&output_obstack, yydefact,    output_table_data (&output_obstack, yydefact,
538                       yydefact[0], 1, nstates);                       yydefact[0], 1, nstates);
539    macro_insert ("defact", obstack_finish (&output_obstack));    muscle_insert ("defact", obstack_finish (&output_obstack));
540        
541    XFREE (actrow);    XFREE (actrow);
542    XFREE (yydefact);    XFREE (yydefact);
# Line 677  goto_actions (void) Line 677  goto_actions (void)
677    
678    output_table_data (&output_obstack, yydefgoto,    output_table_data (&output_obstack, yydefgoto,
679                       yydefgoto[0], 1, nsyms - ntokens);                       yydefgoto[0], 1, nsyms - ntokens);
680    macro_insert ("defgoto", obstack_finish (&output_obstack));    muscle_insert ("defgoto", obstack_finish (&output_obstack));
681    
682    XFREE (state_count);    XFREE (state_count);
683    XFREE (yydefgoto);    XFREE (yydefgoto);
# Line 882  output_base (void) Line 882  output_base (void)
882    /* Output pact. */    /* Output pact. */
883    output_table_data (&output_obstack, base,    output_table_data (&output_obstack, base,
884                       base[0], 1, nstates);                       base[0], 1, nstates);
885    macro_insert ("pact", obstack_finish (&output_obstack));    muscle_insert ("pact", obstack_finish (&output_obstack));
886    
887    /* Output pgoto. */    /* Output pgoto. */
888    output_table_data (&output_obstack, base,    output_table_data (&output_obstack, base,
889                       base[nstates], nstates + 1, nvectors);                       base[nstates], nstates + 1, nvectors);
890    macro_insert ("pgoto", obstack_finish (&output_obstack));    muscle_insert ("pgoto", obstack_finish (&output_obstack));
891    
892    XFREE (base);    XFREE (base);
893  }  }
# Line 898  output_table (void) Line 898  output_table (void)
898  {  {
899    output_table_data (&output_obstack, table,    output_table_data (&output_obstack, table,
900                       table[0], 1, high + 1);                       table[0], 1, high + 1);
901    macro_insert ("table", obstack_finish (&output_obstack));    muscle_insert ("table", obstack_finish (&output_obstack));
902    XFREE (table);    XFREE (table);
903  }  }
904    
# Line 908  output_check (void) Line 908  output_check (void)
908  {  {
909    output_table_data (&output_obstack, check,    output_table_data (&output_obstack, check,
910                       check[0], 1, high + 1);                       check[0], 1, high + 1);
911    macro_insert ("check", obstack_finish (&output_obstack));    muscle_insert ("check", obstack_finish (&output_obstack));
912    XFREE (check);    XFREE (check);
913  }  }
914    
# Line 983  output_parser (void) Line 983  output_parser (void)
983          }          }
984        else if ((c = getc (fskel)) == '%')        else if ((c = getc (fskel)) == '%')
985          {          {
986            /* Read the macro.  */            /* Read the muscle.  */
987            const char *macro_key = 0;            const char *muscle_key = 0;
988            const char *macro_value = 0;            const char *muscle_value = 0;
989            while (isalnum (c = getc (fskel)) || c == '_')            while (isalnum (c = getc (fskel)) || c == '_')
990              obstack_1grow (&macro_obstack, c);              obstack_1grow (&muscle_obstack, c);
991            obstack_1grow (&macro_obstack, 0);            obstack_1grow (&muscle_obstack, 0);
992    
993            /* Output the right value, or see if it's something special.  */            /* Output the right value, or see if it's something special.  */
994            macro_key = obstack_finish (&macro_obstack);            muscle_key = obstack_finish (&muscle_obstack);
995            macro_value = macro_find (macro_key);            muscle_value = muscle_find (muscle_key);
996            if (macro_value)            if (muscle_value)
997              obstack_sgrow (&table_obstack, macro_value);              obstack_sgrow (&table_obstack, muscle_value);
998            else if (!strcmp (macro_key, "line"))            else if (!strcmp (muscle_key, "line"))
999              obstack_fgrow1 (&table_obstack, "%d", line + 1);              obstack_fgrow1 (&table_obstack, "%d", line + 1);
1000            else if (!strcmp (macro_key, "action"))            else if (!strcmp (muscle_key, "action"))
1001              {              {
1002                size_t size = obstack_object_size (&action_obstack);                size_t size = obstack_object_size (&action_obstack);
1003                obstack_grow (&table_obstack,                obstack_grow (&table_obstack,
# Line 1006  output_parser (void) Line 1006  output_parser (void)
1006            else            else
1007              {              {
1008                obstack_sgrow (&table_obstack, "%%");                obstack_sgrow (&table_obstack, "%%");
1009                obstack_sgrow (&table_obstack, macro_key);                obstack_sgrow (&table_obstack, muscle_key);
1010              }              }
1011          }          }
1012        else        else
# Line 1033  free_itemsets (void) Line 1033  free_itemsets (void)
1033    
1034  /* FIXME. */  /* FIXME. */
1035    
1036  #define MACRO_INSERT_INT(Key, Value)                    \  #define MUSCLE_INSERT_INT(Key, Value)                           \
1037  {                                                       \  {                                                               \
1038    obstack_fgrow1 (&macro_obstack, "%d", Value);         \    obstack_fgrow1 (&muscle_obstack, "%d", Value);                \
1039    obstack_1grow (&macro_obstack, 0);                    \    obstack_1grow (&muscle_obstack, 0);                           \
1040    macro_insert (Key, obstack_finish (&macro_obstack));  \    muscle_insert (Key, obstack_finish (&muscle_obstack));        \
1041  }  }
1042    
1043  #define MACRO_INSERT_STRING(Key, Value)                 \  #define MUSCLE_INSERT_STRING(Key, Value)                        \
1044  {                                                       \  {                                                               \
1045    obstack_sgrow (&macro_obstack, Value);                \    obstack_sgrow (&muscle_obstack, Value);                       \
1046    obstack_1grow (&macro_obstack, 0);                    \    obstack_1grow (&muscle_obstack, 0);                           \
1047    macro_insert (Key, obstack_finish (&macro_obstack));  \    muscle_insert (Key, obstack_finish (&muscle_obstack));        \
1048  }  }
1049    
1050  #define MACRO_INSERT_PREFIX(Key, Value)                                 \  #define MUSCLE_INSERT_PREFIX(Key, Value)                                \
1051  {                                                                       \  {                                                                       \
1052    obstack_fgrow2 (&macro_obstack, "%s%s", spec_name_prefix, Value);     \    obstack_fgrow2 (&muscle_obstack, "%s%s", spec_name_prefix, Value);    \
1053    obstack_1grow (&macro_obstack, 0);                                    \    obstack_1grow (&muscle_obstack, 0);                                   \
1054    macro_insert (Key, obstack_finish (&macro_obstack));                  \    muscle_insert (Key, obstack_finish (&muscle_obstack));                \
1055  }  }
1056    
1057  static void  static void
1058  prepare (void)  prepare (void)
1059  {  {
1060    MACRO_INSERT_INT ("last", high);    MUSCLE_INSERT_INT ("last", high);
1061    MACRO_INSERT_INT ("flag", MINSHORT);    MUSCLE_INSERT_INT ("flag", MINSHORT);
1062    MACRO_INSERT_INT ("pure", pure_parser);    MUSCLE_INSERT_INT ("pure", pure_parser);
1063    MACRO_INSERT_INT ("nsym", nsyms);    MUSCLE_INSERT_INT ("nsym", nsyms);
1064    MACRO_INSERT_INT ("debug", debug_flag);    MUSCLE_INSERT_INT ("debug", debug_flag);
1065    MACRO_INSERT_INT ("final", final_state);    MUSCLE_INSERT_INT ("final", final_state);
1066    MACRO_INSERT_INT ("maxtok", max_user_token_number);    MUSCLE_INSERT_INT ("maxtok", max_user_token_number);
1067    MACRO_INSERT_INT ("ntbase", ntokens);    MUSCLE_INSERT_INT ("ntbase", ntokens);
1068    MACRO_INSERT_INT ("verbose", 0);    MUSCLE_INSERT_INT ("verbose", 0);
1069    
1070    MACRO_INSERT_INT ("nnts", nvars);    MUSCLE_INSERT_INT ("nnts", nvars);
1071    MACRO_INSERT_INT ("nrules", nrules);    MUSCLE_INSERT_INT ("nrules", nrules);
1072    MACRO_INSERT_INT ("nstates", nstates);    MUSCLE_INSERT_INT ("nstates", nstates);
1073    MACRO_INSERT_INT ("ntokens", ntokens);    MUSCLE_INSERT_INT ("ntokens", ntokens);
1074    
1075    MACRO_INSERT_INT ("locations_flag", locations_flag);    MUSCLE_INSERT_INT ("locations_flag", locations_flag);
1076    
1077    if (spec_name_prefix)    if (spec_name_prefix)
1078      MACRO_INSERT_STRING ("prefix", spec_name_prefix);      MUSCLE_INSERT_STRING ("prefix", spec_name_prefix);
1079  }  }
1080    
1081  /*----------------------------------------------------------.  /*----------------------------------------------------------.
# Line 1106  output (void) Line 1106  output (void)
1106  #endif  #endif
1107    prepare ();    prepare ();
1108    /* Copy definitions in directive.  */    /* Copy definitions in directive.  */
1109    macro_insert ("prologue", obstack_finish (&attrs_obstack));    muscle_insert ("prologue", obstack_finish (&attrs_obstack));
1110    output_parser ();    output_parser ();
1111    
1112    obstack_free (&macro_obstack, 0);    obstack_free (&muscle_obstack, 0);
1113    obstack_free (&output_obstack, 0);    obstack_free (&output_obstack, 0);
1114  }  }

Legend:
Removed from v.1.54  
changed lines
  Added in v.1.55

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