/* * Main authors: * Guido Tack * * Copyright: * Guido Tack, 2007 * * Last modified: * Pedro in 27-11-2018 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ %pure-parser %code requires{ int run_fzn_model(char* fzn_file_name); } %{ #include #include #include #include #include "actions.h" #define YYDEBUG 1 #include "parser.tab.h" extern int yylex(); extern int yyparse(); extern FILE* yyin; /* * Translate the flatzinc file to a PHACT representation of a CSP */ int run_fzn_model(char* fzn_file_name) { yydebug = FZN_DEBUG; parse(fzn_file_name); return 0; } void yyerror(const char* s) { fprintf(stderr, "Parse error: %s\n", s); exit(1); } %} %union { int iValue; bool bValue; double dValue; int* setValue; double* floatSetValue; char* sValue; } %error-verbose %token FZ_INT_LIT FZ_BOOL_LIT %token FZ_FLOAT_LIT %token FZ_ID FZ_U_ID FZ_STRING_LIT %token FZ_VAR FZ_PAR %token FZ_ANNOTATION %token FZ_ANY %token FZ_ARRAY %token FZ_BOOL %token FZ_CASE %token FZ_COLONCOLON %token FZ_CONSTRAINT %token FZ_DEFAULT %token FZ_DOTDOT %token FZ_ELSE %token FZ_ELSEIF %token FZ_ENDIF %token FZ_ENUM %token FZ_FLOAT %token FZ_FUNCTION %token FZ_IF %token FZ_INCLUDE %token FZ_INT %token FZ_LET %token FZ_MAXIMIZE %token FZ_MINIMIZE %token FZ_OF %token FZ_SATISFY %token FZ_OUTPUT %token FZ_PREDICATE %token FZ_RECORD %token FZ_SET %token FZ_SHOW %token FZ_SHOWCOND %token FZ_SOLVE %token FZ_STRING %token FZ_TEST %token FZ_THEN %token FZ_TUPLE %token FZ_TYPE %token FZ_VARIANT_RECORD %token FZ_WHERE %type var_par_id %type set_literal %type int_init bool_init set_init float_init %type int_ti_expr_tail bool_ti_expr_tail %type vardecl_int_var_array_init %type vardecl_bool_var_array_init %type vardecl_float_var_array_init %type vardecl_set_var_array_init %type int_var_array_literal %type bool_var_array_literal %type float_var_array_literal %type set_var_array_literal %type int_init_list int_init_list_head %type bool_init_list bool_init_list_head %type float_init_list float_init_list_head %type set_init_list set_init_list_head %type int_list int_list_head %type bool_list bool_list_head %type set_literal_list set_literal_list_head %type float_list float_list_head %type flat_expr non_array_expr annotation_expr ann_non_array_expr %type non_array_expr_opt %type flat_expr_list non_array_expr_list non_array_expr_list_head %type solve_expr %type minmax %type annotations annotations_head %type annotation annotation_list %% /********************************/ /* main goal and item lists */ /********************************/ model : preddecl_items vardecl_items constraint_items solve_item ';' preddecl_items: /* empty */ | preddecl_items_head preddecl_items_head: preddecl_item ';' | preddecl_items_head preddecl_item ';' vardecl_items: /* emtpy */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (1)\n"); exit(-1); } | vardecl_items_head { if (FZN_VERBOSE) printf("Ignored 2\n"); } vardecl_items_head: vardecl_item ';' | vardecl_items_head vardecl_item ';' constraint_items: /* emtpy */ | constraint_items_head constraint_items_head: constraint_item ';' | constraint_items_head constraint_item ';' /********************************/ /* predicate declarations */ /********************************/ preddecl_item: FZ_PREDICATE FZ_ID '(' pred_arg_list ')' pred_arg_list: /* empty */ | pred_arg_list_head list_tail pred_arg_list_head: pred_arg | pred_arg_list_head ',' pred_arg pred_arg: pred_arg_type ':' FZ_ID pred_arg_type: FZ_ARRAY '[' pred_array_init ']' FZ_OF pred_arg_simple_type | FZ_ARRAY '[' pred_array_init ']' FZ_OF FZ_VAR pred_arg_simple_type | FZ_VAR pred_arg_simple_type | pred_arg_simple_type pred_arg_simple_type: int_ti_expr_tail | FZ_SET FZ_OF int_ti_expr_tail | FZ_BOOL | FZ_FLOAT pred_array_init: pred_array_init_arg | pred_array_init ',' pred_array_init_arg pred_array_init_arg: FZ_INT | FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT /********************************/ /* variable declarations */ /********************************/ var_par_id : FZ_ID | FZ_U_ID vardecl_item: FZ_VAR int_ti_expr_tail ':' var_par_id annotations non_array_expr_opt { if (FZN_VERBOSE) printf("Implemented 3 -> %s\n", $4); fzn_add_annot_to_object($4); fzn_new_fzn_obj_var(); } | FZ_VAR bool_ti_expr_tail ':' var_par_id annotations non_array_expr_opt { if (FZN_VERBOSE) printf("Implemented 4 -> %s\n", $4); fzn_add_annot_to_object($4); fzn_new_fzn_obj_var(); } | FZ_VAR float_ti_expr_tail ':' var_par_id annotations non_array_expr_opt { printf("This FlatZinc model uses a feature not yet implemented in PHACT (5)\n"); exit(-1); } | FZ_VAR FZ_SET FZ_OF int_ti_expr_tail ':' var_par_id annotations non_array_expr_opt { printf("This FlatZinc model uses a feature not yet implemented in PHACT (6)\n"); exit(-1); } | FZ_INT ':' var_par_id annotations '=' non_array_expr { printf("This FlatZinc model uses a feature not yet implemented in PHACT (7)\n"); exit(-1); } | FZ_BOOL ':' var_par_id annotations '=' non_array_expr { printf("This FlatZinc model uses a feature not yet implemented in PHACT (8)\n"); exit(-1); } | FZ_SET FZ_OF FZ_INT ':' var_par_id annotations '=' non_array_expr { printf("This FlatZinc model uses a feature not yet implemented in PHACT (9)\n"); exit(-1); } | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_VAR int_ti_expr_tail ':' var_par_id annotations vardecl_int_var_array_init { if (FZN_VERBOSE) printf("Implemented 10 -> %d, %d, %s, %s\n", $3, $5, $11, $12); fzn_add_annot_to_object($11); fzn_new_fzn_obj_array(); } | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_VAR bool_ti_expr_tail ':' var_par_id annotations vardecl_bool_var_array_init { if (FZN_VERBOSE) printf("Implemented 11 -> %d, %d, %s, %s\n", $3, $5, $11, $12); fzn_add_annot_to_object($11); fzn_new_fzn_obj_array(); } | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_VAR float_ti_expr_tail ':' var_par_id annotations vardecl_float_var_array_init { printf("This FlatZinc model uses a feature not yet implemented in PHACT (12)\n"); exit(-1); } | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_VAR FZ_SET FZ_OF int_ti_expr_tail ':' var_par_id annotations vardecl_set_var_array_init { printf("This FlatZinc model uses a feature not yet implemented in PHACT (13)\n"); exit(-1); } | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_INT ':' var_par_id annotations '=' '[' int_list ']' { if (FZN_VERBOSE) printf("Implemented 14 -> %d,%d,%s\n", $3, $5, $10); fzn_add_annot_to_object($10); fzn_new_fzn_obj_array(); } | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_BOOL ':' var_par_id annotations '=' '[' bool_list ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (15)\n"); exit(-1); } | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_FLOAT ':' var_par_id annotations '=' '[' float_list ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (16)\n"); exit(-1); } | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_SET FZ_OF FZ_INT ':' var_par_id annotations '=' '[' set_literal_list ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (17)\n"); exit(-1); } int_init : FZ_INT_LIT { if (FZN_VERBOSE) printf("Implemented 18 -> %d\n", $1); fzn_add_val_to_object($1); } | var_par_id { if (FZN_VERBOSE) printf("Implemented 19 -> %s\n", $1); fzn_add_var_or_array_to_object($1); } | var_par_id '[' FZ_INT_LIT ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (20)\n"); exit(-1); } int_init_list : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (21)\n"); exit(-1); } | int_init_list_head list_tail { if (FZN_VERBOSE) printf("Ignored 22\n"); } int_init_list_head : int_init { if (FZN_VERBOSE) printf("Ignored 23\n"); } | int_init_list_head ',' int_init { if (FZN_VERBOSE) printf("Ignored 24\n"); } list_tail : | ',' int_var_array_literal : '[' int_init_list ']' { if (FZN_VERBOSE) printf("Ignored 25\n"); } float_init : FZ_FLOAT_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (26)\n"); exit(-1); } | var_par_id { printf("This FlatZinc model uses a feature not yet implemented in PHACT (27)\n"); exit(-1); } | var_par_id '[' FZ_INT_LIT ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (28)\n"); exit(-1); } float_init_list : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (29)\n"); exit(-1); } | float_init_list_head list_tail { printf("This FlatZinc model uses a feature not yet implemented in PHACT (30)\n"); exit(-1); } float_init_list_head : float_init { printf("This FlatZinc model uses a feature not yet implemented in PHACT (31)\n"); exit(-1); } | float_init_list_head ',' float_init { printf("This FlatZinc model uses a feature not yet implemented in PHACT (32)\n"); exit(-1); } float_var_array_literal : '[' float_init_list ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (33)\n"); exit(-1); } bool_init : FZ_BOOL_LIT { if (FZN_VERBOSE) printf("Implemented 34 -> %d\n", $1); fzn_add_val_to_object($1); } | var_par_id { if (FZN_VERBOSE) printf("Implemented 35 -> %s\n", $1); fzn_add_var_or_array_to_object($1); } | var_par_id '[' FZ_INT_LIT ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (36)\n"); exit(-1); } bool_init_list : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (37)\n"); exit(-1); } | bool_init_list_head list_tail { if (FZN_VERBOSE) printf("Ignored 38\n"); } bool_init_list_head : bool_init { if (FZN_VERBOSE) printf("Ignored 39\n"); } | bool_init_list_head ',' bool_init { if (FZN_VERBOSE) printf("Ignored 40\n"); } bool_var_array_literal : '[' bool_init_list ']' { if (FZN_VERBOSE) printf("Ignored 41\n"); } set_init : set_literal { printf("This FlatZinc model uses a feature not yet implemented in PHACT (42)\n"); exit(-1); } | var_par_id { printf("This FlatZinc model uses a feature not yet implemented in PHACT (43)\n"); exit(-1); } | var_par_id '[' FZ_INT_LIT ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (44)\n"); exit(-1); } set_init_list : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (45)\n"); exit(-1); } | set_init_list_head list_tail { printf("This FlatZinc model uses a feature not yet implemented in PHACT (46)\n"); exit(-1); } set_init_list_head : set_init { printf("This FlatZinc model uses a feature not yet implemented in PHACT (47)\n"); exit(-1); } | set_init_list_head ',' set_init { printf("This FlatZinc model uses a feature not yet implemented in PHACT (48)\n"); exit(-1); } set_var_array_literal : '[' set_init_list ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (49)\n"); exit(-1); } vardecl_int_var_array_init : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (50)\n"); exit(-1); } | '=' int_var_array_literal { if (FZN_VERBOSE) printf("Ignored 51\n"); } vardecl_bool_var_array_init : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (52)\n"); exit(-1); } | '=' bool_var_array_literal { if (FZN_VERBOSE) printf("Ignored 53\n"); } vardecl_float_var_array_init : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (54)\n"); exit(-1); } | '=' float_var_array_literal { printf("This FlatZinc model uses a feature not yet implemented in PHACT (55)\n"); exit(-1); } vardecl_set_var_array_init : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (56)\n"); exit(-1); } | '=' set_var_array_literal { printf("This FlatZinc model uses a feature not yet implemented in PHACT (57)\n"); exit(-1); } constraint_item : FZ_CONSTRAINT FZ_ID '(' flat_expr_list ')' annotations { if (FZN_VERBOSE) printf("Implemented 58 -> %s\n", $2); fzn_add_annot_to_object($2); fzn_new_fzn_obj_constr(); } solve_item : FZ_SOLVE annotations FZ_SATISFY { if (FZN_VERBOSE) printf("Implemented 59\n"); fzn_solve(); } | FZ_SOLVE annotations minmax solve_expr { if (FZN_VERBOSE) printf("Implemented 60\n"); fzn_solve(); } /********************************/ /* type-insts */ /********************************/ int_ti_expr_tail : FZ_INT { if (FZN_VERBOSE) printf("Ignored 61\n"); } | '{' int_list '}' { } | FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT { if (FZN_VERBOSE) printf("Implemented 62 -> %d, %d\n", $1, $3); fzn_add_val_to_object($1); fzn_add_val_to_object($3); fzn_set_fzn_obj_range(true); } bool_ti_expr_tail : FZ_BOOL { if (FZN_VERBOSE) printf("Implemented 63 -> bool\n"); fzn_add_annot_to_object("bool"); } | '{' bool_list_head list_tail '}' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (64)\n"); exit(-1); } float_ti_expr_tail : FZ_FLOAT | '{' float_list_head list_tail '}' /********************************/ /* literals */ /********************************/ set_literal : '{' int_list '}' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (65)\n"); exit(-1); } | FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT { if (FZN_VERBOSE) printf("Ignored 66 -> %d, %d\n", $1, $3); } /* list containing only primitive literals */ int_list : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (67)\n"); exit(-1); } | int_list_head list_tail { if (FZN_VERBOSE) printf("Ignored 68\n"); } int_list_head : FZ_INT_LIT { if (FZN_VERBOSE) printf("Implemented 69 -> %d\n", $1); fzn_add_val_to_object($1); fzn_set_fzn_obj_range(false); } | int_list_head ',' FZ_INT_LIT { if (FZN_VERBOSE) printf("Implemented 70 -> %d\n", $3); fzn_add_val_to_object($3); } bool_list : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (71)\n"); exit(-1); } | bool_list_head list_tail { printf("This FlatZinc model uses a feature not yet implemented in PHACT (72)\n"); exit(-1); } bool_list_head : FZ_BOOL_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (73)\n"); exit(-1); } | bool_list_head ',' FZ_BOOL_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (74)\n"); exit(-1); } float_list : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (75)\n"); exit(-1); } | float_list_head list_tail { printf("This FlatZinc model uses a feature not yet implemented in PHACT (76)\n"); exit(-1); } float_list_head: FZ_FLOAT_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (77)\n"); exit(-1); } | float_list_head ',' FZ_FLOAT_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (78)\n"); exit(-1); } set_literal_list : /* empty */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (79)\n"); exit(-1); } | set_literal_list_head list_tail { printf("This FlatZinc model uses a feature not yet implemented in PHACT (80)\n"); exit(-1); } set_literal_list_head : set_literal { printf("This FlatZinc model uses a feature not yet implemented in PHACT (81)\n"); exit(-1); } | set_literal_list_head ',' set_literal { printf("This FlatZinc model uses a feature not yet implemented in PHACT (82)\n"); exit(-1); } /********************************/ /* constraint expressions */ /********************************/ flat_expr_list : flat_expr { if (FZN_VERBOSE) printf("Ignored 83\n"); } | flat_expr_list ',' flat_expr { if (FZN_VERBOSE) printf("Ignored 84\n"); } flat_expr : non_array_expr { if (FZN_VERBOSE) printf("Ignored 85\n"); } | '[' non_array_expr_list ']' { if (FZN_VERBOSE) printf("Implemented 86\n"); fzn_set_2array_init_pos(); } non_array_expr_opt : /* empty */ { if (FZN_VERBOSE) printf("Ignored 87\n"); } | '=' non_array_expr { if (FZN_VERBOSE) printf("Ignored 88\n"); } non_array_expr : FZ_BOOL_LIT { if (FZN_VERBOSE) printf("Implemented 89 -> %d\n", $1); fzn_add_val_to_object($1); } | FZ_INT_LIT { if (FZN_VERBOSE) printf("Implemented 90 -> %d\n", $1); fzn_add_val_to_object($1); } | FZ_FLOAT_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (91)\n"); exit(-1); } | set_literal { printf("This FlatZinc model uses a feature not yet implemented in PHACT (92)\n"); exit(-1); } | var_par_id /* variable, possibly array */ { if (FZN_VERBOSE) printf("Implemented 93 -> %s\n", $1); fzn_add_var_or_array_to_object($1); } | var_par_id '[' non_array_expr ']' /* array access */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (94)\n"); exit(-1); } non_array_expr_list : /* empty */ { if (FZN_VERBOSE) printf("Ignored 95\n"); } | non_array_expr_list_head list_tail { if (FZN_VERBOSE) printf("Ignored 96\n"); } non_array_expr_list_head : non_array_expr { if (FZN_VERBOSE) printf("Ignored 97\n"); } | non_array_expr_list_head ',' non_array_expr { if (FZN_VERBOSE) printf("Ignored 98\n"); } /********************************/ /* solve expressions */ /********************************/ solve_expr: var_par_id { if (FZN_VERBOSE) printf("Implemented 99 -> %s\n", $1); fzn_set_var_to_optimize($1); } | var_par_id '[' FZ_INT_LIT ']' { printf("This FlatZinc model uses a feature not yet implemented in PHACT (100)\n"); exit(-1); } minmax: FZ_MINIMIZE { if (FZN_VERBOSE) printf("Implemented 101 MINIMIZE\n"); FZN_OPTIMIZE = FZN_MINIMIZE; } | FZ_MAXIMIZE { printf("This FlatZinc model uses a feature not yet implemented in PHACT (102)\n"); exit(-1); } /********************************/ /* annotation expresions */ /********************************/ annotations : /* empty */ { if (FZN_VERBOSE) printf("Ignored 103\n"); } | annotations_head { if (FZN_VERBOSE) printf("Ignored 104\n"); } annotations_head : FZ_COLONCOLON annotation { if (FZN_VERBOSE) printf("Ignored 105\n"); } | annotations_head FZ_COLONCOLON annotation { if (FZN_VERBOSE) printf("Ignored 106\n"); } annotation : FZ_ID '(' annotation_list ')' { if (FZN_VERBOSE) printf("Implemented 107 -> %s\n", $1); fzn_add_annot_to_object($1); } | annotation_expr { if (FZN_VERBOSE) printf("Ignored 108\n"); } annotation_list: annotation { if (FZN_VERBOSE) printf("Ignored 109\n"); } | annotation_list ',' annotation { if (FZN_VERBOSE) printf("Ignored 110\n"); } annotation_expr : ann_non_array_expr { if (FZN_VERBOSE) printf("Ignored 111\n"); } | '[' annotation_list ']' { if (FZN_VERBOSE) printf("Ignored 112\n"); } ann_non_array_expr : FZ_BOOL_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (113)\n"); exit(-1); } | FZ_INT_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (114)\n"); exit(-1); } | FZ_FLOAT_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (115)\n"); exit(-1); } | set_literal { if (FZN_VERBOSE) printf("Ignored 116\n"); } | var_par_id /* variable, possibly array */ { if (FZN_VERBOSE) printf("Implemented 117 -> %s\n", $1); fzn_add_annot_to_object($1); } | var_par_id '[' ann_non_array_expr ']' /* array access */ { printf("This FlatZinc model uses a feature not yet implemented in PHACT (118)\n"); exit(-1); } | FZ_STRING_LIT { printf("This FlatZinc model uses a feature not yet implemented in PHACT (119)\n"); exit(-1); } %%