diff --git a/fzn-parser/flatzinc.y b/fzn-parser/flatzinc.y index ae745fd..842f3f4 100644 --- a/fzn-parser/flatzinc.y +++ b/fzn-parser/flatzinc.y @@ -54,9 +54,6 @@ // push the empty list #define NIL() PUSH (("[]")) -#define BINARY(op) AST ("B,A", ("op(A,B)")) -#define UNARY(op) AST ("X", ("op(X)")) - %} @@ -87,6 +84,7 @@ model : { INIT ("[]"); } var_decl_items { AST ("X", ("vars(X)")); } constraint_items { AST ("X", ("constrs(X)")); } model_end + { AST ("S,C,V,P", ("fzn(P, V, C, S)")); } pred_decl_items : pred_decl_items pred_decl_item ';' { CONS (); } | pred_decl_items error ';' { yyerrok; } @@ -139,8 +137,8 @@ constraint_item: /* -> [ constraint(...) | ] */ constraint_elem: /* -> [ CONSTR_ID, EXPRLIST | _ ] */ IDENT '(' exprs ')' { PUSH (("'%s'", $1)); } -solve_item: - SOLVE annotations solve_kind +solve_item: /* -> [ solve(S,A) | _ ] */ + SOLVE annotations solve_kind { AST ("S,A", ("solve(S, A)")); } solve_kind: SATISFY { PUSH (("satisfy")); } @@ -163,7 +161,7 @@ pred_decl_arg: | ARRAY '[' pred_arg_array_index ']' OF pred_arg_array_tail ':' IDENT { AST ("T,U,L", ("var(array(T,L,U)):'%s'", $8)); } -pred_arg_array_index: +pred_arg_array_index: /* -> [ UB, LB | _ ] */ INT { PUSH (("_,1")); } | INT_LITERAL DOTDOT INT_LITERAL { PUSH (("%d,%d", $3, $1)); } @@ -265,20 +263,24 @@ char* filename; int main(int argc, char *argv[]) { - if (argc != 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(1); - } - + if (argc == 1) { + yyin = stdin; + } + else if (argc == 2) { filename = argv[1]; yyin = fopen(filename, "r"); if (yyin == NULL) { - fprintf(stderr, "cannot open file: '%s'\n", filename); - exit(1); + fprintf(stderr, "cannot open file: '%s'\n", filename); + exit(1); } - - yyparse(); - return 0; + } + else { + fprintf(stderr, "Usage: %s [FILE.fzn]\n", argv[0]); + exit(1); + } + + yyparse(); + return 0; } int yyerror(char *s) -- libgit2 0.21.2