typage.opp.exp 1.96 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
%{
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:
31 32
| _1 = expr _2 = EOF
    {                                ( _1 )}
33 34

expr:
35 36 37 38 39 40 41 42
| _1 = application
    {                                ( _1 )}
| _1 = expr _2 = COMMA _3 = expr
    {                                ( Paire(_1, _3) )}
| _1 = FUN _2 = IDENT _3 = ARROW _4 = expr %prec prec_fun
    {                                ( Fun(_2, _4) )}
| _1 = LET _2 = IDENT _3 = EQUAL _4 = expr _5 = IN _6 = expr %prec prec_let
    {                                ( Let(_2, _4, _6) )}
43 44

application:
45 46 47 48 49 50 51 52 53 54
| _1 = application _2 = closed_expr
    {                                ( App(_1, _2) )}
| _1 = FST _2 = closed_expr
    {                                ( Fst _2 )}
| _1 = SND _2 = closed_expr
    {                                ( Snd _2 )}
| _1 = application _2 = AT _3 = LBRACE _4 = IDENT _5 = EQUAL _6 = expr _7 = RBRACE
    {                                                  ( App (Exten _4, Paire (_1, _6)) )}
| _1 = closed_expr
    {                                ( _1 )}
55 56

closed_expr:
57 58 59 60 61 62 63 64 65 66 67 68
| _1 = IDENT
    {                        ( Var _1 )}
| _1 = OP
    {                        ( Op _1 )}
| _1 = INT
    {                        ( Const _1 )}
| _1 = LPAREN _2 = expr _3 = RPAREN
    {                        ( _2 )}
| _1 = LBRACE _2 = entries _3 = RBRACE
    {                          ( Enreg _2 )}
| _1 = closed_expr _2 = DOT _3 = IDENT
    {                          ( App (Proj _3, _1) )}
69 70

entries:
71 72 73 74
| _1 = entry
    {          ( [ _1 ] )}
| _1 = entries _2 = SEMI _3 = entry
    {                       ( _3 :: _1 )}
75 76

entry:
77 78
| _1 = IDENT _2 = EQUAL _3 = application
    {                            ( _1, _3 )}
79 80 81 82 83

%%