Merge branch 'nico' into jalon1/anri
This commit is contained in:
commit
f9acb6c76e
2 changed files with 98 additions and 6 deletions
|
@ -27,11 +27,18 @@ let integers = '-'? (digit+
|
|||
| bina+
|
||||
| octa+)
|
||||
|
||||
let printable = [' ' '\t' '\n' '\r' (*33-126*)] (*pas sûr*)
|
||||
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
|
||||
let type_variable = ['\'']['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']*
|
||||
(* On ne peut pas différencier au niveau du lexer var_id label_id et type_con, il faudra le faire à l'analyseur syntaxique*)
|
||||
|
||||
let atom = '"'
|
||||
let char = ['\'']atom['\'']
|
||||
let string = ['\"']((atom | '\'' | "\\\""))['\"']
|
||||
|
||||
(*let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"<?" |">?"*)
|
||||
|
||||
let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"<?" |">?"
|
||||
|
||||
rule token = parse
|
||||
(** Layout *)
|
||||
|
@ -57,14 +64,27 @@ rule token = parse
|
|||
| "for" { FOR }
|
||||
| "from" { FROM }
|
||||
| "to" { TO }
|
||||
| "and" { AND }
|
||||
| "for" { FOR }
|
||||
(* Fini ? *)
|
||||
|
||||
(* binar operation : pas sûr pour celui là*)
|
||||
(*
|
||||
| binop as b { BINOP (* TODO *) }
|
||||
|
||||
*)
|
||||
(** Operators *)
|
||||
| '=' { EQUAL }
|
||||
|
||||
(* ponctuation *)
|
||||
| '(' { LPAREN }
|
||||
| ')' { RPAREN }
|
||||
| '[' { LBRACK }
|
||||
| ']' { RBRACK }
|
||||
| '_' { WILDCARD }
|
||||
| ':' { DPOINT }
|
||||
| "->" { ARROW }
|
||||
| "<" { INFERIOR }
|
||||
| ">" { SUPERIOR }
|
||||
|
||||
(** Values *)
|
||||
| integers as i { INT (Mint.of_string i) }
|
||||
|
|
|
@ -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 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<Mint.t> INT
|
||||
%token<string> ID
|
||||
%token<string> ID TID
|
||||
|
||||
%start<HopixAST.t> program
|
||||
|
||||
|
@ -27,7 +27,79 @@ definition:
|
|||
vdefinition: // manque le type ici, on met None en attendant
|
||||
| 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){
|
||||
SimpleValue(i,ts,e)
|
||||
}*)
|
||||
(* marche pas*)
|
||||
|
||||
| FUN f=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)
|
||||
}
|
||||
|(*ts est temp*) DPOINT ts=located(type_scheme) i=located(identifier) p=pattern EQUAL e=located(expression){
|
||||
FunctionDefinition(p,e)
|
||||
}
|
||||
|
||||
|
||||
pattern:
|
||||
| i=located(identifier){
|
||||
PVariable i
|
||||
}
|
||||
| WILDCARD {
|
||||
PWildcard
|
||||
}
|
||||
|
||||
|
||||
|
||||
ty:
|
||||
| tc = type_constructor{
|
||||
TyCon(tc,None)
|
||||
}
|
||||
|
||||
(* 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)
|
||||
}
|
||||
| LPAREN type_var=type_variable RPAREN {
|
||||
TyVar type_var
|
||||
}
|
||||
|
||||
type_scheme:
|
||||
(* il faut peut être modifié le séparateur*)
|
||||
| LBRACK liste_typevar = separated_list(COMMA,located(type_variable)) RBRACK ty=located(ty){
|
||||
ForallTy(liste_typevar,ty)
|
||||
}
|
||||
| ty=located(ty){
|
||||
ForallTy([],ty)
|
||||
}
|
||||
|
||||
|
||||
type_variable:
|
||||
| tid=TID {
|
||||
TId tid
|
||||
}
|
||||
|
||||
type_constructor:
|
||||
| tcon = TID {
|
||||
TCon tcon
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
expression:
|
||||
| l=located(literal) {
|
||||
|
|
Reference in a new issue