re re Parsing.

This commit is contained in:
Léonard Gérard 2010-06-30 15:44:56 +02:00
parent 6ab18a65ec
commit 562c0ab602
3 changed files with 13 additions and 10 deletions

View file

@ -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*)

View file

@ -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");

View file

@ -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 <string> 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)... */