ajout parser et lexer (prof au niveau de RecFunctions)

This commit is contained in:
Nicolas PENELOUX 2023-10-11 20:16:46 +02:00
parent 35ecae440b
commit 04e06654de
2 changed files with 51 additions and 2 deletions

View file

@ -30,6 +30,7 @@ let integers = '-'? (digit+
let ident = ['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']* let ident = ['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']*
let constr_id = ['A'-'Z']['A'-'Z' 'a'-'z' '0'-'9' '_']* let constr_id = ['A'-'Z']['A'-'Z' 'a'-'z' '0'-'9' '_']*
let type_variable = '\''ident let type_variable = '\''ident
(*TODO type_con*)
let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"<?" |">?" let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"<?" |">?"
@ -65,6 +66,13 @@ rule token = parse
(** Operators *) (** Operators *)
| '=' { EQUAL } | '=' { EQUAL }
(* ponctuation *)
| '(' { LPAREN }
| ')' { RPAREN }
| '[' { LBRACK }
| ']' { RBRACK }
| '_' { WILDCARD }
(** Values *) (** Values *)
| integers as i { INT (Mint.of_string i) } | integers as i { INT (Mint.of_string i) }

View file

@ -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<Mint.t> INT %token<Mint.t> INT
%token<string> ID %token<string> ID TID
%start<HopixAST.t> program %start<HopixAST.t> program
@ -28,6 +28,47 @@ vdefinition: // manque le type ici, on met None en attendant
| LET i=located(identifier) EQUAL e=located(expression) { | LET i=located(identifier) EQUAL e=located(expression) {
SimpleValue(i, None, e) 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: expression:
| l=located(literal) { | l=located(literal) {