6
%token <string> META INT IDENT
8
%token LPAR RPAR BAR COMMA COLON BANG FUN DOT RARROW LET COLONEQ IN IF
9
%token THEN ELSE EVAL AT FOR PROP SET TYPE WILDCARD FIX
10
%token COFIX MATCH WITH END AND LBRACE RBRACE STRUCT AS SIMPL PERCENT
14
%type <Ast.constr_ast> main
17
%type <Ast.constr_ast> constr
20
%type <Ast.constr_ast> simple_constr
30
constr COMMA paren_constr { Pair($1,$3) }
36
| oper_constr { close_stack $1 }
40
BANG ne_binders DOT constr { Prod($2, $4) }
41
| FUN ne_binders type_cstr RARROW constr { Lambda($2,mk_cast $5 $3) }
42
| LET IDENT binders type_cstr COLONEQ constr IN constr
43
{ Let($2,mk_lambda $3 (mk_cast $6 $4),$8) }
44
| LET LPAR comma_binders RPAR COLONEQ constr IN constr
46
| IF constr THEN constr ELSE constr { IfCase($2,$4,$6) }
48
| EVAL rfun IN constr { Eval($2,$4) }
52
ne_comma_binders { $1 }
57
binder COMMA ne_comma_binders { $1 :: $3 }
66
/* 2 Conflits shift/reduce */
68
oper_constr oper appl_constr
69
{ parse_term $3 (parse_oper $2 $1) }
70
| oper_constr oper binder_constr
71
{ parse_term $3 (parse_oper $2 $1) }
72
| oper_constr oper { parse_oper $2 $1 }
74
| appl_constr { parse_term $1 empty }
83
simple_constr ne_appl_args { Appl($1,$2) }
84
| AT global simple_constrs { ApplExpl($2,$3) }
85
| simple_constr { $1 }
89
AT INT COLONEQ simple_constr { (Some $2,$4) }
90
| simple_constr { (None,$1) }
95
| appl_arg ne_appl_args { $1::$2 }
100
| match_constr { $1 }
101
| LPAR paren_constr RPAR { $2 }
102
| simple_constr PERCENT IDENT { Scope($3,$1) }
106
simple_constr simple_constrs { $1::$2 }
121
IDENT DOT global { $1 :: $3 }
128
{ let (id,_,_,_,_ as fx) = $2 in Fixp($1,[fx],id) }
129
| fix_kw fix_decl fix_decls FOR IDENT { Fixp($1, $2::$3, $5) }
132
fix_kw: FIX {Fix} | COFIX {CoFix}
136
IDENT binders type_cstr annot COLONEQ constr { ($1,$2,$3,$4,$6) }
140
AND fix_decl fix_decls { $2::$3 }
141
| AND fix_decl { [$2] }
145
LBRACE STRUCT IDENT RBRACE { Some $3 }
150
MATCH case_items case_type WITH branches END { Match($2,$3,$5) }
155
| case_item COMMA case_items { $1::$3 }
159
constr pred_pattern { ($1,$2) }
163
RARROW constr { Some $2 }
168
AS IDENT COLON constr { (Some $2, Some $4) }
169
| AS IDENT { (Some $2, None) }
170
| COLON constr { (None, Some $2) }
175
BAR branch_list { $2 }
181
patterns RARROW constr { [$1, $3] }
182
| patterns RARROW constr BAR branch_list { ($1,$3)::$5 }
187
| pattern COMMA patterns { $1::$3 }
191
pattern AS IDENT { PatAs($1,$3) }
192
| pattern COLON constr { PatType($1,$3) }
193
| IDENT simple_patterns { PatConstr($1,$2) }
194
| simple_pattern { $1 }
199
| LPAR pattern RPAR { $2 }
203
simple_pattern { [$1] }
204
| simple_pattern simple_patterns { $1::$2 }
209
| LPAR IDENT type_cstr RPAR { ($2,$3) }
218
| binder ne_binders { $1::$2 }