diff --git a/flap/src/hopix/hopixAST.ml b/flap/src/hopix/hopixAST.ml index d3df029..9129e63 100644 --- a/flap/src/hopix/hopixAST.ml +++ b/flap/src/hopix/hopixAST.ml @@ -110,7 +110,7 @@ and branch = | Branch of pattern located * expression located and ty = - (** An instantiated type constructor [t ]. *) + (** An instantiated type constructor [t ]. *) | TyCon of type_constructor * ty located list (** A function type [ty₁ → ty₂]. *) | TyArrow of ty located * ty located diff --git a/flap/src/hopix/hopixParser.mly b/flap/src/hopix/hopixParser.mly index e4f9871..4e3fe50 100644 --- a/flap/src/hopix/hopixParser.mly +++ b/flap/src/hopix/hopixParser.mly @@ -30,8 +30,8 @@ program: } /* Attrapes les erreurs de syntaxe */ | e=located(error) { - Error.error "parsing" (Position.position e) "Syntax error." -} + Error.error "parsing" (Position.position e) "Syntax error." + } definition: @@ -71,7 +71,9 @@ list_ty: LPAREN l=separated_nonempty_list(COMMA,located(ty)) RPAREN { label_with_type: -| l=located(label) COLON t=located(ty) { l, t } +| l=located(label) COLON t=located(ty) { + l, t + } vdefinition: @@ -108,17 +110,17 @@ fundef: * TODO : y'a environ 50 warnings ici, surtout au niveau du POr et PAnd */ branches: -| b=separated_nonempty_list(PIPE,located(branch)){ - b -} -| PIPE b = separated_nonempty_list(PIPE,located(branch)){ - b -} +| b=separated_nonempty_list(PIPE, located(branch)) { + b + } +| PIPE b=separated_nonempty_list(PIPE, located(branch)) { + b + } branch: -| p = located(pattern) ARROW e=located(expression){ - Branch(p,e) -} +| p=located(pattern) ARROW e=located(expression) { + Branch(p, e) + } simple_pattern: @@ -136,7 +138,7 @@ simple_pattern: } /* Annotation de type */ | p=located(simple_pattern) COLON ty=located(ty) { - PTypeAnnotation(p,ty) + PTypeAnnotation(p, ty) } /* Entier / Caractère / String */ | l=located(literal) { @@ -160,7 +162,7 @@ simple_pattern: | LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(pattern))) RBRACE { PRecord(l, None) } -| LBRACE l=separated_nonempty_list(COMMA,separated_pair(located(label), EQUAL, located(pattern))) RBRACE INFERIOR SUPERIOR { +| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(pattern))) RBRACE INFERIOR SUPERIOR { PRecord(l, None) } | LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(pattern))) RBRACE INFERIOR liste_ty=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR { @@ -169,17 +171,17 @@ simple_pattern: /* Disjonction */ pattern: -| p1=pattern_and{ - p1 -} +| p1=pattern_and { + p1 + } | p1=located(pattern_and) PIPE p_list=separated_nonempty_list(PIPE, located(pattern_and)) { POr(p1 :: p_list) } /* Conjonction */ pattern_and: | p1=simple_pattern{ - p1 -} + p1 + } | p1=located(simple_pattern) AND p_list=separated_nonempty_list(AND, located(simple_pattern)) { PAnd(p1 :: p_list) } @@ -194,10 +196,10 @@ pattern_list: /********************************* DATA TYPE **********************************/ /* Pour résoudre un conflit, on a du split ty en 2 règles * - * separated_nonempty_list(STAR,located(ty)) -> ty STAR separated_nonempty_list(STAR,located(ty)) + * separated_nonempty_list(STAR, located(ty)) -> ty STAR separated_nonempty_list(STAR, located(ty)) * [ ty ] -> ty * [ ty ] * ET - * ty -> ty STAR separated_nonempty_list(STAR,located(ty)) + * ty -> ty STAR separated_nonempty_list(STAR, located(ty)) * ty -> ty * [ ty ] */ simple_ty: @@ -253,112 +255,117 @@ simple_expression: | l=located(literal) { Literal l } - /* Variable */ - | i = located(identifier){ - Variable(i,None) +/* Variable */ +| i=located(identifier) { + Variable(i, None) } - | i = located(identifier) INFERIOR SUPERIOR { - Variable(i,None) +| i=located(identifier) INFERIOR SUPERIOR { + Variable(i, None) } - | i = located(identifier) INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR{ - Variable(i,t_list) +| i=located(identifier) INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR { + Variable(i, t_list) } - /* Tuple n = 0 and n > 1 */ - | LPAREN RPAREN { +/* Tuple n = 0 and n > 1 */ +| LPAREN RPAREN { Tuple([]) } - | LPAREN e=located(expression) COMMA e_list = separated_nonempty_list(COMMA,located(expression)) RPAREN { +| LPAREN e=located(expression) COMMA e_list=separated_nonempty_list(COMMA, located(expression)) RPAREN { Tuple(e::e_list) } - /* Tagged Value*/ - /* K */ - | const = located(constructor){ - Tagged(const,None,[]) +/* Tagged Value*/ +/* K */ +| const=located(constructor) { + Tagged(const, None, []) } - /* K < > */ - | const = located(constructor) INFERIOR SUPERIOR{ - Tagged(const,None,[]) +/* K < > */ +| const=located(constructor) INFERIOR SUPERIOR { + Tagged(const, None, []) } - /* K < > (e1, ..., en) */ - | const = located(constructor) INFERIOR SUPERIOR LPAREN e_list=separated_nonempty_list(COMMA,located(expression)) RPAREN { - Tagged(const,None,e_list) +/* K < > (e1, ..., en) */ +| const=located(constructor) INFERIOR SUPERIOR LPAREN e_list=separated_nonempty_list(COMMA, located(expression)) RPAREN { + Tagged(const, None, e_list) } - /* K */ - | const = located(constructor) INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR { - Tagged(const,t_list,[]) +/* K */ +| const=located(constructor) INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR { + Tagged(const, t_list, []) } - /* K (e1,...,en) */ - | const = located(constructor) INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR LPAREN e_list=separated_nonempty_list(COMMA,located(expression)) RPAREN{ - Tagged(const,t_list,e_list) +/* K (e1, ..., en) */ +| const=located(constructor) INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR LPAREN e_list=separated_nonempty_list(COMMA, located(expression)) RPAREN { + Tagged(const, t_list, e_list) } - /* Record */ - | LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE { +/* Record */ +| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE { Record(l, None) } - | LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE INFERIOR SUPERIOR { +| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE INFERIOR SUPERIOR { Record(l, None) } - | LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR{ +| LBRACE l=separated_nonempty_list(COMMA, separated_pair(located(label), EQUAL, located(expression))) RBRACE INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR { Record(l, t_list) } - /* Lecture de variable */ - /* ! expr */ - | EXCLA e=located(simple_expression) { +/* Lecture de variable */ +/* ! expr */ +| EXCLA e=located(simple_expression) { Read(e) } - - expression: - | e=simple_expression{ + +expression: +| e=simple_expression { e } - /* Field */ +/* Field */ - /* e.l */ - | e=located(expression) DOT l = located(label){ - Field(e,l,None) +/* e.l */ +| e=located(expression) DOT l=located(label) { + Field(e, l, None) } - /* e.l < > */ - | e=located(expression) DOT l = located(label) INFERIOR SUPERIOR { - Field(e,l,None) +/* e.l < > */ +| e=located(expression) DOT l=located(label) INFERIOR SUPERIOR { + Field(e, l, None) } - /* e.l */ - | e = located(expression) DOT l=located(label) INFERIOR t_list = option(separated_nonempty_list(COMMA,located(ty))) SUPERIOR { - Field(e,l,t_list) +/* e.l */ +| e=located(expression) DOT l=located(label) INFERIOR t_list=option(separated_nonempty_list(COMMA, located(ty))) SUPERIOR { + Field(e, l, t_list) } - /* Sequence */ - /* Pas sûr, voir s'il ne fuat pas une troisième couche d'expression */ - | e = located(simple_expression) SEMICOLON e_list = separated_nonempty_list(SEMICOLON,located(simple_expression)){ +/* Sequence */ +/* Pas sûr, voir s'il ne fuat pas une troisième couche d'expression */ +| e=located(simple_expression) SEMICOLON e_list=separated_nonempty_list(SEMICOLON, located(simple_expression)) { Sequence(e::e_list) } - /* Definition locale */ - | vd= vdefinition SEMICOLON e=located(expression){ - Define(vd,e) +/* Definition locale */ +| vd=vdefinition SEMICOLON e=located(expression) { + Define(vd, e) } - /* Fonction anonyme */ - | BACKSLASH p=located(pattern) ARROW e=located(expression){ - Fun(FunctionDefinition(p,e)) +/* Fonction anonyme */ +| BACKSLASH p=located(pattern) ARROW e=located(expression) { + Fun(FunctionDefinition(p, e)) } - /* Application */ - | e1=located(expression) e2=located(expression){ - Apply(e1,e2) +/* Application */ +| e1=located(expression) e2=located(expression) { + Apply(e1, e2) } +<<<<<<< HEAD +======= +/* TODO operation binaire mais j'ai pas très bien compris encore */ - /* Match (exp) {| ...| ... | ...} */ - | MATCH LPAREN e=located(expression) RPAREN - LBRACE b=branches RBRACE { - Case(e,b) - } +>>>>>>> 726daf228d20fae695ecf903491c8b62d9e6a673 +/* Match (exp) {| ...| ... | ...} */ +| MATCH LPAREN e=located(expression) RPAREN LBRACE b=branches RBRACE { + Case(e, b) + } + +<<<<<<< HEAD /* TODO if ( exp ) then { expr } j'ai RIEN COMPRIS */ /* @@ -375,46 +382,69 @@ simple_expression: } /* Reference ref expr */ +======= +/* TODO if ( exp ) then { expr } j'ai RIEN COMPRIS */ +/* | IF LPAREN e=located(expression) RPAREN + THEN LBRACE e2=located(expression) RBRACE { + IfThenElse(e, e2, None) + } */ +>>>>>>> 726daf228d20fae695ecf903491c8b62d9e6a673 - | REF e=located(expression){ +/* if ( expr ) then { expr } else { expr } */ +| IF LPAREN e=located(expression) RPAREN + THEN LBRACE e2=located(expression) RBRACE + ELSE LBRACE e3=located(expression) RBRACE { + IfThenElse(e, e2, e3) + } + +/* Reference ref expr */ +| REF e=located(expression) { Ref(e) } - /* Affectation */ - /* expr := expr */ - - | e1=located(expression) ASSIGN e2=located(expression){ - Assign(e1,e2) +/* Affectation + * expr := expr */ +| e1=located(expression) ASSIGN e2=located(expression) { + Assign(e1, e2) } - /* While */ - /* while ( expr ) { expr } */ - | WHILE LPAREN e=located(expression) RPAREN +/* While */ +/* while ( expr ) { expr } */ +| WHILE LPAREN e=located(expression) RPAREN LBRACE e2=located(expression) RBRACE { - While(e,e2) + While(e, e2) } - /* Do while TODO */ - /* do { expr } until ( expr ) */ +/* Do while + * do { expr } until ( expr ) */ +/* TODO */ - /* boucle for */ - /* for x in (e1 to e2) { expr } */ - | FOR x=located(identifier) - FROM LPAREN e1=located(expression) RPAREN TO LPAREN e2=located(expression) RPAREN - LBRACE e3=located(expression) RBRACE - { For(x,e1,e2,e3)} +/* boucle for + * for x in (e1 to e2) { expr } */ +| FOR x=located(identifier) + FROM LPAREN e1=located(expression) RPAREN TO LPAREN e2=located(expression) RPAREN + LBRACE e3=located(expression) RBRACE { + For(x, e1, e2, e3) + } - /* Parenthésage pas sûr mais je vois pas sinon*/ - | LPAREN e=expression RPAREN { +/* Parenthésage pas sûr mais je vois pas sinon */ +| LPAREN e=expression RPAREN { e } +<<<<<<< HEAD /* Annotation de type */ /* (e : ty) */ | LPAREN e=located(expression) COLON t=located(ty) RPAREN { TypeAnnotation(e,t) +======= +/* Annotation de type + * (e : ty) */ +| LPAREN e=located(expression) COLON t=located(ty) RPAREN { + TypeAnnotation(e, t) +>>>>>>> 726daf228d20fae695ecf903491c8b62d9e6a673 } @@ -428,9 +458,9 @@ simple_expression: - - + + /******************************** BASIC TYPES *********************************/ type_variable: diff --git a/flap/src/hopix/hopixPrettyPrinter.ml b/flap/src/hopix/hopixPrettyPrinter.ml index 93b9ebe..d59c79a 100644 --- a/flap/src/hopix/hopixPrettyPrinter.ml +++ b/flap/src/hopix/hopixPrettyPrinter.ml @@ -32,11 +32,12 @@ let rec program p = and definition = function | DefineType (t, ts, tdef) -> + let eq = match tdef with Abstract -> empty | _ -> string "=" in nest 2 ( group (group (string "type" ++ located type_constructor t ^^ group (type_parameters_angles ts)) - ++ string "=") + ++ eq) ++ type_definition tdef) | DeclareExtern (x, t) -> group (string "extern" ++ located identifier x diff --git a/flap/src/hopix/hopixTypes.mli b/flap/src/hopix/hopixTypes.mli index e023f3a..981d471 100644 --- a/flap/src/hopix/hopixTypes.mli +++ b/flap/src/hopix/hopixTypes.mli @@ -2,11 +2,8 @@ open HopixAST (** Abstract syntax for types. - The following internal syntax for types is the same as the one for - the types [ty] defined in {!HopixAST} except that all positions - have been erased. - - *) + The following internal syntax for types is the same as the one for the types + [ty] defined in {!HopixAST} except that all positions have been erased. *) type aty = | ATyVar of type_variable | ATyCon of type_constructor * aty list diff --git a/jalons/jalon-1.pdf b/jalons/jalon-1.pdf index 89459ec..e0ef098 100644 Binary files a/jalons/jalon-1.pdf and b/jalons/jalon-1.pdf differ