-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.h
74 lines (62 loc) · 1.25 KB
/
compiler.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
#ifndef clox_compiler_h
#define clox_compiler_h
#include "object.h"
#include "scanner.h"
#include "vm.h"
#include <stdint.h>
typedef enum {
PREC_NONE,
PREC_ASSIGNMENT, // =
PREC_OR, // or
PREC_AND, // and
PREC_EQUALITY, // == !=
PREC_COMPARISON, // < > <= >=
PREC_TERM, // + -
PREC_FACTOR, // * /
PREC_UNARY, // ! -
PREC_CALL, // . ()
PREC_PRIMARY
} Precedence;
typedef void (*ParseFn)(bool canAssign);
typedef struct {
ParseFn prefix;
ParseFn infix;
Precedence precedence;
} ParseRule;
typedef struct {
Token name;
int depth;
bool isCaptured;
} Local;
typedef struct {
uint8_t index;
bool isLocal;
} Upvalue;
typedef enum {
TYPE_FUNCTION,
TYPE_INITIALIZER,
TYPE_METHOD,
TYPE_SCRIPT,
} FunctionType;
typedef struct Compiler {
struct Compiler *enclosing;
ObjFunction *function;
FunctionType type;
Local locals[UINT8_COUNT];
int localCount;
Upvalue upvalues[UINT8_COUNT];
int scopeDepth;
} Compiler;
typedef struct ClassCompiler {
struct ClassCompiler *enclosing;
bool hasSuperclass;
} ClassCompiler;
typedef struct {
Token current;
Token previous;
bool hadError;
bool panicMode;
} Parser;
ObjFunction *compile(const char *source);
void markCompilerRoots();
#endif