-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.h
87 lines (71 loc) · 1.77 KB
/
interface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* symbol table */
struct symbol {
char *name;
char type;
};
/* simple symtab of fixed size */
#define NHASH 9997
struct symbol symtab[NHASH];
struct symbol *lookup(char*, int);
/* list of symbols, for an argument list */
struct symlist {
struct symbol *sym;
struct symlist *next;
};
struct symlist *newsymlist(char *sym, struct symlist *next);
void symlistsettype(char type, struct symlist *sl);
void symlistfree(struct symlist *sl);
/* node types
* P program root node
* L list of declarations or statements
* B boolean declaration
* D decimal declaration
* F loop for
* I iterator
* E iterator list
* = assignment
* + - * / & | ^ !
* 1-3 comparison ops, bit coded 03 equal, 02 less, 01 greater
* K number const
* N symbol ref
*/
/* nodes in the Abstract Syntax Tree */
struct ast
{
int nodetype;
struct ast *l;
struct ast *r;
};
struct numval {
int nodetype; /* type K */
int number;
};
struct symref {
int nodetype; /* type N */
struct symbol *s;
};
struct symasgn {
int nodetype; /* type = */
struct ast *s; /* variable */
struct ast *v; /* value */
};
struct declaration
{
int nodetype; /* type B or D */
struct symlist *symlist;
};
/* build an AST */
struct ast *newast(int nodetype, struct ast *l, struct ast *r);
struct ast *newcmp(int cmptype, struct ast *l, struct ast *r);
struct ast *newref(char *s);
struct ast *newasgn(struct ast *s, struct ast *v);
struct ast *newnum(int d);
struct ast *newdeclar(char type, struct symlist *symlist);
/* delete and free an AST */
void treefree(struct ast *);
/* interface to the lexer */
extern int yylineno;
int yyparse();
int yylex();
void yyerror (char *s, ...);
int dumpast(struct ast * a, int level, const char * description);