]> git.kianting.info Git - uann/blob - ocaml_yacc/parser.ml
9337a959bd71796c076ac6897cdb8ee3d8f90c03
[uann] / ocaml_yacc / parser.ml
1 type token =
2 | INT of (string)
3 | ID of (string)
4 | PLUS
5 | MINUS
6 | TIMES
7 | DIV
8 | LPAREN
9 | RPAREN
10 | ASSIGN
11 | IN
12 | IMPLY
13 | FUNC
14 | EOL
15
16 open Parsing;;
17 let _ = parse_error;;
18 let yytransl_const = [|
19 259 (* PLUS *);
20 260 (* MINUS *);
21 261 (* TIMES *);
22 262 (* DIV *);
23 263 (* LPAREN *);
24 264 (* RPAREN *);
25 265 (* ASSIGN *);
26 266 (* IN *);
27 267 (* IMPLY *);
28 268 (* FUNC *);
29 269 (* EOL *);
30 0|]
31
32 let yytransl_block = [|
33 257 (* INT *);
34 258 (* ID *);
35 0|]
36
37 let yylhs = "\255\255\
38 \001\000\002\000\002\000\003\000\003\000\005\000\006\000\006\000\
39 \004\000\004\000\004\000\009\000\010\000\007\000\008\000\008\000\
40 \008\000\008\000\008\000\008\000\008\000\008\000\000\000"
41
42 let yylen = "\002\000\
43 \002\000\001\000\002\000\001\000\001\000\006\000\001\000\003\000\
44 \001\000\001\000\001\000\003\000\002\000\002\000\001\000\001\000\
45 \003\000\003\000\003\000\003\000\003\000\002\000\002\000"
46
47 let yydefred = "\000\000\
48 \000\000\000\000\015\000\000\000\000\000\000\000\023\000\000\000\
49 \002\000\000\000\005\000\000\000\009\000\010\000\011\000\000\000\
50 \000\000\000\000\000\000\001\000\003\000\000\000\000\000\000\000\
51 \000\000\000\000\000\000\000\000\000\000\013\000\017\000\000\000\
52 \000\000\000\000\000\000\000\000\007\000\000\000\012\000\000\000\
53 \000\000\006\000"
54
55 let yydgoto = "\002\000\
56 \007\000\008\000\009\000\026\000\011\000\018\000\013\000\014\000\
57 \015\000\016\000"
58
59 let yysindex = "\007\000\
60 \120\255\000\000\000\000\000\000\120\255\120\255\000\000\012\255\
61 \000\000\106\255\000\000\001\255\000\000\000\000\000\000\245\254\
62 \124\255\049\255\098\255\000\000\000\000\120\255\120\255\120\255\
63 \120\255\106\255\009\255\024\255\120\255\000\000\000\000\113\255\
64 \124\255\124\255\124\255\120\255\000\000\026\255\000\000\088\255\
65 \120\255\000\000"
66
67 let yyrindex = "\000\000\
68 \000\000\000\000\000\000\042\255\000\000\000\000\000\000\000\000\
69 \000\000\063\255\000\000\000\000\000\000\000\000\000\000\000\000\
70 \028\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
71 \000\000\074\255\050\255\000\000\000\000\000\000\000\000\007\255\
72 \053\255\064\255\075\255\000\000\000\000\052\255\000\000\000\000\
73 \000\000\000\000"
74
75 let yygindex = "\000\000\
76 \000\000\000\000\254\255\255\255\000\000\001\000\000\000\000\000\
77 \000\000\000\000"
78
79 let yytablesize = 131
80 let yytable = "\010\000\
81 \029\000\012\000\027\000\017\000\019\000\021\000\010\000\001\000\
82 \012\000\018\000\018\000\028\000\003\000\004\000\018\000\005\000\
83 \018\000\036\000\006\000\018\000\032\000\033\000\034\000\035\000\
84 \020\000\037\000\039\000\010\000\038\000\012\000\022\000\022\000\
85 \022\000\022\000\040\000\022\000\028\000\022\000\042\000\010\000\
86 \022\000\012\000\016\000\007\000\016\000\016\000\016\000\016\000\
87 \016\000\016\000\030\000\016\000\007\000\008\000\016\000\019\000\
88 \019\000\022\000\022\000\028\000\019\000\013\000\019\000\000\000\
89 \000\000\019\000\020\000\020\000\020\000\020\000\004\000\020\000\
90 \004\000\020\000\000\000\004\000\020\000\021\000\021\000\021\000\
91 \021\000\014\000\021\000\014\000\021\000\000\000\014\000\021\000\
92 \003\000\004\000\022\000\023\000\024\000\025\000\006\000\000\000\
93 \000\000\041\000\003\000\004\000\022\000\023\000\024\000\025\000\
94 \006\000\031\000\003\000\004\000\022\000\023\000\024\000\025\000\
95 \006\000\003\000\004\000\000\000\000\000\024\000\025\000\006\000\
96 \003\000\004\000\000\000\005\000\003\000\004\000\006\000\000\000\
97 \000\000\000\000\006\000"
98
99 let yycheck = "\001\000\
100 \012\001\001\000\002\001\005\000\006\000\008\000\008\000\001\000\
101 \008\000\003\001\004\001\011\001\001\001\002\001\008\001\004\001\
102 \010\001\009\001\007\001\013\001\022\000\023\000\024\000\025\000\
103 \013\001\002\001\029\000\029\000\028\000\029\000\003\001\004\001\
104 \005\001\006\001\036\000\008\001\011\001\010\001\041\000\041\000\
105 \013\001\041\000\001\001\002\001\003\001\004\001\005\001\006\001\
106 \007\001\008\001\002\001\010\001\011\001\002\001\013\001\003\001\
107 \004\001\005\001\006\001\011\001\008\001\012\001\010\001\255\255\
108 \255\255\013\001\003\001\004\001\005\001\006\001\008\001\008\001\
109 \010\001\010\001\255\255\013\001\013\001\003\001\004\001\005\001\
110 \006\001\008\001\008\001\010\001\010\001\255\255\013\001\013\001\
111 \001\001\002\001\003\001\004\001\005\001\006\001\007\001\255\255\
112 \255\255\010\001\001\001\002\001\003\001\004\001\005\001\006\001\
113 \007\001\008\001\001\001\002\001\003\001\004\001\005\001\006\001\
114 \007\001\001\001\002\001\255\255\255\255\005\001\006\001\007\001\
115 \001\001\002\001\255\255\004\001\001\001\002\001\007\001\255\255\
116 \255\255\255\255\007\001"
117
118 let yynames_const = "\
119 PLUS\000\
120 MINUS\000\
121 TIMES\000\
122 DIV\000\
123 LPAREN\000\
124 RPAREN\000\
125 ASSIGN\000\
126 IN\000\
127 IMPLY\000\
128 FUNC\000\
129 EOL\000\
130 "
131
132 let yynames_block = "\
133 INT\000\
134 ID\000\
135 "
136
137 let yyact = [|
138 (fun _ -> failwith "parser")
139 ; (fun __caml_parser_env ->
140 let _1 = (Parsing.peek_val __caml_parser_env 1 : 'blocks) in
141 Obj.repr(
142 # 15 "parser.mly"
143 ( _1 )
144 # 145 "parser.ml"
145 : Ast.ast))
146 ; (fun __caml_parser_env ->
147 let _1 = (Parsing.peek_val __caml_parser_env 0 : 'block) in
148 Obj.repr(
149 # 18 "parser.mly"
150 ( _1 )
151 # 152 "parser.ml"
152 : 'blocks))
153 ; (fun __caml_parser_env ->
154 let _1 = (Parsing.peek_val __caml_parser_env 1 : 'blocks) in
155 let _2 = (Parsing.peek_val __caml_parser_env 0 : 'block) in
156 Obj.repr(
157 # 19 "parser.mly"
158 (match _1 with Ast.Node x -> Ast.Node (x @ [_2])
159 | Ast.Int x -> Ast.Node[_1; _2] | Ast.Leaf x -> Ast.Node [_1; _2])
160 # 161 "parser.ml"
161 : 'blocks))
162 ; (fun __caml_parser_env ->
163 let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
164 Obj.repr(
165 # 24 "parser.mly"
166 (_1)
167 # 168 "parser.ml"
168 : 'block))
169 ; (fun __caml_parser_env ->
170 let _1 = (Parsing.peek_val __caml_parser_env 0 : 'let_bind) in
171 Obj.repr(
172 # 25 "parser.mly"
173 (_1)
174 # 175 "parser.ml"
175 : 'block))
176 ; (fun __caml_parser_env ->
177 let _1 = (Parsing.peek_val __caml_parser_env 5 : 'typ) in
178 let _2 = (Parsing.peek_val __caml_parser_env 4 : string) in
179 let _4 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
180 let _6 = (Parsing.peek_val __caml_parser_env 0 : 'block) in
181 Obj.repr(
182 # 29 "parser.mly"
183 (Ast.Node [Ast.Leaf "%let"; Ast.Node[_1; Ast.Leaf _2; _4]; _6])
184 # 185 "parser.ml"
185 : 'let_bind))
186 ; (fun __caml_parser_env ->
187 let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in
188 Obj.repr(
189 # 33 "parser.mly"
190 (Ast.Leaf _1)
191 # 192 "parser.ml"
192 : 'typ))
193 ; (fun __caml_parser_env ->
194 let _1 = (Parsing.peek_val __caml_parser_env 2 : 'typ) in
195 let _3 = (Parsing.peek_val __caml_parser_env 0 : 'typ) in
196 Obj.repr(
197 # 34 "parser.mly"
198 (Ast.Node [Ast.Leaf "->"; _1 ; _3])
199 # 200 "parser.ml"
200 : 'typ))
201 ; (fun __caml_parser_env ->
202 let _1 = (Parsing.peek_val __caml_parser_env 0 : 'app_expr) in
203 Obj.repr(
204 # 37 "parser.mly"
205 (_1)
206 # 207 "parser.ml"
207 : 'expr))
208 ; (fun __caml_parser_env ->
209 let _1 = (Parsing.peek_val __caml_parser_env 0 : 'bin_expr) in
210 Obj.repr(
211 # 38 "parser.mly"
212 (_1)
213 # 214 "parser.ml"
214 : 'expr))
215 ; (fun __caml_parser_env ->
216 let _1 = (Parsing.peek_val __caml_parser_env 0 : 'lam_expr) in
217 Obj.repr(
218 # 39 "parser.mly"
219 (_1)
220 # 221 "parser.ml"
221 : 'expr))
222 ; (fun __caml_parser_env ->
223 let _1 = (Parsing.peek_val __caml_parser_env 2 : 'arg) in
224 let _3 = (Parsing.peek_val __caml_parser_env 0 : 'block) in
225 Obj.repr(
226 # 43 "parser.mly"
227 (Ast.Node [Ast.Leaf "%lambda"; _1 ; _3])
228 # 229 "parser.ml"
229 : 'lam_expr))
230 ; (fun __caml_parser_env ->
231 let _1 = (Parsing.peek_val __caml_parser_env 1 : 'typ) in
232 let _2 = (Parsing.peek_val __caml_parser_env 0 : string) in
233 Obj.repr(
234 # 46 "parser.mly"
235 ( Ast.Node [_1;Ast.Leaf _2] )
236 # 237 "parser.ml"
237 : 'arg))
238 ; (fun __caml_parser_env ->
239 let _1 = (Parsing.peek_val __caml_parser_env 1 : 'expr) in
240 let _2 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
241 Obj.repr(
242 # 50 "parser.mly"
243 ( Ast.Node [ Ast.Leaf "%apply"; _1; _2] )
244 # 245 "parser.ml"
245 : 'app_expr))
246 ; (fun __caml_parser_env ->
247 let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in
248 Obj.repr(
249 # 54 "parser.mly"
250 ( Ast.Int (int_of_string _1))
251 # 252 "parser.ml"
252 : 'bin_expr))
253 ; (fun __caml_parser_env ->
254 let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in
255 Obj.repr(
256 # 55 "parser.mly"
257 ( Ast.Leaf _1 )
258 # 259 "parser.ml"
259 : 'bin_expr))
260 ; (fun __caml_parser_env ->
261 let _2 = (Parsing.peek_val __caml_parser_env 1 : 'expr) in
262 Obj.repr(
263 # 56 "parser.mly"
264 ( _2 )
265 # 266 "parser.ml"
266 : 'bin_expr))
267 ; (fun __caml_parser_env ->
268 let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
269 let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
270 Obj.repr(
271 # 57 "parser.mly"
272 ( Ast.Node [ Ast.Leaf "+"; _1; _3] )
273 # 274 "parser.ml"
274 : 'bin_expr))
275 ; (fun __caml_parser_env ->
276 let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
277 let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
278 Obj.repr(
279 # 58 "parser.mly"
280 ( Ast.Node[ Ast.Leaf "-"; _1 ; _3] )
281 # 282 "parser.ml"
282 : 'bin_expr))
283 ; (fun __caml_parser_env ->
284 let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
285 let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
286 Obj.repr(
287 # 59 "parser.mly"
288 ( Ast.Node[ Ast.Leaf "*"; _1 ;_3] )
289 # 290 "parser.ml"
290 : 'bin_expr))
291 ; (fun __caml_parser_env ->
292 let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
293 let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
294 Obj.repr(
295 # 60 "parser.mly"
296 ( Ast.Node[ Ast.Leaf "/"; _1; _3] )
297 # 298 "parser.ml"
298 : 'bin_expr))
299 ; (fun __caml_parser_env ->
300 let _2 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
301 Obj.repr(
302 # 61 "parser.mly"
303 ( Ast.Node[ Ast.Leaf "-" ; _2] )
304 # 305 "parser.ml"
305 : 'bin_expr))
306 (* Entry main *)
307 ; (fun __caml_parser_env -> raise (Parsing.YYexit (Parsing.peek_val __caml_parser_env 0)))
308 |]
309 let yytables =
310 { Parsing.actions=yyact;
311 Parsing.transl_const=yytransl_const;
312 Parsing.transl_block=yytransl_block;
313 Parsing.lhs=yylhs;
314 Parsing.len=yylen;
315 Parsing.defred=yydefred;
316 Parsing.dgoto=yydgoto;
317 Parsing.sindex=yysindex;
318 Parsing.rindex=yyrindex;
319 Parsing.gindex=yygindex;
320 Parsing.tablesize=yytablesize;
321 Parsing.table=yytable;
322 Parsing.check=yycheck;
323 Parsing.error_function=parse_error;
324 Parsing.names_const=yynames_const;
325 Parsing.names_block=yynames_block }
326 let main (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =
327 (Parsing.yyparse yytables 1 lexfun lexbuf : Ast.ast)