-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmplr.h
73 lines (60 loc) · 1.29 KB
/
cmplr.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
#ifndef CMPLR_H
#define CMPLR_H
#define MAXIDENT 256
#define MAXARGS 256
#include <stdio.h>
typedef enum token_t {
INTEGER, OP, ENDA,
L_PAREN, R_PAREN, IDENT,
KW_INT, SEMICOLON, ASSIGN_OP,
R_SQUARE_BRACKET, L_SQUARE_BRACKET, COMMA
} token_t;
typedef enum op_t { PLUS, MULTIPLY, MINUS, DIVIDE, POWER } op_t;
typedef union val_t {
int int_val;
op_t op;
char ident[MAXIDENT];
} val_t;
typedef struct Token {
token_t type;
val_t val;
} Token;
typedef enum ast_node_t {
BIN_OP_PLUS,
BIN_OP_TIMES,
BIN_OP_MINUS,
BIN_OP_DIVIDE,
BIN_OP_POWER,
INT,
VAR,
PAREN,
UNDEFINED,
FRAC,
FUNC
} ast_node_t;
typedef struct Node {
ast_node_t type;
int value;
char name[MAXIDENT];
struct Node * args[MAXARGS];
int n_args;
struct Node *left;
struct Node *right;
} Node;
extern Node UNDEFINED_NODE;
void read_one_token(Token * tok, FILE * f);
void print_token(Token * tok);
Node *plus_node(Node * l, Node * r);
Node *times_node(Node * l, Node * r);
Node *minus_node(Node * l, Node * r);
Node *integer_node(int val);
Node *divide_node();
Node *frac_node();
Node *pow_node();
Node *factor();
Node *expression();
Node *term();
Node *parse(FILE * src);
Node *statement();
void attach_argument(Node * out, Node * arg);
#endif