-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.h
128 lines (119 loc) · 2.03 KB
/
parse.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
119
120
121
122
123
124
125
126
127
128
#ifndef PARSE_H
#define PARSE_H
#include <stddef.h>
enum type {
FORM_NOT,
FORM_AND,
FORM_OR,
FORM_IMPL,
FORM_CON,
FORM_NAME,
CMD_PRESUME,
CMD_ASSUME,
CMD_OPEN,
CMD_CLOSE,
CMD_APPLY,
CMD_EXPORT,
INPUT_LINE,
INPUT_BOX,
INPUT_FORM,
RULE_NOT_INTR,
RULE_NOT_ELIM,
RULE_AND_INTR,
RULE_AND_ELIM_1,
RULE_AND_ELIM_2,
RULE_OR_INTR_1,
RULE_OR_INTR_2,
RULE_OR_ELIM,
RULE_IMPL_INTR,
RULE_IMPL_ELIM,
RULE_CON_ELIM,
RULE_NOT_NOT_INTR,
RULE_NOT_NOT_ELIM,
RULE_MT,
RULE_PBC,
RULE_LEM,
RULE_COPY,
};
static inline int is_form(enum type type)
{
switch (type) {
case FORM_NOT:
case FORM_AND:
case FORM_OR:
case FORM_IMPL:
case FORM_CON:
case FORM_NAME:
return 1;
default:
return 0;
}
}
static inline int is_cmd(enum type type)
{
switch (type) {
case CMD_PRESUME:
case CMD_ASSUME:
case CMD_OPEN:
case CMD_CLOSE:
case CMD_APPLY:
case CMD_EXPORT:
return 1;
default:
return 0;
}
}
static inline int is_input(enum type type)
{
switch (type) {
case INPUT_LINE:
case INPUT_BOX:
case INPUT_FORM:
return 1;
default:
return 0;
}
}
static inline int is_rule(enum type type)
{
switch (type) {
case RULE_NOT_INTR:
case RULE_NOT_ELIM:
case RULE_AND_INTR:
case RULE_AND_ELIM_1:
case RULE_AND_ELIM_2:
case RULE_OR_INTR_1:
case RULE_OR_INTR_2:
case RULE_OR_ELIM:
case RULE_IMPL_INTR:
case RULE_IMPL_ELIM:
case RULE_CON_ELIM:
case RULE_NOT_NOT_INTR:
case RULE_NOT_NOT_ELIM:
case RULE_MT:
case RULE_PBC:
case RULE_LEM:
return 1;
default:
return 0;
}
}
struct ast {
enum type type;
char *text;
struct ast *lhs;
struct ast *rhs;
int start;
int end;
};
struct ast *parse(const char *text, size_t length, char *errbuf,
size_t errbuf_length);
struct ast *ast_form(struct ast *cmd);
int ast_rule(struct ast *cmd);
struct ast *ast_rule_input(struct ast *cmd, size_t n);
struct ast *ast_copy(struct ast *ast);
int ast_equal(struct ast *ast1, struct ast *ast2);
void ast_destroy(struct ast *ast);
size_t print_form(struct ast *form, char *buf, size_t s);
size_t print_apply(struct ast *cmd, char *buf, size_t s);
#endif