-
Notifications
You must be signed in to change notification settings - Fork 0
/
expr.h
83 lines (72 loc) · 1.87 KB
/
expr.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
#pragma once
#include "lexer.h"
//#include "types.h"
typedef struct Expression Expression;
/*typedef struct{
Token token;
} VariableExpression;
*/
typedef struct{
union{
double dval;
int64_t ival;
char *sval;
};
} ConstantExpression;
typedef struct{
Expression *left;
Expression *right;
} BinaryExpression;
typedef struct{
Expression *right;
} UnaryExpression;
typedef struct{
Expression *callee;
Expression **args;
uint64_t arity;
} CallExpression;
typedef struct{
Expression *refer;
Expression *parent;
} ReferenceExpression;
typedef enum{
EXPR_CONSTANT,
EXPR_VARIABLE,
EXPR_BINARY,
EXPR_UNARY,
EXPR_CALL,
EXPR_DEFINE, // Same as CALL, except used with Define/Container
EXPR_REFERENCE
} ExpressionType;
struct Expression{
ExpressionType type;
Token token;
int valueType;
int expectedType; // this will flag the need of typecast
// if valueType == expectedType, the expression
// is already in correct form
// Since it is a single variable, the expected
// type should be unambiguous. For an expression
// with possibility Number and Integer, it will
// always be Number.
// -1 will denote the expression has not been
// evaluted yet.
uint64_t hash;
union{
//VariableExpression varex;
ConstantExpression consex;
BinaryExpression binex;
UnaryExpression unex;
CallExpression calex;
ReferenceExpression refex;
};
};
// Functions
void expr_init();
Expression* expr_new(ExpressionType type);
void expr_dispose();
#ifdef DEBUG
void expr_print(Expression *exp, uint64_t printSpace);
void expr_print_space(uint64_t space);
#define print_space() expr_print_space(printSpace)
#endif