some definitions added
This commit is contained in:
parent
fadc63e30a
commit
3dc4a1068c
2 changed files with 56 additions and 25 deletions
|
@ -76,16 +76,20 @@ rule token = parse
|
||||||
| ')' { RPAREN }
|
| ')' { RPAREN }
|
||||||
| '[' { LBRACK }
|
| '[' { LBRACK }
|
||||||
| ']' { RBRACK }
|
| ']' { RBRACK }
|
||||||
|
| '{' { LBRACE }
|
||||||
|
| '}' { RBRACE }
|
||||||
| '_' { WILDCARD }
|
| '_' { WILDCARD }
|
||||||
| ':' { DPOINT }
|
| ':' { DPOINT }
|
||||||
| "->" { ARROW }
|
| "->" { ARROW }
|
||||||
| "<" { INFERIOR }
|
| '<' { INFERIOR }
|
||||||
| ">" { SUPERIOR }
|
| '>' { SUPERIOR }
|
||||||
|
| '|' { PIPE }
|
||||||
|
|
||||||
(** Values *)
|
(** Values *)
|
||||||
| int as i { INT (Mint.of_string i) }
|
| int as i { INT (Mint.of_string i) }
|
||||||
| ident as s { ID s }
|
| ident as s { ID s }
|
||||||
| type_variable as s { TID s }
|
| type_variable as s { TID s }
|
||||||
|
| constr_id as s { CID s }
|
||||||
|
|
||||||
(** Lexing error *)
|
(** Lexing error *)
|
||||||
| _ { error lexbuf "unexpected character." }
|
| _ { error lexbuf "unexpected character." }
|
||||||
|
|
|
@ -1,58 +1,80 @@
|
||||||
%{ (* -*- tuareg -*- *)
|
%{ (* -*- tuareg -*- *)
|
||||||
|
|
||||||
open HopixAST
|
open HopixAST
|
||||||
open Position
|
(* open Position *)
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%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
|
/* Opérateurs à ajouter au fur et a mesure (pour réduire les warnings temporairement) :
|
||||||
|
* BINOP DO ELSE FOR FROM IF INFERIOR MATCH PIPE REF SUPERIOR THEN TO UNTIL WHILE */
|
||||||
|
%token EOF LET TYPE WILDCARD STAR ARROW DPOINT EXTERN FUN COMMA AND EQUAL LPAREN
|
||||||
|
%token RPAREN LBRACK RBRACK LBRACE RBRACE
|
||||||
|
|
||||||
%token<Mint.t> INT
|
%token<Mint.t> INT
|
||||||
%token<string> ID TID
|
%token<string> ID TID CID
|
||||||
|
|
||||||
%start<HopixAST.t> program
|
%start<HopixAST.t> program
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
program:
|
program:
|
||||||
|
/* Programme */
|
||||||
| definition=located(definition)* EOF {
|
| definition=located(definition)* EOF {
|
||||||
definition
|
definition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
definition:
|
definition:
|
||||||
|
/* Définition de types */
|
||||||
|
// Manque le 'type_variable located list' ici, on met une liste vide en attendant
|
||||||
|
| TYPE tc=located(type_constructor) EQUAL td=tdefinition {
|
||||||
|
DefineType (tc, [], td)
|
||||||
|
}
|
||||||
|
/* Valeurs externes */
|
||||||
|
| EXTERN id=located(identifier) ts=located(type_scheme) {
|
||||||
|
DeclareExtern(id, ts)
|
||||||
|
}
|
||||||
|
/* Définition de valeurs */
|
||||||
| v=vdefinition {
|
| v=vdefinition {
|
||||||
DefineValue v
|
DefineValue v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tdefinition:
|
||||||
|
/* Type sommes */
|
||||||
|
/* | option(PIPE) type_constructor option() separated_nonempty_list(COMMA, ty) {
|
||||||
|
DefineSumType()
|
||||||
|
} */
|
||||||
|
/* Type produit étiqueté */
|
||||||
|
| LBRACE lt=separated_nonempty_list(COMMA, label_with_type) RBRACE {
|
||||||
|
DefineRecordType(lt)
|
||||||
|
}
|
||||||
|
|
||||||
|
label_with_type:
|
||||||
|
| l=located(label) DPOINT t=located(ty) { l, t }
|
||||||
|
|
||||||
|
|
||||||
vdefinition:
|
vdefinition:
|
||||||
// manque le type ici, on met None en attendant
|
/* Valeur simple */
|
||||||
| LET i=located(identifier) EQUAL e=located(expression) {
|
// Manque le type ici, on met None en attendant
|
||||||
SimpleValue(i, None, e)
|
| LET i=located(identifier) DPOINT ts=option(located(type_scheme)) EQUAL e=located(expression) {
|
||||||
|
SimpleValue(i, ts, e)
|
||||||
}
|
}
|
||||||
/* // marche pas
|
/* Fonction(s)
|
||||||
| LET i=located(identifier) DPOINT ts=located(type_scheme) EQUAL e=located(expression) {
|
* Exemple :
|
||||||
SimpleValue(i,ts,e)
|
* - fun : int f a = 1
|
||||||
} */
|
* - fun f a = 1 and : int g a = 2 */
|
||||||
/* fun : int f a = 1 */
|
| FUN fs=separated_nonempty_list(AND, fundef) {
|
||||||
| FUN f=fundef {
|
RecFunctions(fs)
|
||||||
RecFunctions([f])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* de même */
|
|
||||||
fundef:
|
fundef:
|
||||||
/* ts est temp */
|
| DPOINT t=option(located(type_scheme)) i=located(identifier) p=located(pattern) EQUAL e=located(expression) {
|
||||||
| i=located(identifier) p=pattern EQUAL e=located(expression) {
|
i, t, FunctionDefinition(p, e)
|
||||||
FunctionDefinition(p, e)
|
|
||||||
}
|
}
|
||||||
/* ts est temp */
|
| i=located(identifier) p=located(pattern) EQUAL e=located(expression) {
|
||||||
| DPOINT ts=located(type_scheme) i=located(identifier) p=located(pattern) EQUAL e=located(expression) {
|
i, None, FunctionDefinition(p, e)
|
||||||
FunctionDefinition(p, e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pattern:
|
pattern:
|
||||||
| i=located(identifier) {
|
| i=located(identifier) {
|
||||||
PVariable i
|
PVariable i
|
||||||
|
@ -100,7 +122,7 @@ type_variable:
|
||||||
|
|
||||||
|
|
||||||
type_constructor:
|
type_constructor:
|
||||||
| tcon=TID {
|
| tcon=CID {
|
||||||
TCon tcon
|
TCon tcon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +138,11 @@ literal:
|
||||||
LInt i
|
LInt i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label:
|
||||||
|
| i=ID {
|
||||||
|
LId i
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
identifier:
|
identifier:
|
||||||
| i=ID {
|
| i=ID {
|
||||||
|
|
Reference in a new issue