1 #ifndef BURG_INCLUDED
2 #define BURG_INCLUDED
3 
4 /* iburg.c: */
5 extern void *alloc(int nbytes);
6 
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 */
12 	Kind kind;		/* TERM */
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 */
17 };
18 
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 */
29 };
30 extern Nonterm nonterm(char *id);
31 extern Term term(char *id, int esn);
32 
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 */
38 };
39 extern Tree tree(char *op, Tree left, Tree right);
40 
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 */
54 };
55 extern Rule rule(char *id, Tree pattern, char *template, char *code);
56 
57 /* gram.y: */
58 void yyerror(char *fmt, ...);
59 int yyparse(void);
60 void yywarn(char *fmt, ...);
61 extern int errcnt;
62 extern FILE *infp;
63 extern FILE *outfp;
64 
65 #endif
66