1 | #ifndef js_parse_h |
2 | #define js_parse_h |
3 | |
4 | enum js_AstType |
5 | { |
6 | AST_LIST, |
7 | AST_FUNDEC, |
8 | AST_IDENTIFIER, |
9 | |
10 | EXP_IDENTIFIER, |
11 | EXP_NUMBER, |
12 | EXP_STRING, |
13 | EXP_REGEXP, |
14 | |
15 | /* literals */ |
16 | EXP_UNDEF, /* for array elisions */ |
17 | EXP_NULL, |
18 | EXP_TRUE, |
19 | EXP_FALSE, |
20 | EXP_THIS, |
21 | |
22 | EXP_ARRAY, |
23 | EXP_OBJECT, |
24 | EXP_PROP_VAL, |
25 | EXP_PROP_GET, |
26 | EXP_PROP_SET, |
27 | |
28 | EXP_FUN, |
29 | |
30 | /* expressions */ |
31 | EXP_INDEX, |
32 | EXP_MEMBER, |
33 | EXP_CALL, |
34 | EXP_NEW, |
35 | |
36 | EXP_POSTINC, |
37 | EXP_POSTDEC, |
38 | |
39 | EXP_DELETE, |
40 | EXP_VOID, |
41 | EXP_TYPEOF, |
42 | EXP_PREINC, |
43 | EXP_PREDEC, |
44 | EXP_POS, |
45 | EXP_NEG, |
46 | EXP_BITNOT, |
47 | EXP_LOGNOT, |
48 | |
49 | EXP_MOD, |
50 | EXP_DIV, |
51 | EXP_MUL, |
52 | EXP_SUB, |
53 | EXP_ADD, |
54 | EXP_USHR, |
55 | EXP_SHR, |
56 | EXP_SHL, |
57 | EXP_IN, |
58 | EXP_INSTANCEOF, |
59 | EXP_GE, |
60 | EXP_LE, |
61 | EXP_GT, |
62 | EXP_LT, |
63 | EXP_STRICTNE, |
64 | EXP_STRICTEQ, |
65 | EXP_NE, |
66 | EXP_EQ, |
67 | EXP_BITAND, |
68 | EXP_BITXOR, |
69 | EXP_BITOR, |
70 | EXP_LOGAND, |
71 | EXP_LOGOR, |
72 | |
73 | EXP_COND, |
74 | |
75 | EXP_ASS, |
76 | EXP_ASS_MUL, |
77 | EXP_ASS_DIV, |
78 | EXP_ASS_MOD, |
79 | EXP_ASS_ADD, |
80 | EXP_ASS_SUB, |
81 | EXP_ASS_SHL, |
82 | EXP_ASS_SHR, |
83 | EXP_ASS_USHR, |
84 | EXP_ASS_BITAND, |
85 | EXP_ASS_BITXOR, |
86 | EXP_ASS_BITOR, |
87 | |
88 | EXP_COMMA, |
89 | |
90 | EXP_VAR, /* var initializer */ |
91 | |
92 | /* statements */ |
93 | STM_BLOCK, |
94 | STM_EMPTY, |
95 | STM_VAR, |
96 | STM_IF, |
97 | STM_DO, |
98 | STM_WHILE, |
99 | STM_FOR, |
100 | STM_FOR_VAR, |
101 | STM_FOR_IN, |
102 | STM_FOR_IN_VAR, |
103 | STM_CONTINUE, |
104 | STM_BREAK, |
105 | STM_RETURN, |
106 | STM_WITH, |
107 | STM_SWITCH, |
108 | STM_THROW, |
109 | STM_TRY, |
110 | STM_DEBUGGER, |
111 | |
112 | STM_LABEL, |
113 | STM_CASE, |
114 | STM_DEFAULT, |
115 | }; |
116 | |
117 | typedef struct js_JumpList js_JumpList; |
118 | |
119 | struct js_JumpList |
120 | { |
121 | enum js_AstType type; |
122 | int inst; |
123 | js_JumpList *next; |
124 | }; |
125 | |
126 | struct js_Ast |
127 | { |
128 | enum js_AstType type; |
129 | int line; |
130 | js_Ast *parent, *a, *b, *c, *d; |
131 | double number; |
132 | const char *string; |
133 | js_JumpList *jumps; /* list of break/continue jumps to patch */ |
134 | int casejump; /* for switch case clauses */ |
135 | js_Ast *gcnext; /* next in alloc list */ |
136 | }; |
137 | |
138 | js_Ast *jsP_parsefunction(js_State *J, const char *filename, const char *params, const char *body); |
139 | js_Ast *jsP_parse(js_State *J, const char *filename, const char *source); |
140 | void jsP_freeparse(js_State *J); |
141 | |
142 | const char *jsP_aststring(enum js_AstType type); |
143 | void jsP_dumpsyntax(js_State *J, js_Ast *prog, int minify); |
144 | void jsP_dumplist(js_State *J, js_Ast *prog); |
145 | |
146 | #endif |
147 | |