Commit 6e2f2ea4f448327870aedccee4100a1ff699dce1
1 parent
f7de4bd3
Exists in
master
continue AST completion
Showing
2 changed files
with
21 additions
and
17 deletions
Show diff stats
fzn-parser/examples/a.ast
... | ... | @@ -9,13 +9,13 @@ _T > [int:lit(1)|_T]. |
9 | 9 | _T > [int:lit(-1)|_T]. |
10 | 10 | [T2:E2,T1:E1|_T] > [(T1,T2):(E1,E2)|_T]. |
11 | 11 | [Es|_T] > [array(_):alit(Es)|_T]. |
12 | -[VAL,AN,T|_T] > [var(array(T,1,2), VAL, AN)|_T]. | |
12 | +[VAL,AN,ID,T|_T] > [var(ID, array(T,1,2), VAL, AN)|_T]. | |
13 | 13 | [H,T|_T] > [[H|T]|_T]. |
14 | 14 | _T > [int(1,3)|_T]. |
15 | 15 | _T > ['wa'|_T]. |
16 | 16 | _T > [_:id('output_var')|_T]. |
17 | 17 | _T > [[]|_T]. |
18 | -[H,T|_T] > [[H|T]|_T]. | |
18 | +[As, E|_T] > [[E|As]|_T]. | |
19 | 19 | _T > [[]|_T]. |
20 | 20 | [VAL,AN,ID,T|_T] > [var(ID, T, VAL, AN)|_T]. |
21 | 21 | [H,T|_T] > [[H|T]|_T]. |
... | ... | @@ -23,7 +23,7 @@ _T > [int(1,3)|_T]. |
23 | 23 | _T > ['nt'|_T]. |
24 | 24 | _T > [_:id('output_var')|_T]. |
25 | 25 | _T > [[]|_T]. |
26 | -[H,T|_T] > [[H|T]|_T]. | |
26 | +[As, E|_T] > [[E|As]|_T]. | |
27 | 27 | _T > [[]|_T]. |
28 | 28 | [VAL,AN,ID,T|_T] > [var(ID, T, VAL, AN)|_T]. |
29 | 29 | [H,T|_T] > [[H|T]|_T]. |
... | ... | @@ -43,3 +43,4 @@ _T > [[]|_T]. |
43 | 43 | [H,T|_T] > [[H|T]|_T]. |
44 | 44 | [X|_T] > [constrs(X)|_T]. |
45 | 45 | _T > [[]|_T]. |
46 | +_T > [satisfy|_T]. | ... | ... |
fzn-parser/flatzinc.y
... | ... | @@ -114,21 +114,21 @@ var_decl_item: /* -> [ var(ID,TYPE,INIT,ANNOT) | _ ] */ |
114 | 114 | | non_array_ti_expr_tail ':' ident_anns '=' expr |
115 | 115 | { AST ("VAL,AN,ID,T", ("var(ID, T, VAL, AN)")); } |
116 | 116 | | ARRAY '[' INT_LITERAL DOTDOT INT_LITERAL ']' OF array_decl_tail |
117 | - { AST ("VAL,AN,T", ("var(array(T,%d,%d), VAL, AN)", $3, $5)); } | |
117 | + { AST ("VAL,AN,ID,T", ("var(ID, array(T,%d,%d), VAL, AN)", $3, $5)); } | |
118 | 118 | |
119 | -var_decl_item2: | |
119 | +var_decl_item2: /* -> [ VAL | _ ] */ | |
120 | 120 | '=' expr { } |
121 | 121 | | /*empty*/ { NIL (); } |
122 | 122 | |
123 | -array_decl_tail: | |
123 | +array_decl_tail: /* -> [ TYPE,VAL,ANNOT,ID | _ ] */ | |
124 | 124 | non_array_ti_expr_tail ':' ident_anns '=' array_literal |
125 | 125 | | VAR non_array_ti_expr_tail ':' ident_anns array_decl_tail2 |
126 | 126 | |
127 | -array_decl_tail2: /* -> [ DECLS | _ ] */ | |
127 | +array_decl_tail2: /* -> [ VAL | _ ] */ | |
128 | 128 | '=' array_literal { } |
129 | 129 | | /*empty*/ { NIL (); } |
130 | 130 | |
131 | -ident_anns: /* -> [ ANNOTATIONS, ID | _ ] */ | |
131 | +ident_anns: /* -> [ ANNOT,ID | _ ] */ | |
132 | 132 | IDENT { PUSH (("'%s'", $1)); } annotations |
133 | 133 | | UNDERSCORE_IDENT { PUSH (("'%s'", $1)); } annotations |
134 | 134 | |
... | ... | @@ -143,9 +143,9 @@ solve_item: |
143 | 143 | SOLVE annotations solve_kind |
144 | 144 | |
145 | 145 | solve_kind: |
146 | - SATISFY | |
147 | - | MINIMIZE expr | |
148 | - | MAXIMIZE expr | |
146 | + SATISFY { PUSH (("satisfy")); } | |
147 | + | MINIMIZE expr { AST ("E", ("minimize(E)")); } | |
148 | + | MAXIMIZE expr { AST ("E", ("maximize(E)")); } | |
149 | 149 | |
150 | 150 | //--------------------------------------------------------------------------- |
151 | 151 | // Predicate parameters |
... | ... | @@ -157,16 +157,19 @@ pred_decl_args: |
157 | 157 | |
158 | 158 | pred_decl_arg: |
159 | 159 | non_array_ti_expr_tail ':' IDENT |
160 | + { AST ("T", ("T:'%s'", $3)); } | |
160 | 161 | | VAR non_array_ti_expr_tail ':' IDENT |
162 | + { AST ("T", ("var(T):'%s'", $4)); } | |
161 | 163 | | ARRAY '[' pred_arg_array_index ']' OF pred_arg_array_tail ':' IDENT |
164 | + { AST ("T,U,L", ("var(array(T,L,U)):'%s'", $8)); } | |
162 | 165 | |
163 | 166 | pred_arg_array_index: |
164 | - INT | |
165 | - | INT_LITERAL DOTDOT INT_LITERAL | |
167 | + INT { PUSH (("_,1")); } | |
168 | + | INT_LITERAL DOTDOT INT_LITERAL { PUSH (("%d,%d", $3, $1)); } | |
166 | 169 | |
167 | -pred_arg_array_tail: | |
168 | - non_array_ti_expr_tail | |
169 | - | VAR non_array_ti_expr_tail | |
170 | +pred_arg_array_tail: /* -> [ TYPE | _ ] */ | |
171 | + non_array_ti_expr_tail { } | |
172 | + | VAR non_array_ti_expr_tail { AST ("T", ("var(T)")); } | |
170 | 173 | |
171 | 174 | //--------------------------------------------------------------------------- |
172 | 175 | // Type-Inst Expression Tails |
... | ... | @@ -251,7 +254,7 @@ array_access_expr: IDENT '[' INT_LITERAL ']' |
251 | 254 | //--------------------------------------------------------------------------- |
252 | 255 | |
253 | 256 | annotations: |
254 | - COLONCOLON expr annotations { CONS (); } | |
257 | + COLONCOLON expr annotations { AST ("As, E", ("[E|As]")); } | |
255 | 258 | | /* empty */ { NIL (); } |
256 | 259 | |
257 | 260 | %% | ... | ... |