-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpr.h
118 lines (103 loc) · 1.82 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef EXPR_H
#define EXPR_H
#include "scanner.h"
typedef struct Expression Expression;
/*
typedef struct{
Token name;
Expression* value;
} Assign;
*/
typedef enum{
LIT_DOUBLE,
LIT_INT,
LIT_STRING,
LIT_LOGICAL,
LIT_NULL
} LiteralType;
static const char *literalNames[] = {
"LIT_DOUBLE",
"LIT_INT",
"LIT_STRING",
"LIT_LOGICAL",
"LIT_NULL"
};
typedef struct{
int line;
LiteralType type;
union{
int lVal;
long iVal;
double dVal;
char *sVal;
};
} Literal;
typedef struct{
int line;
Expression* left;
Token op;
Expression* right;
} Binary;
// Call
typedef struct{
int line;
char *identifer;
int argCount;
Expression **arguments;
} Call;
typedef struct{
int line;
Expression *index;
char *identifier;
} ArrayExpression;
typedef struct{
int line;
Expression* left;
Token op;
Expression* right;
} Logical;
typedef struct{
int line;
char* name;
} Variable;
typedef struct{
int line;
Expression *containerName;
Expression *member;
} Reference;
typedef enum{
// EXPR_ASSIGN,
EXPR_BINARY,
EXPR_LOGICAL,
EXPR_LITERAL,
EXPR_VARIABLE,
EXPR_ARRAY,
EXPR_CALL,
EXPR_REFERENCE,
EXPR_NONE
} ExpressionType;
static const char *expressionNames[] = {
// EXPR_ASSIGN,
"EXPR_BINARY",
"EXPR_LOGICAL",
"EXPR_LITERAL",
"EXPR_VARIABLE",
"EXPR_ARRAY",
"EXPR_CALL",
"EXPR_REFERENCE",
"EXPR_NONE"
};
typedef struct Expression{
ExpressionType type;
union{
// Assign assignment;
Binary binary;
Logical logical;
Literal literal;
ArrayExpression arrayExpression;
Variable variable;
Call callExpression;
Reference referenceExpression;
};
} Expression;
#endif