Commit 39c71c9f62e8d1c7102b0811054e89b5c1194bbb

Authored by Salvador Abreu
1 parent fb2650e6
Exists in master

stack state comments

Showing 1 changed file with 18 additions and 16 deletions   Show diff stats
fzn-parser/flatzinc.y
... ... @@ -54,9 +54,6 @@
54 54 // push the empty list
55 55 #define NIL() PUSH (("[]"))
56 56  
57   -#define BINARY(op) AST ("B,A", ("op(A,B)"))
58   -#define UNARY(op) AST ("X", ("op(X)"))
59   -
60 57 %}
61 58  
62 59  
... ... @@ -87,6 +84,7 @@ model : { INIT ("[]"); }
87 84 var_decl_items { AST ("X", ("vars(X)")); }
88 85 constraint_items { AST ("X", ("constrs(X)")); }
89 86 model_end
  87 + { AST ("S,C,V,P", ("fzn(P, V, C, S)")); }
90 88  
91 89 pred_decl_items : pred_decl_items pred_decl_item ';' { CONS (); }
92 90 | pred_decl_items error ';' { yyerrok; }
... ... @@ -139,8 +137,8 @@ constraint_item: /* -> [ constraint(...) | ] */
139 137 constraint_elem: /* -> [ CONSTR_ID, EXPRLIST | _ ] */
140 138 IDENT '(' exprs ')' { PUSH (("'%s'", $1)); }
141 139  
142   -solve_item:
143   - SOLVE annotations solve_kind
  140 +solve_item: /* -> [ solve(S,A) | _ ] */
  141 + SOLVE annotations solve_kind { AST ("S,A", ("solve(S, A)")); }
144 142  
145 143 solve_kind:
146 144 SATISFY { PUSH (("satisfy")); }
... ... @@ -163,7 +161,7 @@ pred_decl_arg:
163 161 | ARRAY '[' pred_arg_array_index ']' OF pred_arg_array_tail ':' IDENT
164 162 { AST ("T,U,L", ("var(array(T,L,U)):'%s'", $8)); }
165 163  
166   -pred_arg_array_index:
  164 +pred_arg_array_index: /* -> [ UB, LB | _ ] */
167 165 INT { PUSH (("_,1")); }
168 166 | INT_LITERAL DOTDOT INT_LITERAL { PUSH (("%d,%d", $3, $1)); }
169 167  
... ... @@ -265,20 +263,24 @@ char* filename;
265 263  
266 264 int main(int argc, char *argv[])
267 265 {
268   - if (argc != 2) {
269   - fprintf(stderr, "Usage: %s <file.fzn>\n", argv[0]);
270   - exit(1);
271   - }
272   -
  266 + if (argc == 1) {
  267 + yyin = stdin;
  268 + }
  269 + else if (argc == 2) {
273 270 filename = argv[1];
274 271 yyin = fopen(filename, "r");
275 272 if (yyin == NULL) {
276   - fprintf(stderr, "cannot open file: '%s'\n", filename);
277   - exit(1);
  273 + fprintf(stderr, "cannot open file: '%s'\n", filename);
  274 + exit(1);
278 275 }
279   -
280   - yyparse();
281   - return 0;
  276 + }
  277 + else {
  278 + fprintf(stderr, "Usage: %s [FILE.fzn]\n", argv[0]);
  279 + exit(1);
  280 + }
  281 +
  282 + yyparse();
  283 + return 0;
282 284 }
283 285  
284 286 int yyerror(char *s)
... ...