-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefs.h
74 lines (67 loc) · 1.32 KB
/
defs.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
// Structure and enum definitions
// Copyright (c) 2019 Warren Toomey, GPL3
#define TEXTLEN 512 // Length of symbols in input
#define NSYMBOLS 1024 // Number of symbol table entries
// Token types
enum {
T_EOF,
// Binary operators
T_PLUS,
T_MINUS,
T_STAR,
T_SLASH,
T_EQ,
T_NE,
T_LT,
T_GT,
T_LE,
T_GE,
// Assignment operators
T_INTLIT,
T_SEMI,
T_ASSIGN,
T_IDENT,
// Keywords
T_PRINT,
T_INT
};
// Token structure
struct token {
int token; // Token type, from the enum list above
int intvalue; // For T_INTLIT, the integer value
};
// AST node types
enum {
A_ADD = 1,
A_SUBTRACT,
A_MULTIPLY,
A_DIVIDE,
A_EQ,
A_NE,
A_LT,
A_GT,
A_LE,
A_GE,
A_INTLIT,
A_IDENT,
A_LVIDENT,
A_ASSIGN
};
// Abstract Syntax Tree structure
struct ASTnode {
int op; // "Operation" to be performed on this tree
struct ASTnode* left; // Left and right child trees
struct ASTnode* right;
union {
int intvalue; // For A_INTLIT, the integer value
int id; // For A_IDENT, the symbol slot number
} v;
};
// Symbol table structure
struct symtable {
char* name; // Name of a symbol
};