Ejemplo n.º 1
0
static void
prepare_symbols (void)
{
  MUSCLE_INSERT_INT ("tokens_number", ntokens);
  MUSCLE_INSERT_INT ("nterms_number", nvars);
  MUSCLE_INSERT_INT ("symbols_number", nsyms);
  MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
  MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);

  muscle_insert_symbol_number_table ("translate",
                                     token_translations,
                                     token_translations[0],
                                     1, max_user_token_number + 1);

  /* tname -- token names.  */
  {
    int i;
    /* We assume that the table will be output starting at column 2. */
    int j = 2;
    struct quoting_options *qo = clone_quoting_options (0);
    set_quoting_style (qo, c_quoting_style);
    set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS);
    for (i = 0; i < nsyms; i++)
      {
        char *cp = quotearg_alloc (symbols[i]->tag, -1, qo);
        /* Width of the next token, including the two quotes, the
           comma and the space.  */
        int width = strlen (cp) + 2;

        if (j + width > 75)
          {
            obstack_sgrow (&format_obstack, "\n ");
            j = 1;
          }

        if (i)
          obstack_1grow (&format_obstack, ' ');
        obstack_escape (&format_obstack, cp);
        free (cp);
        obstack_1grow (&format_obstack, ',');
        j += width;
      }
    free (qo);
    obstack_sgrow (&format_obstack, " ]b4_null[");

    /* Finish table and store. */
    muscle_insert ("tname", obstack_finish0 (&format_obstack));
  }

  /* Output YYTOKNUM. */
  {
    int i;
    int *values = xnmalloc (ntokens, sizeof *values);
    for (i = 0; i < ntokens; ++i)
      values[i] = symbols[i]->user_token_number;
    muscle_insert_int_table ("toknum", values,
                             values[0], 1, ntokens);
    free (values);
  }
}
Ejemplo n.º 2
0
static void
muscle_grow (const char *key, const char *val,
             const char *separator, const char *terminator)
{
  muscle_entry *entry = muscle_lookup (key);
  size_t vals = strlen (val);
  size_t terms = strlen (terminator);

  if (entry)
    {
      obstack_sgrow (&muscle_obstack, entry->value);
      obstack_sgrow (&muscle_obstack, separator);
      free (entry->storage);
    }
  else
    entry = muscle_entry_new (key);

  obstack_sgrow (&muscle_obstack, val);

  if (terms <= vals
      && STRNEQ (val + vals - terms, terminator))
    obstack_sgrow (&muscle_obstack, terminator);

  {
    char *new_val = obstack_finish0 (&muscle_obstack);
    entry->value = entry->storage = xstrdup (new_val);
    obstack_free (&muscle_obstack, new_val);
  }
}
Ejemplo n.º 3
0
static void
conclude_red (struct obstack *out, int source, rule_number ruleno,
              bool enabled, bool first, FILE *fout)
{
  /* If no lookahead tokens were valid transitions, this reduction is
     actually hidden, so cancel everything. */
  if (first)
    (void) obstack_finish0 (out);
  else
    {
      char const *ed = enabled ? "" : "d";
      char const *color = enabled ? ruleno ? "3" : "1" : "5";

      /* First, build the edge's head. The name of reduction nodes is "nRm",
         with n the source state and m the rule number. This is because we
         don't want all the reductions bearing a same rule number to point to
         the same state, since that is not the desired format. */
      fprintf (fout, "  %d -> \"%dR%d%s\" [",
               source, source, ruleno, ed);

      /* (The lookahead tokens have been added to the beginning of the
         obstack, in the caller function.) */
      if (! obstack_empty_p (out))
        {
          char *label = obstack_finish0 (out);
          fprintf (fout, "label=\"[%s]\", ", label);
          obstack_free (out, label);
        }

      /* Then, the edge's tail. */
      fprintf (fout, "style=solid]\n");

      /* Build the associated diamond representation of the target rule. */
      fprintf (fout, " \"%dR%d%s\" [label=\"",
               source, ruleno, ed);
      if (ruleno)
        fprintf (fout, "R%d", ruleno);
      else
        fprintf (fout, "Acc");

      fprintf (fout, "\", fillcolor=%s, shape=diamond, style=filled]\n",
               color);
    }
}
Ejemplo n.º 4
0
static void
muscle_boundary_grow (char const *key, boundary bound)
{
  char *extension;
  obstack_sgrow  (&muscle_obstack, "[[");
  obstack_escape (&muscle_obstack, bound.file);
  obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column);
  extension = obstack_finish0 (&muscle_obstack);
  muscle_grow (key, extension, "", "");
  obstack_free (&muscle_obstack, extension);
}
Ejemplo n.º 5
0
static void
muscle_syncline_grow (char const *key, location loc)
{
  char *extension = NULL;
  obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
  obstack_quote (&muscle_obstack,
                 quotearg_style (c_quoting_style, loc.start.file));
  obstack_sgrow (&muscle_obstack, ")[");
  extension = obstack_finish0 (&muscle_obstack);
  muscle_grow (key, extension, "", "");
  obstack_free (&muscle_obstack, extension);
}
Ejemplo n.º 6
0
void
muscle_pair_list_grow (const char *muscle,
                       const char *a1, const char *a2)
{
  char *pair;
  obstack_sgrow (&muscle_obstack, "[");
  obstack_quote (&muscle_obstack, a1);
  obstack_sgrow (&muscle_obstack, ", ");
  obstack_quote (&muscle_obstack, a2);
  obstack_sgrow (&muscle_obstack, "]");
  pair = obstack_finish0 (&muscle_obstack);
  muscle_grow (muscle, pair, ",\n", "");
  obstack_free (&muscle_obstack, pair);
}
Ejemplo n.º 7
0
/* Reverse of muscle_location_grow.  */
static location
location_decode (char const *value)
{
  location loc;
  aver (value);
  aver (*value == '[');
  aver (*++value == '[');
  while (*++value)
    switch (*value)
      {
        COMMON_DECODE (value)
        case '[':
          aver (false);
          break;
        case ']':
          {
            char *boundary_str;
            aver (*++value == ']');
            boundary_str = obstack_finish0 (&muscle_obstack);
            switch (*++value)
              {
                case ',':
                  boundary_set_from_string (&loc.start, boundary_str);
                  obstack_free (&muscle_obstack, boundary_str);
                  aver (*++value == ' ');
                  aver (*++value == '[');
                  aver (*++value == '[');
                  break;
                case '\0':
                  boundary_set_from_string (&loc.end, boundary_str);
                  obstack_free (&muscle_obstack, boundary_str);
                  return loc;
                  break;
                default:
                  aver (false);
                  break;
              }
          }
          break;
      }
  aver (false);
  return loc;
}