typage.opp.exp 1.15 KB
Newer Older
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
%{
open Records
%}
%start expression
%token SND
%token SEMI
%token RPAREN
%token RBRACE
%token <string> OP
%token LPAREN
%token LET
%token LBRACE
%token <int> INT
%token IN
%token <string> IDENT
%token FUN
%token FST
%token EQUAL
%token EOF
%token DOT
%token AT
%token ARROW
%token COMMA
%right prec_fun 
%right prec_let 
%right COMMA 
%type <Records.expression> expression
%%

expression:
| expr EOF
    { $1 }

expr:
| application
    { $1 }
| expr COMMA expr
    { Paire($1, $3) }
| FUN IDENT ARROW expr %prec prec_fun
    { Fun($2, $4) }
| LET IDENT EQUAL expr IN expr %prec prec_let
    { Let($2, $4, $6) }

application:
| application closed_expr
    { App($1, $2) }
| FST closed_expr
    { Fst $2 }
| SND closed_expr
    { Snd $2 }
| application AT LBRACE IDENT EQUAL expr RBRACE
    { App (Exten $4, Paire ($1, $6)) }
| closed_expr
    { $1 }

closed_expr:
| IDENT
    { Var $1 }
| OP
    { Op $1 }
| INT
    { Const $1 }
| LPAREN expr RPAREN
    { $2 }
| LBRACE entries RBRACE
    { Enreg $2 }
| closed_expr DOT IDENT
    { App (Proj $3, $1) }

entries:
| entry
    { [ $1 ] }
| entries SEMI entry
    { $3 :: $1 }

entry:
| IDENT EQUAL application
    { $1, $3 }

%%