-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.h
68 lines (56 loc) · 1.56 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
#ifndef PHPINTERP_PARSE_H
#define PHPINTERP_PARSE_H
#include <stdio.h>
#include "lex.h"
#include "enum-util.h"
#define ENUM_ASTTYPE(ENUM_EL) \
ENUM_EL(AST_LIST, =0) \
ENUM_EL(AST_ECHO,) \
ENUM_EL(AST_IF,) \
ENUM_EL(AST_WHILE,) \
ENUM_EL(AST_FOR,) \
ENUM_EL(AST_STRING,) \
ENUM_EL(AST_BINOP,) \
ENUM_EL(AST_POSTFIXOP,) \
ENUM_EL(AST_PREFIXOP,) \
ENUM_EL(AST_NOTOP,) \
ENUM_EL(AST_LONG,) \
ENUM_EL(AST_NULL,) \
ENUM_EL(AST_TRUE,) \
ENUM_EL(AST_FALSE,) \
ENUM_EL(AST_VAR,) \
ENUM_EL(AST_ASSIGNMENT,) \
ENUM_EL(AST_CONSTDECL,) \
ENUM_EL(AST_FUNCTION,) \
ENUM_EL(AST_ARGUMENT,) \
ENUM_EL(AST_IDENTIFIER, ) \
ENUM_EL(AST_CALL,) \
ENUM_EL(AST_RETURN,) \
ENUM_EL(AST_HTML,) \
DECLARE_ENUM(ASTTYPE, ENUM_ASTTYPE);
typedef struct AST {
ASTTYPE type;
union {
char* str;
int64_t lint;
} val;
lineno_t lineno;
struct AST* node1;
struct AST* node2;
struct AST* node3;
struct AST* node4;
struct AST* next;
} AST;
AST* parse(FILE*);
size_t ast_list_count(AST*);
void print_ast(AST*, int level);
void destroy_ast(AST*);
static inline char* overtake_str(Lexer* S)
{
assert(S->val == MALLOCSTR || S->val == STATICSTR);
char* ret = S->u.string;
S->val = NONE;
S->u.string = NULL;
return ret;
}
#endif //PHPINTERP_PARSE_H