suite expressions

This commit is contained in:
Nicolas PENELOUX 2023-10-18 22:35:14 +02:00
parent 648076bb3e
commit aa664edcd4
2 changed files with 77 additions and 3 deletions

View file

@ -104,6 +104,8 @@ rule token = parse
| ',' { COMMA }
| '.' { DOT }
| '\\' {BACKSLASH }
| ":=" { ASSIGN }
| '!' { EXCLA }
(** Strings *)
| '"' { read_string (Buffer.create 16) lexbuf }

View file

@ -8,6 +8,7 @@
%token EOF LET TYPE WILDCARD STAR ARROW COLON EXTERN FUN COMMA AND EQUAL LPAREN
%token RPAREN LBRACK RBRACK LBRACE RBRACE INFERIOR SUPERIOR BINOP DO ELSE FOR
%token FROM IF MATCH PIPE REF THEN TO UNTIL WHILE AND_KW DOT SEMICOLON BACKSLASH
%token ASSIGN EXCLA
%token<Mint.t> INT
%token<string> ID TID CID STRING
@ -293,15 +294,18 @@ simple_expression:
Record(l, t_list)
}
/* Lecture de variable */
/* ! expr */
| EXCLA e=located(simple_expression) {
Read(e)
}
expression:
| e=simple_expression{
e
}
/* Field */
/* e.l */
@ -337,6 +341,74 @@ simple_expression:
Apply(e1,e2)
}
/* 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)
}
/* 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)
}
*/
/* 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)
}
/* While */
/* while ( expr ) { expr } */
| WHILE LPAREN e=located(expression) RPAREN
LBRACE e2=located(expression) RBRACE {
While(e,e2)
}
/* Do while TODO */
/* do { expr } until ( expr ) */
/* 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 {
e
}
/* Annotation de type */
/* (e : ty) */
| LPAREN e=located(expression) COLON t=located(ty) RPAREN {
TypeAnnotation(e,t)
}