diff --git a/flap/src/hopix/hopixLexer.mll b/flap/src/hopix/hopixLexer.mll index 6808086..6523454 100644 --- a/flap/src/hopix/hopixLexer.mll +++ b/flap/src/hopix/hopixLexer.mll @@ -30,6 +30,7 @@ let integers = '-'? (digit+ let ident = ['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']* let constr_id = ['A'-'Z']['A'-'Z' 'a'-'z' '0'-'9' '_']* let type_variable = '\''ident +(*TODO type_con*) let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"?" @@ -65,6 +66,13 @@ rule token = parse (** Operators *) | '=' { EQUAL } + (* ponctuation *) + | '(' { LPAREN } + | ')' { RPAREN } + | '[' { LBRACK } + | ']' { RBRACK } + | '_' { WILDCARD } + (** Values *) | integers as i { INT (Mint.of_string i) } diff --git a/flap/src/hopix/hopixParser.mly b/flap/src/hopix/hopixParser.mly index 50e9587..af3b0d1 100644 --- a/flap/src/hopix/hopixParser.mly +++ b/flap/src/hopix/hopixParser.mly @@ -5,10 +5,10 @@ %} -%token EOF LET TYPE EXTERN FUN MATCH IF THEN ELSE REF WHILE DO UNTIL FOR FROM TO BINOP EQUAL +%token EOF LET TYPE WILDCARD EXTERN FUN MATCH IF THEN ELSE REF AND WHILE DO UNTIL FOR FROM TO BINOP EQUAL LPAREN RPAREN LBRACK RBRACK %token INT -%token ID +%token ID TID %start program @@ -28,6 +28,47 @@ vdefinition: // manque le type ici, on met None en attendant | LET i=located(identifier) EQUAL e=located(expression) { SimpleValue(i, None, e) } + (* marche pas*) +| FUN f=fundef AND* f2=fundef* { + RecFunctions([f::f2]) +} + + +(* de même*) +fundef: +|(*ts est temp*) ts= type_scheme* i=located(identifier) p=pattern EQUAL e=located(expression){ + FunctionDefinition(p,e) +} + + +pattern: +| i=located(identifier){ + PVariable i +} +| WILDCARD { + PWildcard +} + + + +ty: +| LPAREN type_var=type_variable RPAREN { + TyVar type_var +} + +type_scheme: +| LBRACK type_variable=located(type_variable)+ RBRACK ty=located(ty){ + ForallTy(type_variable,ty) +} + + +type_variable: +| tid=TID { + TId tid +} + + + expression: | l=located(literal) {