327 lines
11 KiB
OCaml
327 lines
11 KiB
OCaml
type token =
|
|
| INT of (string)
|
|
| ID of (string)
|
|
| PLUS
|
|
| MINUS
|
|
| TIMES
|
|
| DIV
|
|
| LPAREN
|
|
| RPAREN
|
|
| ASSIGN
|
|
| IN
|
|
| IMPLY
|
|
| FUNC
|
|
| EOL
|
|
|
|
open Parsing;;
|
|
let _ = parse_error;;
|
|
let yytransl_const = [|
|
|
259 (* PLUS *);
|
|
260 (* MINUS *);
|
|
261 (* TIMES *);
|
|
262 (* DIV *);
|
|
263 (* LPAREN *);
|
|
264 (* RPAREN *);
|
|
265 (* ASSIGN *);
|
|
266 (* IN *);
|
|
267 (* IMPLY *);
|
|
268 (* FUNC *);
|
|
269 (* EOL *);
|
|
0|]
|
|
|
|
let yytransl_block = [|
|
|
257 (* INT *);
|
|
258 (* ID *);
|
|
0|]
|
|
|
|
let yylhs = "\255\255\
|
|
\001\000\002\000\002\000\003\000\003\000\005\000\006\000\006\000\
|
|
\004\000\004\000\004\000\009\000\010\000\007\000\008\000\008\000\
|
|
\008\000\008\000\008\000\008\000\008\000\008\000\000\000"
|
|
|
|
let yylen = "\002\000\
|
|
\002\000\001\000\002\000\001\000\001\000\006\000\001\000\003\000\
|
|
\001\000\001\000\001\000\003\000\002\000\002\000\001\000\001\000\
|
|
\003\000\003\000\003\000\003\000\003\000\002\000\002\000"
|
|
|
|
let yydefred = "\000\000\
|
|
\000\000\000\000\015\000\000\000\000\000\000\000\023\000\000\000\
|
|
\002\000\000\000\005\000\000\000\009\000\010\000\011\000\000\000\
|
|
\000\000\000\000\000\000\001\000\003\000\000\000\000\000\000\000\
|
|
\000\000\000\000\000\000\000\000\000\000\013\000\017\000\000\000\
|
|
\000\000\000\000\000\000\000\000\007\000\000\000\012\000\000\000\
|
|
\000\000\006\000"
|
|
|
|
let yydgoto = "\002\000\
|
|
\007\000\008\000\009\000\026\000\011\000\018\000\013\000\014\000\
|
|
\015\000\016\000"
|
|
|
|
let yysindex = "\007\000\
|
|
\120\255\000\000\000\000\000\000\120\255\120\255\000\000\012\255\
|
|
\000\000\106\255\000\000\001\255\000\000\000\000\000\000\245\254\
|
|
\124\255\049\255\098\255\000\000\000\000\120\255\120\255\120\255\
|
|
\120\255\106\255\009\255\024\255\120\255\000\000\000\000\113\255\
|
|
\124\255\124\255\124\255\120\255\000\000\026\255\000\000\088\255\
|
|
\120\255\000\000"
|
|
|
|
let yyrindex = "\000\000\
|
|
\000\000\000\000\000\000\042\255\000\000\000\000\000\000\000\000\
|
|
\000\000\063\255\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
\028\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
\000\000\074\255\050\255\000\000\000\000\000\000\000\000\007\255\
|
|
\053\255\064\255\075\255\000\000\000\000\052\255\000\000\000\000\
|
|
\000\000\000\000"
|
|
|
|
let yygindex = "\000\000\
|
|
\000\000\000\000\254\255\255\255\000\000\001\000\000\000\000\000\
|
|
\000\000\000\000"
|
|
|
|
let yytablesize = 131
|
|
let yytable = "\010\000\
|
|
\029\000\012\000\027\000\017\000\019\000\021\000\010\000\001\000\
|
|
\012\000\018\000\018\000\028\000\003\000\004\000\018\000\005\000\
|
|
\018\000\036\000\006\000\018\000\032\000\033\000\034\000\035\000\
|
|
\020\000\037\000\039\000\010\000\038\000\012\000\022\000\022\000\
|
|
\022\000\022\000\040\000\022\000\028\000\022\000\042\000\010\000\
|
|
\022\000\012\000\016\000\007\000\016\000\016\000\016\000\016\000\
|
|
\016\000\016\000\030\000\016\000\007\000\008\000\016\000\019\000\
|
|
\019\000\022\000\022\000\028\000\019\000\013\000\019\000\000\000\
|
|
\000\000\019\000\020\000\020\000\020\000\020\000\004\000\020\000\
|
|
\004\000\020\000\000\000\004\000\020\000\021\000\021\000\021\000\
|
|
\021\000\014\000\021\000\014\000\021\000\000\000\014\000\021\000\
|
|
\003\000\004\000\022\000\023\000\024\000\025\000\006\000\000\000\
|
|
\000\000\041\000\003\000\004\000\022\000\023\000\024\000\025\000\
|
|
\006\000\031\000\003\000\004\000\022\000\023\000\024\000\025\000\
|
|
\006\000\003\000\004\000\000\000\000\000\024\000\025\000\006\000\
|
|
\003\000\004\000\000\000\005\000\003\000\004\000\006\000\000\000\
|
|
\000\000\000\000\006\000"
|
|
|
|
let yycheck = "\001\000\
|
|
\012\001\001\000\002\001\005\000\006\000\008\000\008\000\001\000\
|
|
\008\000\003\001\004\001\011\001\001\001\002\001\008\001\004\001\
|
|
\010\001\009\001\007\001\013\001\022\000\023\000\024\000\025\000\
|
|
\013\001\002\001\029\000\029\000\028\000\029\000\003\001\004\001\
|
|
\005\001\006\001\036\000\008\001\011\001\010\001\041\000\041\000\
|
|
\013\001\041\000\001\001\002\001\003\001\004\001\005\001\006\001\
|
|
\007\001\008\001\002\001\010\001\011\001\002\001\013\001\003\001\
|
|
\004\001\005\001\006\001\011\001\008\001\012\001\010\001\255\255\
|
|
\255\255\013\001\003\001\004\001\005\001\006\001\008\001\008\001\
|
|
\010\001\010\001\255\255\013\001\013\001\003\001\004\001\005\001\
|
|
\006\001\008\001\008\001\010\001\010\001\255\255\013\001\013\001\
|
|
\001\001\002\001\003\001\004\001\005\001\006\001\007\001\255\255\
|
|
\255\255\010\001\001\001\002\001\003\001\004\001\005\001\006\001\
|
|
\007\001\008\001\001\001\002\001\003\001\004\001\005\001\006\001\
|
|
\007\001\001\001\002\001\255\255\255\255\005\001\006\001\007\001\
|
|
\001\001\002\001\255\255\004\001\001\001\002\001\007\001\255\255\
|
|
\255\255\255\255\007\001"
|
|
|
|
let yynames_const = "\
|
|
PLUS\000\
|
|
MINUS\000\
|
|
TIMES\000\
|
|
DIV\000\
|
|
LPAREN\000\
|
|
RPAREN\000\
|
|
ASSIGN\000\
|
|
IN\000\
|
|
IMPLY\000\
|
|
FUNC\000\
|
|
EOL\000\
|
|
"
|
|
|
|
let yynames_block = "\
|
|
INT\000\
|
|
ID\000\
|
|
"
|
|
|
|
let yyact = [|
|
|
(fun _ -> failwith "parser")
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 1 : 'blocks) in
|
|
Obj.repr(
|
|
# 15 "parser.mly"
|
|
( _1 )
|
|
# 145 "parser.ml"
|
|
: Ast.ast))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'block) in
|
|
Obj.repr(
|
|
# 18 "parser.mly"
|
|
( _1 )
|
|
# 152 "parser.ml"
|
|
: 'blocks))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 1 : 'blocks) in
|
|
let _2 = (Parsing.peek_val __caml_parser_env 0 : 'block) in
|
|
Obj.repr(
|
|
# 19 "parser.mly"
|
|
(match _1 with Ast.Node x -> Ast.Node (x @ [_2])
|
|
| Ast.Int x -> Ast.Node[_1; _2] | Ast.Leaf x -> Ast.Node [_1; _2])
|
|
# 161 "parser.ml"
|
|
: 'blocks))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
|
|
Obj.repr(
|
|
# 24 "parser.mly"
|
|
(_1)
|
|
# 168 "parser.ml"
|
|
: 'block))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'let_bind) in
|
|
Obj.repr(
|
|
# 25 "parser.mly"
|
|
(_1)
|
|
# 175 "parser.ml"
|
|
: 'block))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 5 : 'typ) in
|
|
let _2 = (Parsing.peek_val __caml_parser_env 4 : string) in
|
|
let _4 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
|
|
let _6 = (Parsing.peek_val __caml_parser_env 0 : 'block) in
|
|
Obj.repr(
|
|
# 29 "parser.mly"
|
|
(Ast.Node [Ast.Leaf "%let"; Ast.Node[_1; Ast.Leaf _2; _4]; _6])
|
|
# 185 "parser.ml"
|
|
: 'let_bind))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in
|
|
Obj.repr(
|
|
# 33 "parser.mly"
|
|
(Ast.Leaf _1)
|
|
# 192 "parser.ml"
|
|
: 'typ))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'typ) in
|
|
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'typ) in
|
|
Obj.repr(
|
|
# 34 "parser.mly"
|
|
(Ast.Node [Ast.Leaf "->"; _1 ; _3])
|
|
# 200 "parser.ml"
|
|
: 'typ))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'app_expr) in
|
|
Obj.repr(
|
|
# 37 "parser.mly"
|
|
(_1)
|
|
# 207 "parser.ml"
|
|
: 'expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'bin_expr) in
|
|
Obj.repr(
|
|
# 38 "parser.mly"
|
|
(_1)
|
|
# 214 "parser.ml"
|
|
: 'expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'lam_expr) in
|
|
Obj.repr(
|
|
# 39 "parser.mly"
|
|
(_1)
|
|
# 221 "parser.ml"
|
|
: 'expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'arg) in
|
|
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'block) in
|
|
Obj.repr(
|
|
# 43 "parser.mly"
|
|
(Ast.Node [Ast.Leaf "%lambda"; _1 ; _3])
|
|
# 229 "parser.ml"
|
|
: 'lam_expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 1 : 'typ) in
|
|
let _2 = (Parsing.peek_val __caml_parser_env 0 : string) in
|
|
Obj.repr(
|
|
# 46 "parser.mly"
|
|
( Ast.Node [_1;Ast.Leaf _2] )
|
|
# 237 "parser.ml"
|
|
: 'arg))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 1 : 'expr) in
|
|
let _2 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
|
|
Obj.repr(
|
|
# 50 "parser.mly"
|
|
( Ast.Node [ Ast.Leaf "%apply"; _1; _2] )
|
|
# 245 "parser.ml"
|
|
: 'app_expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in
|
|
Obj.repr(
|
|
# 54 "parser.mly"
|
|
( Ast.Int (int_of_string _1))
|
|
# 252 "parser.ml"
|
|
: 'bin_expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 0 : string) in
|
|
Obj.repr(
|
|
# 55 "parser.mly"
|
|
( Ast.Leaf _1 )
|
|
# 259 "parser.ml"
|
|
: 'bin_expr))
|
|
; (fun __caml_parser_env ->
|
|
let _2 = (Parsing.peek_val __caml_parser_env 1 : 'expr) in
|
|
Obj.repr(
|
|
# 56 "parser.mly"
|
|
( _2 )
|
|
# 266 "parser.ml"
|
|
: 'bin_expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
|
|
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
|
|
Obj.repr(
|
|
# 57 "parser.mly"
|
|
( Ast.Node [ Ast.Leaf "+"; _1; _3] )
|
|
# 274 "parser.ml"
|
|
: 'bin_expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
|
|
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
|
|
Obj.repr(
|
|
# 58 "parser.mly"
|
|
( Ast.Node[ Ast.Leaf "-"; _1 ; _3] )
|
|
# 282 "parser.ml"
|
|
: 'bin_expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
|
|
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
|
|
Obj.repr(
|
|
# 59 "parser.mly"
|
|
( Ast.Node[ Ast.Leaf "*"; _1 ;_3] )
|
|
# 290 "parser.ml"
|
|
: 'bin_expr))
|
|
; (fun __caml_parser_env ->
|
|
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr) in
|
|
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
|
|
Obj.repr(
|
|
# 60 "parser.mly"
|
|
( Ast.Node[ Ast.Leaf "/"; _1; _3] )
|
|
# 298 "parser.ml"
|
|
: 'bin_expr))
|
|
; (fun __caml_parser_env ->
|
|
let _2 = (Parsing.peek_val __caml_parser_env 0 : 'expr) in
|
|
Obj.repr(
|
|
# 61 "parser.mly"
|
|
( Ast.Node[ Ast.Leaf "-" ; _2] )
|
|
# 305 "parser.ml"
|
|
: 'bin_expr))
|
|
(* Entry main *)
|
|
; (fun __caml_parser_env -> raise (Parsing.YYexit (Parsing.peek_val __caml_parser_env 0)))
|
|
|]
|
|
let yytables =
|
|
{ Parsing.actions=yyact;
|
|
Parsing.transl_const=yytransl_const;
|
|
Parsing.transl_block=yytransl_block;
|
|
Parsing.lhs=yylhs;
|
|
Parsing.len=yylen;
|
|
Parsing.defred=yydefred;
|
|
Parsing.dgoto=yydgoto;
|
|
Parsing.sindex=yysindex;
|
|
Parsing.rindex=yyrindex;
|
|
Parsing.gindex=yygindex;
|
|
Parsing.tablesize=yytablesize;
|
|
Parsing.table=yytable;
|
|
Parsing.check=yycheck;
|
|
Parsing.error_function=parse_error;
|
|
Parsing.names_const=yynames_const;
|
|
Parsing.names_block=yynames_block }
|
|
let main (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =
|
|
(Parsing.yyparse yytables 1 lexfun lexbuf : Ast.ast)
|