From 562c0ab602443f5fb9575a135f9944ffb10beac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20G=C3=A9rard?= Date: Wed, 30 Jun 2010 15:44:56 +0200 Subject: [PATCH] re re Parsing. --- compiler/minils/minils.ml | 3 +-- compiler/minils/parsing/mls_lexer.mll | 1 + compiler/minils/parsing/mls_parser.mly | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/compiler/minils/minils.ml b/compiler/minils/minils.ml index 72bd178..5a256da 100644 --- a/compiler/minils/minils.ml +++ b/compiler/minils/minils.ml @@ -61,8 +61,7 @@ and edesc = and array_op = | Erepeat of size_exp * exp | Eselect of size_exp list * exp (*indices, array*) - | Eselect_dyn of exp list * exp * exp (* indices, - array, default*) + | Eselect_dyn of exp list * exp * exp (* indices, array, default*) | Eupdate of size_exp list * exp * exp (*indices, array, value*) | Eselect_slice of size_exp * size_exp * exp (*lower bound, upper bound, array*) diff --git a/compiler/minils/parsing/mls_lexer.mll b/compiler/minils/parsing/mls_lexer.mll index 8cc5c82..5c8baf7 100644 --- a/compiler/minils/parsing/mls_lexer.mll +++ b/compiler/minils/parsing/mls_lexer.mll @@ -41,6 +41,7 @@ List.iter (fun (str,tok) -> Hashtbl.add keyword_table str tok) [ "map", MAP; "fold", FOLD; "mapfold", MAPFOLD; + "default", DEFAULT; "quo", INFIX3("quo"); "mod", INFIX3("mod"); "land", INFIX3("land"); diff --git a/compiler/minils/parsing/mls_parser.mly b/compiler/minils/parsing/mls_parser.mly index d8a10cb..fa7508d 100644 --- a/compiler/minils/parsing/mls_parser.mly +++ b/compiler/minils/parsing/mls_parser.mly @@ -40,6 +40,7 @@ let mk_var name ty = mk_var_dec name ty %token AROBASE %token WITH %token DOTDOT +%token DEFAULT %token LBRACKET RBRACKET %token MAP FOLD MAPFOLD %token PREFIX @@ -182,20 +183,22 @@ exp: | LBRACKET es=slist(COMMA, exp) RBRACKET { mk_exp (Earray es) } array_op: - | e=exp POWER p=e_param { Erepeat(p, e) } - | e=simple_exp i=indexes { Eselect(i, e) } -/*TODO | e=exp i=indexes_dyn DEFAULT d=exp { Eselect_dyn(i,???? ,e ,d) } */ - | LPAREN e=exp WITH i=indexes EQUAL nv=exp { Eupdate(i, e, nv) } + | e=exp POWER p=e_param { Erepeat(p, e) } + | e=simple_exp i=indexes(e_param) { Eselect(i, e) } + | e=exp i=indexes(exp) DEFAULT d=exp { Eselect_dyn(i, e ,d) } + | LPAREN e=exp WITH i=indexes(e_param) EQUAL nv=exp { Eupdate(i, e, nv) } | e=simple_exp LBRACKET i1=e_param DOTDOT i2=e_param RBRACKET { Eselect_slice(i1, i2, e) } - | e1=exp AROBASE e2=exp { Econcat(e1,e2) } + | e1=exp AROBASE e2=exp { Econcat(e1,e2) } | LPAREN f=iterator LPAREN op=funop RPAREN DOUBLE_LESS p=e_param DOUBLE_GREATER /* une seule dimension ? */ - RPAREN a=exps r=reset { Eiterator(f,op,p,a,r) } + RPAREN a=exps r=reset { Eiterator(f,op,p,a,r) } /* Static indexes [p1][p2]... */ -indexes: is=nonempty_list(index) { is } -index: LBRACKET p=e_param RBRACKET { p } +indexes(param): is=nonempty_list(index(param)) { is } +index(param): LBRACKET p=param RBRACKET { p } + + /* Merge handlers ( B -> e)( C -> ec)... */