Commit 6f655449 authored by Akim Demaille's avatar Akim Demaille

style: do not generate tabulation in the output

* src/emit.c (output): Convert tabs to two spaces.
* tests/sample.brg, tests/sample.c.ref: Untabify.
Remove trailing spaces.
parent e32a800d
......@@ -37,9 +37,21 @@ void output (char *fmt, ...)
{
va_list ap;
/* Replace all the tabulations by two spaces. */
char *cp, *cp2;
va_start(ap, fmt);
vfprintf (outputfd, fmt, ap);
cp = g_strdup_vprintf(fmt, ap);
va_end (ap);
for (cp2 = cp; *cp2; ++cp2)
if (*cp2 == '\t')
{
putc (' ', outputfd);
putc (' ', outputfd);
}
else
putc (*cp2, outputfd);
g_free (cp);
}
/** Emit includes of external header files. */
......
/*
* This header (everything before the first "%%") is copied
/*
* This header (everything before the first "%%") is copied
* directly to the output.
*/
......@@ -11,9 +11,9 @@
typedef struct _MBTree MBTree;
struct _MBTree {
guint16 op;
MBTree *left, *right;
gpointer state;
guint16 op;
MBTree *left, *right;
gpointer state;
};
%% these are the monoburg definition
......@@ -28,7 +28,7 @@ struct _MBTree {
#
# we must first define the terminals
# with or without numbers
#
#
%term Assign Constant Fetch=3 Four=8 Mul=5 Plus=6 AltFetch=7
#
......@@ -36,38 +36,38 @@ struct _MBTree {
#
%start reg
con: Constant 0
con: Constant 0
con: Four 0
con: Four 0
addr: con 0
addr: con 0
addr: Plus(con,reg)
addr: Plus(con,reg)
{
int ern = mono_burg_rule (tree->state, MB_NTERM_addr);
printf ("%s\n", mono_burg_rule_string [ern]);
} cost
{
int ern = mono_burg_rule (tree->state, MB_NTERM_addr);
printf ("%s\n", mono_burg_rule_string [ern]);
} cost
{
return 1;
}
addr: Plus(con,Mul(Four,reg)) 2
addr: Plus(con,Mul(Four,reg)) 2
{
int ern = mono_burg_rule (tree->state, MB_NTERM_addr);
printf ("%s\n", mono_burg_rule_string [ern]);
}
int ern = mono_burg_rule (tree->state, MB_NTERM_addr);
printf ("%s\n", mono_burg_rule_string [ern]);
}
reg: AltFetch(addr),
reg: Fetch(addr) 1
reg: Fetch(addr) 1
{
int ern = mono_burg_rule (tree->state, MB_NTERM_reg);
printf ("%s\n", mono_burg_rule_string [ern]);
int ern = mono_burg_rule (tree->state, MB_NTERM_reg);
printf ("%s\n", mono_burg_rule_string [ern]);
}
reg: Assign(addr,reg) 1
reg: Assign(addr,reg) 1
{
int ern = mono_burg_rule (tree->state, MB_NTERM_reg);
printf ("%s\n", mono_burg_rule_string [ern]);
int ern = mono_burg_rule (tree->state, MB_NTERM_reg);
printf ("%s\n", mono_burg_rule_string [ern]);
}
%% the rest is also copied directly to the output
......@@ -78,72 +78,72 @@ reg: Assign(addr,reg) 1
static MBTree *
create_tree (int op, MBTree *left, MBTree *right)
{
MBTree *t = g_new0 (MBTree, 1);
t->op = op;
t->left = left;
t->right = right;
MBTree *t = g_new0 (MBTree, 1);
t->op = op;
t->left = left;
t->right = right;
return t;
return t;
}
static void
reduce (MBTree *tree, int goal)
reduce (MBTree *tree, int goal)
{
MBTree *kids[10];
int ern = mono_burg_rule (tree->state, goal);
const guint16 *nts = mono_burg_nts [ern];
int i, n;
mono_burg_kids (tree, ern, kids);
// printf ("TEST %d %d %s %d\n", goal, ern, mono_burg_rule_string [ern], nts [0]);
for (i = 0; nts [i]; i++)
reduce (kids [i], nts [i]);
n = (tree->left != NULL) + (tree->right != NULL);
if (n) { /* not a terminal */
// printf ("XXTE %s %d\n", mono_burg_rule_string [ern], n);
if (mono_burg_func [ern])
mono_burg_func [ern] (tree, NULL);
else
g_warning ("no code for rule %s\n",
mono_burg_rule_string [ern]);
} else {
if (mono_burg_func [ern])
g_warning ("unused code in rule %s\n",
mono_burg_rule_string [ern]);
}
MBTree *kids[10];
int ern = mono_burg_rule (tree->state, goal);
const guint16 *nts = mono_burg_nts [ern];
int i, n;
mono_burg_kids (tree, ern, kids);
// printf ("TEST %d %d %s %d\n", goal, ern, mono_burg_rule_string [ern], nts [0]);
for (i = 0; nts [i]; i++)
reduce (kids [i], nts [i]);
n = (tree->left != NULL) + (tree->right != NULL);
if (n) { /* not a terminal */
// printf ("XXTE %s %d\n", mono_burg_rule_string [ern], n);
if (mono_burg_func [ern])
mono_burg_func [ern] (tree, NULL);
else
g_warning ("no code for rule %s\n",
mono_burg_rule_string [ern]);
} else {
if (mono_burg_func [ern])
g_warning ("unused code in rule %s\n",
mono_burg_rule_string [ern]);
}
}
int
main ()
{
MBTree *t, *l, *r;
MBState *s;
MBTree *t, *l, *r;
MBState *s;
l = create_tree (MB_TERM_Constant, NULL, NULL);
l = create_tree (MB_TERM_Constant, NULL, NULL);
r = create_tree (MB_TERM_Fetch, l, NULL);
l = create_tree (MB_TERM_Constant, NULL, NULL);
r = create_tree (MB_TERM_Fetch, l, NULL);
l = create_tree (MB_TERM_Constant, NULL, NULL);
r = create_tree (MB_TERM_Assign, l, r);
l = create_tree (MB_TERM_Four, NULL, NULL);
r = create_tree (MB_TERM_Assign, l, r);
l = create_tree (MB_TERM_Four, NULL, NULL);
r = create_tree (MB_TERM_Mul, l, r);
l = create_tree (MB_TERM_Constant, NULL, NULL);
r = create_tree (MB_TERM_Mul, l, r);
l = create_tree (MB_TERM_Constant, NULL, NULL);
l = create_tree (MB_TERM_Plus, l, r);
l = create_tree (MB_TERM_Plus, l, r);
t = create_tree (MB_TERM_Fetch, l, NULL);
t = create_tree (MB_TERM_Fetch, l, NULL);
s = mono_burg_label (t, NULL);
s = mono_burg_label (t, NULL);
g_assert (s);
g_assert (s);
reduce (t, MB_NTERM_reg);
reduce (t, MB_NTERM_reg);
return 0;
return 0;
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment