format
This commit is contained in:
parent
f9acb6c76e
commit
f11c33ff18
2 changed files with 104 additions and 100 deletions
|
@ -10,8 +10,6 @@
|
||||||
|
|
||||||
let error lexbuf =
|
let error lexbuf =
|
||||||
error "during lexing" (lex_join lexbuf.lex_start_p lexbuf.lex_curr_p)
|
error "during lexing" (lex_join lexbuf.lex_start_p lexbuf.lex_curr_p)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let newline = ('\010' | '\013' | "\013\010")
|
let newline = ('\010' | '\013' | "\013\010")
|
||||||
|
@ -31,13 +29,14 @@ let printable = [' ' '\t' '\n' '\r' (*33-126*)] (*pas sûr*)
|
||||||
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 = ['\'']['a'-'z']['A'-'Z' 'a'-'z' '0'-'9' '_']*
|
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*)
|
(* 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 atom = '"'
|
||||||
let char = ['\'']atom['\'']
|
let char = ['\'']atom['\'']
|
||||||
let string = ['\"']((atom | '\'' | "\\\""))['\"']
|
let string = ['\"']((atom | '\'' | "\\\""))['\"']
|
||||||
|
|
||||||
(*let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"<?" |">?"*)
|
(* let binop = '+' | '-' | '*' | '/' | "&&" | "||"| "=?"| "<=?" |">=?" |"<?" |">?" *)
|
||||||
|
|
||||||
|
|
||||||
rule token = parse
|
rule token = parse
|
||||||
|
@ -46,7 +45,7 @@ rule token = parse
|
||||||
| blank+ { token lexbuf }
|
| blank+ { token lexbuf }
|
||||||
| eof { EOF }
|
| eof { EOF }
|
||||||
| "{*" { commentary lexbuf; token lexbuf }
|
| "{*" { commentary lexbuf; token lexbuf }
|
||||||
| "##" {commentary_line lexbuf}
|
| "##" { commentary_line lexbuf }
|
||||||
|
|
||||||
(** Keywords *)
|
(** Keywords *)
|
||||||
| "let" { LET }
|
| "let" { LET }
|
||||||
|
@ -68,12 +67,11 @@ rule token = parse
|
||||||
| "for" { FOR }
|
| "for" { FOR }
|
||||||
(* Fini ? *)
|
(* Fini ? *)
|
||||||
|
|
||||||
(* binar operation : pas sûr pour celui là*)
|
(** Binar operation : pas sûr pour celui là*)
|
||||||
(*
|
(* | binop as b { BINOP (* TODO *) } *)
|
||||||
| binop as b { BINOP (* TODO *) }
|
|
||||||
*)
|
|
||||||
(** Operators *)
|
(** Operators *)
|
||||||
| '=' { EQUAL }
|
(* | '=' { EQUAL } *)
|
||||||
|
|
||||||
(* ponctuation *)
|
(* ponctuation *)
|
||||||
| '(' { LPAREN }
|
| '(' { LPAREN }
|
||||||
|
|
|
@ -19,86 +19,89 @@ program:
|
||||||
definition
|
definition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
definition:
|
definition:
|
||||||
| v=vdefinition {
|
| v=vdefinition {
|
||||||
DefineValue v
|
DefineValue v
|
||||||
}
|
}
|
||||||
|
|
||||||
vdefinition: // manque le type ici, on met None en attendant
|
|
||||||
|
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)
|
||||||
}(*
|
}
|
||||||
| LET i=located(identifier) DPOINT ts=located(type_scheme) EQUAL e=located(expression){
|
/* // marche pas
|
||||||
|
| LET i=located(identifier) DPOINT ts=located(type_scheme) EQUAL e=located(expression) {
|
||||||
SimpleValue(i,ts,e)
|
SimpleValue(i,ts,e)
|
||||||
}*)
|
} */
|
||||||
(* marche pas*)
|
/* fun : int f a = 1 */
|
||||||
|
|
||||||
| FUN f=fundef {
|
| FUN f=fundef {
|
||||||
RecFunctions([f])
|
RecFunctions([f])
|
||||||
}
|
}
|
||||||
(*fun : int f a = 1*)
|
|
||||||
|
|
||||||
(* de même*)
|
|
||||||
|
/* de même */
|
||||||
fundef:
|
fundef:
|
||||||
|(*ts est temp*) i=located(identifier) p=pattern EQUAL e=located(expression){
|
/* ts est temp */
|
||||||
FunctionDefinition(p,e)
|
| 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)
|
/* ts est temp */
|
||||||
}
|
| DPOINT ts=located(type_scheme) i=located(identifier) p=pattern EQUAL e=located(expression) {
|
||||||
|
FunctionDefinition(p, e)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pattern:
|
pattern:
|
||||||
| i=located(identifier){
|
| i=located(identifier) {
|
||||||
PVariable i
|
PVariable i
|
||||||
}
|
}
|
||||||
| WILDCARD {
|
| WILDCARD {
|
||||||
PWildcard
|
PWildcard
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ty:
|
ty:
|
||||||
| tc = type_constructor{
|
| tc = type_constructor {
|
||||||
TyCon(tc,None)
|
TyCon(tc, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
(* Todo version avec l'optionnel*)
|
(* Todo version avec l'optionnel*)
|
||||||
|
| ty1=located(ty) ARROW ty2=located(ty) {
|
||||||
| ty1=located(ty) ARROW ty2=located(ty){
|
TyArrow(ty1, ty2)
|
||||||
TyArrow(ty1,ty2)
|
}
|
||||||
}
|
| ty1=located(ty) STAR ty2=located(ty) {
|
||||||
| ty1=located(ty) STAR ty2=located(ty){
|
TyTuple([ty1; ty2])
|
||||||
TyTuple([ty1;ty2])
|
}
|
||||||
}
|
| ty1=located(ty) STAR ty2=located(ty) STAR liste_ty = separated_list(STAR,located(ty)) {
|
||||||
| ty1=located(ty) STAR ty2= located(ty) STAR liste_ty = separated_list(STAR,located(ty)){
|
|
||||||
TyTuple(ty1::ty2::liste_ty)
|
TyTuple(ty1::ty2::liste_ty)
|
||||||
}
|
}
|
||||||
| LPAREN type_var=type_variable RPAREN {
|
| LPAREN type_var=type_variable RPAREN {
|
||||||
TyVar type_var
|
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_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:
|
type_variable:
|
||||||
| tid=TID {
|
| tid=TID {
|
||||||
TId tid
|
TId tid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type_constructor:
|
type_constructor:
|
||||||
| tcon = TID {
|
| tcon = TID {
|
||||||
TCon tcon
|
TCon tcon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
expression:
|
expression:
|
||||||
|
@ -106,16 +109,19 @@ expression:
|
||||||
Literal l
|
Literal l
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
literal:
|
literal:
|
||||||
| i=INT {
|
| i=INT {
|
||||||
LInt i
|
LInt i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
identifier:
|
identifier:
|
||||||
| i=ID {
|
| i=ID {
|
||||||
Id i
|
Id i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
%inline located(X): x=X {
|
%inline located(X): x=X {
|
||||||
Position.with_poss $startpos $endpos x
|
Position.with_poss $startpos $endpos x
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue