forked from DoctorWkt/acwj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefs.h
46 lines (39 loc) · 1.04 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
#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, T_PLUS, T_MINUS, T_STAR, T_SLASH, T_INTLIT, T_SEMI, T_EQUALS,
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, A_SUBTRACT, A_MULTIPLY, A_DIVIDE, 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
};