2010-06-21 18:19:58 +02:00
|
|
|
%{
|
|
|
|
|
|
|
|
open Signature
|
|
|
|
open Names
|
2010-07-23 19:45:19 +02:00
|
|
|
open Idents
|
2010-06-21 18:19:58 +02:00
|
|
|
open Types
|
|
|
|
open Location
|
|
|
|
open Minils
|
2010-06-27 17:24:31 +02:00
|
|
|
open Mls_utils
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
|
2010-06-21 18:19:58 +02:00
|
|
|
%}
|
|
|
|
|
|
|
|
%token DOT LPAREN RPAREN LBRACE RBRACE COLON SEMICOL
|
2010-07-27 13:31:13 +02:00
|
|
|
%token EQUAL EQUALEQUAL BARBAR COMMA BAR LET TEL CONST
|
2010-06-21 18:19:58 +02:00
|
|
|
%token <string> CONSTRUCTOR
|
|
|
|
%token <string> NAME
|
|
|
|
%token <int> INT
|
|
|
|
%token <float> FLOAT
|
|
|
|
%token <bool> BOOL
|
2010-06-29 19:03:42 +02:00
|
|
|
%token TYPE NODE RETURNS VAR OPEN
|
|
|
|
%token FBY PRE WHEN
|
2010-06-21 18:19:58 +02:00
|
|
|
%token OR STAR NOT
|
|
|
|
%token AMPERSAND
|
|
|
|
%token AMPERAMPER
|
|
|
|
%token RESET
|
2010-06-30 03:26:48 +02:00
|
|
|
%token IF THEN ELSE
|
2010-06-27 17:24:31 +02:00
|
|
|
%token DOUBLE_LESS DOUBLE_GREATER
|
2010-06-30 03:26:48 +02:00
|
|
|
%token ARROW
|
|
|
|
%token MERGE
|
|
|
|
%token POWER
|
|
|
|
%token AROBASE
|
|
|
|
%token WITH
|
|
|
|
%token DOTDOT
|
2010-06-30 15:44:56 +02:00
|
|
|
%token DEFAULT
|
2010-06-30 03:26:48 +02:00
|
|
|
%token LBRACKET RBRACKET
|
|
|
|
%token MAP FOLD MAPFOLD
|
2010-06-21 18:19:58 +02:00
|
|
|
%token <string> PREFIX
|
|
|
|
%token <string> INFIX0
|
|
|
|
%token <string> INFIX1
|
|
|
|
%token <string> INFIX2
|
|
|
|
%token <string> SUBTRACTIVE
|
|
|
|
%token <string> INFIX3
|
|
|
|
%token <string> INFIX4
|
|
|
|
%token EOF
|
|
|
|
|
2010-06-30 03:26:48 +02:00
|
|
|
%right AROBASE
|
2010-07-27 13:31:13 +02:00
|
|
|
%nonassoc DEFAULT
|
2010-06-29 19:03:42 +02:00
|
|
|
%left ELSE
|
2010-06-21 18:19:58 +02:00
|
|
|
%left OR
|
|
|
|
%left AMPERSAND
|
|
|
|
%left INFIX0 EQUAL
|
2010-06-27 17:24:31 +02:00
|
|
|
%right INFIX1 EQUALEQUAL BARBAR AMPERAMPER
|
2010-06-29 19:03:42 +02:00
|
|
|
%left INFIX2 prefixs
|
2010-06-21 18:19:58 +02:00
|
|
|
%left STAR INFIX3
|
|
|
|
%left INFIX4
|
2010-06-30 03:26:48 +02:00
|
|
|
%left WHEN
|
2010-06-21 18:19:58 +02:00
|
|
|
%right FBY
|
|
|
|
%right PRE
|
2010-06-30 15:28:53 +02:00
|
|
|
%right POWER
|
2010-06-21 18:19:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
%start program
|
|
|
|
%type <Minils.program> program
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
/** Tools **/
|
2010-06-27 17:24:31 +02:00
|
|
|
%inline slist(S, x) : l=separated_list(S, x) {l}
|
|
|
|
%inline snlist(S, x) : l=separated_nonempty_list(S, x) {l}
|
|
|
|
%inline tuple(x) : LPAREN h=x COMMA t=snlist(COMMA,x) RPAREN { h::t }
|
|
|
|
%inline option(P,x):
|
|
|
|
|/* empty */ { None }
|
|
|
|
| P v=x { Some(v) }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
|
|
|
qualified(x) :
|
2010-06-27 17:24:31 +02:00
|
|
|
| n=x { Name(n) }
|
2010-06-21 18:19:58 +02:00
|
|
|
| m=CONSTRUCTOR DOT n=x { Modname({ qual = m; id = n }) }
|
2010-06-27 17:24:31 +02:00
|
|
|
|
|
|
|
structure(field): LBRACE s=snlist(SEMICOL,field) RBRACE {s}
|
2010-07-16 17:33:14 +02:00
|
|
|
|
|
|
|
localize(x): y=x { y, (Loc($startpos(y),$endpos(y))) }
|
2010-06-27 17:24:31 +02:00
|
|
|
|
2010-06-21 18:19:58 +02:00
|
|
|
|
|
|
|
program:
|
2010-07-27 13:31:13 +02:00
|
|
|
| o=open_modules c=const_decs t=type_decs n=node_decs EOF
|
|
|
|
{ mk_program o t n c }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
open_modules: l=list(opens) {l}
|
2010-06-24 05:05:58 +02:00
|
|
|
opens: OPEN c=CONSTRUCTOR {c}
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-07-27 13:31:13 +02:00
|
|
|
const_decs: c=list(const_dec) {c}
|
|
|
|
const_dec:
|
|
|
|
| CONST n=NAME COLON t=type_ident EQUAL e=const
|
|
|
|
{ mk_const_dec n t e (Loc($startpos,$endpos)) }
|
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
name: n=NAME | LPAREN n=infix_ RPAREN | LPAREN n=prefix_ RPAREN { n }
|
|
|
|
ident: n=name { ident_of_name n }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
field_type : n=NAME COLON t=type_ident { mk_field n t }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
|
|
|
type_ident: NAME { Tid(Name($1)) }
|
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
type_decs: t=list(type_dec) {t}
|
2010-06-21 18:19:58 +02:00
|
|
|
type_dec:
|
2010-07-16 17:33:14 +02:00
|
|
|
| TYPE n=NAME
|
|
|
|
{ mk_type_dec ~loc:(Loc ($startpos,$endpos)) ~type_desc:Type_abs n }
|
|
|
|
| TYPE n=NAME EQUAL e=snlist(BAR,NAME)
|
|
|
|
{ mk_type_dec ~loc:(Loc ($startpos,$endpos)) ~type_desc:(Type_enum e) n }
|
|
|
|
| TYPE n=NAME EQUAL s=structure(field_type)
|
|
|
|
{ mk_type_dec ~loc:(Loc ($startpos,$endpos)) ~type_desc:(Type_struct s) n }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
node_decs: ns=list(node_dec) {ns}
|
2010-06-21 18:19:58 +02:00
|
|
|
node_dec:
|
2010-06-27 17:24:31 +02:00
|
|
|
NODE n=name p=params(n_param) LPAREN args=args RPAREN
|
|
|
|
RETURNS LPAREN out=args RPAREN vars=loc_vars eqs=equs
|
2010-07-16 17:33:14 +02:00
|
|
|
{ mk_node ~input:args ~output:out ~local:vars
|
|
|
|
~eq:eqs ~loc:(Loc ($startpos,$endpos)) n }
|
2010-06-27 17:24:31 +02:00
|
|
|
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
args_t: SEMICOL p=args {p}
|
|
|
|
args:
|
2010-07-27 13:31:13 +02:00
|
|
|
| /* empty */ { [] }
|
2010-06-27 17:24:31 +02:00
|
|
|
| h=var t=loption(args_t) {h@t}
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-07-27 13:31:13 +02:00
|
|
|
loc_vars_t:
|
|
|
|
| /*empty */ { [] }
|
|
|
|
| SEMICOL { [] }
|
|
|
|
| SEMICOL h=var t=loc_vars_t {h@t}
|
2010-06-27 17:24:31 +02:00
|
|
|
loc_vars_h: VAR h=var t=loc_vars_t {h@t}
|
|
|
|
loc_vars: l=loption(loc_vars_h) {l}
|
2010-06-21 18:19:58 +02:00
|
|
|
|
|
|
|
var:
|
2010-06-27 17:24:31 +02:00
|
|
|
| ns=snlist(COMMA, NAME) COLON t=type_ident
|
2010-07-16 17:33:14 +02:00
|
|
|
{ List.map (fun id -> mk_var_dec (ident_of_name id) t) ns }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
equs: LET e=slist(SEMICOL, equ) TEL { e }
|
2010-07-16 17:33:14 +02:00
|
|
|
equ: p=pat EQUAL e=exp { mk_equation ~loc:(Loc ($startpos,$endpos)) p e }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
|
|
|
pat:
|
2010-06-29 19:03:42 +02:00
|
|
|
| n=NAME {Evarpat (ident_of_name n)}
|
2010-06-27 17:24:31 +02:00
|
|
|
| LPAREN p=snlist(COMMA, pat) RPAREN {Etuplepat p}
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-30 03:26:48 +02:00
|
|
|
longname: l=qualified(name) {l} /* qualified var (not a constructor) */
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-30 03:26:48 +02:00
|
|
|
constructor: /* of type longname */
|
2010-07-27 13:31:13 +02:00
|
|
|
| ln=qualified(CONSTRUCTOR) { ln }
|
2010-06-21 18:19:58 +02:00
|
|
|
| b=BOOL { Name(if b then "true" else "false") }
|
|
|
|
|
2010-08-03 22:38:42 +02:00
|
|
|
/* TODO donner un type !! Phase de typing. */
|
2010-07-27 13:31:13 +02:00
|
|
|
field:
|
|
|
|
| ln=longname { mk_static_exp ~loc:(Loc($startpos,$endpos)) (Sconstructor ln)}
|
|
|
|
|
2010-08-03 22:38:42 +02:00
|
|
|
/* TODO donner un type !! Phase de typing. */
|
2010-07-27 13:31:13 +02:00
|
|
|
const : c=_const { mk_static_exp ~loc:(Loc ($startpos,$endpos)) c }
|
|
|
|
_const:
|
|
|
|
| i=INT { Sint i }
|
|
|
|
| f=FLOAT { Sfloat f }
|
|
|
|
| c=constructor { Sconstructor c }
|
|
|
|
| t=tuple(const) { Stuple t }
|
2010-06-21 18:19:58 +02:00
|
|
|
|
2010-06-27 17:24:31 +02:00
|
|
|
exps: LPAREN e=slist(COMMA, exp) RPAREN {e}
|
2010-06-21 18:19:58 +02:00
|
|
|
|
|
|
|
field_exp: longname EQUAL exp { ($1, $3) }
|
|
|
|
|
|
|
|
simple_exp:
|
2010-07-16 17:33:14 +02:00
|
|
|
| e=_simple_exp {mk_exp e ~loc:(Loc ($startpos,$endpos)) }
|
|
|
|
_simple_exp:
|
2010-07-27 13:31:13 +02:00
|
|
|
| n=NAME { Evar (ident_of_name n) }
|
|
|
|
| s=structure(field_exp) { Estruct s }
|
|
|
|
| t=tuple(exp) { Eapp(mk_app Etuple, t, None) }
|
|
|
|
| LBRACKET es=slist(COMMA, exp) RBRACKET { Eapp(mk_app Earray, es, None) }
|
|
|
|
| LPAREN e=_exp RPAREN { e }
|
2010-07-16 17:33:14 +02:00
|
|
|
|
2010-06-21 18:19:58 +02:00
|
|
|
|
|
|
|
exp:
|
2010-07-16 17:33:14 +02:00
|
|
|
| e=simple_exp { e }
|
|
|
|
| e=_exp { mk_exp e ~loc:(Loc ($startpos,$endpos)) }
|
|
|
|
_exp:
|
|
|
|
| c=const { Econst c }
|
2010-07-27 13:31:13 +02:00
|
|
|
| v=const FBY e=exp { Efby(Some(v), e) }
|
2010-07-16 17:33:14 +02:00
|
|
|
| PRE exp { Efby(None,$2) }
|
2010-07-27 13:31:13 +02:00
|
|
|
| op=funapp a=exps r=reset { Eapp(op, a, r) }
|
2010-06-27 17:24:31 +02:00
|
|
|
| e1=exp i_op=infix e2=exp
|
2010-07-27 13:31:13 +02:00
|
|
|
{ Eapp(mk_app (Efun i_op), [e1; e2], None) }
|
2010-06-27 17:24:31 +02:00
|
|
|
| p_op=prefix e=exp %prec prefixs
|
2010-07-27 13:31:13 +02:00
|
|
|
{ Eapp(mk_app (Efun p_op), [e], None) }
|
|
|
|
| IF e1=exp THEN e2=exp ELSE e3=exp
|
|
|
|
{ Eapp( mk_app Eifthenelse, [e1; e2; e3], None) }
|
|
|
|
| e=simple_exp DOT f=field
|
|
|
|
{ Eapp( mk_app ~params:[f] Efield, [e], None) }
|
|
|
|
| e=exp WHEN c=constructor LPAREN n=ident RPAREN { Ewhen(e, c, n) }
|
|
|
|
| MERGE n=ident h=handlers { Emerge(n, h) }
|
|
|
|
| LPAREN r=exp WITH DOT f=field EQUAL nv=exp
|
|
|
|
{ Eapp(mk_app ~params:[f] Efield_update, [r; nv], None) }
|
|
|
|
| e=exp POWER p=e_param
|
|
|
|
{ Eapp(mk_app ~params:[p] Earray_fill, [e], None) }
|
|
|
|
| e=simple_exp i=indexes(exp) /* not e_params to solve conflicts */
|
|
|
|
{ Eapp(mk_app ~params:(List.map static_exp_of_exp i) Eselect, [e], None) }
|
|
|
|
| e=simple_exp i=indexes(exp) DEFAULT d=exp
|
|
|
|
{ Eapp(mk_app Eselect_dyn, [e; d]@i, None) }
|
|
|
|
| LPAREN e=exp WITH i=indexes(e_param) EQUAL nv=exp
|
|
|
|
{ Eapp(mk_app ~params:i Eupdate, [e; nv], None) }
|
2010-06-30 03:26:48 +02:00
|
|
|
| e=simple_exp LBRACKET i1=e_param DOTDOT i2=e_param RBRACKET
|
2010-07-27 13:31:13 +02:00
|
|
|
{ Eapp(mk_app ~params:[i1; i2] Eselect_slice, [e], None) }
|
|
|
|
| e1=exp AROBASE e2=exp { Eapp(mk_app Econcat, [e1;e2], None) }
|
|
|
|
| LPAREN f=iterator LPAREN op=funapp RPAREN
|
2010-06-30 17:20:56 +02:00
|
|
|
DOUBLE_LESS p=e_param DOUBLE_GREATER
|
2010-07-27 13:31:13 +02:00
|
|
|
RPAREN a=exps r=reset { Eiterator(f,op,p,a,r) }
|
2010-06-30 03:26:48 +02:00
|
|
|
|
|
|
|
/* Static indexes [p1][p2]... */
|
2010-07-27 13:31:13 +02:00
|
|
|
indexes(param): is=nonempty_list(index(param)) { is }
|
2010-06-30 15:44:56 +02:00
|
|
|
index(param): LBRACKET p=param RBRACKET { p }
|
|
|
|
|
|
|
|
|
2010-06-30 03:26:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Merge handlers ( B -> e)( C -> ec)... */
|
|
|
|
handlers: hs=nonempty_list(handler) { hs }
|
|
|
|
handler: LPAREN c=constructor ARROW e=exp RPAREN { c,e }
|
|
|
|
|
|
|
|
|
|
|
|
iterator:
|
|
|
|
| MAP { Imap }
|
|
|
|
| FOLD { Ifold }
|
|
|
|
| MAPFOLD { Imapfold }
|
2010-06-27 17:24:31 +02:00
|
|
|
|
|
|
|
reset: r=option(RESET,ident) { r }
|
|
|
|
|
2010-07-27 13:31:13 +02:00
|
|
|
/* TODO : Scoping to deal with node and fun ! */
|
|
|
|
funapp: ln=longname p=params(e_param) { mk_app ~params:p (Enode ln) }
|
2010-06-27 17:24:31 +02:00
|
|
|
|
2010-07-27 13:31:13 +02:00
|
|
|
/* inline so that precendance of POWER is respected in exp */
|
|
|
|
%inline e_param: e=exp { static_exp_of_exp e }
|
2010-06-27 17:24:31 +02:00
|
|
|
n_param: n=NAME { mk_param n }
|
|
|
|
params(param):
|
|
|
|
| /*empty*/ { [] }
|
|
|
|
| DOUBLE_LESS p=slist(COMMA, param) DOUBLE_GREATER { p }
|
|
|
|
|
|
|
|
|
|
|
|
/*Inlining is compulsory in order to preserve priorities*/
|
|
|
|
%inline infix: op=infix_ { Name(op) }
|
|
|
|
%inline infix_:
|
2010-06-21 18:19:58 +02:00
|
|
|
| op=INFIX0 | op=INFIX1 | op=INFIX2 | op=INFIX3 | op=INFIX4 { op }
|
|
|
|
| STAR { "*" }
|
|
|
|
| EQUAL { "=" }
|
|
|
|
| EQUALEQUAL { "==" }
|
|
|
|
| AMPERSAND { "&" } | AMPERAMPER { "&&" }
|
|
|
|
| OR { "or" } | BARBAR { "||" }
|
|
|
|
|
2010-07-27 13:31:13 +02:00
|
|
|
%inline prefix: op=prefix_ { Name(op) }
|
|
|
|
%inline prefix_:
|
2010-06-21 18:19:58 +02:00
|
|
|
| op = PREFIX { op }
|
|
|
|
| NOT { "not" }
|
|
|
|
| op = SUBTRACTIVE { "~" ^ op } /*TODO test 3 * -2 and co */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%
|