38 |
typedef struct symbol_list |
typedef struct symbol_list |
39 |
{ |
{ |
40 |
struct symbol_list *next; |
struct symbol_list *next; |
41 |
bucket *sym; |
symbol_t *sym; |
42 |
int line; |
int line; |
43 |
|
|
44 |
/* The action is attached to the LHS of a rule. */ |
/* The action is attached to the LHS of a rule. */ |
48 |
/* The guard is attached to the LHS of a rule. */ |
/* The guard is attached to the LHS of a rule. */ |
49 |
const char *guard; |
const char *guard; |
50 |
int guard_line; |
int guard_line; |
51 |
bucket *ruleprec; |
symbol_t *ruleprec; |
52 |
} symbol_list; |
} symbol_list; |
53 |
|
|
54 |
int lineno; |
int lineno; |
55 |
static symbol_list *grammar = NULL; |
static symbol_list *grammar = NULL; |
56 |
static int start_flag = 0; |
static int start_flag = 0; |
57 |
static bucket *startval = NULL; |
static symbol_t *startval = NULL; |
58 |
|
|
59 |
/* Nonzero if components of semantic values are used, implying |
/* Nonzero if components of semantic values are used, implying |
60 |
they must be unions. */ |
they must be unions. */ |
66 |
/* Incremented for each %left, %right or %nonassoc seen */ |
/* Incremented for each %left, %right or %nonassoc seen */ |
67 |
static int lastprec = 0; |
static int lastprec = 0; |
68 |
|
|
69 |
bucket *errtoken = NULL; |
symbol_t *errtoken = NULL; |
70 |
bucket *undeftoken = NULL; |
symbol_t *undeftoken = NULL; |
71 |
bucket *eoftoken = NULL; |
symbol_t *eoftoken = NULL; |
72 |
bucket *axiom = NULL; |
symbol_t *axiom = NULL; |
73 |
|
|
74 |
static symbol_list * |
static symbol_list * |
75 |
symbol_list_new (bucket *sym) |
symbol_list_new (symbol_t *sym) |
76 |
{ |
{ |
77 |
symbol_list *res = XMALLOC (symbol_list, 1); |
symbol_list *res = XMALLOC (symbol_list, 1); |
78 |
res->next = NULL; |
res->next = NULL; |
87 |
} |
} |
88 |
|
|
89 |
/*------------------------. |
/*------------------------. |
90 |
| Operations on buckets. | |
| Operations on symbols. | |
91 |
`------------------------*/ |
`------------------------*/ |
92 |
|
|
93 |
|
|
97 |
`-----------------------------------------------------------*/ |
`-----------------------------------------------------------*/ |
98 |
|
|
99 |
static bool |
static bool |
100 |
bucket_check_defined (bucket *this) |
symbol_check_defined (symbol_t *this) |
101 |
{ |
{ |
102 |
if (this->class == unknown_sym) |
if (this->class == unknown_sym) |
103 |
{ |
{ |
118 |
`-------------------------------------------------------------------*/ |
`-------------------------------------------------------------------*/ |
119 |
|
|
120 |
static bool |
static bool |
121 |
bucket_make_alias (bucket *symbol, char *typename) |
symbol_make_alias (symbol_t *symbol, char *typename) |
122 |
{ |
{ |
123 |
if (symval->alias) |
if (symval->alias) |
124 |
warn (_("symbol `%s' used more than once as a literal string"), |
warn (_("symbol `%s' used more than once as a literal string"), |
151 |
`---------------------------------------------------------*/ |
`---------------------------------------------------------*/ |
152 |
|
|
153 |
static bool |
static bool |
154 |
bucket_check_alias_consistence (bucket *this) |
symbol_check_alias_consistence (symbol_t *this) |
155 |
{ |
{ |
156 |
/* Check only those who _are_ the aliases. */ |
/* Check only those who _are_ the aliases. */ |
157 |
if (this->alias && this->user_token_number == SALIAS) |
if (this->alias && this->user_token_number == SALIAS) |
188 |
`-------------------------------------------------------------------*/ |
`-------------------------------------------------------------------*/ |
189 |
|
|
190 |
static bool |
static bool |
191 |
bucket_pack (bucket *this) |
symbol_pack (symbol_t *this) |
192 |
{ |
{ |
193 |
if (getenv ("DEBUG")) |
if (getenv ("DEBUG")) |
194 |
fprintf (stderr, "Packing %s, %s, number = %d\n", |
fprintf (stderr, "Packing %s, %s, number = %d\n", |
237 |
`--------------------------------------------------*/ |
`--------------------------------------------------*/ |
238 |
|
|
239 |
static bool |
static bool |
240 |
bucket_translation (bucket *this) |
symbol_translation (symbol_t *this) |
241 |
{ |
{ |
242 |
if (getenv ("DEBUG")) |
if (getenv ("DEBUG")) |
243 |
fprintf (stderr, "Considering Setting UserVal %s = %d (val = %d)\n", |
fprintf (stderr, "Considering Setting UserVal %s = %d (val = %d)\n", |
677 |
char *typename = NULL; |
char *typename = NULL; |
678 |
|
|
679 |
/* The symbol being defined. */ |
/* The symbol being defined. */ |
680 |
struct bucket *symbol = NULL; |
symbol_t *symbol = NULL; |
681 |
|
|
682 |
/* After `%token' and `%nterm', any number of symbols maybe be |
/* After `%token' and `%nterm', any number of symbols maybe be |
683 |
defined. */ |
defined. */ |
706 |
} |
} |
707 |
else if (token == tok_identifier && *symval->tag == '\"' && symbol) |
else if (token == tok_identifier && *symval->tag == '\"' && symbol) |
708 |
{ |
{ |
709 |
bucket_make_alias (symbol, typename); |
symbol_make_alias (symbol, typename); |
710 |
symbol = NULL; |
symbol = NULL; |
711 |
} |
} |
712 |
else if (token == tok_identifier) |
else if (token == tok_identifier) |
1023 |
parse_thong_decl (void) |
parse_thong_decl (void) |
1024 |
{ |
{ |
1025 |
token_t token; |
token_t token; |
1026 |
struct bucket *symbol; |
symbol_t *symbol; |
1027 |
char *typename = 0; |
char *typename = 0; |
1028 |
int usrtoknum = SUNDEF; |
int usrtoknum = SUNDEF; |
1029 |
|
|
1365 |
| with the user's names. | |
| with the user's names. | |
1366 |
`-------------------------------------------------------------------*/ |
`-------------------------------------------------------------------*/ |
1367 |
|
|
1368 |
static bucket * |
static symbol_t * |
1369 |
gensym (void) |
gensym (void) |
1370 |
{ |
{ |
1371 |
/* Incremented for each generated symbol */ |
/* Incremented for each generated symbol */ |
1372 |
static int gensym_count = 0; |
static int gensym_count = 0; |
1373 |
static char buf[256]; |
static char buf[256]; |
1374 |
|
|
1375 |
bucket *sym; |
symbol_t *sym; |
1376 |
|
|
1377 |
sprintf (buf, "@%d", ++gensym_count); |
sprintf (buf, "@%d", ++gensym_count); |
1378 |
token_buffer = buf; |
token_buffer = buf; |
1404 |
readgram (void) |
readgram (void) |
1405 |
{ |
{ |
1406 |
token_t t; |
token_t t; |
1407 |
bucket *lhs = NULL; |
symbol_t *lhs = NULL; |
1408 |
symbol_list *p = NULL; |
symbol_list *p = NULL; |
1409 |
symbol_list *p1 = NULL; |
symbol_list *p1 = NULL; |
1410 |
|
|
1423 |
/* Number of symbols in rhs of this rule so far */ |
/* Number of symbols in rhs of this rule so far */ |
1424 |
int rulelength = 0; |
int rulelength = 0; |
1425 |
int xactions = 0; /* JF for error checking */ |
int xactions = 0; /* JF for error checking */ |
1426 |
bucket *first_rhs = 0; |
symbol_t *first_rhs = 0; |
1427 |
|
|
1428 |
if (t == tok_identifier) |
if (t == tok_identifier) |
1429 |
{ |
{ |
1494 |
If one does, exit this rule now. */ |
If one does, exit this rule now. */ |
1495 |
if (t == tok_identifier) |
if (t == tok_identifier) |
1496 |
{ |
{ |
1497 |
bucket *ssave; |
symbol_t *ssave; |
1498 |
token_t t1; |
token_t t1; |
1499 |
|
|
1500 |
ssave = symval; |
ssave = symval; |
1523 |
inserting the new rule before it. */ |
inserting the new rule before it. */ |
1524 |
|
|
1525 |
/* Make a dummy nonterminal, a gensym. */ |
/* Make a dummy nonterminal, a gensym. */ |
1526 |
bucket *sdummy = gensym (); |
symbol_t *sdummy = gensym (); |
1527 |
|
|
1528 |
/* Make a new rule, whose body is empty, before the |
/* Make a new rule, whose body is empty, before the |
1529 |
current one, so that the action just read can |
current one, so that the action just read can |
1638 |
fatal (_("no rules in the input grammar")); |
fatal (_("no rules in the input grammar")); |
1639 |
|
|
1640 |
/* Report any undefined symbols and consider them nonterminals. */ |
/* Report any undefined symbols and consider them nonterminals. */ |
1641 |
buckets_do (bucket_check_defined, NULL); |
symbols_do (symbol_check_defined, NULL); |
1642 |
|
|
1643 |
/* Insert the initial rule, which line is that of the first rule |
/* Insert the initial rule, which line is that of the first rule |
1644 |
(not that of the start symbol): |
(not that of the start symbol): |
1705 |
/* Set the user numbers. */ |
/* Set the user numbers. */ |
1706 |
for (i = 0; i < ntokens; ++i) |
for (i = 0; i < ntokens; ++i) |
1707 |
{ |
{ |
1708 |
bucket *this = symbols[i]; |
symbol_t *this = symbols[i]; |
1709 |
if (getenv ("DEBUG")) |
if (getenv ("DEBUG")) |
1710 |
fprintf (stderr, "UserVal %s = %d (val = %d)\n", |
fprintf (stderr, "UserVal %s = %d (val = %d)\n", |
1711 |
this->tag, this->user_token_number, this->number); |
this->tag, this->user_token_number, this->number); |
1726 |
for (i = 0; i < max_user_token_number + 1; i++) |
for (i = 0; i < max_user_token_number + 1; i++) |
1727 |
token_translations[i] = 2; |
token_translations[i] = 2; |
1728 |
|
|
1729 |
buckets_do (bucket_translation, NULL); |
symbols_do (symbol_translation, NULL); |
1730 |
} |
} |
1731 |
|
|
1732 |
|
|
1738 |
static void |
static void |
1739 |
packsymbols (void) |
packsymbols (void) |
1740 |
{ |
{ |
1741 |
symbols = XCALLOC (bucket *, nsyms); |
symbols = XCALLOC (symbol_t *, nsyms); |
1742 |
|
|
1743 |
buckets_do (bucket_check_alias_consistence, NULL); |
symbols_do (symbol_check_alias_consistence, NULL); |
1744 |
buckets_do (bucket_pack, NULL); |
symbols_do (symbol_pack, NULL); |
1745 |
|
|
1746 |
token_translations_init (); |
token_translations_init (); |
1747 |
|
|
1781 |
p = grammar; |
p = grammar; |
1782 |
while (p) |
while (p) |
1783 |
{ |
{ |
1784 |
bucket *ruleprec = p->ruleprec; |
symbol_t *ruleprec = p->ruleprec; |
1785 |
rules[ruleno].user_number = ruleno; |
rules[ruleno].user_number = ruleno; |
1786 |
rules[ruleno].number = ruleno; |
rules[ruleno].number = ruleno; |
1787 |
rules[ruleno].lhs = p->sym; |
rules[ruleno].lhs = p->sym; |
1845 |
obstack_init (&muscle_obstack); |
obstack_init (&muscle_obstack); |
1846 |
|
|
1847 |
/* Initialize the symbol table. */ |
/* Initialize the symbol table. */ |
1848 |
buckets_new (); |
symbols_new (); |
1849 |
|
|
1850 |
/* Construct the axiom symbol. */ |
/* Construct the axiom symbol. */ |
1851 |
axiom = getsym ("$axiom"); |
axiom = getsym ("$axiom"); |
1913 |
XFREE (ritem); |
XFREE (ritem); |
1914 |
free (rules + 1); |
free (rules + 1); |
1915 |
/* Free the symbol table data structure. */ |
/* Free the symbol table data structure. */ |
1916 |
buckets_free (); |
symbols_free (); |
1917 |
} |
} |