summaryrefslogtreecommitdiff
path: root/expr.h
blob: 0d7422d66567793e1c53a0b175516abe87723197 (plain)
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
typedef struct sheet sheet;

typedef struct expr expr; 
typedef struct value value;  /* for recursive case */
typedef struct postfix postfix;

typedef enum exprType {
	VALUE,
	POSTFIX,	
	NESTED,
} exprType;

typedef enum valueType {
	NUM,
	LOC,
} valueType;

typedef struct loc {
        int x, y;
} loc;

typedef struct expr {
	char *expr;
	exprType t;
	union {
		expr *nested;
		struct {
			value *value;
			postfix *postfix;
		};
	};
} expr;

typedef struct postfix {
	char op;
	expr *expr;
} postfix;

typedef struct value {
	valueType t;
	union {
		int num;
		loc *loc;
	};
} value;

extern char *in;
extern char *Pin;

char isop(char c);
void consumeleading(char c);
expr *parseExpr(); 
loc *parseLoc();
postfix *parsePostfix(); 
value *parseValue(); 
expr *parseExpr(); 
double evalValue(value *v, sheet *s);
double evalPostfix(value *v, postfix *p, sheet *s);
double evalExpr(expr *e, sheet *s); 
expr *makeNumber(int n);
void freeExpr(expr *e);