-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecls.h
92 lines (77 loc) · 1.75 KB
/
decls.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
#ifndef SKKU_PLCOMP_PROJECT2_MAIN_DECLS_H
#define SKKU_PLCOMP_PROJECT2_MAIN_DECLS_H
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#define PTABLE_SIZE 2048
using namespace std;
typedef enum {
SHIFT = 1000,
REDUCE,
GOTO,
ACCEPT,
PROGS, // prog'
PROG, // prog
DECLS, // decls
DECL, // decl
WORDS, // words
VTYPE, // vtype
BLOCK, // block
SLIST, // slist
STAT, // stat
COND, // cond
EXPR, // expr
TERM, // term
FACT, // fact
PHL, // (
PHR, // )
SEMICOLON, // ;
COMMA, // ,
INT, // INT
CHAR, // CHAR
MPHL, // {
MPHR, // }
IF, // IF
THEN, // THEN
ELSE, // ELSE
WHILE, // WHILE
EQUAL, // =
RETURN, // RETURN
GREATER, // >
LESS, // <
PLUS, // +
MUL, // *
WORD, // word
NUM, // num
END, // $
NONE
} type_t;
typedef struct _Token {
int type;
char *value;
_Token() : type(NONE), value(nullptr) {}
_Token(int type_, char *value_) : type(type_), value(value_) {}
} Token;
typedef struct _Ptable {
int state;
int token;
int action;
int next;
} Ptable;
typedef struct _Rtable {
int pop_count;
int push;
} Rtable;
typedef struct _Stable {
type_t token;
type_t right_child;
type_t next;
} Stable;
extern vector<Token> token_list, parsed_list;
extern const int ptable_n, stable_n;
extern Ptable ptable[];
extern Rtable rtable[];
extern Stable stable[];
const char *get_type_name(type_t type);
#endif //SKKU_PLCOMP_PROJECT2_MAIN_DECLS_H