style: factor complex expressions

* src/print-xml.c, src/print.c: Introduce a variable pointing to the
current symbol.
This commit is contained in:
Akim Demaille
2020-07-11 08:28:34 +02:00
parent aa766d1560
commit 2608b0cf12
2 changed files with 14 additions and 11 deletions

View File

@@ -382,9 +382,10 @@ print_grammar (FILE *out, int level)
for (int i = 0; i < max_code + 1; i++)
if (token_translations[i] != undeftoken->content->number)
{
char const *tag = symbols[token_translations[i]]->tag;
int precedence = symbols[token_translations[i]]->content->prec;
assoc associativity = symbols[token_translations[i]]->content->assoc;
symbol const *sym = symbols[token_translations[i]];
char const *tag = sym->tag;
int precedence = sym->content->prec;
assoc associativity = sym->content->assoc;
xml_indent (out, level + 2);
fprintf (out,
"<terminal symbol-number=\"%d\" token-number=\"%d\""
@@ -404,7 +405,8 @@ print_grammar (FILE *out, int level)
xml_puts (out, level + 1, "<nonterminals>");
for (symbol_number i = ntokens; i < nsyms + nuseless_nonterminals; i++)
{
char const *tag = symbols[i]->tag;
symbol const *sym = symbols[i];
char const *tag = sym->tag;
xml_printf (out, level + 2,
"<nonterminal symbol-number=\"%d\" name=\"%s\""
" usefulness=\"%s\"/>",

View File

@@ -377,11 +377,11 @@ print_terminal_symbols (FILE *out)
for (int i = 0; i < max_code + 1; ++i)
if (token_translations[i] != undeftoken->content->number)
{
const char *tag = symbols[token_translations[i]]->tag;
const symbol *sym = symbols[token_translations[i]];
const char *tag = sym->tag;
fprintf (out, "%4s%s", "", tag);
if (symbols[token_translations[i]]->content->type_name)
fprintf (out, " <%s>",
symbols[token_translations[i]]->content->type_name);
if (sym->content->type_name)
fprintf (out, " <%s>", sym->content->type_name);
fprintf (out, " (%d)", i);
for (rule_number r = 0; r < nrules; r++)
@@ -403,7 +403,8 @@ print_nonterminal_symbols (FILE *out)
fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear"));
for (symbol_number i = ntokens; i < nsyms; i++)
{
const char *tag = symbols[i]->tag;
const symbol *sym = symbols[i];
const char *tag = sym->tag;
bool on_left = false;
bool on_right = false;
@@ -418,9 +419,9 @@ print_nonterminal_symbols (FILE *out)
int column = 4 + mbswidth (tag, 0);
fprintf (out, "%4s%s", "", tag);
if (symbols[i]->content->type_name)
if (sym->content->type_name)
column += fprintf (out, " <%s>",
symbols[i]->content->type_name);
sym->content->type_name);
fprintf (out, " (%d)\n", i);
if (on_left)