diff --git a/flap/src/hopix/hopixLexer.mll b/flap/src/hopix/hopixLexer.mll index 2f02e21..e4eb1eb 100644 --- a/flap/src/hopix/hopixLexer.mll +++ b/flap/src/hopix/hopixLexer.mll @@ -81,7 +81,7 @@ rule token = parse | '[' { LBRACK } | ']' { RBRACK } | '_' { WILDCARD } - | ':' { DPOINT } + | ':' { COLON } | "->" { ARROW } | "<" { INFERIOR } | ">" { SUPERIOR } diff --git a/flap/src/hopix/hopixParser.mly b/flap/src/hopix/hopixParser.mly index 4dcdd8f..d808b6f 100644 --- a/flap/src/hopix/hopixParser.mly +++ b/flap/src/hopix/hopixParser.mly @@ -5,14 +5,18 @@ %} -%token EOF LET TYPE WILDCARD STAR INFERIOR SUPERIOR ARROW DPOINT EXTERN FUN MATCH COMMA IF THEN ELSE REF AND WHILE DO UNTIL FOR FROM TO BINOP EQUAL LPAREN RPAREN LBRACK RBRACK +%token EOF LET TYPE WILDCARD STAR INFERIOR SUPERIOR ARROW COLON EXTERN FUN MATCH COMMA IF THEN ELSE REF AND WHILE DO UNTIL FOR FROM TO BINOP EQUAL LPAREN RPAREN LBRACK RBRACK %token INT -%token ID TID +%token ID TID CID STRING +%token CHAR %start program %% + (************** PROGRAM ****************) + + program: | definition=located(definition)* EOF { @@ -24,30 +28,34 @@ definition: DefineValue v } -vdefinition: // manque le type ici, on met None en attendant +vdefinition: | LET i=located(identifier) EQUAL e=located(expression) { SimpleValue(i, None, e) - }(* -| LET i=located(identifier) DPOINT ts=located(type_scheme) EQUAL e=located(expression){ + } +| LET i=located(identifier) COLON ts=option(located(type_scheme)) EQUAL e=located(expression){ SimpleValue(i,ts,e) -}*) - (* marche pas*) - +} + /* | FUN f=fundef { RecFunctions([f]) +}*/ +| FUN f=separated_nonempty_list(AND,fundef){ + RecFunctions(f) } -(*fun : int f a = 1*) -(* de même*) fundef: -|(*ts est temp*) i=located(identifier) p=pattern EQUAL e=located(expression){ - FunctionDefinition(p,e) +| i=located(identifier) p=located(pattern) EQUAL e=located(expression){ + i,None,FunctionDefinition(p,e) } -|(*ts est temp*) DPOINT ts=located(type_scheme) i=located(identifier) p=pattern EQUAL e=located(expression){ - FunctionDefinition(p,e) +| DPOINT ts=option(located(type_scheme)) i=located(identifier) p=located(pattern) EQUAL e=located(expression){ + i,ts,FunctionDefinition(p,e) } + + (************* PATTERN **************) + + pattern: | i=located(identifier){ PVariable i @@ -57,22 +65,20 @@ pattern: } + (************** DATA TYPE **************) ty: | tc = type_constructor{ - TyCon(tc,None) + TyCon(tc,[]) +} +| tc= type_constructor INFERIOR liste_ty=separated_nonempty_list(COMMA,located(ty)) SUPERIOR{ + TyCon(tc,liste_ty) } - -(* Todo version avec l'optionnel*) - | ty1=located(ty) ARROW ty2=located(ty){ TyArrow(ty1,ty2) } -| ty1=located(ty) STAR ty2=located(ty){ - TyTuple([ty1;ty2]) -} -| ty1=located(ty) STAR ty2= located(ty) STAR liste_ty = separated_list(STAR,located(ty)){ - TyTuple(ty1::ty2::liste_ty) +| ty1=located(ty) STAR liste_ty = separated_nonempty_list(STAR,located(ty)){ + TyTuple(ty1::liste_ty) } | LPAREN type_var=type_variable RPAREN { TyVar type_var @@ -88,6 +94,20 @@ ty: } + (************ EXPRESSION **************) + + +expression: +| l=located(literal) { + Literal l + } + + + + (******* BASIC TYPES *********) + + + type_variable: | tid=TID { TId tid @@ -98,18 +118,21 @@ type_constructor: TCon tcon } +constructor: +| kid = CID { + KId kid +} +label: +| label = TID { + TId = label +} -expression: -| l=located(literal) { - Literal l - } - literal: -| i=INT { - LInt i - } +| i=INT { LInt i} +| c=CHAR { LChar c} +| s = STRING { LString s } identifier: | i=ID {