5
extern void *alloc(int nbytes);
7
typedef enum { TERM=1, NONTERM } Kind;
8
typedef struct rule *Rule;
9
typedef struct term *Term;
10
struct term { /* terminals: */
11
char *name; /* terminal name */
13
int esn; /* external symbol number */
14
int arity; /* operator arity */
15
Term link; /* next terminal in esn order */
16
Rule rules; /* rules whose pattern starts with term */
19
typedef struct nonterm *Nonterm;
20
struct nonterm { /* nonterminals: */
21
char *name; /* nonterminal name */
22
Kind kind; /* NONTERM */
23
int number; /* identifying number */
24
int lhscount; /* # times nt appears in a rule lhs */
25
int reached; /* 1 iff reached from start nonterminal */
26
Rule rules; /* rules w/nonterminal on lhs */
27
Rule chain; /* chain rules w/nonterminal on rhs */
28
Nonterm link; /* next terminal in number order */
30
extern Nonterm nonterm(char *id);
31
extern Term term(char *id, int esn);
33
typedef struct tree *Tree;
34
struct tree { /* tree patterns: */
35
void *op; /* a terminal or nonterminal */
36
Tree left, right; /* operands */
37
int nterms; /* number of terminal nodes in this tree */
39
extern Tree tree(char *op, Tree left, Tree right);
41
struct rule { /* rules: */
42
Nonterm lhs; /* lefthand side nonterminal */
43
Tree pattern; /* rule pattern */
44
int ern; /* external rule number */
45
int packed; /* packed external rule number */
46
int cost; /* cost, if a constant */
47
char *code; /* cost, if an expression */
48
char *template; /* assembler template */
49
Rule link; /* next rule in ern order */
50
Rule next; /* next rule with same pattern root */
51
Rule chain; /* next chain rule with same rhs */
52
Rule decode; /* next rule with same lhs */
53
Rule kids; /* next rule with same _kids pattern */
55
extern Rule rule(char *id, Tree pattern, char *template, char *code);
58
void yyerror(char *fmt, ...);
60
void yywarn(char *fmt, ...);