Compare View

switch
from
...
to
 
Commits (2)
.gitignore
1 1 *.o
  2 +*-mpi
... ...
fz/Makefile 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +HEADERS=ast.hh conexpr.hh flatzinc.hh option.hh parser.hh parser.tab.hh registry.hh symboltable.hh varspec.hh
  2 +SOURCES=flatzinc.cpp fz.cpp lexer.yy.cpp parser.tab.cpp registry.cpp
  3 +
  4 +CXXFLAGS=-O2 -g
  5 +
  6 +all: fz
  7 +
  8 +%.o: %.cpp $(HEADERS)
  9 + $(CXX) $(CXXFLAGS) -c $< -o $@
  10 +
  11 +fz: $(SOURCES:%.cpp=%.o)
  12 + $(CXX) $(CXXFLAGS) -o $@ $(SOURCES:%.cpp=%.o)
  13 +
  14 +lexer.yy.cpp: lexer.lxx parser.tab.hh
  15 + flex -olexer.yy.cpp lexer.lxx
  16 +
  17 +parser.tab.hh parser.tab.cpp: parser.yxx
  18 + bison -t -o parser.tab.cpp -d $<
  19 + mv parser.tab.hpp parser.tab.hh
  20 +
  21 +.PHONY: clean distclean
  22 +clean:
  23 + rm -f $(SOURCES:%.cpp=%.o)
  24 + rm -f fz
  25 +
  26 +distclean: clean
  27 + rm -f lexer.yy.cpp parser.tab.hh parser.tab.cpp
... ...
fz/README 0 → 100644
... ... @@ -0,0 +1,67 @@
  1 +Parser Skeleton for FlatZinc
  2 +============================
  3 +
  4 +This is the Gecode FlatZinc parser and interpreter, stripped of all
  5 +Gecode-specific stuff. You can use it as a starting point for your own
  6 +FlatZinc interpreter.
  7 +
  8 +This is version 1.0, released 2011-01-17.
  9 +
  10 +If you have questions, don't hesitate to contact me by email: tack@gecode.org
  11 +
  12 +The copyright and license information is listed in the header of each file.
  13 +
  14 +Guido Tack, 2011
  15 +
  16 +Implementing solver-specific methods
  17 +------------------------------------
  18 +
  19 +In order to hook up your solver to the parser, look at the file flatzinc.hh.
  20 +It contains a class FlatZincModel, which is implemented in flatzinc.cpp. It
  21 +defines a number of methods that you have to implement, e.g. methods that
  22 +create variables, that post constraints, or that run the actual search.
  23 +
  24 +All these methods are marked with TODO comments and an output on stderr. Just
  25 +search for these comments and make the necessary changes.
  26 +
  27 +The actual constraint posting is done in the file registry.cpp. You have to
  28 +add a posting function for each constraint you want to implement, and register
  29 +it with the corresponding flatzinc name (see the examples in the file).
  30 +
  31 +Compilation
  32 +-----------
  33 +
  34 +Compile the *.cpp files using your favorite C++ compiler (tested with gcc 4.2
  35 +and Microsoft Visual C++ 2008). If you want to rebuild the lexer and parser
  36 +from the sources, you need flex (version 2.5.33 or better) and bison (version
  37 +2.3 or better), and run the following commands:
  38 +
  39 +flex -olexer.yy.cpp lexer.lxx
  40 +bison -t -o parser.tab.cpp -d parser.yxx
  41 +
  42 +If you want to use the parser as a library, link the object code from all .cpp
  43 +files except fz.cpp with you own code. The file fz.cpp contains a main method
  44 +that constructs a parser and executes a FlatZinc program, so you can use this
  45 +to get a standalone executable.
  46 +
  47 +The code archive contains a Makefile that should build the standalone fz
  48 +executable on any platform where a recent version of gcc and make are
  49 +installed.
  50 +
  51 +Changelog
  52 +---------
  53 +
  54 +1.0 (2010-01-17)
  55 +Initial release.
  56 +
  57 +1.1 (2010-01-18)
  58 +Added missing includes to enable compilation with gcc >= 4.3. Added sample
  59 +Makefile.
  60 +
  61 +1.2 (2012-03-09) for FlatZinc 1.4
  62 +Fixed some bugs in the parser and lexer, and updated to latest FlatZinc spec.
  63 +
  64 +1.3 (2012-03-19) for FlatZinc 1.5
  65 +Removed code from the parser that has become redundant because of changes in
  66 +the FlatZinc spec. Empty domains for int variables no longer cause an error,
  67 +but have to be handled by the solver.
... ...
fz/ast.hh 0 → 100644
... ... @@ -0,0 +1,508 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2010-07-02 19:18:43 +1000 (Fri, 02 Jul 2010) $ by $Author: tack $
  11 + * $Revision: 11149 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#ifndef __GECODE_FLATZINC_AST_HH__
  39 +#define __GECODE_FLATZINC_AST_HH__
  40 +
  41 +#include <vector>
  42 +#include <string>
  43 +#include <iostream>
  44 +#include <cstdlib>
  45 +
  46 +/**
  47 + * \namespace FlatZinc::AST
  48 + * \brief Abstract syntax trees for the %FlatZinc interpreter
  49 + */
  50 +
  51 +namespace FlatZinc { namespace AST {
  52 +
  53 + class Call;
  54 + class Array;
  55 + class Atom;
  56 + class SetLit;
  57 +
  58 + /// %Exception signaling type error
  59 + class TypeError {
  60 + private:
  61 + std::string _what;
  62 + public:
  63 + TypeError() : _what("") {}
  64 + TypeError(std::string what) : _what(what) {}
  65 + std::string what(void) const { return _what; }
  66 + };
  67 +
  68 + /**
  69 + * \brief A node in a %FlatZinc abstract syntax tree
  70 + */
  71 + class Node {
  72 + public:
  73 + /// Destructor
  74 + virtual ~Node(void);
  75 +
  76 + /// Append \a n to an array node
  77 + void append(Node* n);
  78 +
  79 + /// Test if node has atom with \a id
  80 + bool hasAtom(const std::string& id);
  81 + /// Test if node is int, if yes set \a i to the value
  82 + bool isInt(int& i);
  83 + /// Test if node is function call with \a id
  84 + bool isCall(const std::string& id);
  85 + /// Return function call
  86 + Call* getCall(void);
  87 + /// Test if node is function call or array containing function call \a id
  88 + bool hasCall(const std::string& id);
  89 + /// Return function call \a id
  90 + Call* getCall(const std::string& id);
  91 + /// Cast this node to an array node
  92 + Array* getArray(void);
  93 + /// Cast this node to an Atom node
  94 + Atom* getAtom(void);
  95 + /// Cast this node to an integer variable node
  96 + int getIntVar(void);
  97 + /// Cast this node to a Boolean variable node
  98 + int getBoolVar(void);
  99 + /// Cast this node to a set variable node
  100 + int getSetVar(void);
  101 +
  102 + /// Cast this node to an integer node
  103 + int getInt(void);
  104 + /// Cast this node to a Boolean node
  105 + bool getBool(void);
  106 + /// Cast this node to a Float node
  107 + double getFloat(void);
  108 + /// Cast this node to a set literal node
  109 + SetLit *getSet(void);
  110 +
  111 + /// Cast this node to a string node
  112 + std::string getString(void);
  113 +
  114 + /// Test if node is an integer variable node
  115 + bool isIntVar(void);
  116 + /// Test if node is a Boolean variable node
  117 + bool isBoolVar(void);
  118 + /// Test if node is a set variable node
  119 + bool isSetVar(void);
  120 + /// Test if node is an integer node
  121 + bool isInt(void);
  122 + /// Test if node is a Boolean node
  123 + bool isBool(void);
  124 + /// Test if node is a string node
  125 + bool isString(void);
  126 + /// Test if node is an array node
  127 + bool isArray(void);
  128 + /// Test if node is a set literal node
  129 + bool isSet(void);
  130 + /// Test if node is an atom node
  131 + bool isAtom(void);
  132 +
  133 + /// Output string representation
  134 + virtual void print(std::ostream&) const = 0;
  135 + };
  136 +
  137 + template<class Char, class Traits>
  138 + std::basic_ostream<Char,Traits>&
  139 + operator <<(std::basic_ostream<Char,Traits>& os, const Node& x) {
  140 + if (&x==NULL)
  141 + return os << "NULL";
  142 + x.print(os); return os;
  143 + }
  144 +
  145 +
  146 + /// Boolean literal node
  147 + class BoolLit : public Node {
  148 + public:
  149 + bool b;
  150 + BoolLit(bool b0) : b(b0) {}
  151 + virtual void print(std::ostream& os) const {
  152 + os << "b(" << (b ? "true" : "false") << ")";
  153 + }
  154 + };
  155 + /// Integer literal node
  156 + class IntLit : public Node {
  157 + public:
  158 + int i;
  159 + IntLit(int i0) : i(i0) {}
  160 + virtual void print(std::ostream& os) const {
  161 + os << "i("<<i<<")";
  162 + }
  163 + };
  164 + /// Float literal node
  165 + class FloatLit : public Node {
  166 + public:
  167 + double d;
  168 + FloatLit(double d0) : d(d0) {}
  169 + virtual void print(std::ostream& os) const {
  170 + os << "f("<<d<<")";
  171 + }
  172 + };
  173 + /// %Set literal node
  174 + class SetLit : public Node {
  175 + public:
  176 + bool interval;
  177 + int min; int max;
  178 + std::vector<int> s;
  179 + SetLit(void) {}
  180 + SetLit(int min0, int max0) : interval(true), min(min0), max(max0) {}
  181 + SetLit(const std::vector<int>& s0) : interval(false), s(s0) {}
  182 + bool empty(void) const {
  183 + return ( (interval && min>max) || (!interval && s.size() == 0));
  184 + }
  185 + virtual void print(std::ostream& os) const {
  186 + if (interval)
  187 + os << "s("<<min<<".."<<max<<")";
  188 + else {
  189 + os << "s({";
  190 + for (int i=0; i<s.size(); i++)
  191 + os << s[i] << ",";
  192 + os << "})";
  193 + }
  194 + }
  195 + };
  196 +
  197 + /// Variable node base class
  198 + class Var : public Node {
  199 + public:
  200 + int i;
  201 + Var(int i0) : i(i0) {}
  202 + };
  203 + /// Boolean variable node
  204 + class BoolVar : public Var {
  205 + public:
  206 + BoolVar(int i0) : Var(i0) {}
  207 + virtual void print(std::ostream& os) const {
  208 + os << "xb("<<i<<")";
  209 + }
  210 + };
  211 + /// Integer variable node
  212 + class IntVar : public Var {
  213 + public:
  214 + IntVar(int i0) : Var(i0) {}
  215 + virtual void print(std::ostream& os) const {
  216 + os << "xi("<<i<<")";
  217 + }
  218 + };
  219 + /// Float variable node
  220 + class FloatVar : public Var {
  221 + public:
  222 + FloatVar(int i0) : Var(i0) {}
  223 + virtual void print(std::ostream& os) const {
  224 + os << "xf("<<i<<")";
  225 + }
  226 + };
  227 + /// %Set variable node
  228 + class SetVar : public Var {
  229 + public:
  230 + SetVar(int i0) : Var(i0) {}
  231 + virtual void print(std::ostream& os) const {
  232 + os << "xs("<<i<<")";
  233 + }
  234 + };
  235 +
  236 + /// %Array node
  237 + class Array : public Node {
  238 + public:
  239 + std::vector<Node*> a;
  240 + Array(const std::vector<Node*>& a0)
  241 + : a(a0) {}
  242 + Array(Node* n)
  243 + : a(1) { a[0] = n; }
  244 + Array(int n=0) : a(n) {}
  245 + virtual void print(std::ostream& os) const {
  246 + os << "[";
  247 + for (unsigned int i=0; i<a.size(); i++) {
  248 + a[i]->print(os);
  249 + if (i<a.size()-1)
  250 + os << ", ";
  251 + }
  252 + os << "]";
  253 + }
  254 + ~Array(void) {
  255 + for (int i=a.size(); i--;)
  256 + delete a[i];
  257 + }
  258 + };
  259 +
  260 + /// %Node representing a function call
  261 + class Call : public Node {
  262 + public:
  263 + std::string id;
  264 + Node* args;
  265 + Call(const std::string& id0, Node* args0)
  266 + : id(id0), args(args0) {}
  267 + ~Call(void) { delete args; }
  268 + virtual void print(std::ostream& os) const {
  269 + os << id << "("; args->print(os); os << ")";
  270 + }
  271 + Array* getArgs(unsigned int n) {
  272 + Array *a = args->getArray();
  273 + if (a->a.size() != n)
  274 + throw TypeError("arity mismatch");
  275 + return a;
  276 + }
  277 + };
  278 +
  279 + /// %Node representing an array access
  280 + class ArrayAccess : public Node {
  281 + public:
  282 + Node* a;
  283 + Node* idx;
  284 + ArrayAccess(Node* a0, Node* idx0)
  285 + : a(a0), idx(idx0) {}
  286 + ~ArrayAccess(void) { delete a; delete idx; }
  287 + virtual void print(std::ostream& os) const {
  288 + a->print(os);
  289 + os << "[";
  290 + idx->print(os);
  291 + os << "]";
  292 + }
  293 + };
  294 +
  295 + /// %Node representing an atom
  296 + class Atom : public Node {
  297 + public:
  298 + std::string id;
  299 + Atom(const std::string& id0) : id(id0) {}
  300 + virtual void print(std::ostream& os) const {
  301 + os << id;
  302 + }
  303 + };
  304 +
  305 + /// %String node
  306 + class String : public Node {
  307 + public:
  308 + std::string s;
  309 + String(const std::string& s0) : s(s0) {}
  310 + virtual void print(std::ostream& os) const {
  311 + os << "s(\"" << s << "\")";
  312 + }
  313 + };
  314 +
  315 + inline
  316 + Node::~Node(void) {}
  317 +
  318 + inline void
  319 + Node::append(Node* newNode) {
  320 + Array* a = dynamic_cast<Array*>(this);
  321 + if (!a)
  322 + throw TypeError("array expected");
  323 + a->a.push_back(newNode);
  324 + }
  325 +
  326 + inline bool
  327 + Node::hasAtom(const std::string& id) {
  328 + if (Array* a = dynamic_cast<Array*>(this)) {
  329 + for (int i=a->a.size(); i--;)
  330 + if (Atom* at = dynamic_cast<Atom*>(a->a[i]))
  331 + if (at->id == id)
  332 + return true;
  333 + } else if (Atom* a = dynamic_cast<Atom*>(this)) {
  334 + return a->id == id;
  335 + }
  336 + return false;
  337 + }
  338 +
  339 + inline bool
  340 + Node::isCall(const std::string& id) {
  341 + if (Call* a = dynamic_cast<Call*>(this)) {
  342 + if (a->id == id)
  343 + return true;
  344 + }
  345 + return false;
  346 + }
  347 +
  348 + inline Call*
  349 + Node::getCall(void) {
  350 + if (Call* a = dynamic_cast<Call*>(this))
  351 + return a;
  352 + throw TypeError("call expected");
  353 + }
  354 +
  355 + inline bool
  356 + Node::hasCall(const std::string& id) {
  357 + if (Array* a = dynamic_cast<Array*>(this)) {
  358 + for (int i=a->a.size(); i--;)
  359 + if (Call* at = dynamic_cast<Call*>(a->a[i]))
  360 + if (at->id == id) {
  361 + return true;
  362 + }
  363 + } else if (Call* a = dynamic_cast<Call*>(this)) {
  364 + return a->id == id;
  365 + }
  366 + return false;
  367 + }
  368 +
  369 + inline bool
  370 + Node::isInt(int& i) {
  371 + if (IntLit* il = dynamic_cast<IntLit*>(this)) {
  372 + i = il->i;
  373 + return true;
  374 + }
  375 + return false;
  376 + }
  377 +
  378 + inline Call*
  379 + Node::getCall(const std::string& id) {
  380 + if (Array* a = dynamic_cast<Array*>(this)) {
  381 + for (int i=a->a.size(); i--;)
  382 + if (Call* at = dynamic_cast<Call*>(a->a[i]))
  383 + if (at->id == id)
  384 + return at;
  385 + } else if (Call* a = dynamic_cast<Call*>(this)) {
  386 + if (a->id == id)
  387 + return a;
  388 + }
  389 + throw TypeError("call expected");
  390 + }
  391 +
  392 + inline Array*
  393 + Node::getArray(void) {
  394 + if (Array* a = dynamic_cast<Array*>(this))
  395 + return a;
  396 + throw TypeError("array expected");
  397 + }
  398 +
  399 + inline Atom*
  400 + Node::getAtom(void) {
  401 + if (Atom* a = dynamic_cast<Atom*>(this))
  402 + return a;
  403 + throw TypeError("atom expected");
  404 + }
  405 +
  406 + inline int
  407 + Node::getIntVar(void) {
  408 + if (IntVar* a = dynamic_cast<IntVar*>(this))
  409 + return a->i;
  410 + throw TypeError("integer variable expected");
  411 + }
  412 + inline int
  413 + Node::getBoolVar(void) {
  414 + if (BoolVar* a = dynamic_cast<BoolVar*>(this))
  415 + return a->i;
  416 + throw TypeError("bool variable expected");
  417 + }
  418 + inline int
  419 + Node::getSetVar(void) {
  420 + if (SetVar* a = dynamic_cast<SetVar*>(this))
  421 + return a->i;
  422 + throw TypeError("set variable expected");
  423 + }
  424 + inline int
  425 + Node::getInt(void) {
  426 + if (IntLit* a = dynamic_cast<IntLit*>(this))
  427 + return a->i;
  428 + throw TypeError("integer literal expected");
  429 + }
  430 + inline bool
  431 + Node::getBool(void) {
  432 + if (BoolLit* a = dynamic_cast<BoolLit*>(this))
  433 + return a->b;
  434 + throw TypeError("bool literal expected");
  435 + }
  436 + inline double
  437 + Node::getFloat(void) {
  438 + if (FloatLit* a = dynamic_cast<FloatLit*>(this))
  439 + return a->d;
  440 + throw TypeError("float literal expected");
  441 + }
  442 + inline SetLit*
  443 + Node::getSet(void) {
  444 + if (SetLit* a = dynamic_cast<SetLit*>(this))
  445 + return a;
  446 + throw TypeError("set literal expected");
  447 + }
  448 + inline std::string
  449 + Node::getString(void) {
  450 + if (String* a = dynamic_cast<String*>(this))
  451 + return a->s;
  452 + throw TypeError("string literal expected");
  453 + }
  454 + inline bool
  455 + Node::isIntVar(void) {
  456 + return (dynamic_cast<IntVar*>(this) != NULL);
  457 + }
  458 + inline bool
  459 + Node::isBoolVar(void) {
  460 + return (dynamic_cast<BoolVar*>(this) != NULL);
  461 + }
  462 + inline bool
  463 + Node::isSetVar(void) {
  464 + return (dynamic_cast<SetVar*>(this) != NULL);
  465 + }
  466 + inline bool
  467 + Node::isInt(void) {
  468 + return (dynamic_cast<IntLit*>(this) != NULL);
  469 + }
  470 + inline bool
  471 + Node::isBool(void) {
  472 + return (dynamic_cast<BoolLit*>(this) != NULL);
  473 + }
  474 + inline bool
  475 + Node::isSet(void) {
  476 + return (dynamic_cast<SetLit*>(this) != NULL);
  477 + }
  478 + inline bool
  479 + Node::isString(void) {
  480 + return (dynamic_cast<String*>(this) != NULL);
  481 + }
  482 + inline bool
  483 + Node::isArray(void) {
  484 + return (dynamic_cast<Array*>(this) != NULL);
  485 + }
  486 + inline bool
  487 + Node::isAtom(void) {
  488 + return (dynamic_cast<Atom*>(this) != NULL);
  489 + }
  490 +
  491 + inline Node*
  492 + extractSingleton(Node* n) {
  493 + if (Array* a = dynamic_cast<Array*>(n)) {
  494 + if (a->a.size() == 1) {
  495 + Node *ret = a->a[0];
  496 + a->a[0] = NULL;
  497 + delete a;
  498 + return ret;
  499 + }
  500 + }
  501 + return n;
  502 + }
  503 +
  504 +}}
  505 +
  506 +#endif
  507 +
  508 +// STATISTICS: flatzinc-any
... ...
fz/conexpr.hh 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2010-07-02 19:18:43 +1000 (Fri, 02 Jul 2010) $ by $Author: tack $
  11 + * $Revision: 11149 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#ifndef __GECODE_FLATZINC_CONEXPR_HH__
  39 +#define __GECODE_FLATZINC_CONEXPR_HH__
  40 +
  41 +#include <string>
  42 +#include "ast.hh"
  43 +
  44 +namespace FlatZinc {
  45 +
  46 + /// Abstract representation of a constraint
  47 + class ConExpr {
  48 + public:
  49 + /// Identifier for the constraint
  50 + std::string id;
  51 + /// Constraint arguments
  52 + AST::Array* args;
  53 + /// Constructor
  54 + ConExpr(const std::string& id0, AST::Array* args0);
  55 + /// Return argument \a i
  56 + AST::Node* operator[](int i) const;
  57 + /// Destructor
  58 + ~ConExpr(void);
  59 + };
  60 +
  61 + inline
  62 + ConExpr::ConExpr(const std::string& id0, AST::Array* args0)
  63 + : id(id0), args(args0) {}
  64 +
  65 + inline AST::Node*
  66 + ConExpr::operator[](int i) const { return args->a[i]; }
  67 +
  68 + inline
  69 + ConExpr::~ConExpr(void) {
  70 + delete args;
  71 + }
  72 +
  73 +}
  74 +
  75 +#endif
  76 +
  77 +// STATISTICS: flatzinc-any
... ...
fz/flatzinc.cpp 0 → 100644
... ... @@ -0,0 +1,342 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2010-07-02 19:18:43 +1000 (Fri, 02 Jul 2010) $ by $Author: tack $
  11 + * $Revision: 11149 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#include "flatzinc.hh"
  39 +#include "registry.hh"
  40 +
  41 +#include <vector>
  42 +#include <string>
  43 +using namespace std;
  44 +
  45 +namespace FlatZinc {
  46 +
  47 + FlatZincModel::FlatZincModel(void)
  48 + : intVarCount(-1), boolVarCount(-1), setVarCount(-1), _optVar(-1),
  49 + _solveAnnotations(NULL) {}
  50 +
  51 + void
  52 + FlatZincModel::init(int intVars, int boolVars, int setVars) {
  53 + intVarCount = 0;
  54 + iv = std::vector<IntVar>(intVars);
  55 + iv_introduced = std::vector<bool>(intVars);
  56 + iv_boolalias = std::vector<int>(intVars);
  57 + boolVarCount = 0;
  58 + bv = std::vector<BoolVar>(boolVars);
  59 + bv_introduced = std::vector<bool>(boolVars);
  60 + setVarCount = 0;
  61 + sv = std::vector<SetVar>(setVars);
  62 + sv_introduced = std::vector<bool>(setVars);
  63 + }
  64 +
  65 + void
  66 + FlatZincModel::newIntVar(IntVarSpec* vs) {
  67 + if (vs->alias) {
  68 + iv[intVarCount++] = iv[vs->i];
  69 + } else {
  70 + std::cerr << "create new IntVar " << intVarCount << "\n";
  71 + /// TODO: create actual integer variable from vs
  72 + iv[intVarCount++] = IntVar();
  73 + }
  74 + iv_introduced[intVarCount-1] = vs->introduced;
  75 + iv_boolalias[intVarCount-1] = -1;
  76 + }
  77 +
  78 + void
  79 + FlatZincModel::aliasBool2Int(int iv, int bv) {
  80 + iv_boolalias[iv] = bv;
  81 + }
  82 + int
  83 + FlatZincModel::aliasBool2Int(int iv) {
  84 + return iv_boolalias[iv];
  85 + }
  86 +
  87 + void
  88 + FlatZincModel::newBoolVar(BoolVarSpec* vs) {
  89 + if (vs->alias) {
  90 + bv[boolVarCount++] = bv[vs->i];
  91 + } else {
  92 + std::cerr << "create new BoolVar " << boolVarCount << "\n";
  93 + /// TODO: create actual Boolean variable from vs
  94 + bv[boolVarCount++] = BoolVar();
  95 + }
  96 + bv_introduced[boolVarCount-1] = vs->introduced;
  97 + }
  98 +
  99 + void
  100 + FlatZincModel::newSetVar(SetVarSpec* vs) {
  101 + if (vs->alias) {
  102 + sv[setVarCount++] = sv[vs->i];
  103 + } else {
  104 + std::cerr << "create new SetVar " << setVarCount << "\n";
  105 + /// TODO: create actual set variable from vs
  106 + sv[setVarCount++] = SetVar();
  107 + }
  108 + sv_introduced[setVarCount-1] = vs->introduced;
  109 + }
  110 +
  111 + void
  112 + FlatZincModel::postConstraint(const ConExpr& ce, AST::Node* ann) {
  113 + try {
  114 + registry().post(*this, ce, ann);
  115 + } catch (AST::TypeError& e) {
  116 + throw FlatZinc::Error("Type error", e.what());
  117 + }
  118 + }
  119 +
  120 + void flattenAnnotations(AST::Array* ann, std::vector<AST::Node*>& out) {
  121 + for (unsigned int i=0; i<ann->a.size(); i++) {
  122 + if (ann->a[i]->isCall("seq_search")) {
  123 + AST::Call* c = ann->a[i]->getCall();
  124 + if (c->args->isArray())
  125 + flattenAnnotations(c->args->getArray(), out);
  126 + else
  127 + out.push_back(c->args);
  128 + } else {
  129 + out.push_back(ann->a[i]);
  130 + }
  131 + }
  132 + }
  133 +
  134 + void
  135 + FlatZincModel::createBranchers(AST::Node* ann, bool ignoreUnknown,
  136 + std::ostream& err) {
  137 + if (ann) {
  138 + std::vector<AST::Node*> flatAnn;
  139 + if (ann->isArray()) {
  140 + flattenAnnotations(ann->getArray() , flatAnn);
  141 + } else {
  142 + flatAnn.push_back(ann);
  143 + }
  144 +
  145 + for (unsigned int i=0; i<flatAnn.size(); i++) {
  146 + try {
  147 + AST::Call *call = flatAnn[i]->getCall("int_search");
  148 + AST::Array *args = call->getArgs(4);
  149 + AST::Array *vars = args->a[0]->getArray();
  150 + std::cerr << "int_search\n";
  151 + // TODO: install search
  152 + } catch (AST::TypeError& e) {
  153 + (void) e;
  154 + try {
  155 + AST::Call *call = flatAnn[i]->getCall("bool_search");
  156 + AST::Array *args = call->getArgs(4);
  157 + AST::Array *vars = args->a[0]->getArray();
  158 + std::cerr << "bool_search\n";
  159 + // TODO: install search
  160 + } catch (AST::TypeError& e) {
  161 + (void) e;
  162 + try {
  163 + AST::Call *call = flatAnn[i]->getCall("set_search");
  164 + AST::Array *args = call->getArgs(4);
  165 + AST::Array *vars = args->a[0]->getArray();
  166 + std::cerr << "set_search\n";
  167 + // TODO: install search
  168 + } catch (AST::TypeError& e) {
  169 + (void) e;
  170 + if (!ignoreUnknown) {
  171 + err << "Warning, ignored search annotation: ";
  172 + flatAnn[i]->print(err);
  173 + err << std::endl;
  174 + }
  175 + }
  176 + }
  177 + }
  178 + }
  179 + }
  180 + // TODO: install search for all remaining variables
  181 + }
  182 +
  183 + AST::Array*
  184 + FlatZincModel::solveAnnotations(void) const {
  185 + return _solveAnnotations;
  186 + }
  187 +
  188 + void
  189 + FlatZincModel::solve(AST::Array* ann) {
  190 + _method = SAT;
  191 + _solveAnnotations = ann;
  192 + }
  193 +
  194 + void
  195 + FlatZincModel::minimize(int var, AST::Array* ann) {
  196 + _method = MIN;
  197 + _optVar = var;
  198 + _solveAnnotations = ann;
  199 + // Branch on optimization variable to ensure that it is given a value.
  200 + AST::Array* args = new AST::Array(4);
  201 + args->a[0] = new AST::Array(new AST::IntVar(_optVar));
  202 + args->a[1] = new AST::Atom("input_order");
  203 + args->a[2] = new AST::Atom("indomain_min");
  204 + args->a[3] = new AST::Atom("complete");
  205 + AST::Call* c = new AST::Call("int_search", args);
  206 + if (!ann)
  207 + ann = new AST::Array(c);
  208 + else
  209 + ann->a.push_back(c);
  210 + }
  211 +
  212 + void
  213 + FlatZincModel::maximize(int var, AST::Array* ann) {
  214 + _method = MAX;
  215 + _optVar = var;
  216 + _solveAnnotations = ann;
  217 + // Branch on optimization variable to ensure that it is given a value.
  218 + AST::Array* args = new AST::Array(4);
  219 + args->a[0] = new AST::Array(new AST::IntVar(_optVar));
  220 + args->a[1] = new AST::Atom("input_order");
  221 + args->a[2] = new AST::Atom("indomain_min");
  222 + args->a[3] = new AST::Atom("complete");
  223 + AST::Call* c = new AST::Call("int_search", args);
  224 + if (!ann)
  225 + ann = new AST::Array(c);
  226 + else
  227 + ann->a.push_back(c);
  228 + }
  229 +
  230 + FlatZincModel::~FlatZincModel(void) {
  231 + delete _solveAnnotations;
  232 + }
  233 +
  234 + void
  235 + FlatZincModel::run(std::ostream& out, const Printer& p) {
  236 + switch (_method) {
  237 + case MIN:
  238 + case MAX:
  239 + std::cerr << "start optimization search\n";
  240 + // TODO: perform actual search
  241 + break;
  242 + case SAT:
  243 + std::cerr << "start satisfiability search\n";
  244 + // TODO: perform actual search
  245 + break;
  246 + }
  247 + }
  248 +
  249 + FlatZincModel::Meth
  250 + FlatZincModel::method(void) const {
  251 + return _method;
  252 + }
  253 +
  254 + int
  255 + FlatZincModel::optVar(void) const {
  256 + return _optVar;
  257 + }
  258 +
  259 + void
  260 + FlatZincModel::print(std::ostream& out, const Printer& p) const {
  261 + p.print(out, *this);
  262 + }
  263 +
  264 + void
  265 + Printer::init(AST::Array* output) {
  266 + _output = output;
  267 + }
  268 +
  269 + void
  270 + Printer::printElem(std::ostream& out, AST::Node* ai,
  271 + const FlatZincModel& m) const {
  272 + int k;
  273 + if (ai->isInt(k)) {
  274 + out << k;
  275 + } else if (ai->isIntVar()) {
  276 + // TODO: output actual variable
  277 + out << ai->getIntVar();
  278 + } else if (ai->isBoolVar()) {
  279 + // TODO: output actual variable
  280 + out << ai->getBoolVar();
  281 + } else if (ai->isSetVar()) {
  282 + // TODO: output actual variable
  283 + out << ai->getSetVar();
  284 + } else if (ai->isBool()) {
  285 + out << (ai->getBool() ? "true" : "false");
  286 + } else if (ai->isSet()) {
  287 + AST::SetLit* s = ai->getSet();
  288 + if (s->interval) {
  289 + out << s->min << ".." << s->max;
  290 + } else {
  291 + out << "{";
  292 + for (unsigned int i=0; i<s->s.size(); i++) {
  293 + out << s->s[i] << (i < s->s.size()-1 ? ", " : "}");
  294 + }
  295 + }
  296 + } else if (ai->isString()) {
  297 + std::string s = ai->getString();
  298 + for (unsigned int i=0; i<s.size(); i++) {
  299 + if (s[i] == '\\' && i<s.size()-1) {
  300 + switch (s[i+1]) {
  301 + case 'n': out << "\n"; break;
  302 + case '\\': out << "\\"; break;
  303 + case 't': out << "\t"; break;
  304 + default: out << "\\" << s[i+1];
  305 + }
  306 + i++;
  307 + } else {
  308 + out << s[i];
  309 + }
  310 + }
  311 + }
  312 + }
  313 +
  314 + void
  315 + Printer::print(std::ostream& out, const FlatZincModel& m) const {
  316 + if (_output == NULL)
  317 + return;
  318 + for (unsigned int i=0; i< _output->a.size(); i++) {
  319 + AST::Node* ai = _output->a[i];
  320 + if (ai->isArray()) {
  321 + AST::Array* aia = ai->getArray();
  322 + int size = aia->a.size();
  323 + out << "[";
  324 + for (int j=0; j<size; j++) {
  325 + printElem(out,aia->a[j],m);
  326 + if (j<size-1)
  327 + out << ", ";
  328 + }
  329 + out << "]";
  330 + } else {
  331 + printElem(out,ai,m);
  332 + }
  333 + }
  334 + }
  335 +
  336 + Printer::~Printer(void) {
  337 + delete _output;
  338 + }
  339 +
  340 +}
  341 +
  342 +// STATISTICS: flatzinc-any
... ...
fz/flatzinc.hh 0 → 100644
... ... @@ -0,0 +1,220 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2010-07-02 19:18:43 +1000 (Fri, 02 Jul 2010) $ by $Author: tack $
  11 + * $Revision: 11149 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#ifndef __GECODE_FLATZINC_HH__
  39 +#define __GECODE_FLATZINC_HH__
  40 +
  41 +#include <iostream>
  42 +#include <map>
  43 +#include <cassert>
  44 +
  45 +#include "conexpr.hh"
  46 +#include "ast.hh"
  47 +#include "varspec.hh"
  48 +
  49 +/**
  50 + * \namespace FlatZinc
  51 + * \brief Interpreter for the %FlatZinc language
  52 + *
  53 + * The Gecode::FlatZinc namespace contains all functionality required
  54 + * to parse and solve constraint models written in the %FlatZinc language.
  55 + *
  56 + */
  57 +
  58 +namespace FlatZinc {
  59 +
  60 + class IntVar {};
  61 + class BoolVar {};
  62 + class SetVar {};
  63 +
  64 + class Printer;
  65 +
  66 + /**
  67 + * \brief A space that can be initialized with a %FlatZinc model
  68 + *
  69 + */
  70 + class FlatZincModel {
  71 + public:
  72 + enum Meth {
  73 + SAT, //< Solve as satisfaction problem
  74 + MIN, //< Solve as minimization problem
  75 + MAX //< Solve as maximization problem
  76 + };
  77 + protected:
  78 + /// Number of integer variables
  79 + int intVarCount;
  80 + /// Number of Boolean variables
  81 + int boolVarCount;
  82 + /// Number of set variables
  83 + int setVarCount;
  84 +
  85 + /// Index of the integer variable to optimize
  86 + int _optVar;
  87 +
  88 + /// Whether to solve as satisfaction or optimization problem
  89 + Meth _method;
  90 +
  91 + /// Annotations on the solve item
  92 + AST::Array* _solveAnnotations;
  93 +
  94 + public:
  95 + /// The integer variables
  96 + std::vector<IntVar> iv;
  97 + /// Indicates whether an integer variable is introduced by mzn2fzn
  98 + std::vector<bool> iv_introduced;
  99 + /// Indicates whether an integer variable aliases a Boolean variable
  100 + std::vector<int> iv_boolalias;
  101 + /// The Boolean variables
  102 + std::vector<BoolVar> bv;
  103 + /// Indicates whether a Boolean variable is introduced by mzn2fzn
  104 + std::vector<bool> bv_introduced;
  105 + /// The set variables
  106 + std::vector<SetVar> sv;
  107 + /// Indicates whether a set variable is introduced by mzn2fzn
  108 + std::vector<bool> sv_introduced;
  109 +
  110 + /// Construct empty space
  111 + FlatZincModel(void);
  112 +
  113 + /// Destructor
  114 + ~FlatZincModel(void);
  115 +
  116 + /// Initialize space with given number of variables
  117 + void init(int intVars, int boolVars, int setVars);
  118 +
  119 + /// Create new integer variable from specification
  120 + void newIntVar(IntVarSpec* vs);
  121 + /// Link integer variable \a iv to Boolean variable \a bv
  122 + void aliasBool2Int(int iv, int bv);
  123 + /// Return linked Boolean variable for integer variable \a iv
  124 + int aliasBool2Int(int iv);
  125 + /// Create new Boolean variable from specification
  126 + void newBoolVar(BoolVarSpec* vs);
  127 + /// Create new set variable from specification
  128 + void newSetVar(SetVarSpec* vs);
  129 +
  130 + /// Post a constraint specified by \a ce
  131 + void postConstraint(const ConExpr& ce, AST::Node* annotation);
  132 +
  133 + /// Post the solve item
  134 + void solve(AST::Array* annotation);
  135 + /// Post that integer variable \a var should be minimized
  136 + void minimize(int var, AST::Array* annotation);
  137 + /// Post that integer variable \a var should be maximized
  138 + void maximize(int var, AST::Array* annotation);
  139 +
  140 + /// Run the search
  141 + void run(std::ostream& out, const Printer& p);
  142 +
  143 + /// Produce output on \a out using \a p
  144 + void print(std::ostream& out, const Printer& p) const;
  145 +
  146 + /// Return whether to solve a satisfaction or optimization problem
  147 + Meth method(void) const;
  148 +
  149 + /// Return index of variable used for optimization
  150 + int optVar(void) const;
  151 +
  152 + /**
  153 + * \brief Create branchers corresponding to the solve item annotations
  154 + *
  155 + * If \a ignoreUnknown is true, unknown solve item annotations will be
  156 + * ignored, otherwise a warning is written to \a err.
  157 + */
  158 + void createBranchers(AST::Node* ann, bool ignoreUnknown,
  159 + std::ostream& err = std::cerr);
  160 +
  161 + /// Return the solve item annotations
  162 + AST::Array* solveAnnotations(void) const;
  163 +
  164 + };
  165 +
  166 + /**
  167 + * \brief Output support class for %FlatZinc interpreter
  168 + *
  169 + */
  170 + class Printer {
  171 + private:
  172 + AST::Array* _output;
  173 + void printElem(std::ostream& out,
  174 + AST::Node* ai, const FlatZincModel& m) const;
  175 + public:
  176 + Printer(void) : _output(NULL) {}
  177 + void init(AST::Array* output);
  178 +
  179 + void print(std::ostream& out, const FlatZincModel& m) const;
  180 +
  181 + ~Printer(void);
  182 +
  183 + private:
  184 + Printer(const Printer&);
  185 + Printer& operator=(const Printer&);
  186 + };
  187 +
  188 + /// %Exception class for %FlatZinc errors
  189 + class Error {
  190 + private:
  191 + const std::string msg;
  192 + public:
  193 + Error(const std::string& where, const std::string& what)
  194 + : msg(where+": "+what) {}
  195 + const std::string& toString(void) const { return msg; }
  196 + };
  197 +
  198 + /**
  199 + * \brief Parse FlatZinc file \a fileName into \a fzs and return it.
  200 + *
  201 + * Creates a new empty FlatZincModel if \a fzs is NULL.
  202 + */
  203 + FlatZincModel* parse(const std::string& fileName,
  204 + Printer& p, std::ostream& err = std::cerr,
  205 + FlatZincModel* fzs=NULL);
  206 +
  207 + /**
  208 + * \brief Parse FlatZinc from \a is into \a fzs and return it.
  209 + *
  210 + * Creates a new empty FlatZincModel if \a fzs is NULL.
  211 + */
  212 + FlatZincModel* parse(std::istream& is,
  213 + Printer& p, std::ostream& err = std::cerr,
  214 + FlatZincModel* fzs=NULL);
  215 +
  216 +}
  217 +
  218 +#endif
  219 +
  220 +// STATISTICS: flatzinc-any
... ...
fz/fz.cpp 0 → 100644
... ... @@ -0,0 +1,73 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2011-01-18 20:06:16 +1100 (Tue, 18 Jan 2011) $ by $Author: tack $
  11 + * $Revision: 11538 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#include <iostream>
  39 +#include <fstream>
  40 +#include <cstring>
  41 +#include "flatzinc.hh"
  42 +
  43 +using namespace std;
  44 +
  45 +int main(int argc, char** argv) {
  46 +
  47 + if (argc!=2) {
  48 + cerr << "Usage: " << argv[0] << " <file>" << endl;
  49 + exit(EXIT_FAILURE);
  50 + }
  51 +
  52 + const char* filename = argv[1];
  53 +
  54 + FlatZinc::Printer p;
  55 + FlatZinc::FlatZincModel* fg = NULL;
  56 + if (!strcmp(filename, "-")) {
  57 + fg = FlatZinc::parse(cin, p);
  58 + } else {
  59 + fg = FlatZinc::parse(filename, p);
  60 + }
  61 +
  62 + if (fg) {
  63 + fg->createBranchers(fg->solveAnnotations(), false, std::cerr);
  64 + fg->run(std::cout, p);
  65 + } else {
  66 + exit(EXIT_FAILURE);
  67 + }
  68 + delete fg;
  69 +
  70 + return 0;
  71 +}
  72 +
  73 +// STATISTICS: flatzinc-any
... ...
fz/lexer.lxx 0 → 100644
... ... @@ -0,0 +1,130 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2006-12-11 03:27:31 +1100 (Mon, 11 Dec 2006) $ by $Author: schulte $
  11 + * $Revision: 4024 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +%option reentrant
  39 +%option bison-bridge
  40 +%option noyywrap
  41 +%option yylineno
  42 +
  43 +%{
  44 +
  45 +void yyerror(void*, const char*);
  46 +#define yyerror(s) yyerror(yyextra, s)
  47 +
  48 +#include "parser.hh"
  49 +
  50 +const char* stringbuf;
  51 +int stringbuflen;
  52 +int stringbufpos;
  53 +
  54 +int yy_input_proc(char* buf, int size, yyscan_t yyscanner);
  55 +#define YY_INPUT(buf, result, max_size) \
  56 + result = yy_input_proc(buf, max_size, yyscanner);
  57 +%}
  58 +
  59 +%%
  60 +
  61 +\n { /*yylineno++;*/ /* ignore EOL */ }
  62 +[ \t\r] { /* ignore whitespace */ }
  63 +%.* { /* ignore comments */ }
  64 +
  65 +"true" { yylval->iValue = 1; return FZ_BOOL_LIT; }
  66 +"false" { yylval->iValue = 0; return FZ_BOOL_LIT; }
  67 +-?[0-9]+ { yylval->iValue = atoi(yytext); return FZ_INT_LIT; }
  68 +-?0x[0-9A-Fa-f]+ { yylval->iValue = atoi(yytext); return FZ_INT_LIT; }
  69 +-?0o[0-7]+ { yylval->iValue = atoi(yytext); return FZ_INT_LIT; }
  70 +-?[0-9]+\.[0-9]+ { yylval->dValue = strtod(yytext,NULL);
  71 + return FZ_FLOAT_LIT; }
  72 +-?[0-9]+\.[0-9]+[Ee][+-]?[0-9]+ { yylval->dValue = strtod(yytext,NULL);
  73 + return FZ_FLOAT_LIT; }
  74 +-?[0-9]+[Ee][+-]?[0-9]+ { yylval->dValue = strtod(yytext,NULL);
  75 + return FZ_FLOAT_LIT; }
  76 +[=:;{}(),\[\]\.] { return *yytext; }
  77 +\.\. { return FZ_DOTDOT; }
  78 +:: { return FZ_COLONCOLON; }
  79 +"annotation" { return FZ_ANNOTATION; }
  80 +"any" { return FZ_ANY; }
  81 +"array" { return FZ_ARRAY; }
  82 +"bool" { return FZ_BOOL; }
  83 +"case" { return FZ_CASE; }
  84 +"constraint" { return FZ_CONSTRAINT; }
  85 +"default" { return FZ_DEFAULT; }
  86 +"else" { return FZ_ELSE; }
  87 +"elseif" { return FZ_ELSEIF; }
  88 +"endif" { return FZ_ENDIF; }
  89 +"enum" { return FZ_ENUM; }
  90 +"float" { return FZ_FLOAT; }
  91 +"function" { return FZ_FUNCTION; }
  92 +"if" { return FZ_IF; }
  93 +"include" { return FZ_INCLUDE; }
  94 +"int" { return FZ_INT; }
  95 +"let" { return FZ_LET; }
  96 +"maximize" { yylval->bValue = false; return FZ_MAXIMIZE; }
  97 +"minimize" { yylval->bValue = true; return FZ_MINIMIZE; }
  98 +"of" { return FZ_OF; }
  99 +"satisfy" { return FZ_SATISFY; }
  100 +"output" { return FZ_OUTPUT; }
  101 +"par" { yylval->bValue = false; return FZ_PAR; }
  102 +"predicate" { return FZ_PREDICATE; }
  103 +"record" { return FZ_RECORD; }
  104 +"set" { return FZ_SET; }
  105 +"show_cond" { return FZ_SHOWCOND; }
  106 +"show" { return FZ_SHOW; }
  107 +"solve" { return FZ_SOLVE; }
  108 +"string" { return FZ_STRING; }
  109 +"test" { return FZ_TEST; }
  110 +"then" { return FZ_THEN; }
  111 +"tuple" { return FZ_TUPLE; }
  112 +"type" { return FZ_TYPE; }
  113 +"var" { yylval->bValue = true; return FZ_VAR; }
  114 +"variant_record" { return FZ_VARIANT_RECORD; }
  115 +"where" { return FZ_WHERE; }
  116 +[A-Za-z][A-Za-z0-9_]* { yylval->sValue = strdup(yytext); return FZ_ID; }
  117 +_[_]*[A-Za-z][A-Za-z0-9_]* { yylval->sValue = strdup(yytext); return FZ_U_ID; }
  118 +\"[^"\n]*\" {
  119 + yylval->sValue = strdup(yytext+1);
  120 + yylval->sValue[strlen(yytext)-2] = 0;
  121 + return FZ_STRING_LIT; }
  122 +. { yyerror("Unknown character"); }
  123 +%%
  124 +int yy_input_proc(char* buf, int size, yyscan_t yyscanner) {
  125 + FlatZinc::ParserState* parm =
  126 + static_cast<FlatZinc::ParserState*>(yyget_extra(yyscanner));
  127 + return parm->fillBuffer(buf, size);
  128 + // work around warning that yyunput is unused
  129 + yyunput (0,buf,yyscanner);
  130 +}
... ...
fz/lexer.yy.cpp 0 → 100644
... ... @@ -0,0 +1,2451 @@
  1 +#line 2 "lexer.yy.cpp"
  2 +
  3 +#line 4 "lexer.yy.cpp"
  4 +
  5 +#define YY_INT_ALIGNED short int
  6 +
  7 +/* A lexical scanner generated by flex */
  8 +
  9 +#define FLEX_SCANNER
  10 +#define YY_FLEX_MAJOR_VERSION 2
  11 +#define YY_FLEX_MINOR_VERSION 5
  12 +#define YY_FLEX_SUBMINOR_VERSION 35
  13 +#if YY_FLEX_SUBMINOR_VERSION > 0
  14 +#define FLEX_BETA
  15 +#endif
  16 +
  17 +/* First, we deal with platform-specific or compiler-specific issues. */
  18 +
  19 +/* begin standard C headers. */
  20 +#include <stdio.h>
  21 +#include <string.h>
  22 +#include <errno.h>
  23 +#include <stdlib.h>
  24 +
  25 +/* end standard C headers. */
  26 +
  27 +/* flex integer type definitions */
  28 +
  29 +#ifndef FLEXINT_H
  30 +#define FLEXINT_H
  31 +
  32 +/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
  33 +
  34 +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  35 +
  36 +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
  37 + * if you want the limit (max/min) macros for int types.
  38 + */
  39 +#ifndef __STDC_LIMIT_MACROS
  40 +#define __STDC_LIMIT_MACROS 1
  41 +#endif
  42 +
  43 +#include <inttypes.h>
  44 +typedef int8_t flex_int8_t;
  45 +typedef uint8_t flex_uint8_t;
  46 +typedef int16_t flex_int16_t;
  47 +typedef uint16_t flex_uint16_t;
  48 +typedef int32_t flex_int32_t;
  49 +typedef uint32_t flex_uint32_t;
  50 +#else
  51 +typedef signed char flex_int8_t;
  52 +typedef short int flex_int16_t;
  53 +typedef int flex_int32_t;
  54 +typedef unsigned char flex_uint8_t;
  55 +typedef unsigned short int flex_uint16_t;
  56 +typedef unsigned int flex_uint32_t;
  57 +#endif /* ! C99 */
  58 +
  59 +/* Limits of integral types. */
  60 +#ifndef INT8_MIN
  61 +#define INT8_MIN (-128)
  62 +#endif
  63 +#ifndef INT16_MIN
  64 +#define INT16_MIN (-32767-1)
  65 +#endif
  66 +#ifndef INT32_MIN
  67 +#define INT32_MIN (-2147483647-1)
  68 +#endif
  69 +#ifndef INT8_MAX
  70 +#define INT8_MAX (127)
  71 +#endif
  72 +#ifndef INT16_MAX
  73 +#define INT16_MAX (32767)
  74 +#endif
  75 +#ifndef INT32_MAX
  76 +#define INT32_MAX (2147483647)
  77 +#endif
  78 +#ifndef UINT8_MAX
  79 +#define UINT8_MAX (255U)
  80 +#endif
  81 +#ifndef UINT16_MAX
  82 +#define UINT16_MAX (65535U)
  83 +#endif
  84 +#ifndef UINT32_MAX
  85 +#define UINT32_MAX (4294967295U)
  86 +#endif
  87 +
  88 +#endif /* ! FLEXINT_H */
  89 +
  90 +#ifdef __cplusplus
  91 +
  92 +/* The "const" storage-class-modifier is valid. */
  93 +#define YY_USE_CONST
  94 +
  95 +#else /* ! __cplusplus */
  96 +
  97 +/* C99 requires __STDC__ to be defined as 1. */
  98 +#if defined (__STDC__)
  99 +
  100 +#define YY_USE_CONST
  101 +
  102 +#endif /* defined (__STDC__) */
  103 +#endif /* ! __cplusplus */
  104 +
  105 +#ifdef YY_USE_CONST
  106 +#define yyconst const
  107 +#else
  108 +#define yyconst
  109 +#endif
  110 +
  111 +/* Returned upon end-of-file. */
  112 +#define YY_NULL 0
  113 +
  114 +/* Promotes a possibly negative, possibly signed char to an unsigned
  115 + * integer for use as an array index. If the signed char is negative,
  116 + * we want to instead treat it as an 8-bit unsigned char, hence the
  117 + * double cast.
  118 + */
  119 +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
  120 +
  121 +/* An opaque pointer. */
  122 +#ifndef YY_TYPEDEF_YY_SCANNER_T
  123 +#define YY_TYPEDEF_YY_SCANNER_T
  124 +typedef void* yyscan_t;
  125 +#endif
  126 +
  127 +/* For convenience, these vars (plus the bison vars far below)
  128 + are macros in the reentrant scanner. */
  129 +#define yyin yyg->yyin_r
  130 +#define yyout yyg->yyout_r
  131 +#define yyextra yyg->yyextra_r
  132 +#define yyleng yyg->yyleng_r
  133 +#define yytext yyg->yytext_r
  134 +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
  135 +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
  136 +#define yy_flex_debug yyg->yy_flex_debug_r
  137 +
  138 +/* Enter a start condition. This macro really ought to take a parameter,
  139 + * but we do it the disgusting crufty way forced on us by the ()-less
  140 + * definition of BEGIN.
  141 + */
  142 +#define BEGIN yyg->yy_start = 1 + 2 *
  143 +
  144 +/* Translate the current start state into a value that can be later handed
  145 + * to BEGIN to return to the state. The YYSTATE alias is for lex
  146 + * compatibility.
  147 + */
  148 +#define YY_START ((yyg->yy_start - 1) / 2)
  149 +#define YYSTATE YY_START
  150 +
  151 +/* Action number for EOF rule of a given start state. */
  152 +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
  153 +
  154 +/* Special action meaning "start processing a new file". */
  155 +#define YY_NEW_FILE yyrestart(yyin ,yyscanner )
  156 +
  157 +#define YY_END_OF_BUFFER_CHAR 0
  158 +
  159 +/* Size of default input buffer. */
  160 +#ifndef YY_BUF_SIZE
  161 +#define YY_BUF_SIZE 16384
  162 +#endif
  163 +
  164 +/* The state buf must be large enough to hold one state per character in the main buffer.
  165 + */
  166 +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
  167 +
  168 +#ifndef YY_TYPEDEF_YY_BUFFER_STATE
  169 +#define YY_TYPEDEF_YY_BUFFER_STATE
  170 +typedef struct yy_buffer_state *YY_BUFFER_STATE;
  171 +#endif
  172 +
  173 +#define EOB_ACT_CONTINUE_SCAN 0
  174 +#define EOB_ACT_END_OF_FILE 1
  175 +#define EOB_ACT_LAST_MATCH 2
  176 +
  177 + /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires
  178 + * access to the local variable yy_act. Since yyless() is a macro, it would break
  179 + * existing scanners that call yyless() from OUTSIDE yylex.
  180 + * One obvious solution it to make yy_act a global. I tried that, and saw
  181 + * a 5% performance hit in a non-yylineno scanner, because yy_act is
  182 + * normally declared as a register variable-- so it is not worth it.
  183 + */
  184 + #define YY_LESS_LINENO(n) \
  185 + do { \
  186 + int yyl;\
  187 + for ( yyl = n; yyl < yyleng; ++yyl )\
  188 + if ( yytext[yyl] == '\n' )\
  189 + --yylineno;\
  190 + }while(0)
  191 +
  192 +/* Return all but the first "n" matched characters back to the input stream. */
  193 +#define yyless(n) \
  194 + do \
  195 + { \
  196 + /* Undo effects of setting up yytext. */ \
  197 + int yyless_macro_arg = (n); \
  198 + YY_LESS_LINENO(yyless_macro_arg);\
  199 + *yy_cp = yyg->yy_hold_char; \
  200 + YY_RESTORE_YY_MORE_OFFSET \
  201 + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
  202 + YY_DO_BEFORE_ACTION; /* set up yytext again */ \
  203 + } \
  204 + while ( 0 )
  205 +
  206 +#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
  207 +
  208 +#ifndef YY_TYPEDEF_YY_SIZE_T
  209 +#define YY_TYPEDEF_YY_SIZE_T
  210 +typedef size_t yy_size_t;
  211 +#endif
  212 +
  213 +#ifndef YY_STRUCT_YY_BUFFER_STATE
  214 +#define YY_STRUCT_YY_BUFFER_STATE
  215 +struct yy_buffer_state
  216 + {
  217 + FILE *yy_input_file;
  218 +
  219 + char *yy_ch_buf; /* input buffer */
  220 + char *yy_buf_pos; /* current position in input buffer */
  221 +
  222 + /* Size of input buffer in bytes, not including room for EOB
  223 + * characters.
  224 + */
  225 + yy_size_t yy_buf_size;
  226 +
  227 + /* Number of characters read into yy_ch_buf, not including EOB
  228 + * characters.
  229 + */
  230 + int yy_n_chars;
  231 +
  232 + /* Whether we "own" the buffer - i.e., we know we created it,
  233 + * and can realloc() it to grow it, and should free() it to
  234 + * delete it.
  235 + */
  236 + int yy_is_our_buffer;
  237 +
  238 + /* Whether this is an "interactive" input source; if so, and
  239 + * if we're using stdio for input, then we want to use getc()
  240 + * instead of fread(), to make sure we stop fetching input after
  241 + * each newline.
  242 + */
  243 + int yy_is_interactive;
  244 +
  245 + /* Whether we're considered to be at the beginning of a line.
  246 + * If so, '^' rules will be active on the next match, otherwise
  247 + * not.
  248 + */
  249 + int yy_at_bol;
  250 +
  251 + int yy_bs_lineno; /**< The line count. */
  252 + int yy_bs_column; /**< The column count. */
  253 +
  254 + /* Whether to try to fill the input buffer when we reach the
  255 + * end of it.
  256 + */
  257 + int yy_fill_buffer;
  258 +
  259 + int yy_buffer_status;
  260 +
  261 +#define YY_BUFFER_NEW 0
  262 +#define YY_BUFFER_NORMAL 1
  263 + /* When an EOF's been seen but there's still some text to process
  264 + * then we mark the buffer as YY_EOF_PENDING, to indicate that we
  265 + * shouldn't try reading from the input source any more. We might
  266 + * still have a bunch of tokens to match, though, because of
  267 + * possible backing-up.
  268 + *
  269 + * When we actually see the EOF, we change the status to "new"
  270 + * (via yyrestart()), so that the user can continue scanning by
  271 + * just pointing yyin at a new input file.
  272 + */
  273 +#define YY_BUFFER_EOF_PENDING 2
  274 +
  275 + };
  276 +#endif /* !YY_STRUCT_YY_BUFFER_STATE */
  277 +
  278 +/* We provide macros for accessing buffer states in case in the
  279 + * future we want to put the buffer states in a more general
  280 + * "scanner state".
  281 + *
  282 + * Returns the top of the stack, or NULL.
  283 + */
  284 +#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
  285 + ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
  286 + : NULL)
  287 +
  288 +/* Same as previous macro, but useful when we know that the buffer stack is not
  289 + * NULL or when we need an lvalue. For internal use only.
  290 + */
  291 +#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
  292 +
  293 +void yyrestart (FILE *input_file ,yyscan_t yyscanner );
  294 +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
  295 +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
  296 +void yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
  297 +void yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
  298 +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
  299 +void yypop_buffer_state (yyscan_t yyscanner );
  300 +
  301 +static void yyensure_buffer_stack (yyscan_t yyscanner );
  302 +static void yy_load_buffer_state (yyscan_t yyscanner );
  303 +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
  304 +
  305 +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
  306 +
  307 +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
  308 +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
  309 +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
  310 +
  311 +void *yyalloc (yy_size_t ,yyscan_t yyscanner );
  312 +void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
  313 +void yyfree (void * ,yyscan_t yyscanner );
  314 +
  315 +#define yy_new_buffer yy_create_buffer
  316 +
  317 +#define yy_set_interactive(is_interactive) \
  318 + { \
  319 + if ( ! YY_CURRENT_BUFFER ){ \
  320 + yyensure_buffer_stack (yyscanner); \
  321 + YY_CURRENT_BUFFER_LVALUE = \
  322 + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
  323 + } \
  324 + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
  325 + }
  326 +
  327 +#define yy_set_bol(at_bol) \
  328 + { \
  329 + if ( ! YY_CURRENT_BUFFER ){\
  330 + yyensure_buffer_stack (yyscanner); \
  331 + YY_CURRENT_BUFFER_LVALUE = \
  332 + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
  333 + } \
  334 + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
  335 + }
  336 +
  337 +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
  338 +
  339 +/* Begin user sect3 */
  340 +
  341 +#define yywrap(n) 1
  342 +#define YY_SKIP_YYWRAP
  343 +
  344 +typedef unsigned char YY_CHAR;
  345 +
  346 +typedef int yy_state_type;
  347 +
  348 +#define yytext_ptr yytext_r
  349 +
  350 +static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
  351 +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
  352 +static int yy_get_next_buffer (yyscan_t yyscanner );
  353 +static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
  354 +
  355 +/* Done after the current pattern has been matched and before the
  356 + * corresponding action - sets up yytext.
  357 + */
  358 +#define YY_DO_BEFORE_ACTION \
  359 + yyg->yytext_ptr = yy_bp; \
  360 + yyleng = (size_t) (yy_cp - yy_bp); \
  361 + yyg->yy_hold_char = *yy_cp; \
  362 + *yy_cp = '\0'; \
  363 + yyg->yy_c_buf_p = yy_cp;
  364 +
  365 +#define YY_NUM_RULES 56
  366 +#define YY_END_OF_BUFFER 57
  367 +/* This struct is not used in this scanner,
  368 + but its presence is necessary. */
  369 +struct yy_trans_info
  370 + {
  371 + flex_int32_t yy_verify;
  372 + flex_int32_t yy_nxt;
  373 + };
  374 +static yyconst flex_int16_t yy_accept[221] =
  375 + { 0,
  376 + 0, 0, 57, 55, 2, 1, 55, 3, 12, 55,
  377 + 12, 6, 6, 12, 52, 55, 52, 52, 52, 52,
  378 + 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
  379 + 52, 52, 0, 54, 3, 6, 6, 13, 0, 0,
  380 + 0, 0, 14, 52, 53, 0, 52, 52, 52, 52,
  381 + 52, 52, 52, 52, 52, 52, 52, 28, 52, 52,
  382 + 52, 52, 34, 52, 52, 52, 52, 52, 52, 52,
  383 + 52, 52, 52, 52, 52, 52, 52, 52, 52, 9,
  384 + 0, 11, 8, 7, 53, 52, 16, 52, 52, 52,
  385 + 52, 52, 52, 52, 52, 52, 52, 52, 52, 30,
  386 +
  387 + 31, 52, 52, 52, 37, 52, 52, 52, 40, 52,
  388 + 52, 52, 52, 52, 52, 52, 52, 49, 52, 0,
  389 + 52, 52, 18, 19, 52, 52, 22, 52, 25, 52,
  390 + 52, 52, 52, 52, 52, 52, 52, 52, 52, 42,
  391 + 52, 52, 45, 46, 4, 52, 48, 52, 52, 0,
  392 + 10, 52, 17, 52, 52, 52, 24, 5, 26, 52,
  393 + 52, 52, 52, 52, 52, 52, 52, 52, 43, 52,
  394 + 47, 52, 51, 52, 52, 52, 23, 52, 52, 52,
  395 + 52, 36, 52, 39, 52, 52, 44, 52, 52, 52,
  396 + 21, 52, 29, 52, 52, 52, 35, 52, 52, 52,
  397 +
  398 + 52, 27, 32, 33, 52, 52, 52, 52, 52, 38,
  399 + 41, 52, 15, 20, 52, 52, 52, 52, 50, 0
  400 + } ;
  401 +
  402 +static yyconst flex_int32_t yy_ec[256] =
  403 + { 0,
  404 + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
  405 + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
  406 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  407 + 1, 2, 1, 4, 1, 1, 5, 1, 1, 6,
  408 + 6, 1, 7, 6, 8, 9, 1, 10, 11, 11,
  409 + 11, 11, 11, 11, 11, 12, 12, 13, 6, 1,
  410 + 6, 1, 1, 1, 14, 14, 14, 14, 15, 14,
  411 + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  412 + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  413 + 6, 1, 6, 1, 17, 1, 18, 19, 20, 21,
  414 +
  415 + 22, 23, 24, 25, 26, 16, 16, 27, 28, 29,
  416 + 30, 31, 16, 32, 33, 34, 35, 36, 37, 38,
  417 + 39, 40, 6, 1, 6, 1, 1, 1, 1, 1,
  418 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  419 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  420 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  421 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  422 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  423 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  424 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  425 +
  426 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  427 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  428 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  429 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  430 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  431 + 1, 1, 1, 1, 1
  432 + } ;
  433 +
  434 +static yyconst flex_int32_t yy_meta[41] =
  435 + { 0,
  436 + 1, 1, 2, 1, 1, 1, 1, 1, 1, 3,
  437 + 3, 3, 1, 4, 4, 5, 5, 4, 4, 4,
  438 + 4, 4, 4, 5, 5, 5, 5, 5, 5, 5,
  439 + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
  440 + } ;
  441 +
  442 +static yyconst flex_int16_t yy_base[227] =
  443 + { 0,
  444 + 0, 0, 276, 277, 277, 277, 271, 0, 277, 31,
  445 + 265, 35, 18, 260, 0, 255, 20, 241, 33, 248,
  446 + 26, 40, 31, 247, 43, 36, 44, 246, 52, 56,
  447 + 249, 241, 261, 277, 0, 0, 0, 277, 73, 82,
  448 + 69, 0, 277, 0, 0, 247, 58, 231, 232, 228,
  449 + 231, 236, 225, 75, 230, 226, 226, 0, 78, 220,
  450 + 215, 223, 0, 217, 218, 227, 228, 213, 212, 215,
  451 + 217, 211, 209, 219, 205, 208, 207, 205, 214, 89,
  452 + 95, 103, 92, 0, 0, 205, 0, 216, 206, 210,
  453 + 198, 212, 207, 202, 199, 193, 207, 204, 196, 0,
  454 +
  455 + 0, 196, 195, 189, 0, 198, 188, 191, 0, 179,
  456 + 179, 188, 179, 183, 189, 183, 187, 182, 175, 109,
  457 + 172, 166, 0, 0, 170, 168, 176, 178, 0, 178,
  458 + 165, 164, 162, 168, 167, 159, 167, 160, 158, 173,
  459 + 167, 159, 0, 0, 0, 165, 0, 168, 163, 112,
  460 + 115, 166, 0, 151, 155, 158, 0, 0, 0, 154,
  461 + 158, 152, 151, 142, 155, 153, 150, 152, 0, 147,
  462 + 0, 141, 0, 135, 150, 133, 0, 136, 143, 124,
  463 + 123, 0, 144, 0, 122, 130, 0, 125, 132, 131,
  464 + 0, 127, 0, 133, 132, 119, 0, 123, 134, 120,
  465 +
  466 + 120, 0, 0, 0, 126, 113, 97, 89, 75, 0,
  467 + 0, 86, 0, 0, 52, 38, 34, 43, 0, 277,
  468 + 127, 132, 135, 137, 140, 142
  469 + } ;
  470 +
  471 +static yyconst flex_int16_t yy_def[227] =
  472 + { 0,
  473 + 220, 1, 220, 220, 220, 220, 221, 222, 220, 220,
  474 + 220, 220, 12, 220, 223, 224, 223, 223, 223, 223,
  475 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  476 + 223, 223, 221, 220, 222, 12, 13, 220, 220, 220,
  477 + 220, 225, 220, 223, 226, 224, 223, 223, 223, 223,
  478 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  479 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  480 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 220,
  481 + 220, 220, 220, 225, 226, 223, 223, 223, 223, 223,
  482 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  483 +
  484 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  485 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 220,
  486 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  487 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  488 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 220,
  489 + 220, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  490 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  491 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  492 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  493 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  494 +
  495 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223,
  496 + 223, 223, 223, 223, 223, 223, 223, 223, 223, 0,
  497 + 220, 220, 220, 220, 220, 220
  498 + } ;
  499 +
  500 +static yyconst flex_int16_t yy_nxt[318] =
  501 + { 0,
  502 + 4, 5, 6, 7, 8, 9, 4, 10, 11, 12,
  503 + 13, 13, 14, 15, 15, 15, 16, 17, 18, 19,
  504 + 20, 21, 22, 15, 15, 23, 24, 25, 15, 26,
  505 + 27, 28, 29, 30, 15, 31, 32, 15, 15, 15,
  506 + 36, 37, 37, 39, 37, 37, 37, 220, 47, 40,
  507 + 50, 48, 53, 58, 54, 220, 40, 55, 63, 59,
  508 + 61, 65, 51, 219, 41, 218, 56, 217, 62, 68,
  509 + 64, 216, 42, 69, 57, 66, 70, 73, 83, 83,
  510 + 74, 71, 80, 80, 80, 72, 86, 75, 81, 81,
  511 + 76, 82, 82, 82, 77, 94, 87, 99, 80, 80,
  512 +
  513 + 80, 83, 83, 120, 82, 82, 82, 215, 214, 95,
  514 + 120, 100, 82, 82, 82, 150, 150, 213, 151, 151,
  515 + 151, 151, 151, 151, 151, 151, 151, 33, 212, 33,
  516 + 33, 33, 35, 211, 35, 35, 35, 44, 44, 44,
  517 + 45, 45, 84, 84, 85, 85, 85, 210, 209, 208,
  518 + 207, 206, 205, 204, 203, 202, 201, 200, 199, 198,
  519 + 197, 196, 195, 194, 193, 192, 191, 190, 189, 188,
  520 + 187, 186, 185, 184, 183, 182, 181, 180, 179, 178,
  521 + 177, 176, 175, 174, 173, 172, 171, 170, 169, 168,
  522 + 167, 166, 165, 164, 163, 162, 161, 160, 159, 158,
  523 +
  524 + 157, 156, 155, 154, 153, 152, 149, 148, 147, 146,
  525 + 145, 144, 143, 142, 141, 140, 139, 138, 137, 136,
  526 + 135, 134, 133, 132, 131, 130, 129, 128, 127, 126,
  527 + 125, 124, 123, 122, 121, 119, 118, 117, 116, 115,
  528 + 114, 113, 112, 111, 110, 109, 108, 107, 106, 105,
  529 + 104, 103, 102, 101, 98, 97, 96, 93, 92, 91,
  530 + 90, 89, 88, 46, 34, 79, 78, 67, 60, 52,
  531 + 49, 46, 43, 38, 34, 220, 3, 220, 220, 220,
  532 + 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
  533 + 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
  534 +
  535 + 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
  536 + 220, 220, 220, 220, 220, 220, 220
  537 + } ;
  538 +
  539 +static yyconst flex_int16_t yy_chk[318] =
  540 + { 0,
  541 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  542 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  543 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  544 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  545 + 10, 10, 10, 12, 12, 12, 12, 13, 17, 12,
  546 + 19, 17, 21, 23, 21, 13, 12, 22, 26, 23,
  547 + 25, 27, 19, 218, 12, 217, 22, 216, 25, 29,
  548 + 26, 215, 12, 29, 22, 27, 29, 30, 41, 41,
  549 + 30, 29, 39, 39, 39, 29, 47, 30, 40, 40,
  550 + 30, 40, 40, 40, 30, 54, 47, 59, 80, 80,
  551 +
  552 + 80, 83, 83, 80, 81, 81, 81, 212, 209, 54,
  553 + 80, 59, 82, 82, 82, 120, 120, 208, 120, 120,
  554 + 120, 150, 150, 150, 151, 151, 151, 221, 207, 221,
  555 + 221, 221, 222, 206, 222, 222, 222, 223, 223, 223,
  556 + 224, 224, 225, 225, 226, 226, 226, 205, 201, 200,
  557 + 199, 198, 196, 195, 194, 192, 190, 189, 188, 186,
  558 + 185, 183, 181, 180, 179, 178, 176, 175, 174, 172,
  559 + 170, 168, 167, 166, 165, 164, 163, 162, 161, 160,
  560 + 156, 155, 154, 152, 149, 148, 146, 142, 141, 140,
  561 + 139, 138, 137, 136, 135, 134, 133, 132, 131, 130,
  562 +
  563 + 128, 127, 126, 125, 122, 121, 119, 118, 117, 116,
  564 + 115, 114, 113, 112, 111, 110, 108, 107, 106, 104,
  565 + 103, 102, 99, 98, 97, 96, 95, 94, 93, 92,
  566 + 91, 90, 89, 88, 86, 79, 78, 77, 76, 75,
  567 + 74, 73, 72, 71, 70, 69, 68, 67, 66, 65,
  568 + 64, 62, 61, 60, 57, 56, 55, 53, 52, 51,
  569 + 50, 49, 48, 46, 33, 32, 31, 28, 24, 20,
  570 + 18, 16, 14, 11, 7, 3, 220, 220, 220, 220,
  571 + 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
  572 + 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
  573 +
  574 + 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
  575 + 220, 220, 220, 220, 220, 220, 220
  576 + } ;
  577 +
  578 +/* Table of booleans, true if rule could match eol. */
  579 +static yyconst flex_int32_t yy_rule_can_match_eol[57] =
  580 + { 0,
  581 +1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  582 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  583 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
  584 +
  585 +/* The intent behind this definition is that it'll catch
  586 + * any uses of REJECT which flex missed.
  587 + */
  588 +#define REJECT reject_used_but_not_detected
  589 +#define yymore() yymore_used_but_not_detected
  590 +#define YY_MORE_ADJ 0
  591 +#define YY_RESTORE_YY_MORE_OFFSET
  592 +#line 1 "lexer.lxx"
  593 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  594 +/*
  595 + * Main authors:
  596 + * Guido Tack <tack@gecode.org>
  597 + *
  598 + * Copyright:
  599 + * Guido Tack, 2007
  600 + *
  601 + * Last modified:
  602 + * $Date: 2012-03-09 09:58:49 +1100 (Fri, 09 Mar 2012) $ by $Author: tack $
  603 + * $Revision: 12564 $
  604 + *
  605 + * This file is part of Gecode, the generic constraint
  606 + * development environment:
  607 + * http://www.gecode.org
  608 + *
  609 + * Permission is hereby granted, free of charge, to any person obtaining
  610 + * a copy of this software and associated documentation files (the
  611 + * "Software"), to deal in the Software without restriction, including
  612 + * without limitation the rights to use, copy, modify, merge, publish,
  613 + * distribute, sublicense, and/or sell copies of the Software, and to
  614 + * permit persons to whom the Software is furnished to do so, subject to
  615 + * the following conditions:
  616 + *
  617 + * The above copyright notice and this permission notice shall be
  618 + * included in all copies or substantial portions of the Software.
  619 + *
  620 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  621 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  622 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  623 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  624 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  625 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  626 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  627 + *
  628 + */
  629 +#line 44 "lexer.lxx"
  630 +
  631 +void yyerror(void*, const char*);
  632 +#define yyerror(s) yyerror(yyextra, s)
  633 +
  634 +#include "parser.hh"
  635 +
  636 +const char* stringbuf;
  637 +int stringbuflen;
  638 +int stringbufpos;
  639 +
  640 +int yy_input_proc(char* buf, int size, yyscan_t yyscanner);
  641 +#define YY_INPUT(buf, result, max_size) \
  642 + result = yy_input_proc(buf, max_size, yyscanner);
  643 +#line 644 "lexer.yy.cpp"
  644 +
  645 +#define INITIAL 0
  646 +
  647 +#ifndef YY_NO_UNISTD_H
  648 +/* Special case for "unistd.h", since it is non-ANSI. We include it way
  649 + * down here because we want the user's section 1 to have been scanned first.
  650 + * The user has a chance to override it with an option.
  651 + */
  652 +#include <unistd.h>
  653 +#endif
  654 +
  655 +#ifndef YY_EXTRA_TYPE
  656 +#define YY_EXTRA_TYPE void *
  657 +#endif
  658 +
  659 +/* Holds the entire state of the reentrant scanner. */
  660 +struct yyguts_t
  661 + {
  662 +
  663 + /* User-defined. Not touched by flex. */
  664 + YY_EXTRA_TYPE yyextra_r;
  665 +
  666 + /* The rest are the same as the globals declared in the non-reentrant scanner. */
  667 + FILE *yyin_r, *yyout_r;
  668 + size_t yy_buffer_stack_top; /**< index of top of stack. */
  669 + size_t yy_buffer_stack_max; /**< capacity of stack. */
  670 + YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
  671 + char yy_hold_char;
  672 + int yy_n_chars;
  673 + int yyleng_r;
  674 + char *yy_c_buf_p;
  675 + int yy_init;
  676 + int yy_start;
  677 + int yy_did_buffer_switch_on_eof;
  678 + int yy_start_stack_ptr;
  679 + int yy_start_stack_depth;
  680 + int *yy_start_stack;
  681 + yy_state_type yy_last_accepting_state;
  682 + char* yy_last_accepting_cpos;
  683 +
  684 + int yylineno_r;
  685 + int yy_flex_debug_r;
  686 +
  687 + char *yytext_r;
  688 + int yy_more_flag;
  689 + int yy_more_len;
  690 +
  691 + YYSTYPE * yylval_r;
  692 +
  693 + }; /* end struct yyguts_t */
  694 +
  695 +static int yy_init_globals (yyscan_t yyscanner );
  696 +
  697 + /* This must go here because YYSTYPE and YYLTYPE are included
  698 + * from bison output in section 1.*/
  699 + # define yylval yyg->yylval_r
  700 +
  701 +int yylex_init (yyscan_t* scanner);
  702 +
  703 +int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
  704 +
  705 +/* Accessor methods to globals.
  706 + These are made visible to non-reentrant scanners for convenience. */
  707 +
  708 +int yylex_destroy (yyscan_t yyscanner );
  709 +
  710 +int yyget_debug (yyscan_t yyscanner );
  711 +
  712 +void yyset_debug (int debug_flag ,yyscan_t yyscanner );
  713 +
  714 +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner );
  715 +
  716 +void yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
  717 +
  718 +FILE *yyget_in (yyscan_t yyscanner );
  719 +
  720 +void yyset_in (FILE * in_str ,yyscan_t yyscanner );
  721 +
  722 +FILE *yyget_out (yyscan_t yyscanner );
  723 +
  724 +void yyset_out (FILE * out_str ,yyscan_t yyscanner );
  725 +
  726 +int yyget_leng (yyscan_t yyscanner );
  727 +
  728 +char *yyget_text (yyscan_t yyscanner );
  729 +
  730 +int yyget_lineno (yyscan_t yyscanner );
  731 +
  732 +void yyset_lineno (int line_number ,yyscan_t yyscanner );
  733 +
  734 +YYSTYPE * yyget_lval (yyscan_t yyscanner );
  735 +
  736 +void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
  737 +
  738 +/* Macros after this point can all be overridden by user definitions in
  739 + * section 1.
  740 + */
  741 +
  742 +#ifndef YY_SKIP_YYWRAP
  743 +#ifdef __cplusplus
  744 +extern "C" int yywrap (yyscan_t yyscanner );
  745 +#else
  746 +extern int yywrap (yyscan_t yyscanner );
  747 +#endif
  748 +#endif
  749 +
  750 + static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner);
  751 +
  752 +#ifndef yytext_ptr
  753 +static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
  754 +#endif
  755 +
  756 +#ifdef YY_NEED_STRLEN
  757 +static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
  758 +#endif
  759 +
  760 +#ifndef YY_NO_INPUT
  761 +
  762 +#ifdef __cplusplus
  763 +static int yyinput (yyscan_t yyscanner );
  764 +#else
  765 +static int input (yyscan_t yyscanner );
  766 +#endif
  767 +
  768 +#endif
  769 +
  770 +/* Amount of stuff to slurp up with each read. */
  771 +#ifndef YY_READ_BUF_SIZE
  772 +#define YY_READ_BUF_SIZE 8192
  773 +#endif
  774 +
  775 +/* Copy whatever the last rule matched to the standard output. */
  776 +#ifndef ECHO
  777 +/* This used to be an fputs(), but since the string might contain NUL's,
  778 + * we now use fwrite().
  779 + */
  780 +#define ECHO fwrite( yytext, yyleng, 1, yyout )
  781 +#endif
  782 +
  783 +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
  784 + * is returned in "result".
  785 + */
  786 +#ifndef YY_INPUT
  787 +#define YY_INPUT(buf,result,max_size) \
  788 + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
  789 + { \
  790 + int c = '*'; \
  791 + yy_size_t n; \
  792 + for ( n = 0; n < max_size && \
  793 + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
  794 + buf[n] = (char) c; \
  795 + if ( c == '\n' ) \
  796 + buf[n++] = (char) c; \
  797 + if ( c == EOF && ferror( yyin ) ) \
  798 + YY_FATAL_ERROR( "input in flex scanner failed" ); \
  799 + result = n; \
  800 + } \
  801 + else \
  802 + { \
  803 + errno=0; \
  804 + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
  805 + { \
  806 + if( errno != EINTR) \
  807 + { \
  808 + YY_FATAL_ERROR( "input in flex scanner failed" ); \
  809 + break; \
  810 + } \
  811 + errno=0; \
  812 + clearerr(yyin); \
  813 + } \
  814 + }\
  815 +\
  816 +
  817 +#endif
  818 +
  819 +/* No semi-colon after return; correct usage is to write "yyterminate();" -
  820 + * we don't want an extra ';' after the "return" because that will cause
  821 + * some compilers to complain about unreachable statements.
  822 + */
  823 +#ifndef yyterminate
  824 +#define yyterminate() return YY_NULL
  825 +#endif
  826 +
  827 +/* Number of entries by which start-condition stack grows. */
  828 +#ifndef YY_START_STACK_INCR
  829 +#define YY_START_STACK_INCR 25
  830 +#endif
  831 +
  832 +/* Report a fatal error. */
  833 +#ifndef YY_FATAL_ERROR
  834 +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
  835 +#endif
  836 +
  837 +/* end tables serialization structures and prototypes */
  838 +
  839 +/* Default declaration of generated scanner - a define so the user can
  840 + * easily add parameters.
  841 + */
  842 +#ifndef YY_DECL
  843 +#define YY_DECL_IS_OURS 1
  844 +
  845 +extern int yylex \
  846 + (YYSTYPE * yylval_param ,yyscan_t yyscanner);
  847 +
  848 +#define YY_DECL int yylex \
  849 + (YYSTYPE * yylval_param , yyscan_t yyscanner)
  850 +#endif /* !YY_DECL */
  851 +
  852 +/* Code executed at the beginning of each rule, after yytext and yyleng
  853 + * have been set up.
  854 + */
  855 +#ifndef YY_USER_ACTION
  856 +#define YY_USER_ACTION
  857 +#endif
  858 +
  859 +/* Code executed at the end of each rule. */
  860 +#ifndef YY_BREAK
  861 +#define YY_BREAK break;
  862 +#endif
  863 +
  864 +#define YY_RULE_SETUP \
  865 + YY_USER_ACTION
  866 +
  867 +/** The main scanner function which does all the work.
  868 + */
  869 +YY_DECL
  870 +{
  871 + register yy_state_type yy_current_state;
  872 + register char *yy_cp, *yy_bp;
  873 + register int yy_act;
  874 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  875 +
  876 +#line 59 "lexer.lxx"
  877 +
  878 +
  879 +#line 880 "lexer.yy.cpp"
  880 +
  881 + yylval = yylval_param;
  882 +
  883 + if ( !yyg->yy_init )
  884 + {
  885 + yyg->yy_init = 1;
  886 +
  887 +#ifdef YY_USER_INIT
  888 + YY_USER_INIT;
  889 +#endif
  890 +
  891 + if ( ! yyg->yy_start )
  892 + yyg->yy_start = 1; /* first start state */
  893 +
  894 + if ( ! yyin )
  895 + yyin = stdin;
  896 +
  897 + if ( ! yyout )
  898 + yyout = stdout;
  899 +
  900 + if ( ! YY_CURRENT_BUFFER ) {
  901 + yyensure_buffer_stack (yyscanner);
  902 + YY_CURRENT_BUFFER_LVALUE =
  903 + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
  904 + }
  905 +
  906 + yy_load_buffer_state(yyscanner );
  907 + }
  908 +
  909 + while ( 1 ) /* loops until end-of-file is reached */
  910 + {
  911 + yy_cp = yyg->yy_c_buf_p;
  912 +
  913 + /* Support of yytext. */
  914 + *yy_cp = yyg->yy_hold_char;
  915 +
  916 + /* yy_bp points to the position in yy_ch_buf of the start of
  917 + * the current run.
  918 + */
  919 + yy_bp = yy_cp;
  920 +
  921 + yy_current_state = yyg->yy_start;
  922 +yy_match:
  923 + do
  924 + {
  925 + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
  926 + if ( yy_accept[yy_current_state] )
  927 + {
  928 + yyg->yy_last_accepting_state = yy_current_state;
  929 + yyg->yy_last_accepting_cpos = yy_cp;
  930 + }
  931 + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  932 + {
  933 + yy_current_state = (int) yy_def[yy_current_state];
  934 + if ( yy_current_state >= 221 )
  935 + yy_c = yy_meta[(unsigned int) yy_c];
  936 + }
  937 + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  938 + ++yy_cp;
  939 + }
  940 + while ( yy_base[yy_current_state] != 277 );
  941 +
  942 +yy_find_action:
  943 + yy_act = yy_accept[yy_current_state];
  944 + if ( yy_act == 0 )
  945 + { /* have to back up */
  946 + yy_cp = yyg->yy_last_accepting_cpos;
  947 + yy_current_state = yyg->yy_last_accepting_state;
  948 + yy_act = yy_accept[yy_current_state];
  949 + }
  950 +
  951 + YY_DO_BEFORE_ACTION;
  952 +
  953 + if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
  954 + {
  955 + yy_size_t yyl;
  956 + for ( yyl = 0; yyl < yyleng; ++yyl )
  957 + if ( yytext[yyl] == '\n' )
  958 +
  959 + do{ yylineno++;
  960 + yycolumn=0;
  961 + }while(0)
  962 +;
  963 + }
  964 +
  965 +do_action: /* This label is used only to access EOF actions. */
  966 +
  967 + switch ( yy_act )
  968 + { /* beginning of action switch */
  969 + case 0: /* must back up */
  970 + /* undo the effects of YY_DO_BEFORE_ACTION */
  971 + *yy_cp = yyg->yy_hold_char;
  972 + yy_cp = yyg->yy_last_accepting_cpos;
  973 + yy_current_state = yyg->yy_last_accepting_state;
  974 + goto yy_find_action;
  975 +
  976 +case 1:
  977 +/* rule 1 can match eol */
  978 +YY_RULE_SETUP
  979 +#line 61 "lexer.lxx"
  980 +{ /*yylineno++;*/ /* ignore EOL */ }
  981 + YY_BREAK
  982 +case 2:
  983 +YY_RULE_SETUP
  984 +#line 62 "lexer.lxx"
  985 +{ /* ignore whitespace */ }
  986 + YY_BREAK
  987 +case 3:
  988 +YY_RULE_SETUP
  989 +#line 63 "lexer.lxx"
  990 +{ /* ignore comments */ }
  991 + YY_BREAK
  992 +case 4:
  993 +YY_RULE_SETUP
  994 +#line 65 "lexer.lxx"
  995 +{ yylval->iValue = 1; return FZ_BOOL_LIT; }
  996 + YY_BREAK
  997 +case 5:
  998 +YY_RULE_SETUP
  999 +#line 66 "lexer.lxx"
  1000 +{ yylval->iValue = 0; return FZ_BOOL_LIT; }
  1001 + YY_BREAK
  1002 +case 6:
  1003 +YY_RULE_SETUP
  1004 +#line 67 "lexer.lxx"
  1005 +{ yylval->iValue = atoi(yytext); return FZ_INT_LIT; }
  1006 + YY_BREAK
  1007 +case 7:
  1008 +YY_RULE_SETUP
  1009 +#line 68 "lexer.lxx"
  1010 +{ yylval->iValue = atoi(yytext); return FZ_INT_LIT; }
  1011 + YY_BREAK
  1012 +case 8:
  1013 +YY_RULE_SETUP
  1014 +#line 69 "lexer.lxx"
  1015 +{ yylval->iValue = atoi(yytext); return FZ_INT_LIT; }
  1016 + YY_BREAK
  1017 +case 9:
  1018 +YY_RULE_SETUP
  1019 +#line 70 "lexer.lxx"
  1020 +{ yylval->dValue = strtod(yytext,NULL);
  1021 + return FZ_FLOAT_LIT; }
  1022 + YY_BREAK
  1023 +case 10:
  1024 +YY_RULE_SETUP
  1025 +#line 72 "lexer.lxx"
  1026 +{ yylval->dValue = strtod(yytext,NULL);
  1027 + return FZ_FLOAT_LIT; }
  1028 + YY_BREAK
  1029 +case 11:
  1030 +YY_RULE_SETUP
  1031 +#line 74 "lexer.lxx"
  1032 +{ yylval->dValue = strtod(yytext,NULL);
  1033 + return FZ_FLOAT_LIT; }
  1034 + YY_BREAK
  1035 +case 12:
  1036 +YY_RULE_SETUP
  1037 +#line 76 "lexer.lxx"
  1038 +{ return *yytext; }
  1039 + YY_BREAK
  1040 +case 13:
  1041 +YY_RULE_SETUP
  1042 +#line 77 "lexer.lxx"
  1043 +{ return FZ_DOTDOT; }
  1044 + YY_BREAK
  1045 +case 14:
  1046 +YY_RULE_SETUP
  1047 +#line 78 "lexer.lxx"
  1048 +{ return FZ_COLONCOLON; }
  1049 + YY_BREAK
  1050 +case 15:
  1051 +YY_RULE_SETUP
  1052 +#line 79 "lexer.lxx"
  1053 +{ return FZ_ANNOTATION; }
  1054 + YY_BREAK
  1055 +case 16:
  1056 +YY_RULE_SETUP
  1057 +#line 80 "lexer.lxx"
  1058 +{ return FZ_ANY; }
  1059 + YY_BREAK
  1060 +case 17:
  1061 +YY_RULE_SETUP
  1062 +#line 81 "lexer.lxx"
  1063 +{ return FZ_ARRAY; }
  1064 + YY_BREAK
  1065 +case 18:
  1066 +YY_RULE_SETUP
  1067 +#line 82 "lexer.lxx"
  1068 +{ return FZ_BOOL; }
  1069 + YY_BREAK
  1070 +case 19:
  1071 +YY_RULE_SETUP
  1072 +#line 83 "lexer.lxx"
  1073 +{ return FZ_CASE; }
  1074 + YY_BREAK
  1075 +case 20:
  1076 +YY_RULE_SETUP
  1077 +#line 84 "lexer.lxx"
  1078 +{ return FZ_CONSTRAINT; }
  1079 + YY_BREAK
  1080 +case 21:
  1081 +YY_RULE_SETUP
  1082 +#line 85 "lexer.lxx"
  1083 +{ return FZ_DEFAULT; }
  1084 + YY_BREAK
  1085 +case 22:
  1086 +YY_RULE_SETUP
  1087 +#line 86 "lexer.lxx"
  1088 +{ return FZ_ELSE; }
  1089 + YY_BREAK
  1090 +case 23:
  1091 +YY_RULE_SETUP
  1092 +#line 87 "lexer.lxx"
  1093 +{ return FZ_ELSEIF; }
  1094 + YY_BREAK
  1095 +case 24:
  1096 +YY_RULE_SETUP
  1097 +#line 88 "lexer.lxx"
  1098 +{ return FZ_ENDIF; }
  1099 + YY_BREAK
  1100 +case 25:
  1101 +YY_RULE_SETUP
  1102 +#line 89 "lexer.lxx"
  1103 +{ return FZ_ENUM; }
  1104 + YY_BREAK
  1105 +case 26:
  1106 +YY_RULE_SETUP
  1107 +#line 90 "lexer.lxx"
  1108 +{ return FZ_FLOAT; }
  1109 + YY_BREAK
  1110 +case 27:
  1111 +YY_RULE_SETUP
  1112 +#line 91 "lexer.lxx"
  1113 +{ return FZ_FUNCTION; }
  1114 + YY_BREAK
  1115 +case 28:
  1116 +YY_RULE_SETUP
  1117 +#line 92 "lexer.lxx"
  1118 +{ return FZ_IF; }
  1119 + YY_BREAK
  1120 +case 29:
  1121 +YY_RULE_SETUP
  1122 +#line 93 "lexer.lxx"
  1123 +{ return FZ_INCLUDE; }
  1124 + YY_BREAK
  1125 +case 30:
  1126 +YY_RULE_SETUP
  1127 +#line 94 "lexer.lxx"
  1128 +{ return FZ_INT; }
  1129 + YY_BREAK
  1130 +case 31:
  1131 +YY_RULE_SETUP
  1132 +#line 95 "lexer.lxx"
  1133 +{ return FZ_LET; }
  1134 + YY_BREAK
  1135 +case 32:
  1136 +YY_RULE_SETUP
  1137 +#line 96 "lexer.lxx"
  1138 +{ yylval->bValue = false; return FZ_MAXIMIZE; }
  1139 + YY_BREAK
  1140 +case 33:
  1141 +YY_RULE_SETUP
  1142 +#line 97 "lexer.lxx"
  1143 +{ yylval->bValue = true; return FZ_MINIMIZE; }
  1144 + YY_BREAK
  1145 +case 34:
  1146 +YY_RULE_SETUP
  1147 +#line 98 "lexer.lxx"
  1148 +{ return FZ_OF; }
  1149 + YY_BREAK
  1150 +case 35:
  1151 +YY_RULE_SETUP
  1152 +#line 99 "lexer.lxx"
  1153 +{ return FZ_SATISFY; }
  1154 + YY_BREAK
  1155 +case 36:
  1156 +YY_RULE_SETUP
  1157 +#line 100 "lexer.lxx"
  1158 +{ return FZ_OUTPUT; }
  1159 + YY_BREAK
  1160 +case 37:
  1161 +YY_RULE_SETUP
  1162 +#line 101 "lexer.lxx"
  1163 +{ yylval->bValue = false; return FZ_PAR; }
  1164 + YY_BREAK
  1165 +case 38:
  1166 +YY_RULE_SETUP
  1167 +#line 102 "lexer.lxx"
  1168 +{ return FZ_PREDICATE; }
  1169 + YY_BREAK
  1170 +case 39:
  1171 +YY_RULE_SETUP
  1172 +#line 103 "lexer.lxx"
  1173 +{ return FZ_RECORD; }
  1174 + YY_BREAK
  1175 +case 40:
  1176 +YY_RULE_SETUP
  1177 +#line 104 "lexer.lxx"
  1178 +{ return FZ_SET; }
  1179 + YY_BREAK
  1180 +case 41:
  1181 +YY_RULE_SETUP
  1182 +#line 105 "lexer.lxx"
  1183 +{ return FZ_SHOWCOND; }
  1184 + YY_BREAK
  1185 +case 42:
  1186 +YY_RULE_SETUP
  1187 +#line 106 "lexer.lxx"
  1188 +{ return FZ_SHOW; }
  1189 + YY_BREAK
  1190 +case 43:
  1191 +YY_RULE_SETUP
  1192 +#line 107 "lexer.lxx"
  1193 +{ return FZ_SOLVE; }
  1194 + YY_BREAK
  1195 +case 44:
  1196 +YY_RULE_SETUP
  1197 +#line 108 "lexer.lxx"
  1198 +{ return FZ_STRING; }
  1199 + YY_BREAK
  1200 +case 45:
  1201 +YY_RULE_SETUP
  1202 +#line 109 "lexer.lxx"
  1203 +{ return FZ_TEST; }
  1204 + YY_BREAK
  1205 +case 46:
  1206 +YY_RULE_SETUP
  1207 +#line 110 "lexer.lxx"
  1208 +{ return FZ_THEN; }
  1209 + YY_BREAK
  1210 +case 47:
  1211 +YY_RULE_SETUP
  1212 +#line 111 "lexer.lxx"
  1213 +{ return FZ_TUPLE; }
  1214 + YY_BREAK
  1215 +case 48:
  1216 +YY_RULE_SETUP
  1217 +#line 112 "lexer.lxx"
  1218 +{ return FZ_TYPE; }
  1219 + YY_BREAK
  1220 +case 49:
  1221 +YY_RULE_SETUP
  1222 +#line 113 "lexer.lxx"
  1223 +{ yylval->bValue = true; return FZ_VAR; }
  1224 + YY_BREAK
  1225 +case 50:
  1226 +YY_RULE_SETUP
  1227 +#line 114 "lexer.lxx"
  1228 +{ return FZ_VARIANT_RECORD; }
  1229 + YY_BREAK
  1230 +case 51:
  1231 +YY_RULE_SETUP
  1232 +#line 115 "lexer.lxx"
  1233 +{ return FZ_WHERE; }
  1234 + YY_BREAK
  1235 +case 52:
  1236 +YY_RULE_SETUP
  1237 +#line 116 "lexer.lxx"
  1238 +{ yylval->sValue = strdup(yytext); return FZ_ID; }
  1239 + YY_BREAK
  1240 +case 53:
  1241 +YY_RULE_SETUP
  1242 +#line 117 "lexer.lxx"
  1243 +{ yylval->sValue = strdup(yytext); return FZ_U_ID; }
  1244 + YY_BREAK
  1245 +case 54:
  1246 +YY_RULE_SETUP
  1247 +#line 118 "lexer.lxx"
  1248 +{
  1249 + yylval->sValue = strdup(yytext+1);
  1250 + yylval->sValue[strlen(yytext)-2] = 0;
  1251 + return FZ_STRING_LIT; }
  1252 + YY_BREAK
  1253 +case 55:
  1254 +YY_RULE_SETUP
  1255 +#line 122 "lexer.lxx"
  1256 +{ yyerror("Unknown character"); }
  1257 + YY_BREAK
  1258 +case 56:
  1259 +YY_RULE_SETUP
  1260 +#line 123 "lexer.lxx"
  1261 +ECHO;
  1262 + YY_BREAK
  1263 +#line 1264 "lexer.yy.cpp"
  1264 +case YY_STATE_EOF(INITIAL):
  1265 + yyterminate();
  1266 +
  1267 + case YY_END_OF_BUFFER:
  1268 + {
  1269 + /* Amount of text matched not including the EOB char. */
  1270 + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
  1271 +
  1272 + /* Undo the effects of YY_DO_BEFORE_ACTION. */
  1273 + *yy_cp = yyg->yy_hold_char;
  1274 + YY_RESTORE_YY_MORE_OFFSET
  1275 +
  1276 + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
  1277 + {
  1278 + /* We're scanning a new file or input source. It's
  1279 + * possible that this happened because the user
  1280 + * just pointed yyin at a new source and called
  1281 + * yylex(). If so, then we have to assure
  1282 + * consistency between YY_CURRENT_BUFFER and our
  1283 + * globals. Here is the right place to do so, because
  1284 + * this is the first action (other than possibly a
  1285 + * back-up) that will match for the new input source.
  1286 + */
  1287 + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
  1288 + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
  1289 + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
  1290 + }
  1291 +
  1292 + /* Note that here we test for yy_c_buf_p "<=" to the position
  1293 + * of the first EOB in the buffer, since yy_c_buf_p will
  1294 + * already have been incremented past the NUL character
  1295 + * (since all states make transitions on EOB to the
  1296 + * end-of-buffer state). Contrast this with the test
  1297 + * in input().
  1298 + */
  1299 + if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
  1300 + { /* This was really a NUL. */
  1301 + yy_state_type yy_next_state;
  1302 +
  1303 + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
  1304 +
  1305 + yy_current_state = yy_get_previous_state( yyscanner );
  1306 +
  1307 + /* Okay, we're now positioned to make the NUL
  1308 + * transition. We couldn't have
  1309 + * yy_get_previous_state() go ahead and do it
  1310 + * for us because it doesn't know how to deal
  1311 + * with the possibility of jamming (and we don't
  1312 + * want to build jamming into it because then it
  1313 + * will run more slowly).
  1314 + */
  1315 +
  1316 + yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
  1317 +
  1318 + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
  1319 +
  1320 + if ( yy_next_state )
  1321 + {
  1322 + /* Consume the NUL. */
  1323 + yy_cp = ++yyg->yy_c_buf_p;
  1324 + yy_current_state = yy_next_state;
  1325 + goto yy_match;
  1326 + }
  1327 +
  1328 + else
  1329 + {
  1330 + yy_cp = yyg->yy_c_buf_p;
  1331 + goto yy_find_action;
  1332 + }
  1333 + }
  1334 +
  1335 + else switch ( yy_get_next_buffer( yyscanner ) )
  1336 + {
  1337 + case EOB_ACT_END_OF_FILE:
  1338 + {
  1339 + yyg->yy_did_buffer_switch_on_eof = 0;
  1340 +
  1341 + if ( yywrap(yyscanner ) )
  1342 + {
  1343 + /* Note: because we've taken care in
  1344 + * yy_get_next_buffer() to have set up
  1345 + * yytext, we can now set up
  1346 + * yy_c_buf_p so that if some total
  1347 + * hoser (like flex itself) wants to
  1348 + * call the scanner after we return the
  1349 + * YY_NULL, it'll still work - another
  1350 + * YY_NULL will get returned.
  1351 + */
  1352 + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
  1353 +
  1354 + yy_act = YY_STATE_EOF(YY_START);
  1355 + goto do_action;
  1356 + }
  1357 +
  1358 + else
  1359 + {
  1360 + if ( ! yyg->yy_did_buffer_switch_on_eof )
  1361 + YY_NEW_FILE;
  1362 + }
  1363 + break;
  1364 + }
  1365 +
  1366 + case EOB_ACT_CONTINUE_SCAN:
  1367 + yyg->yy_c_buf_p =
  1368 + yyg->yytext_ptr + yy_amount_of_matched_text;
  1369 +
  1370 + yy_current_state = yy_get_previous_state( yyscanner );
  1371 +
  1372 + yy_cp = yyg->yy_c_buf_p;
  1373 + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
  1374 + goto yy_match;
  1375 +
  1376 + case EOB_ACT_LAST_MATCH:
  1377 + yyg->yy_c_buf_p =
  1378 + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
  1379 +
  1380 + yy_current_state = yy_get_previous_state( yyscanner );
  1381 +
  1382 + yy_cp = yyg->yy_c_buf_p;
  1383 + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
  1384 + goto yy_find_action;
  1385 + }
  1386 + break;
  1387 + }
  1388 +
  1389 + default:
  1390 + YY_FATAL_ERROR(
  1391 + "fatal flex scanner internal error--no action found" );
  1392 + } /* end of action switch */
  1393 + } /* end of scanning one token */
  1394 +} /* end of yylex */
  1395 +
  1396 +/* yy_get_next_buffer - try to read in a new buffer
  1397 + *
  1398 + * Returns a code representing an action:
  1399 + * EOB_ACT_LAST_MATCH -
  1400 + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
  1401 + * EOB_ACT_END_OF_FILE - end of file
  1402 + */
  1403 +static int yy_get_next_buffer (yyscan_t yyscanner)
  1404 +{
  1405 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1406 + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
  1407 + register char *source = yyg->yytext_ptr;
  1408 + register int number_to_move, i;
  1409 + int ret_val;
  1410 +
  1411 + if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
  1412 + YY_FATAL_ERROR(
  1413 + "fatal flex scanner internal error--end of buffer missed" );
  1414 +
  1415 + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
  1416 + { /* Don't try to fill the buffer, so this is an EOF. */
  1417 + if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
  1418 + {
  1419 + /* We matched a single character, the EOB, so
  1420 + * treat this as a final EOF.
  1421 + */
  1422 + return EOB_ACT_END_OF_FILE;
  1423 + }
  1424 +
  1425 + else
  1426 + {
  1427 + /* We matched some text prior to the EOB, first
  1428 + * process it.
  1429 + */
  1430 + return EOB_ACT_LAST_MATCH;
  1431 + }
  1432 + }
  1433 +
  1434 + /* Try to read more data. */
  1435 +
  1436 + /* First move last chars to start of buffer. */
  1437 + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
  1438 +
  1439 + for ( i = 0; i < number_to_move; ++i )
  1440 + *(dest++) = *(source++);
  1441 +
  1442 + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
  1443 + /* don't do the read, it's not guaranteed to return an EOF,
  1444 + * just force an EOF
  1445 + */
  1446 + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
  1447 +
  1448 + else
  1449 + {
  1450 + int num_to_read =
  1451 + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
  1452 +
  1453 + while ( num_to_read <= 0 )
  1454 + { /* Not enough room in the buffer - grow it. */
  1455 +
  1456 + /* just a shorter name for the current buffer */
  1457 + YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
  1458 +
  1459 + int yy_c_buf_p_offset =
  1460 + (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
  1461 +
  1462 + if ( b->yy_is_our_buffer )
  1463 + {
  1464 + int new_size = b->yy_buf_size * 2;
  1465 +
  1466 + if ( new_size <= 0 )
  1467 + b->yy_buf_size += b->yy_buf_size / 8;
  1468 + else
  1469 + b->yy_buf_size *= 2;
  1470 +
  1471 + b->yy_ch_buf = (char *)
  1472 + /* Include room in for 2 EOB chars. */
  1473 + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
  1474 + }
  1475 + else
  1476 + /* Can't grow it, we don't own it. */
  1477 + b->yy_ch_buf = 0;
  1478 +
  1479 + if ( ! b->yy_ch_buf )
  1480 + YY_FATAL_ERROR(
  1481 + "fatal error - scanner input buffer overflow" );
  1482 +
  1483 + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
  1484 +
  1485 + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
  1486 + number_to_move - 1;
  1487 +
  1488 + }
  1489 +
  1490 + if ( num_to_read > YY_READ_BUF_SIZE )
  1491 + num_to_read = YY_READ_BUF_SIZE;
  1492 +
  1493 + /* Read in more data. */
  1494 + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
  1495 + yyg->yy_n_chars, (size_t) num_to_read );
  1496 +
  1497 + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
  1498 + }
  1499 +
  1500 + if ( yyg->yy_n_chars == 0 )
  1501 + {
  1502 + if ( number_to_move == YY_MORE_ADJ )
  1503 + {
  1504 + ret_val = EOB_ACT_END_OF_FILE;
  1505 + yyrestart(yyin ,yyscanner);
  1506 + }
  1507 +
  1508 + else
  1509 + {
  1510 + ret_val = EOB_ACT_LAST_MATCH;
  1511 + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
  1512 + YY_BUFFER_EOF_PENDING;
  1513 + }
  1514 + }
  1515 +
  1516 + else
  1517 + ret_val = EOB_ACT_CONTINUE_SCAN;
  1518 +
  1519 + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
  1520 + /* Extend the array by 50%, plus the number we really need. */
  1521 + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
  1522 + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
  1523 + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
  1524 + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
  1525 + }
  1526 +
  1527 + yyg->yy_n_chars += number_to_move;
  1528 + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  1529 + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  1530 +
  1531 + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
  1532 +
  1533 + return ret_val;
  1534 +}
  1535 +
  1536 +/* yy_get_previous_state - get the state just before the EOB char was reached */
  1537 +
  1538 + static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
  1539 +{
  1540 + register yy_state_type yy_current_state;
  1541 + register char *yy_cp;
  1542 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1543 +
  1544 + yy_current_state = yyg->yy_start;
  1545 +
  1546 + for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
  1547 + {
  1548 + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
  1549 + if ( yy_accept[yy_current_state] )
  1550 + {
  1551 + yyg->yy_last_accepting_state = yy_current_state;
  1552 + yyg->yy_last_accepting_cpos = yy_cp;
  1553 + }
  1554 + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  1555 + {
  1556 + yy_current_state = (int) yy_def[yy_current_state];
  1557 + if ( yy_current_state >= 221 )
  1558 + yy_c = yy_meta[(unsigned int) yy_c];
  1559 + }
  1560 + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  1561 + }
  1562 +
  1563 + return yy_current_state;
  1564 +}
  1565 +
  1566 +/* yy_try_NUL_trans - try to make a transition on the NUL character
  1567 + *
  1568 + * synopsis
  1569 + * next_state = yy_try_NUL_trans( current_state );
  1570 + */
  1571 + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
  1572 +{
  1573 + register int yy_is_jam;
  1574 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
  1575 + register char *yy_cp = yyg->yy_c_buf_p;
  1576 +
  1577 + register YY_CHAR yy_c = 1;
  1578 + if ( yy_accept[yy_current_state] )
  1579 + {
  1580 + yyg->yy_last_accepting_state = yy_current_state;
  1581 + yyg->yy_last_accepting_cpos = yy_cp;
  1582 + }
  1583 + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  1584 + {
  1585 + yy_current_state = (int) yy_def[yy_current_state];
  1586 + if ( yy_current_state >= 221 )
  1587 + yy_c = yy_meta[(unsigned int) yy_c];
  1588 + }
  1589 + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
  1590 + yy_is_jam = (yy_current_state == 220);
  1591 +
  1592 + return yy_is_jam ? 0 : yy_current_state;
  1593 +}
  1594 +
  1595 + static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
  1596 +{
  1597 + register char *yy_cp;
  1598 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1599 +
  1600 + yy_cp = yyg->yy_c_buf_p;
  1601 +
  1602 + /* undo effects of setting up yytext */
  1603 + *yy_cp = yyg->yy_hold_char;
  1604 +
  1605 + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
  1606 + { /* need to shift things up to make room */
  1607 + /* +2 for EOB chars. */
  1608 + register int number_to_move = yyg->yy_n_chars + 2;
  1609 + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
  1610 + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
  1611 + register char *source =
  1612 + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
  1613 +
  1614 + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
  1615 + *--dest = *--source;
  1616 +
  1617 + yy_cp += (int) (dest - source);
  1618 + yy_bp += (int) (dest - source);
  1619 + YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
  1620 + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
  1621 +
  1622 + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
  1623 + YY_FATAL_ERROR( "flex scanner push-back overflow" );
  1624 + }
  1625 +
  1626 + *--yy_cp = (char) c;
  1627 +
  1628 + if ( c == '\n' ){
  1629 + --yylineno;
  1630 + }
  1631 +
  1632 + yyg->yytext_ptr = yy_bp;
  1633 + yyg->yy_hold_char = *yy_cp;
  1634 + yyg->yy_c_buf_p = yy_cp;
  1635 +}
  1636 +
  1637 +#ifndef YY_NO_INPUT
  1638 +#ifdef __cplusplus
  1639 + static int yyinput (yyscan_t yyscanner)
  1640 +#else
  1641 + static int input (yyscan_t yyscanner)
  1642 +#endif
  1643 +
  1644 +{
  1645 + int c;
  1646 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1647 +
  1648 + *yyg->yy_c_buf_p = yyg->yy_hold_char;
  1649 +
  1650 + if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
  1651 + {
  1652 + /* yy_c_buf_p now points to the character we want to return.
  1653 + * If this occurs *before* the EOB characters, then it's a
  1654 + * valid NUL; if not, then we've hit the end of the buffer.
  1655 + */
  1656 + if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
  1657 + /* This was really a NUL. */
  1658 + *yyg->yy_c_buf_p = '\0';
  1659 +
  1660 + else
  1661 + { /* need more input */
  1662 + int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
  1663 + ++yyg->yy_c_buf_p;
  1664 +
  1665 + switch ( yy_get_next_buffer( yyscanner ) )
  1666 + {
  1667 + case EOB_ACT_LAST_MATCH:
  1668 + /* This happens because yy_g_n_b()
  1669 + * sees that we've accumulated a
  1670 + * token and flags that we need to
  1671 + * try matching the token before
  1672 + * proceeding. But for input(),
  1673 + * there's no matching to consider.
  1674 + * So convert the EOB_ACT_LAST_MATCH
  1675 + * to EOB_ACT_END_OF_FILE.
  1676 + */
  1677 +
  1678 + /* Reset buffer status. */
  1679 + yyrestart(yyin ,yyscanner);
  1680 +
  1681 + /*FALLTHROUGH*/
  1682 +
  1683 + case EOB_ACT_END_OF_FILE:
  1684 + {
  1685 + if ( yywrap(yyscanner ) )
  1686 + return EOF;
  1687 +
  1688 + if ( ! yyg->yy_did_buffer_switch_on_eof )
  1689 + YY_NEW_FILE;
  1690 +#ifdef __cplusplus
  1691 + return yyinput(yyscanner);
  1692 +#else
  1693 + return input(yyscanner);
  1694 +#endif
  1695 + }
  1696 +
  1697 + case EOB_ACT_CONTINUE_SCAN:
  1698 + yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
  1699 + break;
  1700 + }
  1701 + }
  1702 + }
  1703 +
  1704 + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
  1705 + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
  1706 + yyg->yy_hold_char = *++yyg->yy_c_buf_p;
  1707 +
  1708 + if ( c == '\n' )
  1709 +
  1710 + do{ yylineno++;
  1711 + yycolumn=0;
  1712 + }while(0)
  1713 +;
  1714 +
  1715 + return c;
  1716 +}
  1717 +#endif /* ifndef YY_NO_INPUT */
  1718 +
  1719 +/** Immediately switch to a different input stream.
  1720 + * @param input_file A readable stream.
  1721 + * @param yyscanner The scanner object.
  1722 + * @note This function does not reset the start condition to @c INITIAL .
  1723 + */
  1724 + void yyrestart (FILE * input_file , yyscan_t yyscanner)
  1725 +{
  1726 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1727 +
  1728 + if ( ! YY_CURRENT_BUFFER ){
  1729 + yyensure_buffer_stack (yyscanner);
  1730 + YY_CURRENT_BUFFER_LVALUE =
  1731 + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
  1732 + }
  1733 +
  1734 + yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
  1735 + yy_load_buffer_state(yyscanner );
  1736 +}
  1737 +
  1738 +/** Switch to a different input buffer.
  1739 + * @param new_buffer The new input buffer.
  1740 + * @param yyscanner The scanner object.
  1741 + */
  1742 + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
  1743 +{
  1744 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1745 +
  1746 + /* TODO. We should be able to replace this entire function body
  1747 + * with
  1748 + * yypop_buffer_state();
  1749 + * yypush_buffer_state(new_buffer);
  1750 + */
  1751 + yyensure_buffer_stack (yyscanner);
  1752 + if ( YY_CURRENT_BUFFER == new_buffer )
  1753 + return;
  1754 +
  1755 + if ( YY_CURRENT_BUFFER )
  1756 + {
  1757 + /* Flush out information for old buffer. */
  1758 + *yyg->yy_c_buf_p = yyg->yy_hold_char;
  1759 + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
  1760 + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
  1761 + }
  1762 +
  1763 + YY_CURRENT_BUFFER_LVALUE = new_buffer;
  1764 + yy_load_buffer_state(yyscanner );
  1765 +
  1766 + /* We don't actually know whether we did this switch during
  1767 + * EOF (yywrap()) processing, but the only time this flag
  1768 + * is looked at is after yywrap() is called, so it's safe
  1769 + * to go ahead and always set it.
  1770 + */
  1771 + yyg->yy_did_buffer_switch_on_eof = 1;
  1772 +}
  1773 +
  1774 +static void yy_load_buffer_state (yyscan_t yyscanner)
  1775 +{
  1776 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1777 + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
  1778 + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
  1779 + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
  1780 + yyg->yy_hold_char = *yyg->yy_c_buf_p;
  1781 +}
  1782 +
  1783 +/** Allocate and initialize an input buffer state.
  1784 + * @param file A readable stream.
  1785 + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
  1786 + * @param yyscanner The scanner object.
  1787 + * @return the allocated buffer state.
  1788 + */
  1789 + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
  1790 +{
  1791 + YY_BUFFER_STATE b;
  1792 +
  1793 + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
  1794 + if ( ! b )
  1795 + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
  1796 +
  1797 + b->yy_buf_size = size;
  1798 +
  1799 + /* yy_ch_buf has to be 2 characters longer than the size given because
  1800 + * we need to put in 2 end-of-buffer characters.
  1801 + */
  1802 + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ,yyscanner );
  1803 + if ( ! b->yy_ch_buf )
  1804 + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
  1805 +
  1806 + b->yy_is_our_buffer = 1;
  1807 +
  1808 + yy_init_buffer(b,file ,yyscanner);
  1809 +
  1810 + return b;
  1811 +}
  1812 +
  1813 +/** Destroy the buffer.
  1814 + * @param b a buffer created with yy_create_buffer()
  1815 + * @param yyscanner The scanner object.
  1816 + */
  1817 + void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
  1818 +{
  1819 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1820 +
  1821 + if ( ! b )
  1822 + return;
  1823 +
  1824 + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
  1825 + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
  1826 +
  1827 + if ( b->yy_is_our_buffer )
  1828 + yyfree((void *) b->yy_ch_buf ,yyscanner );
  1829 +
  1830 + yyfree((void *) b ,yyscanner );
  1831 +}
  1832 +
  1833 +#ifndef __cplusplus
  1834 +extern int isatty (int );
  1835 +#endif /* __cplusplus */
  1836 +
  1837 +/* Initializes or reinitializes a buffer.
  1838 + * This function is sometimes called more than once on the same buffer,
  1839 + * such as during a yyrestart() or at EOF.
  1840 + */
  1841 + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
  1842 +
  1843 +{
  1844 + int oerrno = errno;
  1845 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1846 +
  1847 + yy_flush_buffer(b ,yyscanner);
  1848 +
  1849 + b->yy_input_file = file;
  1850 + b->yy_fill_buffer = 1;
  1851 +
  1852 + /* If b is the current buffer, then yy_init_buffer was _probably_
  1853 + * called from yyrestart() or through yy_get_next_buffer.
  1854 + * In that case, we don't want to reset the lineno or column.
  1855 + */
  1856 + if (b != YY_CURRENT_BUFFER){
  1857 + b->yy_bs_lineno = 1;
  1858 + b->yy_bs_column = 0;
  1859 + }
  1860 +
  1861 + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
  1862 +
  1863 + errno = oerrno;
  1864 +}
  1865 +
  1866 +/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
  1867 + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
  1868 + * @param yyscanner The scanner object.
  1869 + */
  1870 + void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
  1871 +{
  1872 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1873 + if ( ! b )
  1874 + return;
  1875 +
  1876 + b->yy_n_chars = 0;
  1877 +
  1878 + /* We always need two end-of-buffer characters. The first causes
  1879 + * a transition to the end-of-buffer state. The second causes
  1880 + * a jam in that state.
  1881 + */
  1882 + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
  1883 + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
  1884 +
  1885 + b->yy_buf_pos = &b->yy_ch_buf[0];
  1886 +
  1887 + b->yy_at_bol = 1;
  1888 + b->yy_buffer_status = YY_BUFFER_NEW;
  1889 +
  1890 + if ( b == YY_CURRENT_BUFFER )
  1891 + yy_load_buffer_state(yyscanner );
  1892 +}
  1893 +
  1894 +/** Pushes the new state onto the stack. The new state becomes
  1895 + * the current state. This function will allocate the stack
  1896 + * if necessary.
  1897 + * @param new_buffer The new state.
  1898 + * @param yyscanner The scanner object.
  1899 + */
  1900 +void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
  1901 +{
  1902 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1903 + if (new_buffer == NULL)
  1904 + return;
  1905 +
  1906 + yyensure_buffer_stack(yyscanner);
  1907 +
  1908 + /* This block is copied from yy_switch_to_buffer. */
  1909 + if ( YY_CURRENT_BUFFER )
  1910 + {
  1911 + /* Flush out information for old buffer. */
  1912 + *yyg->yy_c_buf_p = yyg->yy_hold_char;
  1913 + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
  1914 + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
  1915 + }
  1916 +
  1917 + /* Only push if top exists. Otherwise, replace top. */
  1918 + if (YY_CURRENT_BUFFER)
  1919 + yyg->yy_buffer_stack_top++;
  1920 + YY_CURRENT_BUFFER_LVALUE = new_buffer;
  1921 +
  1922 + /* copied from yy_switch_to_buffer. */
  1923 + yy_load_buffer_state(yyscanner );
  1924 + yyg->yy_did_buffer_switch_on_eof = 1;
  1925 +}
  1926 +
  1927 +/** Removes and deletes the top of the stack, if present.
  1928 + * The next element becomes the new top.
  1929 + * @param yyscanner The scanner object.
  1930 + */
  1931 +void yypop_buffer_state (yyscan_t yyscanner)
  1932 +{
  1933 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1934 + if (!YY_CURRENT_BUFFER)
  1935 + return;
  1936 +
  1937 + yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
  1938 + YY_CURRENT_BUFFER_LVALUE = NULL;
  1939 + if (yyg->yy_buffer_stack_top > 0)
  1940 + --yyg->yy_buffer_stack_top;
  1941 +
  1942 + if (YY_CURRENT_BUFFER) {
  1943 + yy_load_buffer_state(yyscanner );
  1944 + yyg->yy_did_buffer_switch_on_eof = 1;
  1945 + }
  1946 +}
  1947 +
  1948 +/* Allocates the stack if it does not exist.
  1949 + * Guarantees space for at least one push.
  1950 + */
  1951 +static void yyensure_buffer_stack (yyscan_t yyscanner)
  1952 +{
  1953 + int num_to_alloc;
  1954 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  1955 +
  1956 + if (!yyg->yy_buffer_stack) {
  1957 +
  1958 + /* First allocation is just for 2 elements, since we don't know if this
  1959 + * scanner will even need a stack. We use 2 instead of 1 to avoid an
  1960 + * immediate realloc on the next call.
  1961 + */
  1962 + num_to_alloc = 1;
  1963 + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
  1964 + (num_to_alloc * sizeof(struct yy_buffer_state*)
  1965 + , yyscanner);
  1966 + if ( ! yyg->yy_buffer_stack )
  1967 + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
  1968 +
  1969 + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
  1970 +
  1971 + yyg->yy_buffer_stack_max = num_to_alloc;
  1972 + yyg->yy_buffer_stack_top = 0;
  1973 + return;
  1974 + }
  1975 +
  1976 + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
  1977 +
  1978 + /* Increase the buffer to prepare for a possible push. */
  1979 + int grow_size = 8 /* arbitrary grow size */;
  1980 +
  1981 + num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
  1982 + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc
  1983 + (yyg->yy_buffer_stack,
  1984 + num_to_alloc * sizeof(struct yy_buffer_state*)
  1985 + , yyscanner);
  1986 + if ( ! yyg->yy_buffer_stack )
  1987 + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
  1988 +
  1989 + /* zero only the new slots.*/
  1990 + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
  1991 + yyg->yy_buffer_stack_max = num_to_alloc;
  1992 + }
  1993 +}
  1994 +
  1995 +/** Setup the input buffer state to scan directly from a user-specified character buffer.
  1996 + * @param base the character buffer
  1997 + * @param size the size in bytes of the character buffer
  1998 + * @param yyscanner The scanner object.
  1999 + * @return the newly allocated buffer state object.
  2000 + */
  2001 +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
  2002 +{
  2003 + YY_BUFFER_STATE b;
  2004 +
  2005 + if ( size < 2 ||
  2006 + base[size-2] != YY_END_OF_BUFFER_CHAR ||
  2007 + base[size-1] != YY_END_OF_BUFFER_CHAR )
  2008 + /* They forgot to leave room for the EOB's. */
  2009 + return 0;
  2010 +
  2011 + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
  2012 + if ( ! b )
  2013 + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
  2014 +
  2015 + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
  2016 + b->yy_buf_pos = b->yy_ch_buf = base;
  2017 + b->yy_is_our_buffer = 0;
  2018 + b->yy_input_file = 0;
  2019 + b->yy_n_chars = b->yy_buf_size;
  2020 + b->yy_is_interactive = 0;
  2021 + b->yy_at_bol = 1;
  2022 + b->yy_fill_buffer = 0;
  2023 + b->yy_buffer_status = YY_BUFFER_NEW;
  2024 +
  2025 + yy_switch_to_buffer(b ,yyscanner );
  2026 +
  2027 + return b;
  2028 +}
  2029 +
  2030 +/** Setup the input buffer state to scan a string. The next call to yylex() will
  2031 + * scan from a @e copy of @a str.
  2032 + * @param yystr a NUL-terminated string to scan
  2033 + * @param yyscanner The scanner object.
  2034 + * @return the newly allocated buffer state object.
  2035 + * @note If you want to scan bytes that may contain NUL values, then use
  2036 + * yy_scan_bytes() instead.
  2037 + */
  2038 +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
  2039 +{
  2040 +
  2041 + return yy_scan_bytes(yystr,strlen(yystr) ,yyscanner);
  2042 +}
  2043 +
  2044 +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
  2045 + * scan from a @e copy of @a bytes.
  2046 + * @param bytes the byte buffer to scan
  2047 + * @param len the number of bytes in the buffer pointed to by @a bytes.
  2048 + * @param yyscanner The scanner object.
  2049 + * @return the newly allocated buffer state object.
  2050 + */
  2051 +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
  2052 +{
  2053 + YY_BUFFER_STATE b;
  2054 + char *buf;
  2055 + yy_size_t n;
  2056 + int i;
  2057 +
  2058 + /* Get memory for full buffer, including space for trailing EOB's. */
  2059 + n = _yybytes_len + 2;
  2060 + buf = (char *) yyalloc(n ,yyscanner );
  2061 + if ( ! buf )
  2062 + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
  2063 +
  2064 + for ( i = 0; i < _yybytes_len; ++i )
  2065 + buf[i] = yybytes[i];
  2066 +
  2067 + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
  2068 +
  2069 + b = yy_scan_buffer(buf,n ,yyscanner);
  2070 + if ( ! b )
  2071 + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
  2072 +
  2073 + /* It's okay to grow etc. this buffer, and we should throw it
  2074 + * away when we're done.
  2075 + */
  2076 + b->yy_is_our_buffer = 1;
  2077 +
  2078 + return b;
  2079 +}
  2080 +
  2081 +#ifndef YY_EXIT_FAILURE
  2082 +#define YY_EXIT_FAILURE 2
  2083 +#endif
  2084 +
  2085 +static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
  2086 +{
  2087 + (void) fprintf( stderr, "%s\n", msg );
  2088 + exit( YY_EXIT_FAILURE );
  2089 +}
  2090 +
  2091 +/* Redefine yyless() so it works in section 3 code. */
  2092 +
  2093 +#undef yyless
  2094 +#define yyless(n) \
  2095 + do \
  2096 + { \
  2097 + /* Undo effects of setting up yytext. */ \
  2098 + int yyless_macro_arg = (n); \
  2099 + YY_LESS_LINENO(yyless_macro_arg);\
  2100 + yytext[yyleng] = yyg->yy_hold_char; \
  2101 + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
  2102 + yyg->yy_hold_char = *yyg->yy_c_buf_p; \
  2103 + *yyg->yy_c_buf_p = '\0'; \
  2104 + yyleng = yyless_macro_arg; \
  2105 + } \
  2106 + while ( 0 )
  2107 +
  2108 +/* Accessor methods (get/set functions) to struct members. */
  2109 +
  2110 +/** Get the user-defined data for this scanner.
  2111 + * @param yyscanner The scanner object.
  2112 + */
  2113 +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner)
  2114 +{
  2115 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2116 + return yyextra;
  2117 +}
  2118 +
  2119 +/** Get the current line number.
  2120 + * @param yyscanner The scanner object.
  2121 + */
  2122 +int yyget_lineno (yyscan_t yyscanner)
  2123 +{
  2124 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2125 +
  2126 + if (! YY_CURRENT_BUFFER)
  2127 + return 0;
  2128 +
  2129 + return yylineno;
  2130 +}
  2131 +
  2132 +/** Get the current column number.
  2133 + * @param yyscanner The scanner object.
  2134 + */
  2135 +int yyget_column (yyscan_t yyscanner)
  2136 +{
  2137 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2138 +
  2139 + if (! YY_CURRENT_BUFFER)
  2140 + return 0;
  2141 +
  2142 + return yycolumn;
  2143 +}
  2144 +
  2145 +/** Get the input stream.
  2146 + * @param yyscanner The scanner object.
  2147 + */
  2148 +FILE *yyget_in (yyscan_t yyscanner)
  2149 +{
  2150 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2151 + return yyin;
  2152 +}
  2153 +
  2154 +/** Get the output stream.
  2155 + * @param yyscanner The scanner object.
  2156 + */
  2157 +FILE *yyget_out (yyscan_t yyscanner)
  2158 +{
  2159 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2160 + return yyout;
  2161 +}
  2162 +
  2163 +/** Get the length of the current token.
  2164 + * @param yyscanner The scanner object.
  2165 + */
  2166 +int yyget_leng (yyscan_t yyscanner)
  2167 +{
  2168 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2169 + return yyleng;
  2170 +}
  2171 +
  2172 +/** Get the current token.
  2173 + * @param yyscanner The scanner object.
  2174 + */
  2175 +
  2176 +char *yyget_text (yyscan_t yyscanner)
  2177 +{
  2178 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2179 + return yytext;
  2180 +}
  2181 +
  2182 +/** Set the user-defined data. This data is never touched by the scanner.
  2183 + * @param user_defined The data to be associated with this scanner.
  2184 + * @param yyscanner The scanner object.
  2185 + */
  2186 +void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
  2187 +{
  2188 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2189 + yyextra = user_defined ;
  2190 +}
  2191 +
  2192 +/** Set the current line number.
  2193 + * @param line_number
  2194 + * @param yyscanner The scanner object.
  2195 + */
  2196 +void yyset_lineno (int line_number , yyscan_t yyscanner)
  2197 +{
  2198 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2199 +
  2200 + /* lineno is only valid if an input buffer exists. */
  2201 + if (! YY_CURRENT_BUFFER )
  2202 + yy_fatal_error( "yyset_lineno called with no buffer" , yyscanner);
  2203 +
  2204 + yylineno = line_number;
  2205 +}
  2206 +
  2207 +/** Set the current column.
  2208 + * @param line_number
  2209 + * @param yyscanner The scanner object.
  2210 + */
  2211 +void yyset_column (int column_no , yyscan_t yyscanner)
  2212 +{
  2213 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2214 +
  2215 + /* column is only valid if an input buffer exists. */
  2216 + if (! YY_CURRENT_BUFFER )
  2217 + yy_fatal_error( "yyset_column called with no buffer" , yyscanner);
  2218 +
  2219 + yycolumn = column_no;
  2220 +}
  2221 +
  2222 +/** Set the input stream. This does not discard the current
  2223 + * input buffer.
  2224 + * @param in_str A readable stream.
  2225 + * @param yyscanner The scanner object.
  2226 + * @see yy_switch_to_buffer
  2227 + */
  2228 +void yyset_in (FILE * in_str , yyscan_t yyscanner)
  2229 +{
  2230 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2231 + yyin = in_str ;
  2232 +}
  2233 +
  2234 +void yyset_out (FILE * out_str , yyscan_t yyscanner)
  2235 +{
  2236 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2237 + yyout = out_str ;
  2238 +}
  2239 +
  2240 +int yyget_debug (yyscan_t yyscanner)
  2241 +{
  2242 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2243 + return yy_flex_debug;
  2244 +}
  2245 +
  2246 +void yyset_debug (int bdebug , yyscan_t yyscanner)
  2247 +{
  2248 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2249 + yy_flex_debug = bdebug ;
  2250 +}
  2251 +
  2252 +/* Accessor methods for yylval and yylloc */
  2253 +
  2254 +YYSTYPE * yyget_lval (yyscan_t yyscanner)
  2255 +{
  2256 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2257 + return yylval;
  2258 +}
  2259 +
  2260 +void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
  2261 +{
  2262 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2263 + yylval = yylval_param;
  2264 +}
  2265 +
  2266 +/* User-visible API */
  2267 +
  2268 +/* yylex_init is special because it creates the scanner itself, so it is
  2269 + * the ONLY reentrant function that doesn't take the scanner as the last argument.
  2270 + * That's why we explicitly handle the declaration, instead of using our macros.
  2271 + */
  2272 +
  2273 +int yylex_init(yyscan_t* ptr_yy_globals)
  2274 +
  2275 +{
  2276 + if (ptr_yy_globals == NULL){
  2277 + errno = EINVAL;
  2278 + return 1;
  2279 + }
  2280 +
  2281 + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
  2282 +
  2283 + if (*ptr_yy_globals == NULL){
  2284 + errno = ENOMEM;
  2285 + return 1;
  2286 + }
  2287 +
  2288 + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
  2289 + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
  2290 +
  2291 + return yy_init_globals ( *ptr_yy_globals );
  2292 +}
  2293 +
  2294 +/* yylex_init_extra has the same functionality as yylex_init, but follows the
  2295 + * convention of taking the scanner as the last argument. Note however, that
  2296 + * this is a *pointer* to a scanner, as it will be allocated by this call (and
  2297 + * is the reason, too, why this function also must handle its own declaration).
  2298 + * The user defined value in the first argument will be available to yyalloc in
  2299 + * the yyextra field.
  2300 + */
  2301 +
  2302 +int yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
  2303 +
  2304 +{
  2305 + struct yyguts_t dummy_yyguts;
  2306 +
  2307 + yyset_extra (yy_user_defined, &dummy_yyguts);
  2308 +
  2309 + if (ptr_yy_globals == NULL){
  2310 + errno = EINVAL;
  2311 + return 1;
  2312 + }
  2313 +
  2314 + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
  2315 +
  2316 + if (*ptr_yy_globals == NULL){
  2317 + errno = ENOMEM;
  2318 + return 1;
  2319 + }
  2320 +
  2321 + /* By setting to 0xAA, we expose bugs in
  2322 + yy_init_globals. Leave at 0x00 for releases. */
  2323 + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
  2324 +
  2325 + yyset_extra (yy_user_defined, *ptr_yy_globals);
  2326 +
  2327 + return yy_init_globals ( *ptr_yy_globals );
  2328 +}
  2329 +
  2330 +static int yy_init_globals (yyscan_t yyscanner)
  2331 +{
  2332 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2333 + /* Initialization is the same as for the non-reentrant scanner.
  2334 + * This function is called from yylex_destroy(), so don't allocate here.
  2335 + */
  2336 +
  2337 + yyg->yy_buffer_stack = 0;
  2338 + yyg->yy_buffer_stack_top = 0;
  2339 + yyg->yy_buffer_stack_max = 0;
  2340 + yyg->yy_c_buf_p = (char *) 0;
  2341 + yyg->yy_init = 0;
  2342 + yyg->yy_start = 0;
  2343 +
  2344 + yyg->yy_start_stack_ptr = 0;
  2345 + yyg->yy_start_stack_depth = 0;
  2346 + yyg->yy_start_stack = NULL;
  2347 +
  2348 +/* Defined in main.c */
  2349 +#ifdef YY_STDINIT
  2350 + yyin = stdin;
  2351 + yyout = stdout;
  2352 +#else
  2353 + yyin = (FILE *) 0;
  2354 + yyout = (FILE *) 0;
  2355 +#endif
  2356 +
  2357 + /* For future reference: Set errno on error, since we are called by
  2358 + * yylex_init()
  2359 + */
  2360 + return 0;
  2361 +}
  2362 +
  2363 +/* yylex_destroy is for both reentrant and non-reentrant scanners. */
  2364 +int yylex_destroy (yyscan_t yyscanner)
  2365 +{
  2366 + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  2367 +
  2368 + /* Pop the buffer stack, destroying each element. */
  2369 + while(YY_CURRENT_BUFFER){
  2370 + yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
  2371 + YY_CURRENT_BUFFER_LVALUE = NULL;
  2372 + yypop_buffer_state(yyscanner);
  2373 + }
  2374 +
  2375 + /* Destroy the stack itself. */
  2376 + yyfree(yyg->yy_buffer_stack ,yyscanner);
  2377 + yyg->yy_buffer_stack = NULL;
  2378 +
  2379 + /* Destroy the start condition stack. */
  2380 + yyfree(yyg->yy_start_stack ,yyscanner );
  2381 + yyg->yy_start_stack = NULL;
  2382 +
  2383 + /* Reset the globals. This is important in a non-reentrant scanner so the next time
  2384 + * yylex() is called, initialization will occur. */
  2385 + yy_init_globals( yyscanner);
  2386 +
  2387 + /* Destroy the main struct (reentrant only). */
  2388 + yyfree ( yyscanner , yyscanner );
  2389 + yyscanner = NULL;
  2390 + return 0;
  2391 +}
  2392 +
  2393 +/*
  2394 + * Internal utility routines.
  2395 + */
  2396 +
  2397 +#ifndef yytext_ptr
  2398 +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
  2399 +{
  2400 + register int i;
  2401 + for ( i = 0; i < n; ++i )
  2402 + s1[i] = s2[i];
  2403 +}
  2404 +#endif
  2405 +
  2406 +#ifdef YY_NEED_STRLEN
  2407 +static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
  2408 +{
  2409 + register int n;
  2410 + for ( n = 0; s[n]; ++n )
  2411 + ;
  2412 +
  2413 + return n;
  2414 +}
  2415 +#endif
  2416 +
  2417 +void *yyalloc (yy_size_t size , yyscan_t yyscanner)
  2418 +{
  2419 + return (void *) malloc( size );
  2420 +}
  2421 +
  2422 +void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
  2423 +{
  2424 + /* The cast to (char *) in the following accommodates both
  2425 + * implementations that use char* generic pointers, and those
  2426 + * that use void* generic pointers. It works with the latter
  2427 + * because both ANSI C and C++ allow castless assignment from
  2428 + * any pointer type to void*, and deal with argument conversions
  2429 + * as though doing an assignment.
  2430 + */
  2431 + return (void *) realloc( (char *) ptr, size );
  2432 +}
  2433 +
  2434 +void yyfree (void * ptr , yyscan_t yyscanner)
  2435 +{
  2436 + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
  2437 +}
  2438 +
  2439 +#define YYTABLES_NAME "yytables"
  2440 +
  2441 +#line 123 "lexer.lxx"
  2442 +
  2443 +
  2444 +int yy_input_proc(char* buf, int size, yyscan_t yyscanner) {
  2445 + FlatZinc::ParserState* parm =
  2446 + static_cast<FlatZinc::ParserState*>(yyget_extra(yyscanner));
  2447 + return parm->fillBuffer(buf, size);
  2448 + // work around warning that yyunput is unused
  2449 + yyunput (0,buf,yyscanner);
  2450 +}
  2451 +
... ...
fz/option.hh 0 → 100644
... ... @@ -0,0 +1,70 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2010-07-02 19:18:43 +1000 (Fri, 02 Jul 2010) $ by $Author: tack $
  11 + * $Revision: 11149 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#ifndef __FLATZINC_OPTION_HH__
  39 +#define __FLATZINC_OPTION_HH__
  40 +
  41 +namespace FlatZinc {
  42 +
  43 + /// Optional value
  44 + template<class Val>
  45 + struct Option {
  46 + private:
  47 + bool _some;
  48 + Val _v;
  49 + public:
  50 + bool operator()(void) const { return _some; }
  51 + const Val& some(void) const { return _v; }
  52 + static Option<Val> none(void) {
  53 + Option<Val> o;
  54 + o._some = false;
  55 + new (&o._v) Val();
  56 + return o;
  57 + }
  58 + static Option<Val> some(const Val& v) {
  59 + Option<Val> o;
  60 + o._some = true;
  61 + o._v = v;
  62 + return o;
  63 + }
  64 + };
  65 +
  66 +}
  67 +
  68 +#endif
  69 +
  70 +// STATISTICS: flatzinc-any
... ...
fz/parser.hh 0 → 100644
... ... @@ -0,0 +1,172 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2011-01-18 20:06:16 +1100 (Tue, 18 Jan 2011) $ by $Author: tack $
  11 + * $Revision: 11538 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#ifndef __FLATZINC_PARSER_HH__
  39 +#define __FLATZINC_PARSER_HH__
  40 +
  41 +#include <cstring>
  42 +#include "flatzinc.hh"
  43 +
  44 +// This is a workaround for a bug in flex that only shows up
  45 +// with the Microsoft C++ compiler
  46 +#if defined(_MSC_VER)
  47 +#define YY_NO_UNISTD_H
  48 +#ifdef __cplusplus
  49 +extern "C" int isatty(int);
  50 +#endif
  51 +#endif
  52 +
  53 +// The Microsoft C++ compiler marks certain functions as deprecated,
  54 +// so let's take the alternative definitions
  55 +#if defined(_MSC_VER)
  56 +#define strdup _strdup
  57 +#define fileno _fileno
  58 +#endif
  59 +
  60 +#include <string>
  61 +#include <vector>
  62 +#include <iostream>
  63 +#include <algorithm>
  64 +
  65 +#include "option.hh"
  66 +#include "varspec.hh"
  67 +#include "conexpr.hh"
  68 +#include "ast.hh"
  69 +#include "parser.tab.hh"
  70 +#include "symboltable.hh"
  71 +
  72 +namespace FlatZinc {
  73 +
  74 + typedef std::pair<std::string,Option<std::vector<int>* > > intvartype;
  75 +
  76 + class VarSpec;
  77 + typedef std::pair<std::string, VarSpec*> varspec;
  78 +
  79 + /// Strict weak ordering for output items
  80 + class OutputOrder {
  81 + public:
  82 + /// Return if \a x is less than \a y, based on first component
  83 + bool operator ()(const std::pair<std::string,AST::Node*>& x,
  84 + const std::pair<std::string,AST::Node*>& y) {
  85 + return x.first < y.first;
  86 + }
  87 + };
  88 +
  89 + /// %State of the %FlatZinc parser
  90 + class ParserState {
  91 + public:
  92 + ParserState(const std::string& b, std::ostream& err0,
  93 + FlatZinc::FlatZincModel* fg0)
  94 + : buf(b.c_str()), pos(0), length(b.size()), fg(fg0),
  95 + hadError(false), err(err0) {}
  96 +
  97 + ParserState(char* buf0, int length0, std::ostream& err0,
  98 + FlatZinc::FlatZincModel* fg0)
  99 + : buf(buf0), pos(0), length(length0), fg(fg0),
  100 + hadError(false), err(err0) {}
  101 +
  102 + void* yyscanner;
  103 + const char* buf;
  104 + unsigned int pos, length;
  105 + FlatZinc::FlatZincModel* fg;
  106 + std::vector<std::pair<std::string,AST::Node*> > _output;
  107 +
  108 + SymbolTable<int> intvarTable;
  109 + SymbolTable<int> boolvarTable;
  110 + SymbolTable<int> floatvarTable;
  111 + SymbolTable<int> setvarTable;
  112 + SymbolTable<std::vector<int> > intvararrays;
  113 + SymbolTable<std::vector<int> > boolvararrays;
  114 + SymbolTable<std::vector<int> > floatvararrays;
  115 + SymbolTable<std::vector<int> > setvararrays;
  116 + SymbolTable<std::vector<int> > intvalarrays;
  117 + SymbolTable<std::vector<int> > boolvalarrays;
  118 + SymbolTable<int> intvals;
  119 + SymbolTable<bool> boolvals;
  120 + SymbolTable<AST::SetLit> setvals;
  121 + SymbolTable<std::vector<AST::SetLit> > setvalarrays;
  122 +
  123 + std::vector<varspec> intvars;
  124 + std::vector<varspec> boolvars;
  125 + std::vector<varspec> setvars;
  126 +
  127 + std::vector<ConExpr*> domainConstraints;
  128 +
  129 + bool hadError;
  130 + std::ostream& err;
  131 +
  132 + int fillBuffer(char* lexBuf, unsigned int lexBufSize) {
  133 + if (pos >= length)
  134 + return 0;
  135 + int num = std::min(length - pos, lexBufSize);
  136 + memcpy(lexBuf,buf+pos,num);
  137 + pos += num;
  138 + return num;
  139 + }
  140 +
  141 + void output(std::string x, AST::Node* n) {
  142 + _output.push_back(std::pair<std::string,AST::Node*>(x,n));
  143 + }
  144 +
  145 + AST::Array* getOutput(void) {
  146 + OutputOrder oo;
  147 + std::sort(_output.begin(),_output.end(),oo);
  148 + AST::Array* a = new AST::Array();
  149 + for (unsigned int i=0; i<_output.size(); i++) {
  150 + a->a.push_back(new AST::String(_output[i].first+" = "));
  151 + if (_output[i].second->isArray()) {
  152 + AST::Array* oa = _output[i].second->getArray();
  153 + for (unsigned int j=0; j<oa->a.size(); j++) {
  154 + a->a.push_back(oa->a[j]);
  155 + oa->a[j] = NULL;
  156 + }
  157 + delete _output[i].second;
  158 + } else {
  159 + a->a.push_back(_output[i].second);
  160 + }
  161 + a->a.push_back(new AST::String(";\n"));
  162 + }
  163 + return a;
  164 + }
  165 +
  166 + };
  167 +
  168 +}
  169 +
  170 +#endif
  171 +
  172 +// STATISTICS: flatzinc-any
... ...
fz/parser.tab.cpp 0 → 100644
... ... @@ -0,0 +1,3441 @@
  1 +/* A Bison parser, made by GNU Bison 2.3. */
  2 +
  3 +/* Skeleton implementation for Bison's Yacc-like parsers in C
  4 +
  5 + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
  6 + Free Software Foundation, Inc.
  7 +
  8 + This program is free software; you can redistribute it and/or modify
  9 + it under the terms of the GNU General Public License as published by
  10 + the Free Software Foundation; either version 2, or (at your option)
  11 + any later version.
  12 +
  13 + This program is distributed in the hope that it will be useful,
  14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + GNU General Public License for more details.
  17 +
  18 + You should have received a copy of the GNU General Public License
  19 + along with this program; if not, write to the Free Software
  20 + Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21 + Boston, MA 02110-1301, USA. */
  22 +
  23 +/* As a special exception, you may create a larger work that contains
  24 + part or all of the Bison parser skeleton and distribute that work
  25 + under terms of your choice, so long as that work isn't itself a
  26 + parser generator using the skeleton or a modified version thereof
  27 + as a parser skeleton. Alternatively, if you modify or redistribute
  28 + the parser skeleton itself, you may (at your option) remove this
  29 + special exception, which will cause the skeleton and the resulting
  30 + Bison output files to be licensed under the GNU General Public
  31 + License without this special exception.
  32 +
  33 + This special exception was added by the Free Software Foundation in
  34 + version 2.2 of Bison. */
  35 +
  36 +/* C LALR(1) parser skeleton written by Richard Stallman, by
  37 + simplifying the original so-called "semantic" parser. */
  38 +
  39 +/* All symbols defined below should begin with yy or YY, to avoid
  40 + infringing on user name space. This should be done even for local
  41 + variables, as they might otherwise be expanded by user macros.
  42 + There are some unavoidable exceptions within include files to
  43 + define necessary library symbols; they are noted "INFRINGES ON
  44 + USER NAME SPACE" below. */
  45 +
  46 +/* Identify Bison output. */
  47 +#define YYBISON 1
  48 +
  49 +/* Bison version. */
  50 +#define YYBISON_VERSION "2.3"
  51 +
  52 +/* Skeleton name. */
  53 +#define YYSKELETON_NAME "yacc.c"
  54 +
  55 +/* Pure parsers. */
  56 +#define YYPURE 1
  57 +
  58 +/* Using locations. */
  59 +#define YYLSP_NEEDED 0
  60 +
  61 +
  62 +
  63 +/* Tokens. */
  64 +#ifndef YYTOKENTYPE
  65 +# define YYTOKENTYPE
  66 + /* Put the tokens into the symbol table, so that GDB and other debuggers
  67 + know about them. */
  68 + enum yytokentype {
  69 + FZ_INT_LIT = 258,
  70 + FZ_BOOL_LIT = 259,
  71 + FZ_FLOAT_LIT = 260,
  72 + FZ_ID = 261,
  73 + FZ_U_ID = 262,
  74 + FZ_STRING_LIT = 263,
  75 + FZ_VAR = 264,
  76 + FZ_PAR = 265,
  77 + FZ_ANNOTATION = 266,
  78 + FZ_ANY = 267,
  79 + FZ_ARRAY = 268,
  80 + FZ_BOOL = 269,
  81 + FZ_CASE = 270,
  82 + FZ_COLONCOLON = 271,
  83 + FZ_CONSTRAINT = 272,
  84 + FZ_DEFAULT = 273,
  85 + FZ_DOTDOT = 274,
  86 + FZ_ELSE = 275,
  87 + FZ_ELSEIF = 276,
  88 + FZ_ENDIF = 277,
  89 + FZ_ENUM = 278,
  90 + FZ_FLOAT = 279,
  91 + FZ_FUNCTION = 280,
  92 + FZ_IF = 281,
  93 + FZ_INCLUDE = 282,
  94 + FZ_INT = 283,
  95 + FZ_LET = 284,
  96 + FZ_MAXIMIZE = 285,
  97 + FZ_MINIMIZE = 286,
  98 + FZ_OF = 287,
  99 + FZ_SATISFY = 288,
  100 + FZ_OUTPUT = 289,
  101 + FZ_PREDICATE = 290,
  102 + FZ_RECORD = 291,
  103 + FZ_SET = 292,
  104 + FZ_SHOW = 293,
  105 + FZ_SHOWCOND = 294,
  106 + FZ_SOLVE = 295,
  107 + FZ_STRING = 296,
  108 + FZ_TEST = 297,
  109 + FZ_THEN = 298,
  110 + FZ_TUPLE = 299,
  111 + FZ_TYPE = 300,
  112 + FZ_VARIANT_RECORD = 301,
  113 + FZ_WHERE = 302
  114 + };
  115 +#endif
  116 +/* Tokens. */
  117 +#define FZ_INT_LIT 258
  118 +#define FZ_BOOL_LIT 259
  119 +#define FZ_FLOAT_LIT 260
  120 +#define FZ_ID 261
  121 +#define FZ_U_ID 262
  122 +#define FZ_STRING_LIT 263
  123 +#define FZ_VAR 264
  124 +#define FZ_PAR 265
  125 +#define FZ_ANNOTATION 266
  126 +#define FZ_ANY 267
  127 +#define FZ_ARRAY 268
  128 +#define FZ_BOOL 269
  129 +#define FZ_CASE 270
  130 +#define FZ_COLONCOLON 271
  131 +#define FZ_CONSTRAINT 272
  132 +#define FZ_DEFAULT 273
  133 +#define FZ_DOTDOT 274
  134 +#define FZ_ELSE 275
  135 +#define FZ_ELSEIF 276
  136 +#define FZ_ENDIF 277
  137 +#define FZ_ENUM 278
  138 +#define FZ_FLOAT 279
  139 +#define FZ_FUNCTION 280
  140 +#define FZ_IF 281
  141 +#define FZ_INCLUDE 282
  142 +#define FZ_INT 283
  143 +#define FZ_LET 284
  144 +#define FZ_MAXIMIZE 285
  145 +#define FZ_MINIMIZE 286
  146 +#define FZ_OF 287
  147 +#define FZ_SATISFY 288
  148 +#define FZ_OUTPUT 289
  149 +#define FZ_PREDICATE 290
  150 +#define FZ_RECORD 291
  151 +#define FZ_SET 292
  152 +#define FZ_SHOW 293
  153 +#define FZ_SHOWCOND 294
  154 +#define FZ_SOLVE 295
  155 +#define FZ_STRING 296
  156 +#define FZ_TEST 297
  157 +#define FZ_THEN 298
  158 +#define FZ_TUPLE 299
  159 +#define FZ_TYPE 300
  160 +#define FZ_VARIANT_RECORD 301
  161 +#define FZ_WHERE 302
  162 +
  163 +
  164 +
  165 +
  166 +/* Copy the first part of user declarations. */
  167 +#line 40 "parser.yxx"
  168 +
  169 +#define YYPARSE_PARAM parm
  170 +#define YYLEX_PARAM static_cast<ParserState*>(parm)->yyscanner
  171 +#include "flatzinc.hh"
  172 +#include "parser.hh"
  173 +#include <iostream>
  174 +#include <fstream>
  175 +#include <sstream>
  176 +
  177 +#include <stdio.h>
  178 +#include <stdlib.h>
  179 +#include <fcntl.h>
  180 +#include <unistd.h>
  181 +#include <sys/types.h>
  182 +#include <sys/mman.h>
  183 +#include <sys/stat.h>
  184 +
  185 +using namespace std;
  186 +
  187 +int yyparse(void*);
  188 +int yylex(YYSTYPE*, void* scanner);
  189 +int yylex_init (void** scanner);
  190 +int yylex_destroy (void* scanner);
  191 +int yyget_lineno (void* scanner);
  192 +void yyset_extra (void* user_defined ,void* yyscanner );
  193 +
  194 +extern int yydebug;
  195 +
  196 +using namespace FlatZinc;
  197 +
  198 +void yyerror(void* parm, const char *str) {
  199 + ParserState* pp = static_cast<ParserState*>(parm);
  200 + pp->err << "Error: " << str
  201 + << " in line no. " << yyget_lineno(pp->yyscanner)
  202 + << std::endl;
  203 + pp->hadError = true;
  204 +}
  205 +
  206 +void yyassert(ParserState* pp, bool cond, const char* str)
  207 +{
  208 + if (!cond) {
  209 + pp->err << "Error: " << str
  210 + << " in line no. " << yyget_lineno(pp->yyscanner)
  211 + << std::endl;
  212 + pp->hadError = true;
  213 + }
  214 +}
  215 +
  216 +/*
  217 + * The symbol tables
  218 + *
  219 + */
  220 +
  221 +AST::Node* getArrayElement(ParserState* pp, string id, unsigned int offset) {
  222 + if (offset > 0) {
  223 + vector<int> tmp;
  224 + if (pp->intvararrays.get(id, tmp) && offset<=tmp.size())
  225 + return new AST::IntVar(tmp[offset-1]);
  226 + if (pp->boolvararrays.get(id, tmp) && offset<=tmp.size())
  227 + return new AST::BoolVar(tmp[offset-1]);
  228 + if (pp->setvararrays.get(id, tmp) && offset<=tmp.size())
  229 + return new AST::SetVar(tmp[offset-1]);
  230 +
  231 + if (pp->intvalarrays.get(id, tmp) && offset<=tmp.size())
  232 + return new AST::IntLit(tmp[offset-1]);
  233 + if (pp->boolvalarrays.get(id, tmp) && offset<=tmp.size())
  234 + return new AST::BoolLit(tmp[offset-1]);
  235 + vector<AST::SetLit> tmpS;
  236 + if (pp->setvalarrays.get(id, tmpS) && offset<=tmpS.size())
  237 + return new AST::SetLit(tmpS[offset-1]);
  238 + }
  239 +
  240 + pp->err << "Error: array access to " << id << " invalid"
  241 + << " in line no. "
  242 + << yyget_lineno(pp->yyscanner) << std::endl;
  243 + pp->hadError = true;
  244 + return new AST::IntVar(0); // keep things consistent
  245 +}
  246 +AST::Node* getVarRefArg(ParserState* pp, string id, bool annotation = false) {
  247 + int tmp;
  248 + if (pp->intvarTable.get(id, tmp))
  249 + return new AST::IntVar(tmp);
  250 + if (pp->boolvarTable.get(id, tmp))
  251 + return new AST::BoolVar(tmp);
  252 + if (pp->setvarTable.get(id, tmp))
  253 + return new AST::SetVar(tmp);
  254 + if (annotation)
  255 + return new AST::Atom(id);
  256 + pp->err << "Error: undefined variable " << id
  257 + << " in line no. "
  258 + << yyget_lineno(pp->yyscanner) << std::endl;
  259 + pp->hadError = true;
  260 + return new AST::IntVar(0); // keep things consistent
  261 +}
  262 +
  263 +void addDomainConstraint(ParserState* pp, std::string id, AST::Node* var,
  264 + Option<AST::SetLit* >& dom) {
  265 + if (!dom())
  266 + return;
  267 + AST::Array* args = new AST::Array(2);
  268 + args->a[0] = var;
  269 + args->a[1] = dom.some();
  270 + pp->domainConstraints.push_back(new ConExpr(id, args));
  271 +}
  272 +
  273 +/*
  274 + * Initialize the root gecode space
  275 + *
  276 + */
  277 +
  278 +void initfg(ParserState* pp) {
  279 + if (!pp->hadError)
  280 + pp->fg->init(pp->intvars.size(),
  281 + pp->boolvars.size(),
  282 + pp->setvars.size());
  283 +
  284 + for (unsigned int i=0; i<pp->intvars.size(); i++) {
  285 + if (!pp->hadError) {
  286 + try {
  287 + pp->fg->newIntVar(static_cast<IntVarSpec*>(pp->intvars[i].second));
  288 + } catch (FlatZinc::Error& e) {
  289 + yyerror(pp, e.toString().c_str());
  290 + }
  291 + }
  292 + if (pp->intvars[i].first[0] != '[') {
  293 + delete pp->intvars[i].second;
  294 + pp->intvars[i].second = NULL;
  295 + }
  296 + }
  297 + for (unsigned int i=0; i<pp->boolvars.size(); i++) {
  298 + if (!pp->hadError) {
  299 + try {
  300 + pp->fg->newBoolVar(
  301 + static_cast<BoolVarSpec*>(pp->boolvars[i].second));
  302 + } catch (FlatZinc::Error& e) {
  303 + yyerror(pp, e.toString().c_str());
  304 + }
  305 + }
  306 + if (pp->boolvars[i].first[0] != '[') {
  307 + delete pp->boolvars[i].second;
  308 + pp->boolvars[i].second = NULL;
  309 + }
  310 + }
  311 + for (unsigned int i=0; i<pp->setvars.size(); i++) {
  312 + if (!pp->hadError) {
  313 + try {
  314 + pp->fg->newSetVar(static_cast<SetVarSpec*>(pp->setvars[i].second));
  315 + } catch (FlatZinc::Error& e) {
  316 + yyerror(pp, e.toString().c_str());
  317 + }
  318 + }
  319 + if (pp->setvars[i].first[0] != '[') {
  320 + delete pp->setvars[i].second;
  321 + pp->setvars[i].second = NULL;
  322 + }
  323 + }
  324 + for (unsigned int i=pp->domainConstraints.size(); i--;) {
  325 + if (!pp->hadError) {
  326 + try {
  327 + assert(pp->domainConstraints[i]->args->a.size() == 2);
  328 + pp->fg->postConstraint(*pp->domainConstraints[i], NULL);
  329 + delete pp->domainConstraints[i];
  330 + } catch (FlatZinc::Error& e) {
  331 + yyerror(pp, e.toString().c_str());
  332 + }
  333 + }
  334 + }
  335 +}
  336 +
  337 +void fillPrinter(ParserState& pp, FlatZinc::Printer& p) {
  338 + p.init(pp.getOutput());
  339 +}
  340 +
  341 +AST::Node* arrayOutput(AST::Call* ann) {
  342 + AST::Array* a = NULL;
  343 +
  344 + if (ann->args->isArray()) {
  345 + a = ann->args->getArray();
  346 + } else {
  347 + a = new AST::Array(ann->args);
  348 + }
  349 +
  350 + std::ostringstream oss;
  351 +
  352 + oss << "array" << a->a.size() << "d(";
  353 + for (unsigned int i=0; i<a->a.size(); i++) {
  354 + AST::SetLit* s = a->a[i]->getSet();
  355 + if (s->empty())
  356 + oss << "{}, ";
  357 + else if (s->interval)
  358 + oss << s->min << ".." << s->max << ", ";
  359 + else {
  360 + oss << "{";
  361 + for (unsigned int j=0; j<s->s.size(); j++) {
  362 + oss << s->s[j];
  363 + if (j<s->s.size()-1)
  364 + oss << ",";
  365 + }
  366 + oss << "}, ";
  367 + }
  368 + }
  369 +
  370 + if (!ann->args->isArray()) {
  371 + a->a[0] = NULL;
  372 + delete a;
  373 + }
  374 + return new AST::String(oss.str());
  375 +}
  376 +
  377 +/*
  378 + * The main program
  379 + *
  380 + */
  381 +
  382 +namespace FlatZinc {
  383 +
  384 + FlatZincModel* parse(const std::string& filename, Printer& p, std::ostream& err,
  385 + FlatZincModel* fzs) {
  386 +#ifdef HAVE_MMAP
  387 + int fd;
  388 + char* data;
  389 + struct stat sbuf;
  390 + fd = open(filename.c_str(), O_RDONLY);
  391 + if (fd == -1) {
  392 + err << "Cannot open file " << filename << endl;
  393 + return NULL;
  394 + }
  395 + if (stat(filename.c_str(), &sbuf) == -1) {
  396 + err << "Cannot stat file " << filename << endl;
  397 + return NULL;
  398 + }
  399 + data = (char*)mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_SHARED, fd,0);
  400 + if (data == (caddr_t)(-1)) {
  401 + err << "Cannot mmap file " << filename << endl;
  402 + return NULL;
  403 + }
  404 +
  405 + if (fzs == NULL) {
  406 + fzs = new FlatZincModel();
  407 + }
  408 + ParserState pp(data, sbuf.st_size, err, fzs);
  409 +#else
  410 + std::ifstream file;
  411 + file.open(filename.c_str());
  412 + if (!file.is_open()) {
  413 + err << "Cannot open file " << filename << endl;
  414 + return NULL;
  415 + }
  416 + std::string s = string(istreambuf_iterator<char>(file),
  417 + istreambuf_iterator<char>());
  418 + if (fzs == NULL) {
  419 + fzs = new FlatZincModel();
  420 + }
  421 + ParserState pp(s, err, fzs);
  422 +#endif
  423 + yylex_init(&pp.yyscanner);
  424 + yyset_extra(&pp, pp.yyscanner);
  425 + // yydebug = 1;
  426 + yyparse(&pp);
  427 + fillPrinter(pp, p);
  428 +
  429 + if (pp.yyscanner)
  430 + yylex_destroy(pp.yyscanner);
  431 + return pp.hadError ? NULL : pp.fg;
  432 + }
  433 +
  434 + FlatZincModel* parse(std::istream& is, Printer& p, std::ostream& err,
  435 + FlatZincModel* fzs) {
  436 + std::string s = string(istreambuf_iterator<char>(is),
  437 + istreambuf_iterator<char>());
  438 +
  439 + if (fzs == NULL) {
  440 + fzs = new FlatZincModel();
  441 + }
  442 + ParserState pp(s, err, fzs);
  443 + yylex_init(&pp.yyscanner);
  444 + yyset_extra(&pp, pp.yyscanner);
  445 + // yydebug = 1;
  446 + yyparse(&pp);
  447 + fillPrinter(pp, p);
  448 +
  449 + if (pp.yyscanner)
  450 + yylex_destroy(pp.yyscanner);
  451 + return pp.hadError ? NULL : pp.fg;
  452 + }
  453 +
  454 +}
  455 +
  456 +
  457 +
  458 +/* Enabling traces. */
  459 +#ifndef YYDEBUG
  460 +# define YYDEBUG 1
  461 +#endif
  462 +
  463 +/* Enabling verbose error messages. */
  464 +#ifdef YYERROR_VERBOSE
  465 +# undef YYERROR_VERBOSE
  466 +# define YYERROR_VERBOSE 1
  467 +#else
  468 +# define YYERROR_VERBOSE 1
  469 +#endif
  470 +
  471 +/* Enabling the token table. */
  472 +#ifndef YYTOKEN_TABLE
  473 +# define YYTOKEN_TABLE 0
  474 +#endif
  475 +
  476 +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  477 +typedef union YYSTYPE
  478 +#line 330 "parser.yxx"
  479 +{ int iValue; char* sValue; bool bValue; double dValue;
  480 + std::vector<int>* setValue;
  481 + FlatZinc::AST::SetLit* setLit;
  482 + std::vector<double>* floatSetValue;
  483 + std::vector<FlatZinc::AST::SetLit>* setValueList;
  484 + FlatZinc::Option<FlatZinc::AST::SetLit* > oSet;
  485 + FlatZinc::VarSpec* varSpec;
  486 + FlatZinc::Option<FlatZinc::AST::Node*> oArg;
  487 + std::vector<FlatZinc::VarSpec*>* varSpecVec;
  488 + FlatZinc::Option<std::vector<FlatZinc::VarSpec*>* > oVarSpecVec;
  489 + FlatZinc::AST::Node* arg;
  490 + FlatZinc::AST::Array* argVec;
  491 + }
  492 +/* Line 193 of yacc.c. */
  493 +#line 494 "parser.tab.cpp"
  494 + YYSTYPE;
  495 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */
  496 +# define YYSTYPE_IS_DECLARED 1
  497 +# define YYSTYPE_IS_TRIVIAL 1
  498 +#endif
  499 +
  500 +
  501 +
  502 +/* Copy the second part of user declarations. */
  503 +
  504 +
  505 +/* Line 216 of yacc.c. */
  506 +#line 507 "parser.tab.cpp"
  507 +
  508 +#ifdef short
  509 +# undef short
  510 +#endif
  511 +
  512 +#ifdef YYTYPE_UINT8
  513 +typedef YYTYPE_UINT8 yytype_uint8;
  514 +#else
  515 +typedef unsigned char yytype_uint8;
  516 +#endif
  517 +
  518 +#ifdef YYTYPE_INT8
  519 +typedef YYTYPE_INT8 yytype_int8;
  520 +#elif (defined __STDC__ || defined __C99__FUNC__ \
  521 + || defined __cplusplus || defined _MSC_VER)
  522 +typedef signed char yytype_int8;
  523 +#else
  524 +typedef short int yytype_int8;
  525 +#endif
  526 +
  527 +#ifdef YYTYPE_UINT16
  528 +typedef YYTYPE_UINT16 yytype_uint16;
  529 +#else
  530 +typedef unsigned short int yytype_uint16;
  531 +#endif
  532 +
  533 +#ifdef YYTYPE_INT16
  534 +typedef YYTYPE_INT16 yytype_int16;
  535 +#else
  536 +typedef short int yytype_int16;
  537 +#endif
  538 +
  539 +#ifndef YYSIZE_T
  540 +# ifdef __SIZE_TYPE__
  541 +# define YYSIZE_T __SIZE_TYPE__
  542 +# elif defined size_t
  543 +# define YYSIZE_T size_t
  544 +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
  545 + || defined __cplusplus || defined _MSC_VER)
  546 +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  547 +# define YYSIZE_T size_t
  548 +# else
  549 +# define YYSIZE_T unsigned int
  550 +# endif
  551 +#endif
  552 +
  553 +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
  554 +
  555 +#ifndef YY_
  556 +# if defined YYENABLE_NLS && YYENABLE_NLS
  557 +# if ENABLE_NLS
  558 +# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
  559 +# define YY_(msgid) dgettext ("bison-runtime", msgid)
  560 +# endif
  561 +# endif
  562 +# ifndef YY_
  563 +# define YY_(msgid) msgid
  564 +# endif
  565 +#endif
  566 +
  567 +/* Suppress unused-variable warnings by "using" E. */
  568 +#if ! defined lint || defined __GNUC__
  569 +# define YYUSE(e) ((void) (e))
  570 +#else
  571 +# define YYUSE(e) /* empty */
  572 +#endif
  573 +
  574 +/* Identity function, used to suppress warnings about constant conditions. */
  575 +#ifndef lint
  576 +# define YYID(n) (n)
  577 +#else
  578 +#if (defined __STDC__ || defined __C99__FUNC__ \
  579 + || defined __cplusplus || defined _MSC_VER)
  580 +static int
  581 +YYID (int i)
  582 +#else
  583 +static int
  584 +YYID (i)
  585 + int i;
  586 +#endif
  587 +{
  588 + return i;
  589 +}
  590 +#endif
  591 +
  592 +#if ! defined yyoverflow || YYERROR_VERBOSE
  593 +
  594 +/* The parser invokes alloca or malloc; define the necessary symbols. */
  595 +
  596 +# ifdef YYSTACK_USE_ALLOCA
  597 +# if YYSTACK_USE_ALLOCA
  598 +# ifdef __GNUC__
  599 +# define YYSTACK_ALLOC __builtin_alloca
  600 +# elif defined __BUILTIN_VA_ARG_INCR
  601 +# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
  602 +# elif defined _AIX
  603 +# define YYSTACK_ALLOC __alloca
  604 +# elif defined _MSC_VER
  605 +# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
  606 +# define alloca _alloca
  607 +# else
  608 +# define YYSTACK_ALLOC alloca
  609 +# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  610 + || defined __cplusplus || defined _MSC_VER)
  611 +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  612 +# ifndef _STDLIB_H
  613 +# define _STDLIB_H 1
  614 +# endif
  615 +# endif
  616 +# endif
  617 +# endif
  618 +# endif
  619 +
  620 +# ifdef YYSTACK_ALLOC
  621 + /* Pacify GCC's `empty if-body' warning. */
  622 +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
  623 +# ifndef YYSTACK_ALLOC_MAXIMUM
  624 + /* The OS might guarantee only one guard page at the bottom of the stack,
  625 + and a page size can be as small as 4096 bytes. So we cannot safely
  626 + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
  627 + to allow for a few compiler-allocated temporary stack slots. */
  628 +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
  629 +# endif
  630 +# else
  631 +# define YYSTACK_ALLOC YYMALLOC
  632 +# define YYSTACK_FREE YYFREE
  633 +# ifndef YYSTACK_ALLOC_MAXIMUM
  634 +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
  635 +# endif
  636 +# if (defined __cplusplus && ! defined _STDLIB_H \
  637 + && ! ((defined YYMALLOC || defined malloc) \
  638 + && (defined YYFREE || defined free)))
  639 +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  640 +# ifndef _STDLIB_H
  641 +# define _STDLIB_H 1
  642 +# endif
  643 +# endif
  644 +# ifndef YYMALLOC
  645 +# define YYMALLOC malloc
  646 +# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  647 + || defined __cplusplus || defined _MSC_VER)
  648 +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
  649 +# endif
  650 +# endif
  651 +# ifndef YYFREE
  652 +# define YYFREE free
  653 +# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  654 + || defined __cplusplus || defined _MSC_VER)
  655 +void free (void *); /* INFRINGES ON USER NAME SPACE */
  656 +# endif
  657 +# endif
  658 +# endif
  659 +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
  660 +
  661 +
  662 +#if (! defined yyoverflow \
  663 + && (! defined __cplusplus \
  664 + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  665 +
  666 +/* A type that is properly aligned for any stack member. */
  667 +union yyalloc
  668 +{
  669 + yytype_int16 yyss;
  670 + YYSTYPE yyvs;
  671 + };
  672 +
  673 +/* The size of the maximum gap between one aligned stack and the next. */
  674 +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
  675 +
  676 +/* The size of an array large to enough to hold all stacks, each with
  677 + N elements. */
  678 +# define YYSTACK_BYTES(N) \
  679 + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
  680 + + YYSTACK_GAP_MAXIMUM)
  681 +
  682 +/* Copy COUNT objects from FROM to TO. The source and destination do
  683 + not overlap. */
  684 +# ifndef YYCOPY
  685 +# if defined __GNUC__ && 1 < __GNUC__
  686 +# define YYCOPY(To, From, Count) \
  687 + __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
  688 +# else
  689 +# define YYCOPY(To, From, Count) \
  690 + do \
  691 + { \
  692 + YYSIZE_T yyi; \
  693 + for (yyi = 0; yyi < (Count); yyi++) \
  694 + (To)[yyi] = (From)[yyi]; \
  695 + } \
  696 + while (YYID (0))
  697 +# endif
  698 +# endif
  699 +
  700 +/* Relocate STACK from its old location to the new one. The
  701 + local variables YYSIZE and YYSTACKSIZE give the old and new number of
  702 + elements in the stack, and YYPTR gives the new location of the
  703 + stack. Advance YYPTR to a properly aligned location for the next
  704 + stack. */
  705 +# define YYSTACK_RELOCATE(Stack) \
  706 + do \
  707 + { \
  708 + YYSIZE_T yynewbytes; \
  709 + YYCOPY (&yyptr->Stack, Stack, yysize); \
  710 + Stack = &yyptr->Stack; \
  711 + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  712 + yyptr += yynewbytes / sizeof (*yyptr); \
  713 + } \
  714 + while (YYID (0))
  715 +
  716 +#endif
  717 +
  718 +/* YYFINAL -- State number of the termination state. */
  719 +#define YYFINAL 7
  720 +/* YYLAST -- Last index in YYTABLE. */
  721 +#define YYLAST 337
  722 +
  723 +/* YYNTOKENS -- Number of terminals. */
  724 +#define YYNTOKENS 58
  725 +/* YYNNTS -- Number of nonterminals. */
  726 +#define YYNNTS 67
  727 +/* YYNRULES -- Number of rules. */
  728 +#define YYNRULES 156
  729 +/* YYNRULES -- Number of states. */
  730 +#define YYNSTATES 336
  731 +
  732 +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
  733 +#define YYUNDEFTOK 2
  734 +#define YYMAXUTOK 302
  735 +
  736 +#define YYTRANSLATE(YYX) \
  737 + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  738 +
  739 +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
  740 +static const yytype_uint8 yytranslate[] =
  741 +{
  742 + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  743 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  744 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  745 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  746 + 49, 50, 2, 2, 51, 2, 2, 2, 2, 2,
  747 + 2, 2, 2, 2, 2, 2, 2, 2, 52, 48,
  748 + 2, 55, 2, 2, 2, 2, 2, 2, 2, 2,
  749 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  750 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  751 + 2, 53, 2, 54, 2, 2, 2, 2, 2, 2,
  752 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  753 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  754 + 2, 2, 2, 56, 2, 57, 2, 2, 2, 2,
  755 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  756 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  757 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  758 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  759 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  760 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  761 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  762 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  763 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  764 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  765 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  766 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  767 + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
  768 + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  769 + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  770 + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
  771 + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
  772 + 45, 46, 47
  773 +};
  774 +
  775 +#if YYDEBUG
  776 +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
  777 + YYRHS. */
  778 +static const yytype_uint16 yyprhs[] =
  779 +{
  780 + 0, 0, 3, 9, 10, 12, 15, 19, 20, 22,
  781 + 25, 29, 30, 32, 35, 39, 45, 46, 49, 51,
  782 + 55, 59, 66, 74, 77, 79, 81, 85, 87, 89,
  783 + 91, 95, 97, 101, 103, 105, 112, 119, 126, 135,
  784 + 142, 149, 158, 172, 186, 200, 216, 232, 248, 264,
  785 + 282, 284, 286, 291, 292, 295, 297, 301, 302, 304,
  786 + 308, 310, 312, 317, 318, 321, 323, 327, 331, 333,
  787 + 335, 340, 341, 344, 346, 350, 354, 356, 358, 363,
  788 + 364, 367, 369, 373, 377, 378, 381, 382, 385, 386,
  789 + 389, 390, 393, 400, 404, 409, 411, 415, 419, 421,
  790 + 426, 428, 433, 437, 441, 442, 445, 447, 451, 452,
  791 + 455, 457, 461, 462, 465, 467, 471, 472, 475, 477,
  792 + 481, 483, 487, 489, 493, 494, 497, 499, 501, 503,
  793 + 505, 507, 512, 513, 516, 518, 522, 524, 529, 531,
  794 + 533, 534, 536, 539, 543, 548, 550, 552, 556, 558,
  795 + 562, 564, 566, 568, 570, 572, 577
  796 +};
  797 +
  798 +/* YYRHS -- A `-1'-separated list of the rules' RHS. */
  799 +static const yytype_int8 yyrhs[] =
  800 +{
  801 + 59, 0, -1, 60, 62, 64, 98, 48, -1, -1,
  802 + 61, -1, 66, 48, -1, 61, 66, 48, -1, -1,
  803 + 63, -1, 75, 48, -1, 63, 75, 48, -1, -1,
  804 + 65, -1, 97, 48, -1, 65, 97, 48, -1, 35,
  805 + 6, 49, 67, 50, -1, -1, 68, 79, -1, 69,
  806 + -1, 68, 51, 69, -1, 70, 52, 6, -1, 13,
  807 + 53, 72, 54, 32, 71, -1, 13, 53, 72, 54,
  808 + 32, 9, 71, -1, 9, 71, -1, 71, -1, 99,
  809 + -1, 37, 32, 99, -1, 14, -1, 24, -1, 73,
  810 + -1, 72, 51, 73, -1, 28, -1, 3, 19, 3,
  811 + -1, 6, -1, 7, -1, 9, 99, 52, 74, 119,
  812 + 113, -1, 9, 100, 52, 74, 119, 113, -1, 9,
  813 + 101, 52, 74, 119, 113, -1, 9, 37, 32, 99,
  814 + 52, 74, 119, 113, -1, 28, 52, 74, 119, 55,
  815 + 114, -1, 14, 52, 74, 119, 55, 114, -1, 37,
  816 + 32, 28, 52, 74, 119, 55, 114, -1, 13, 53,
  817 + 3, 19, 3, 54, 32, 9, 99, 52, 74, 119,
  818 + 93, -1, 13, 53, 3, 19, 3, 54, 32, 9,
  819 + 100, 52, 74, 119, 94, -1, 13, 53, 3, 19,
  820 + 3, 54, 32, 9, 101, 52, 74, 119, 95, -1,
  821 + 13, 53, 3, 19, 3, 54, 32, 9, 37, 32,
  822 + 99, 52, 74, 119, 96, -1, 13, 53, 3, 19,
  823 + 3, 54, 32, 28, 52, 74, 119, 55, 53, 103,
  824 + 54, -1, 13, 53, 3, 19, 3, 54, 32, 14,
  825 + 52, 74, 119, 55, 53, 105, 54, -1, 13, 53,
  826 + 3, 19, 3, 54, 32, 24, 52, 74, 119, 55,
  827 + 53, 107, 54, -1, 13, 53, 3, 19, 3, 54,
  828 + 32, 37, 32, 28, 52, 74, 119, 55, 53, 109,
  829 + 54, -1, 3, -1, 74, -1, 74, 53, 3, 54,
  830 + -1, -1, 78, 79, -1, 76, -1, 78, 51, 76,
  831 + -1, -1, 51, -1, 53, 77, 54, -1, 5, -1,
  832 + 74, -1, 74, 53, 3, 54, -1, -1, 83, 79,
  833 + -1, 81, -1, 83, 51, 81, -1, 53, 82, 54,
  834 + -1, 4, -1, 74, -1, 74, 53, 3, 54, -1,
  835 + -1, 87, 79, -1, 85, -1, 87, 51, 85, -1,
  836 + 53, 86, 54, -1, 102, -1, 74, -1, 74, 53,
  837 + 3, 54, -1, -1, 91, 79, -1, 89, -1, 91,
  838 + 51, 89, -1, 53, 90, 54, -1, -1, 55, 80,
  839 + -1, -1, 55, 88, -1, -1, 55, 84, -1, -1,
  840 + 55, 92, -1, 17, 6, 49, 111, 50, 119, -1,
  841 + 40, 119, 33, -1, 40, 119, 118, 117, -1, 28,
  842 + -1, 56, 103, 57, -1, 3, 19, 3, -1, 14,
  843 + -1, 56, 106, 79, 57, -1, 24, -1, 56, 108,
  844 + 79, 57, -1, 56, 103, 57, -1, 3, 19, 3,
  845 + -1, -1, 104, 79, -1, 3, -1, 104, 51, 3,
  846 + -1, -1, 106, 79, -1, 4, -1, 106, 51, 4,
  847 + -1, -1, 108, 79, -1, 5, -1, 108, 51, 5,
  848 + -1, -1, 110, 79, -1, 102, -1, 110, 51, 102,
  849 + -1, 112, -1, 111, 51, 112, -1, 114, -1, 53,
  850 + 115, 54, -1, -1, 55, 114, -1, 4, -1, 3,
  851 + -1, 5, -1, 102, -1, 74, -1, 74, 53, 114,
  852 + 54, -1, -1, 116, 79, -1, 114, -1, 116, 51,
  853 + 114, -1, 74, -1, 74, 53, 3, 54, -1, 31,
  854 + -1, 30, -1, -1, 120, -1, 16, 121, -1, 120,
  855 + 16, 121, -1, 6, 49, 122, 50, -1, 123, -1,
  856 + 121, -1, 122, 51, 121, -1, 124, -1, 53, 122,
  857 + 54, -1, 4, -1, 3, -1, 5, -1, 102, -1,
  858 + 74, -1, 74, 53, 124, 54, -1, 8, -1
  859 +};
  860 +
  861 +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
  862 +static const yytype_uint16 yyrline[] =
  863 +{
  864 + 0, 430, 430, 432, 434, 437, 438, 442, 443, 447,
  865 + 448, 450, 452, 455, 456, 463, 465, 467, 470, 471,
  866 + 474, 477, 478, 479, 480, 483, 484, 485, 486, 489,
  867 + 490, 493, 494, 500, 500, 503, 532, 561, 566, 596,
  868 + 603, 610, 619, 678, 730, 737, 794, 807, 820, 827,
  869 + 841, 845, 860, 884, 885, 889, 891, 894, 894, 896,
  870 + 900, 902, 917, 941, 942, 946, 948, 952, 956, 958,
  871 + 973, 997, 998, 1002, 1004, 1007, 1010, 1012, 1027, 1051,
  872 + 1052, 1056, 1058, 1061, 1066, 1067, 1072, 1073, 1078, 1079,
  873 + 1084, 1085, 1089, 1103, 1116, 1138, 1140, 1142, 1148, 1150,
  874 + 1163, 1164, 1171, 1173, 1180, 1181, 1185, 1187, 1192, 1193,
  875 + 1197, 1199, 1204, 1205, 1209, 1211, 1216, 1217, 1221, 1223,
  876 + 1231, 1233, 1237, 1239, 1244, 1245, 1249, 1251, 1253, 1255,
  877 + 1257, 1306, 1320, 1321, 1325, 1327, 1335, 1346, 1368, 1369,
  878 + 1377, 1378, 1382, 1384, 1388, 1392, 1396, 1398, 1402, 1404,
  879 + 1408, 1410, 1412, 1414, 1416, 1459, 1470
  880 +};
  881 +#endif
  882 +
  883 +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
  884 +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
  885 + First, the terminals, then, starting at YYNTOKENS, nonterminals. */
  886 +static const char *const yytname[] =
  887 +{
  888 + "$end", "error", "$undefined", "FZ_INT_LIT", "FZ_BOOL_LIT",
  889 + "FZ_FLOAT_LIT", "FZ_ID", "FZ_U_ID", "FZ_STRING_LIT", "FZ_VAR", "FZ_PAR",
  890 + "FZ_ANNOTATION", "FZ_ANY", "FZ_ARRAY", "FZ_BOOL", "FZ_CASE",
  891 + "FZ_COLONCOLON", "FZ_CONSTRAINT", "FZ_DEFAULT", "FZ_DOTDOT", "FZ_ELSE",
  892 + "FZ_ELSEIF", "FZ_ENDIF", "FZ_ENUM", "FZ_FLOAT", "FZ_FUNCTION", "FZ_IF",
  893 + "FZ_INCLUDE", "FZ_INT", "FZ_LET", "FZ_MAXIMIZE", "FZ_MINIMIZE", "FZ_OF",
  894 + "FZ_SATISFY", "FZ_OUTPUT", "FZ_PREDICATE", "FZ_RECORD", "FZ_SET",
  895 + "FZ_SHOW", "FZ_SHOWCOND", "FZ_SOLVE", "FZ_STRING", "FZ_TEST", "FZ_THEN",
  896 + "FZ_TUPLE", "FZ_TYPE", "FZ_VARIANT_RECORD", "FZ_WHERE", "';'", "'('",
  897 + "')'", "','", "':'", "'['", "']'", "'='", "'{'", "'}'", "$accept",
  898 + "model", "preddecl_items", "preddecl_items_head", "vardecl_items",
  899 + "vardecl_items_head", "constraint_items", "constraint_items_head",
  900 + "preddecl_item", "pred_arg_list", "pred_arg_list_head", "pred_arg",
  901 + "pred_arg_type", "pred_arg_simple_type", "pred_array_init",
  902 + "pred_array_init_arg", "var_par_id", "vardecl_item", "int_init",
  903 + "int_init_list", "int_init_list_head", "list_tail",
  904 + "int_var_array_literal", "float_init", "float_init_list",
  905 + "float_init_list_head", "float_var_array_literal", "bool_init",
  906 + "bool_init_list", "bool_init_list_head", "bool_var_array_literal",
  907 + "set_init", "set_init_list", "set_init_list_head",
  908 + "set_var_array_literal", "vardecl_int_var_array_init",
  909 + "vardecl_bool_var_array_init", "vardecl_float_var_array_init",
  910 + "vardecl_set_var_array_init", "constraint_item", "solve_item",
  911 + "int_ti_expr_tail", "bool_ti_expr_tail", "float_ti_expr_tail",
  912 + "set_literal", "int_list", "int_list_head", "bool_list",
  913 + "bool_list_head", "float_list", "float_list_head", "set_literal_list",
  914 + "set_literal_list_head", "flat_expr_list", "flat_expr",
  915 + "non_array_expr_opt", "non_array_expr", "non_array_expr_list",
  916 + "non_array_expr_list_head", "solve_expr", "minmax", "annotations",
  917 + "annotations_head", "annotation", "annotation_list", "annotation_expr",
  918 + "ann_non_array_expr", 0
  919 +};
  920 +#endif
  921 +
  922 +# ifdef YYPRINT
  923 +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
  924 + token YYLEX-NUM. */
  925 +static const yytype_uint16 yytoknum[] =
  926 +{
  927 + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
  928 + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
  929 + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
  930 + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
  931 + 295, 296, 297, 298, 299, 300, 301, 302, 59, 40,
  932 + 41, 44, 58, 91, 93, 61, 123, 125
  933 +};
  934 +# endif
  935 +
  936 +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  937 +static const yytype_uint8 yyr1[] =
  938 +{
  939 + 0, 58, 59, 60, 60, 61, 61, 62, 62, 63,
  940 + 63, 64, 64, 65, 65, 66, 67, 67, 68, 68,
  941 + 69, 70, 70, 70, 70, 71, 71, 71, 71, 72,
  942 + 72, 73, 73, 74, 74, 75, 75, 75, 75, 75,
  943 + 75, 75, 75, 75, 75, 75, 75, 75, 75, 75,
  944 + 76, 76, 76, 77, 77, 78, 78, 79, 79, 80,
  945 + 81, 81, 81, 82, 82, 83, 83, 84, 85, 85,
  946 + 85, 86, 86, 87, 87, 88, 89, 89, 89, 90,
  947 + 90, 91, 91, 92, 93, 93, 94, 94, 95, 95,
  948 + 96, 96, 97, 98, 98, 99, 99, 99, 100, 100,
  949 + 101, 101, 102, 102, 103, 103, 104, 104, 105, 105,
  950 + 106, 106, 107, 107, 108, 108, 109, 109, 110, 110,
  951 + 111, 111, 112, 112, 113, 113, 114, 114, 114, 114,
  952 + 114, 114, 115, 115, 116, 116, 117, 117, 118, 118,
  953 + 119, 119, 120, 120, 121, 121, 122, 122, 123, 123,
  954 + 124, 124, 124, 124, 124, 124, 124
  955 +};
  956 +
  957 +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
  958 +static const yytype_uint8 yyr2[] =
  959 +{
  960 + 0, 2, 5, 0, 1, 2, 3, 0, 1, 2,
  961 + 3, 0, 1, 2, 3, 5, 0, 2, 1, 3,
  962 + 3, 6, 7, 2, 1, 1, 3, 1, 1, 1,
  963 + 3, 1, 3, 1, 1, 6, 6, 6, 8, 6,
  964 + 6, 8, 13, 13, 13, 15, 15, 15, 15, 17,
  965 + 1, 1, 4, 0, 2, 1, 3, 0, 1, 3,
  966 + 1, 1, 4, 0, 2, 1, 3, 3, 1, 1,
  967 + 4, 0, 2, 1, 3, 3, 1, 1, 4, 0,
  968 + 2, 1, 3, 3, 0, 2, 0, 2, 0, 2,
  969 + 0, 2, 6, 3, 4, 1, 3, 3, 1, 4,
  970 + 1, 4, 3, 3, 0, 2, 1, 3, 0, 2,
  971 + 1, 3, 0, 2, 1, 3, 0, 2, 1, 3,
  972 + 1, 3, 1, 3, 0, 2, 1, 1, 1, 1,
  973 + 1, 4, 0, 2, 1, 3, 1, 4, 1, 1,
  974 + 0, 1, 2, 3, 4, 1, 1, 3, 1, 3,
  975 + 1, 1, 1, 1, 1, 4, 1
  976 +};
  977 +
  978 +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
  979 + STATE-NUM when YYTABLE doesn't specify something else to do. Zero
  980 + means the default is an error. */
  981 +static const yytype_uint8 yydefact[] =
  982 +{
  983 + 3, 0, 0, 7, 4, 0, 0, 1, 0, 0,
  984 + 0, 0, 0, 11, 8, 0, 0, 5, 16, 0,
  985 + 98, 100, 95, 0, 104, 0, 0, 0, 0, 0,
  986 + 0, 0, 0, 0, 12, 0, 0, 9, 6, 0,
  987 + 0, 27, 28, 0, 104, 0, 57, 18, 0, 24,
  988 + 25, 0, 0, 106, 110, 114, 0, 57, 57, 57,
  989 + 0, 0, 0, 0, 33, 34, 140, 140, 0, 0,
  990 + 140, 0, 0, 13, 10, 23, 0, 0, 15, 58,
  991 + 17, 0, 97, 0, 96, 58, 105, 58, 0, 58,
  992 + 0, 140, 140, 140, 0, 0, 0, 141, 0, 0,
  993 + 0, 0, 2, 14, 0, 31, 0, 29, 26, 19,
  994 + 20, 0, 107, 111, 99, 115, 101, 124, 124, 124,
  995 + 0, 151, 150, 152, 33, 156, 0, 104, 154, 153,
  996 + 142, 145, 148, 0, 0, 0, 140, 127, 126, 128,
  997 + 132, 130, 129, 0, 120, 122, 139, 138, 93, 0,
  998 + 0, 0, 0, 140, 0, 35, 36, 37, 0, 0,
  999 + 0, 146, 0, 0, 0, 40, 143, 39, 0, 134,
  1000 + 0, 57, 0, 140, 0, 136, 94, 32, 30, 0,
  1001 + 124, 125, 0, 103, 0, 0, 149, 102, 0, 0,
  1002 + 123, 58, 133, 0, 92, 121, 0, 0, 21, 38,
  1003 + 0, 0, 0, 0, 0, 144, 147, 155, 41, 135,
  1004 + 131, 0, 22, 0, 0, 0, 0, 0, 0, 0,
  1005 + 0, 137, 0, 0, 0, 0, 140, 140, 140, 0,
  1006 + 0, 140, 140, 140, 0, 0, 0, 0, 0, 84,
  1007 + 86, 88, 0, 0, 0, 140, 140, 0, 42, 0,
  1008 + 43, 0, 44, 108, 112, 104, 0, 90, 53, 85,
  1009 + 71, 87, 63, 89, 0, 57, 0, 57, 0, 0,
  1010 + 0, 45, 50, 51, 55, 0, 57, 68, 69, 73,
  1011 + 0, 57, 60, 61, 65, 0, 57, 47, 109, 48,
  1012 + 113, 46, 116, 79, 91, 0, 59, 58, 54, 0,
  1013 + 75, 58, 72, 0, 67, 58, 64, 0, 118, 0,
  1014 + 57, 77, 81, 0, 57, 76, 0, 56, 0, 74,
  1015 + 0, 66, 49, 58, 117, 0, 83, 58, 80, 52,
  1016 + 70, 62, 119, 0, 82, 78
  1017 +};
  1018 +
  1019 +/* YYDEFGOTO[NTERM-NUM]. */
  1020 +static const yytype_int16 yydefgoto[] =
  1021 +{
  1022 + -1, 2, 3, 4, 13, 14, 33, 34, 5, 45,
  1023 + 46, 47, 48, 49, 106, 107, 141, 15, 274, 275,
  1024 + 276, 80, 259, 284, 285, 286, 263, 279, 280, 281,
  1025 + 261, 312, 313, 314, 294, 248, 250, 252, 271, 35,
  1026 + 71, 50, 26, 27, 142, 56, 57, 264, 58, 266,
  1027 + 59, 309, 310, 143, 144, 155, 145, 170, 171, 176,
  1028 + 149, 96, 97, 161, 162, 131, 132
  1029 +};
  1030 +
  1031 +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  1032 + STATE-NUM. */
  1033 +#define YYPACT_NINF -120
  1034 +static const yytype_int16 yypact[] =
  1035 +{
  1036 + 0, 34, 46, 101, 0, 1, 12, -120, 97, -3,
  1037 + 29, 33, 71, 96, 101, 68, 74, -120, 50, 100,
  1038 + -120, -120, -120, 94, 64, 76, 78, 80, 136, 23,
  1039 + 23, 112, 151, 119, 96, 113, 114, -120, -120, 144,
  1040 + 110, -120, -120, 132, 163, 117, 118, -120, 126, -120,
  1041 + -120, 167, 24, -120, -120, -120, 122, 120, 129, 131,
  1042 + 23, 23, 23, 164, -120, -120, 168, 168, 133, 137,
  1043 + 168, 139, 149, -120, -120, -120, 15, 24, -120, 50,
  1044 + -120, 186, -120, 146, -120, 198, -120, 201, 150, 209,
  1045 + 158, 168, 168, 168, 203, 9, 162, 202, 165, 23,
  1046 + 51, 53, -120, -120, 200, -120, -15, -120, -120, -120,
  1047 + -120, 23, -120, -120, -120, -120, -120, 169, 169, 169,
  1048 + 174, 204, -120, -120, 187, -120, 9, 163, 182, -120,
  1049 + -120, -120, -120, 170, 9, 170, 168, 204, -120, -120,
  1050 + 170, 184, -120, 44, -120, -120, -120, -120, -120, 23,
  1051 + 236, 15, 208, 168, 170, -120, -120, -120, 210, 238,
  1052 + 9, -120, -10, 189, 85, -120, -120, -120, 190, -120,
  1053 + 193, 192, 170, 168, 51, 195, -120, -120, -120, 109,
  1054 + 169, -120, 10, -120, 58, 9, -120, -120, 196, 170,
  1055 + -120, 170, -120, 197, -120, -120, 246, 144, -120, -120,
  1056 + 188, 205, 206, 207, 220, -120, -120, -120, -120, -120,
  1057 + -120, 199, -120, 222, 211, 213, 214, 23, 23, 23,
  1058 + 227, -120, 24, 23, 23, 23, 168, 168, 168, 215,
  1059 + 217, 168, 168, 168, 216, 218, 219, 23, 23, 223,
  1060 + 224, 225, 228, 229, 233, 168, 168, 234, -120, 239,
  1061 + -120, 240, -120, 257, 265, 163, 241, 242, 19, -120,
  1062 + 148, -120, 138, -120, 221, 129, 237, 131, 245, 247,
  1063 + 248, -120, -120, 251, -120, 252, 226, -120, 254, -120,
  1064 + 255, 243, -120, 258, -120, 256, 244, -120, -120, -120,
  1065 + -120, -120, 17, 95, -120, 259, -120, 19, -120, 302,
  1066 + -120, 148, -120, 305, -120, 138, -120, 204, -120, 260,
  1067 + 261, 262, -120, 263, 267, -120, 266, -120, 268, -120,
  1068 + 269, -120, -120, 17, -120, 310, -120, 95, -120, -120,
  1069 + -120, -120, -120, 270, -120, -120
  1070 +};
  1071 +
  1072 +/* YYPGOTO[NTERM-NUM]. */
  1073 +static const yytype_int16 yypgoto[] =
  1074 +{
  1075 + -120, -120, -120, -120, -120, -120, -120, -120, 312, -120,
  1076 + -120, 249, -120, -37, -120, 175, -29, 307, 22, -120,
  1077 + -120, -54, -120, 20, -120, -120, -120, 26, -120, -120,
  1078 + -120, 2, -120, -120, -120, -120, -120, -120, -120, 296,
  1079 + -120, -1, 134, 135, -89, -119, -120, -120, 79, -120,
  1080 + 77, -120, -120, -120, 159, -108, -112, -120, -120, -120,
  1081 + -120, 57, -120, -86, 176, -120, 173
  1082 +};
  1083 +
  1084 +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
  1085 + positive, shift that token. If negative, reduce the rule which
  1086 + number is the opposite. If zero, do what YYDEFACT says.
  1087 + If YYTABLE_NINF, syntax error. */
  1088 +#define YYTABLE_NINF -1
  1089 +static const yytype_uint16 yytable[] =
  1090 +{
  1091 + 66, 67, 75, 86, 88, 90, 129, 25, 163, 130,
  1092 + 156, 157, 121, 122, 123, 124, 65, 125, 104, 200,
  1093 + 307, 165, 272, 167, 201, 64, 65, 19, 169, 64,
  1094 + 65, 91, 92, 93, 202, 1, 151, 129, 203, 152,
  1095 + 6, 185, 181, 105, 186, 129, 7, 204, 166, 17,
  1096 + 28, 83, 22, 19, 137, 138, 139, 64, 65, 39,
  1097 + 193, 18, 126, 40, 41, 127, 128, 53, 54, 55,
  1098 + 136, 129, 199, 127, 42, 129, 108, 208, 22, 209,
  1099 + 44, 29, 153, 146, 147, 30, 148, 43, 121, 122,
  1100 + 123, 64, 65, 125, 173, 174, 129, 128, 307, 206,
  1101 + 19, 64, 65, 31, 140, 128, 44, 127, 205, 185,
  1102 + 8, 20, 19, 32, 9, 10, 37, 192, 197, 51,
  1103 + 175, 21, 38, 41, 98, 22, 52, 101, 60, 11,
  1104 + 61, 128, 62, 42, 23, 128, 268, 22, 12, 63,
  1105 + 68, 127, 198, 282, 64, 65, 43, 19, 117, 118,
  1106 + 119, 127, 277, 24, 64, 65, 128, 69, 41, 70,
  1107 + 212, 73, 74, 76, 77, 44, 53, 78, 42, 79,
  1108 + 82, 85, 22, 137, 138, 139, 64, 65, 81, 84,
  1109 + 87, 43, 89, 94, 95, 99, 100, 102, 226, 227,
  1110 + 228, 19, 110, 168, 231, 232, 233, 103, 111, 214,
  1111 + 44, 112, 20, 308, 315, 113, 120, 114, 245, 246,
  1112 + 180, 288, 21, 290, 115, 116, 22, 133, 134, 150,
  1113 + 135, 230, 298, 159, 154, 213, 127, 302, 158, 273,
  1114 + 194, 278, 306, 283, 332, 164, 160, 172, 315, 177,
  1115 + 179, 183, 182, 191, 24, 189, 187, 190, 196, 211,
  1116 + 207, 210, 220, 221, 222, 229, 324, 217, 218, 219,
  1117 + 328, 54, 316, 223, 311, 224, 225, 237, 273, 238,
  1118 + 55, 242, 278, 243, 244, 287, 283, 297, 247, 249,
  1119 + 251, 253, 254, 234, 235, 236, 255, 258, 239, 240,
  1120 + 241, 289, 260, 262, 301, 305, 269, 270, 311, 291,
  1121 + 292, 293, 256, 257, 295, 318, 296, 299, 320, 300,
  1122 + 304, 303, 323, 333, 322, 325, 16, 326, 327, 317,
  1123 + 329, 36, 330, 331, 335, 321, 178, 319, 109, 334,
  1124 + 72, 267, 265, 195, 215, 216, 184, 188
  1125 +};
  1126 +
  1127 +static const yytype_uint16 yycheck[] =
  1128 +{
  1129 + 29, 30, 39, 57, 58, 59, 95, 8, 127, 95,
  1130 + 118, 119, 3, 4, 5, 6, 7, 8, 3, 9,
  1131 + 3, 133, 3, 135, 14, 6, 7, 3, 140, 6,
  1132 + 7, 60, 61, 62, 24, 35, 51, 126, 28, 54,
  1133 + 6, 51, 154, 28, 54, 134, 0, 37, 134, 48,
  1134 + 53, 52, 28, 3, 3, 4, 5, 6, 7, 9,
  1135 + 172, 49, 53, 13, 14, 56, 95, 3, 4, 5,
  1136 + 99, 160, 180, 56, 24, 164, 77, 189, 28, 191,
  1137 + 56, 52, 111, 30, 31, 52, 33, 37, 3, 4,
  1138 + 5, 6, 7, 8, 50, 51, 185, 126, 3, 185,
  1139 + 3, 6, 7, 32, 53, 134, 56, 56, 50, 51,
  1140 + 9, 14, 3, 17, 13, 14, 48, 171, 9, 19,
  1141 + 149, 24, 48, 14, 67, 28, 32, 70, 52, 28,
  1142 + 52, 160, 52, 24, 37, 164, 255, 28, 37, 3,
  1143 + 28, 56, 179, 5, 6, 7, 37, 3, 91, 92,
  1144 + 93, 56, 4, 56, 6, 7, 185, 6, 14, 40,
  1145 + 197, 48, 48, 53, 32, 56, 3, 50, 24, 51,
  1146 + 3, 51, 28, 3, 4, 5, 6, 7, 52, 57,
  1147 + 51, 37, 51, 19, 16, 52, 49, 48, 217, 218,
  1148 + 219, 3, 6, 136, 223, 224, 225, 48, 52, 200,
  1149 + 56, 3, 14, 292, 293, 4, 3, 57, 237, 238,
  1150 + 153, 265, 24, 267, 5, 57, 28, 55, 16, 19,
  1151 + 55, 222, 276, 19, 55, 37, 56, 281, 54, 258,
  1152 + 173, 260, 286, 262, 323, 53, 49, 53, 327, 3,
  1153 + 32, 3, 32, 51, 56, 55, 57, 54, 53, 3,
  1154 + 54, 54, 32, 54, 32, 28, 310, 52, 52, 52,
  1155 + 314, 4, 3, 52, 293, 52, 52, 52, 297, 52,
  1156 + 5, 55, 301, 55, 55, 54, 305, 51, 55, 55,
  1157 + 55, 53, 53, 226, 227, 228, 53, 53, 231, 232,
  1158 + 233, 54, 53, 53, 51, 51, 55, 55, 327, 54,
  1159 + 53, 53, 245, 246, 53, 3, 54, 53, 3, 54,
  1160 + 54, 53, 51, 3, 54, 53, 4, 54, 51, 297,
  1161 + 54, 14, 54, 54, 54, 305, 151, 301, 79, 327,
  1162 + 34, 254, 253, 174, 200, 200, 160, 164
  1163 +};
  1164 +
  1165 +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  1166 + symbol of state STATE-NUM. */
  1167 +static const yytype_uint8 yystos[] =
  1168 +{
  1169 + 0, 35, 59, 60, 61, 66, 6, 0, 9, 13,
  1170 + 14, 28, 37, 62, 63, 75, 66, 48, 49, 3,
  1171 + 14, 24, 28, 37, 56, 99, 100, 101, 53, 52,
  1172 + 52, 32, 17, 64, 65, 97, 75, 48, 48, 9,
  1173 + 13, 14, 24, 37, 56, 67, 68, 69, 70, 71,
  1174 + 99, 19, 32, 3, 4, 5, 103, 104, 106, 108,
  1175 + 52, 52, 52, 3, 6, 7, 74, 74, 28, 6,
  1176 + 40, 98, 97, 48, 48, 71, 53, 32, 50, 51,
  1177 + 79, 52, 3, 99, 57, 51, 79, 51, 79, 51,
  1178 + 79, 74, 74, 74, 19, 16, 119, 120, 119, 52,
  1179 + 49, 119, 48, 48, 3, 28, 72, 73, 99, 69,
  1180 + 6, 52, 3, 4, 57, 5, 57, 119, 119, 119,
  1181 + 3, 3, 4, 5, 6, 8, 53, 56, 74, 102,
  1182 + 121, 123, 124, 55, 16, 55, 74, 3, 4, 5,
  1183 + 53, 74, 102, 111, 112, 114, 30, 31, 33, 118,
  1184 + 19, 51, 54, 74, 55, 113, 113, 113, 54, 19,
  1185 + 49, 121, 122, 103, 53, 114, 121, 114, 119, 114,
  1186 + 115, 116, 53, 50, 51, 74, 117, 3, 73, 32,
  1187 + 119, 114, 32, 3, 122, 51, 54, 57, 124, 55,
  1188 + 54, 51, 79, 114, 119, 112, 53, 9, 71, 113,
  1189 + 9, 14, 24, 28, 37, 50, 121, 54, 114, 114,
  1190 + 54, 3, 71, 37, 99, 100, 101, 52, 52, 52,
  1191 + 32, 54, 32, 52, 52, 52, 74, 74, 74, 28,
  1192 + 99, 74, 74, 74, 119, 119, 119, 52, 52, 119,
  1193 + 119, 119, 55, 55, 55, 74, 74, 55, 93, 55,
  1194 + 94, 55, 95, 53, 53, 53, 119, 119, 53, 80,
  1195 + 53, 88, 53, 84, 105, 106, 107, 108, 103, 55,
  1196 + 55, 96, 3, 74, 76, 77, 78, 4, 74, 85,
  1197 + 86, 87, 5, 74, 81, 82, 83, 54, 79, 54,
  1198 + 79, 54, 53, 53, 92, 53, 54, 51, 79, 53,
  1199 + 54, 51, 79, 53, 54, 51, 79, 3, 102, 109,
  1200 + 110, 74, 89, 90, 91, 102, 3, 76, 3, 85,
  1201 + 3, 81, 54, 51, 79, 53, 54, 51, 79, 54,
  1202 + 54, 54, 102, 3, 89, 54
  1203 +};
  1204 +
  1205 +#define yyerrok (yyerrstatus = 0)
  1206 +#define yyclearin (yychar = YYEMPTY)
  1207 +#define YYEMPTY (-2)
  1208 +#define YYEOF 0
  1209 +
  1210 +#define YYACCEPT goto yyacceptlab
  1211 +#define YYABORT goto yyabortlab
  1212 +#define YYERROR goto yyerrorlab
  1213 +
  1214 +
  1215 +/* Like YYERROR except do call yyerror. This remains here temporarily
  1216 + to ease the transition to the new meaning of YYERROR, for GCC.
  1217 + Once GCC version 2 has supplanted version 1, this can go. */
  1218 +
  1219 +#define YYFAIL goto yyerrlab
  1220 +
  1221 +#define YYRECOVERING() (!!yyerrstatus)
  1222 +
  1223 +#define YYBACKUP(Token, Value) \
  1224 +do \
  1225 + if (yychar == YYEMPTY && yylen == 1) \
  1226 + { \
  1227 + yychar = (Token); \
  1228 + yylval = (Value); \
  1229 + yytoken = YYTRANSLATE (yychar); \
  1230 + YYPOPSTACK (1); \
  1231 + goto yybackup; \
  1232 + } \
  1233 + else \
  1234 + { \
  1235 + yyerror (parm, YY_("syntax error: cannot back up")); \
  1236 + YYERROR; \
  1237 + } \
  1238 +while (YYID (0))
  1239 +
  1240 +
  1241 +#define YYTERROR 1
  1242 +#define YYERRCODE 256
  1243 +
  1244 +
  1245 +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  1246 + If N is 0, then set CURRENT to the empty location which ends
  1247 + the previous symbol: RHS[0] (always defined). */
  1248 +
  1249 +#define YYRHSLOC(Rhs, K) ((Rhs)[K])
  1250 +#ifndef YYLLOC_DEFAULT
  1251 +# define YYLLOC_DEFAULT(Current, Rhs, N) \
  1252 + do \
  1253 + if (YYID (N)) \
  1254 + { \
  1255 + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  1256 + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  1257 + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  1258 + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  1259 + } \
  1260 + else \
  1261 + { \
  1262 + (Current).first_line = (Current).last_line = \
  1263 + YYRHSLOC (Rhs, 0).last_line; \
  1264 + (Current).first_column = (Current).last_column = \
  1265 + YYRHSLOC (Rhs, 0).last_column; \
  1266 + } \
  1267 + while (YYID (0))
  1268 +#endif
  1269 +
  1270 +
  1271 +/* YY_LOCATION_PRINT -- Print the location on the stream.
  1272 + This macro was not mandated originally: define only if we know
  1273 + we won't break user code: when these are the locations we know. */
  1274 +
  1275 +#ifndef YY_LOCATION_PRINT
  1276 +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
  1277 +# define YY_LOCATION_PRINT(File, Loc) \
  1278 + fprintf (File, "%d.%d-%d.%d", \
  1279 + (Loc).first_line, (Loc).first_column, \
  1280 + (Loc).last_line, (Loc).last_column)
  1281 +# else
  1282 +# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  1283 +# endif
  1284 +#endif
  1285 +
  1286 +
  1287 +/* YYLEX -- calling `yylex' with the right arguments. */
  1288 +
  1289 +#ifdef YYLEX_PARAM
  1290 +# define YYLEX yylex (&yylval, YYLEX_PARAM)
  1291 +#else
  1292 +# define YYLEX yylex (&yylval)
  1293 +#endif
  1294 +
  1295 +/* Enable debugging if requested. */
  1296 +#if YYDEBUG
  1297 +
  1298 +# ifndef YYFPRINTF
  1299 +# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
  1300 +# define YYFPRINTF fprintf
  1301 +# endif
  1302 +
  1303 +# define YYDPRINTF(Args) \
  1304 +do { \
  1305 + if (yydebug) \
  1306 + YYFPRINTF Args; \
  1307 +} while (YYID (0))
  1308 +
  1309 +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  1310 +do { \
  1311 + if (yydebug) \
  1312 + { \
  1313 + YYFPRINTF (stderr, "%s ", Title); \
  1314 + yy_symbol_print (stderr, \
  1315 + Type, Value, parm); \
  1316 + YYFPRINTF (stderr, "\n"); \
  1317 + } \
  1318 +} while (YYID (0))
  1319 +
  1320 +
  1321 +/*--------------------------------.
  1322 +| Print this symbol on YYOUTPUT. |
  1323 +`--------------------------------*/
  1324 +
  1325 +/*ARGSUSED*/
  1326 +#if (defined __STDC__ || defined __C99__FUNC__ \
  1327 + || defined __cplusplus || defined _MSC_VER)
  1328 +static void
  1329 +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *parm)
  1330 +#else
  1331 +static void
  1332 +yy_symbol_value_print (yyoutput, yytype, yyvaluep, parm)
  1333 + FILE *yyoutput;
  1334 + int yytype;
  1335 + YYSTYPE const * const yyvaluep;
  1336 + void *parm;
  1337 +#endif
  1338 +{
  1339 + if (!yyvaluep)
  1340 + return;
  1341 + YYUSE (parm);
  1342 +# ifdef YYPRINT
  1343 + if (yytype < YYNTOKENS)
  1344 + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
  1345 +# else
  1346 + YYUSE (yyoutput);
  1347 +# endif
  1348 + switch (yytype)
  1349 + {
  1350 + default:
  1351 + break;
  1352 + }
  1353 +}
  1354 +
  1355 +
  1356 +/*--------------------------------.
  1357 +| Print this symbol on YYOUTPUT. |
  1358 +`--------------------------------*/
  1359 +
  1360 +#if (defined __STDC__ || defined __C99__FUNC__ \
  1361 + || defined __cplusplus || defined _MSC_VER)
  1362 +static void
  1363 +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *parm)
  1364 +#else
  1365 +static void
  1366 +yy_symbol_print (yyoutput, yytype, yyvaluep, parm)
  1367 + FILE *yyoutput;
  1368 + int yytype;
  1369 + YYSTYPE const * const yyvaluep;
  1370 + void *parm;
  1371 +#endif
  1372 +{
  1373 + if (yytype < YYNTOKENS)
  1374 + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
  1375 + else
  1376 + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
  1377 +
  1378 + yy_symbol_value_print (yyoutput, yytype, yyvaluep, parm);
  1379 + YYFPRINTF (yyoutput, ")");
  1380 +}
  1381 +
  1382 +/*------------------------------------------------------------------.
  1383 +| yy_stack_print -- Print the state stack from its BOTTOM up to its |
  1384 +| TOP (included). |
  1385 +`------------------------------------------------------------------*/
  1386 +
  1387 +#if (defined __STDC__ || defined __C99__FUNC__ \
  1388 + || defined __cplusplus || defined _MSC_VER)
  1389 +static void
  1390 +yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
  1391 +#else
  1392 +static void
  1393 +yy_stack_print (bottom, top)
  1394 + yytype_int16 *bottom;
  1395 + yytype_int16 *top;
  1396 +#endif
  1397 +{
  1398 + YYFPRINTF (stderr, "Stack now");
  1399 + for (; bottom <= top; ++bottom)
  1400 + YYFPRINTF (stderr, " %d", *bottom);
  1401 + YYFPRINTF (stderr, "\n");
  1402 +}
  1403 +
  1404 +# define YY_STACK_PRINT(Bottom, Top) \
  1405 +do { \
  1406 + if (yydebug) \
  1407 + yy_stack_print ((Bottom), (Top)); \
  1408 +} while (YYID (0))
  1409 +
  1410 +
  1411 +/*------------------------------------------------.
  1412 +| Report that the YYRULE is going to be reduced. |
  1413 +`------------------------------------------------*/
  1414 +
  1415 +#if (defined __STDC__ || defined __C99__FUNC__ \
  1416 + || defined __cplusplus || defined _MSC_VER)
  1417 +static void
  1418 +yy_reduce_print (YYSTYPE *yyvsp, int yyrule, void *parm)
  1419 +#else
  1420 +static void
  1421 +yy_reduce_print (yyvsp, yyrule, parm)
  1422 + YYSTYPE *yyvsp;
  1423 + int yyrule;
  1424 + void *parm;
  1425 +#endif
  1426 +{
  1427 + int yynrhs = yyr2[yyrule];
  1428 + int yyi;
  1429 + unsigned long int yylno = yyrline[yyrule];
  1430 + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
  1431 + yyrule - 1, yylno);
  1432 + /* The symbols being reduced. */
  1433 + for (yyi = 0; yyi < yynrhs; yyi++)
  1434 + {
  1435 + fprintf (stderr, " $%d = ", yyi + 1);
  1436 + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
  1437 + &(yyvsp[(yyi + 1) - (yynrhs)])
  1438 + , parm);
  1439 + fprintf (stderr, "\n");
  1440 + }
  1441 +}
  1442 +
  1443 +# define YY_REDUCE_PRINT(Rule) \
  1444 +do { \
  1445 + if (yydebug) \
  1446 + yy_reduce_print (yyvsp, Rule, parm); \
  1447 +} while (YYID (0))
  1448 +
  1449 +/* Nonzero means print parse trace. It is left uninitialized so that
  1450 + multiple parsers can coexist. */
  1451 +int yydebug;
  1452 +#else /* !YYDEBUG */
  1453 +# define YYDPRINTF(Args)
  1454 +# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
  1455 +# define YY_STACK_PRINT(Bottom, Top)
  1456 +# define YY_REDUCE_PRINT(Rule)
  1457 +#endif /* !YYDEBUG */
  1458 +
  1459 +
  1460 +/* YYINITDEPTH -- initial size of the parser's stacks. */
  1461 +#ifndef YYINITDEPTH
  1462 +# define YYINITDEPTH 200
  1463 +#endif
  1464 +
  1465 +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
  1466 + if the built-in stack extension method is used).
  1467 +
  1468 + Do not make this value too large; the results are undefined if
  1469 + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
  1470 + evaluated with infinite-precision integer arithmetic. */
  1471 +
  1472 +#ifndef YYMAXDEPTH
  1473 +# define YYMAXDEPTH 10000
  1474 +#endif
  1475 +
  1476 +
  1477 +
  1478 +#if YYERROR_VERBOSE
  1479 +
  1480 +# ifndef yystrlen
  1481 +# if defined __GLIBC__ && defined _STRING_H
  1482 +# define yystrlen strlen
  1483 +# else
  1484 +/* Return the length of YYSTR. */
  1485 +#if (defined __STDC__ || defined __C99__FUNC__ \
  1486 + || defined __cplusplus || defined _MSC_VER)
  1487 +static YYSIZE_T
  1488 +yystrlen (const char *yystr)
  1489 +#else
  1490 +static YYSIZE_T
  1491 +yystrlen (yystr)
  1492 + const char *yystr;
  1493 +#endif
  1494 +{
  1495 + YYSIZE_T yylen;
  1496 + for (yylen = 0; yystr[yylen]; yylen++)
  1497 + continue;
  1498 + return yylen;
  1499 +}
  1500 +# endif
  1501 +# endif
  1502 +
  1503 +# ifndef yystpcpy
  1504 +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
  1505 +# define yystpcpy stpcpy
  1506 +# else
  1507 +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
  1508 + YYDEST. */
  1509 +#if (defined __STDC__ || defined __C99__FUNC__ \
  1510 + || defined __cplusplus || defined _MSC_VER)
  1511 +static char *
  1512 +yystpcpy (char *yydest, const char *yysrc)
  1513 +#else
  1514 +static char *
  1515 +yystpcpy (yydest, yysrc)
  1516 + char *yydest;
  1517 + const char *yysrc;
  1518 +#endif
  1519 +{
  1520 + char *yyd = yydest;
  1521 + const char *yys = yysrc;
  1522 +
  1523 + while ((*yyd++ = *yys++) != '\0')
  1524 + continue;
  1525 +
  1526 + return yyd - 1;
  1527 +}
  1528 +# endif
  1529 +# endif
  1530 +
  1531 +# ifndef yytnamerr
  1532 +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
  1533 + quotes and backslashes, so that it's suitable for yyerror. The
  1534 + heuristic is that double-quoting is unnecessary unless the string
  1535 + contains an apostrophe, a comma, or backslash (other than
  1536 + backslash-backslash). YYSTR is taken from yytname. If YYRES is
  1537 + null, do not copy; instead, return the length of what the result
  1538 + would have been. */
  1539 +static YYSIZE_T
  1540 +yytnamerr (char *yyres, const char *yystr)
  1541 +{
  1542 + if (*yystr == '"')
  1543 + {
  1544 + YYSIZE_T yyn = 0;
  1545 + char const *yyp = yystr;
  1546 +
  1547 + for (;;)
  1548 + switch (*++yyp)
  1549 + {
  1550 + case '\'':
  1551 + case ',':
  1552 + goto do_not_strip_quotes;
  1553 +
  1554 + case '\\':
  1555 + if (*++yyp != '\\')
  1556 + goto do_not_strip_quotes;
  1557 + /* Fall through. */
  1558 + default:
  1559 + if (yyres)
  1560 + yyres[yyn] = *yyp;
  1561 + yyn++;
  1562 + break;
  1563 +
  1564 + case '"':
  1565 + if (yyres)
  1566 + yyres[yyn] = '\0';
  1567 + return yyn;
  1568 + }
  1569 + do_not_strip_quotes: ;
  1570 + }
  1571 +
  1572 + if (! yyres)
  1573 + return yystrlen (yystr);
  1574 +
  1575 + return yystpcpy (yyres, yystr) - yyres;
  1576 +}
  1577 +# endif
  1578 +
  1579 +/* Copy into YYRESULT an error message about the unexpected token
  1580 + YYCHAR while in state YYSTATE. Return the number of bytes copied,
  1581 + including the terminating null byte. If YYRESULT is null, do not
  1582 + copy anything; just return the number of bytes that would be
  1583 + copied. As a special case, return 0 if an ordinary "syntax error"
  1584 + message will do. Return YYSIZE_MAXIMUM if overflow occurs during
  1585 + size calculation. */
  1586 +static YYSIZE_T
  1587 +yysyntax_error (char *yyresult, int yystate, int yychar)
  1588 +{
  1589 + int yyn = yypact[yystate];
  1590 +
  1591 + if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
  1592 + return 0;
  1593 + else
  1594 + {
  1595 + int yytype = YYTRANSLATE (yychar);
  1596 + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
  1597 + YYSIZE_T yysize = yysize0;
  1598 + YYSIZE_T yysize1;
  1599 + int yysize_overflow = 0;
  1600 + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  1601 + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  1602 + int yyx;
  1603 +
  1604 +# if 0
  1605 + /* This is so xgettext sees the translatable formats that are
  1606 + constructed on the fly. */
  1607 + YY_("syntax error, unexpected %s");
  1608 + YY_("syntax error, unexpected %s, expecting %s");
  1609 + YY_("syntax error, unexpected %s, expecting %s or %s");
  1610 + YY_("syntax error, unexpected %s, expecting %s or %s or %s");
  1611 + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
  1612 +# endif
  1613 + char *yyfmt;
  1614 + char const *yyf;
  1615 + static char const yyunexpected[] = "syntax error, unexpected %s";
  1616 + static char const yyexpecting[] = ", expecting %s";
  1617 + static char const yyor[] = " or %s";
  1618 + char yyformat[sizeof yyunexpected
  1619 + + sizeof yyexpecting - 1
  1620 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
  1621 + * (sizeof yyor - 1))];
  1622 + char const *yyprefix = yyexpecting;
  1623 +
  1624 + /* Start YYX at -YYN if negative to avoid negative indexes in
  1625 + YYCHECK. */
  1626 + int yyxbegin = yyn < 0 ? -yyn : 0;
  1627 +
  1628 + /* Stay within bounds of both yycheck and yytname. */
  1629 + int yychecklim = YYLAST - yyn + 1;
  1630 + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
  1631 + int yycount = 1;
  1632 +
  1633 + yyarg[0] = yytname[yytype];
  1634 + yyfmt = yystpcpy (yyformat, yyunexpected);
  1635 +
  1636 + for (yyx = yyxbegin; yyx < yyxend; ++yyx)
  1637 + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
  1638 + {
  1639 + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
  1640 + {
  1641 + yycount = 1;
  1642 + yysize = yysize0;
  1643 + yyformat[sizeof yyunexpected - 1] = '\0';
  1644 + break;
  1645 + }
  1646 + yyarg[yycount++] = yytname[yyx];
  1647 + yysize1 = yysize + yytnamerr (0, yytname[yyx]);
  1648 + yysize_overflow |= (yysize1 < yysize);
  1649 + yysize = yysize1;
  1650 + yyfmt = yystpcpy (yyfmt, yyprefix);
  1651 + yyprefix = yyor;
  1652 + }
  1653 +
  1654 + yyf = YY_(yyformat);
  1655 + yysize1 = yysize + yystrlen (yyf);
  1656 + yysize_overflow |= (yysize1 < yysize);
  1657 + yysize = yysize1;
  1658 +
  1659 + if (yysize_overflow)
  1660 + return YYSIZE_MAXIMUM;
  1661 +
  1662 + if (yyresult)
  1663 + {
  1664 + /* Avoid sprintf, as that infringes on the user's name space.
  1665 + Don't have undefined behavior even if the translation
  1666 + produced a string with the wrong number of "%s"s. */
  1667 + char *yyp = yyresult;
  1668 + int yyi = 0;
  1669 + while ((*yyp = *yyf) != '\0')
  1670 + {
  1671 + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
  1672 + {
  1673 + yyp += yytnamerr (yyp, yyarg[yyi++]);
  1674 + yyf += 2;
  1675 + }
  1676 + else
  1677 + {
  1678 + yyp++;
  1679 + yyf++;
  1680 + }
  1681 + }
  1682 + }
  1683 + return yysize;
  1684 + }
  1685 +}
  1686 +#endif /* YYERROR_VERBOSE */
  1687 +
  1688 +
  1689 +/*-----------------------------------------------.
  1690 +| Release the memory associated to this symbol. |
  1691 +`-----------------------------------------------*/
  1692 +
  1693 +/*ARGSUSED*/
  1694 +#if (defined __STDC__ || defined __C99__FUNC__ \
  1695 + || defined __cplusplus || defined _MSC_VER)
  1696 +static void
  1697 +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, void *parm)
  1698 +#else
  1699 +static void
  1700 +yydestruct (yymsg, yytype, yyvaluep, parm)
  1701 + const char *yymsg;
  1702 + int yytype;
  1703 + YYSTYPE *yyvaluep;
  1704 + void *parm;
  1705 +#endif
  1706 +{
  1707 + YYUSE (yyvaluep);
  1708 + YYUSE (parm);
  1709 +
  1710 + if (!yymsg)
  1711 + yymsg = "Deleting";
  1712 + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
  1713 +
  1714 + switch (yytype)
  1715 + {
  1716 +
  1717 + default:
  1718 + break;
  1719 + }
  1720 +}
  1721 +
  1722 +
  1723 +/* Prevent warnings from -Wmissing-prototypes. */
  1724 +
  1725 +#ifdef YYPARSE_PARAM
  1726 +#if defined __STDC__ || defined __cplusplus
  1727 +int yyparse (void *YYPARSE_PARAM);
  1728 +#else
  1729 +int yyparse ();
  1730 +#endif
  1731 +#else /* ! YYPARSE_PARAM */
  1732 +#if defined __STDC__ || defined __cplusplus
  1733 +int yyparse (void *parm);
  1734 +#else
  1735 +int yyparse ();
  1736 +#endif
  1737 +#endif /* ! YYPARSE_PARAM */
  1738 +
  1739 +
  1740 +
  1741 +
  1742 +
  1743 +
  1744 +/*----------.
  1745 +| yyparse. |
  1746 +`----------*/
  1747 +
  1748 +#ifdef YYPARSE_PARAM
  1749 +#if (defined __STDC__ || defined __C99__FUNC__ \
  1750 + || defined __cplusplus || defined _MSC_VER)
  1751 +int
  1752 +yyparse (void *YYPARSE_PARAM)
  1753 +#else
  1754 +int
  1755 +yyparse (YYPARSE_PARAM)
  1756 + void *YYPARSE_PARAM;
  1757 +#endif
  1758 +#else /* ! YYPARSE_PARAM */
  1759 +#if (defined __STDC__ || defined __C99__FUNC__ \
  1760 + || defined __cplusplus || defined _MSC_VER)
  1761 +int
  1762 +yyparse (void *parm)
  1763 +#else
  1764 +int
  1765 +yyparse (parm)
  1766 + void *parm;
  1767 +#endif
  1768 +#endif
  1769 +{
  1770 + /* The look-ahead symbol. */
  1771 +int yychar;
  1772 +
  1773 +/* The semantic value of the look-ahead symbol. */
  1774 +YYSTYPE yylval;
  1775 +
  1776 +/* Number of syntax errors so far. */
  1777 +int yynerrs;
  1778 +
  1779 + int yystate;
  1780 + int yyn;
  1781 + int yyresult;
  1782 + /* Number of tokens to shift before error messages enabled. */
  1783 + int yyerrstatus;
  1784 + /* Look-ahead token as an internal (translated) token number. */
  1785 + int yytoken = 0;
  1786 +#if YYERROR_VERBOSE
  1787 + /* Buffer for error messages, and its allocated size. */
  1788 + char yymsgbuf[128];
  1789 + char *yymsg = yymsgbuf;
  1790 + YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
  1791 +#endif
  1792 +
  1793 + /* Three stacks and their tools:
  1794 + `yyss': related to states,
  1795 + `yyvs': related to semantic values,
  1796 + `yyls': related to locations.
  1797 +
  1798 + Refer to the stacks thru separate pointers, to allow yyoverflow
  1799 + to reallocate them elsewhere. */
  1800 +
  1801 + /* The state stack. */
  1802 + yytype_int16 yyssa[YYINITDEPTH];
  1803 + yytype_int16 *yyss = yyssa;
  1804 + yytype_int16 *yyssp;
  1805 +
  1806 + /* The semantic value stack. */
  1807 + YYSTYPE yyvsa[YYINITDEPTH];
  1808 + YYSTYPE *yyvs = yyvsa;
  1809 + YYSTYPE *yyvsp;
  1810 +
  1811 +
  1812 +
  1813 +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
  1814 +
  1815 + YYSIZE_T yystacksize = YYINITDEPTH;
  1816 +
  1817 + /* The variables used to return semantic value and location from the
  1818 + action routines. */
  1819 + YYSTYPE yyval;
  1820 +
  1821 +
  1822 + /* The number of symbols on the RHS of the reduced rule.
  1823 + Keep to zero when no symbol should be popped. */
  1824 + int yylen = 0;
  1825 +
  1826 + YYDPRINTF ((stderr, "Starting parse\n"));
  1827 +
  1828 + yystate = 0;
  1829 + yyerrstatus = 0;
  1830 + yynerrs = 0;
  1831 + yychar = YYEMPTY; /* Cause a token to be read. */
  1832 +
  1833 + /* Initialize stack pointers.
  1834 + Waste one element of value and location stack
  1835 + so that they stay on the same level as the state stack.
  1836 + The wasted elements are never initialized. */
  1837 +
  1838 + yyssp = yyss;
  1839 + yyvsp = yyvs;
  1840 +
  1841 + goto yysetstate;
  1842 +
  1843 +/*------------------------------------------------------------.
  1844 +| yynewstate -- Push a new state, which is found in yystate. |
  1845 +`------------------------------------------------------------*/
  1846 + yynewstate:
  1847 + /* In all cases, when you get here, the value and location stacks
  1848 + have just been pushed. So pushing a state here evens the stacks. */
  1849 + yyssp++;
  1850 +
  1851 + yysetstate:
  1852 + *yyssp = yystate;
  1853 +
  1854 + if (yyss + yystacksize - 1 <= yyssp)
  1855 + {
  1856 + /* Get the current used size of the three stacks, in elements. */
  1857 + YYSIZE_T yysize = yyssp - yyss + 1;
  1858 +
  1859 +#ifdef yyoverflow
  1860 + {
  1861 + /* Give user a chance to reallocate the stack. Use copies of
  1862 + these so that the &'s don't force the real ones into
  1863 + memory. */
  1864 + YYSTYPE *yyvs1 = yyvs;
  1865 + yytype_int16 *yyss1 = yyss;
  1866 +
  1867 +
  1868 + /* Each stack pointer address is followed by the size of the
  1869 + data in use in that stack, in bytes. This used to be a
  1870 + conditional around just the two extra args, but that might
  1871 + be undefined if yyoverflow is a macro. */
  1872 + yyoverflow (YY_("memory exhausted"),
  1873 + &yyss1, yysize * sizeof (*yyssp),
  1874 + &yyvs1, yysize * sizeof (*yyvsp),
  1875 +
  1876 + &yystacksize);
  1877 +
  1878 + yyss = yyss1;
  1879 + yyvs = yyvs1;
  1880 + }
  1881 +#else /* no yyoverflow */
  1882 +# ifndef YYSTACK_RELOCATE
  1883 + goto yyexhaustedlab;
  1884 +# else
  1885 + /* Extend the stack our own way. */
  1886 + if (YYMAXDEPTH <= yystacksize)
  1887 + goto yyexhaustedlab;
  1888 + yystacksize *= 2;
  1889 + if (YYMAXDEPTH < yystacksize)
  1890 + yystacksize = YYMAXDEPTH;
  1891 +
  1892 + {
  1893 + yytype_int16 *yyss1 = yyss;
  1894 + union yyalloc *yyptr =
  1895 + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  1896 + if (! yyptr)
  1897 + goto yyexhaustedlab;
  1898 + YYSTACK_RELOCATE (yyss);
  1899 + YYSTACK_RELOCATE (yyvs);
  1900 +
  1901 +# undef YYSTACK_RELOCATE
  1902 + if (yyss1 != yyssa)
  1903 + YYSTACK_FREE (yyss1);
  1904 + }
  1905 +# endif
  1906 +#endif /* no yyoverflow */
  1907 +
  1908 + yyssp = yyss + yysize - 1;
  1909 + yyvsp = yyvs + yysize - 1;
  1910 +
  1911 +
  1912 + YYDPRINTF ((stderr, "Stack size increased to %lu\n",
  1913 + (unsigned long int) yystacksize));
  1914 +
  1915 + if (yyss + yystacksize - 1 <= yyssp)
  1916 + YYABORT;
  1917 + }
  1918 +
  1919 + YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  1920 +
  1921 + goto yybackup;
  1922 +
  1923 +/*-----------.
  1924 +| yybackup. |
  1925 +`-----------*/
  1926 +yybackup:
  1927 +
  1928 + /* Do appropriate processing given the current state. Read a
  1929 + look-ahead token if we need one and don't already have one. */
  1930 +
  1931 + /* First try to decide what to do without reference to look-ahead token. */
  1932 + yyn = yypact[yystate];
  1933 + if (yyn == YYPACT_NINF)
  1934 + goto yydefault;
  1935 +
  1936 + /* Not known => get a look-ahead token if don't already have one. */
  1937 +
  1938 + /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
  1939 + if (yychar == YYEMPTY)
  1940 + {
  1941 + YYDPRINTF ((stderr, "Reading a token: "));
  1942 + yychar = YYLEX;
  1943 + }
  1944 +
  1945 + if (yychar <= YYEOF)
  1946 + {
  1947 + yychar = yytoken = YYEOF;
  1948 + YYDPRINTF ((stderr, "Now at end of input.\n"));
  1949 + }
  1950 + else
  1951 + {
  1952 + yytoken = YYTRANSLATE (yychar);
  1953 + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
  1954 + }
  1955 +
  1956 + /* If the proper action on seeing token YYTOKEN is to reduce or to
  1957 + detect an error, take that action. */
  1958 + yyn += yytoken;
  1959 + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
  1960 + goto yydefault;
  1961 + yyn = yytable[yyn];
  1962 + if (yyn <= 0)
  1963 + {
  1964 + if (yyn == 0 || yyn == YYTABLE_NINF)
  1965 + goto yyerrlab;
  1966 + yyn = -yyn;
  1967 + goto yyreduce;
  1968 + }
  1969 +
  1970 + if (yyn == YYFINAL)
  1971 + YYACCEPT;
  1972 +
  1973 + /* Count tokens shifted since error; after three, turn off error
  1974 + status. */
  1975 + if (yyerrstatus)
  1976 + yyerrstatus--;
  1977 +
  1978 + /* Shift the look-ahead token. */
  1979 + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
  1980 +
  1981 + /* Discard the shifted token unless it is eof. */
  1982 + if (yychar != YYEOF)
  1983 + yychar = YYEMPTY;
  1984 +
  1985 + yystate = yyn;
  1986 + *++yyvsp = yylval;
  1987 +
  1988 + goto yynewstate;
  1989 +
  1990 +
  1991 +/*-----------------------------------------------------------.
  1992 +| yydefault -- do the default action for the current state. |
  1993 +`-----------------------------------------------------------*/
  1994 +yydefault:
  1995 + yyn = yydefact[yystate];
  1996 + if (yyn == 0)
  1997 + goto yyerrlab;
  1998 + goto yyreduce;
  1999 +
  2000 +
  2001 +/*-----------------------------.
  2002 +| yyreduce -- Do a reduction. |
  2003 +`-----------------------------*/
  2004 +yyreduce:
  2005 + /* yyn is the number of a rule to reduce with. */
  2006 + yylen = yyr2[yyn];
  2007 +
  2008 + /* If YYLEN is nonzero, implement the default value of the action:
  2009 + `$$ = $1'.
  2010 +
  2011 + Otherwise, the following line sets YYVAL to garbage.
  2012 + This behavior is undocumented and Bison
  2013 + users should not rely upon it. Assigning to YYVAL
  2014 + unconditionally makes the parser a bit smaller, and it avoids a
  2015 + GCC warning that YYVAL may be used uninitialized. */
  2016 + yyval = yyvsp[1-yylen];
  2017 +
  2018 +
  2019 + YY_REDUCE_PRINT (yyn);
  2020 + switch (yyn)
  2021 + {
  2022 + case 7:
  2023 +#line 442 "parser.yxx"
  2024 + { initfg(static_cast<ParserState*>(parm)); ;}
  2025 + break;
  2026 +
  2027 + case 8:
  2028 +#line 444 "parser.yxx"
  2029 + { initfg(static_cast<ParserState*>(parm)); ;}
  2030 + break;
  2031 +
  2032 + case 35:
  2033 +#line 504 "parser.yxx"
  2034 + {
  2035 + ParserState* pp = static_cast<ParserState*>(parm);
  2036 + bool print = (yyvsp[(5) - (6)].argVec)->hasAtom("output_var");
  2037 + bool introduced = (yyvsp[(5) - (6)].argVec)->hasAtom("var_is_introduced");
  2038 + pp->intvarTable.put((yyvsp[(4) - (6)].sValue), pp->intvars.size());
  2039 + if (print) {
  2040 + pp->output(std::string((yyvsp[(4) - (6)].sValue)), new AST::IntVar(pp->intvars.size()));
  2041 + }
  2042 + if ((yyvsp[(6) - (6)].oArg)()) {
  2043 + AST::Node* arg = (yyvsp[(6) - (6)].oArg).some();
  2044 + if (arg->isInt()) {
  2045 + pp->intvars.push_back(varspec((yyvsp[(4) - (6)].sValue),
  2046 + new IntVarSpec(arg->getInt(),introduced)));
  2047 + } else if (arg->isIntVar()) {
  2048 + pp->intvars.push_back(varspec((yyvsp[(4) - (6)].sValue),
  2049 + new IntVarSpec(Alias(arg->getIntVar()),introduced)));
  2050 + } else {
  2051 + yyassert(pp, false, "Invalid var int initializer.");
  2052 + }
  2053 + if (!pp->hadError)
  2054 + addDomainConstraint(pp, "int_in",
  2055 + new AST::IntVar(pp->intvars.size()-1), (yyvsp[(2) - (6)].oSet));
  2056 + delete arg;
  2057 + } else {
  2058 + pp->intvars.push_back(varspec((yyvsp[(4) - (6)].sValue), new IntVarSpec((yyvsp[(2) - (6)].oSet),introduced)));
  2059 + }
  2060 + delete (yyvsp[(5) - (6)].argVec); free((yyvsp[(4) - (6)].sValue));
  2061 + ;}
  2062 + break;
  2063 +
  2064 + case 36:
  2065 +#line 533 "parser.yxx"
  2066 + {
  2067 + ParserState* pp = static_cast<ParserState*>(parm);
  2068 + bool print = (yyvsp[(5) - (6)].argVec)->hasAtom("output_var");
  2069 + bool introduced = (yyvsp[(5) - (6)].argVec)->hasAtom("var_is_introduced");
  2070 + pp->boolvarTable.put((yyvsp[(4) - (6)].sValue), pp->boolvars.size());
  2071 + if (print) {
  2072 + pp->output(std::string((yyvsp[(4) - (6)].sValue)), new AST::BoolVar(pp->boolvars.size()));
  2073 + }
  2074 + if ((yyvsp[(6) - (6)].oArg)()) {
  2075 + AST::Node* arg = (yyvsp[(6) - (6)].oArg).some();
  2076 + if (arg->isBool()) {
  2077 + pp->boolvars.push_back(varspec((yyvsp[(4) - (6)].sValue),
  2078 + new BoolVarSpec(arg->getBool(),introduced)));
  2079 + } else if (arg->isBoolVar()) {
  2080 + pp->boolvars.push_back(varspec((yyvsp[(4) - (6)].sValue),
  2081 + new BoolVarSpec(Alias(arg->getBoolVar()),introduced)));
  2082 + } else {
  2083 + yyassert(pp, false, "Invalid var bool initializer.");
  2084 + }
  2085 + if (!pp->hadError)
  2086 + addDomainConstraint(pp, "int_in",
  2087 + new AST::BoolVar(pp->boolvars.size()-1), (yyvsp[(2) - (6)].oSet));
  2088 + delete arg;
  2089 + } else {
  2090 + pp->boolvars.push_back(varspec((yyvsp[(4) - (6)].sValue), new BoolVarSpec((yyvsp[(2) - (6)].oSet),introduced)));
  2091 + }
  2092 + delete (yyvsp[(5) - (6)].argVec); free((yyvsp[(4) - (6)].sValue));
  2093 + ;}
  2094 + break;
  2095 +
  2096 + case 37:
  2097 +#line 562 "parser.yxx"
  2098 + { ParserState* pp = static_cast<ParserState*>(parm);
  2099 + yyassert(pp, false, "Floats not supported.");
  2100 + delete (yyvsp[(5) - (6)].argVec); free((yyvsp[(4) - (6)].sValue));
  2101 + ;}
  2102 + break;
  2103 +
  2104 + case 38:
  2105 +#line 567 "parser.yxx"
  2106 + {
  2107 + ParserState* pp = static_cast<ParserState*>(parm);
  2108 + bool print = (yyvsp[(7) - (8)].argVec)->hasAtom("output_var");
  2109 + bool introduced = (yyvsp[(7) - (8)].argVec)->hasAtom("var_is_introduced");
  2110 + pp->setvarTable.put((yyvsp[(6) - (8)].sValue), pp->setvars.size());
  2111 + if (print) {
  2112 + pp->output(std::string((yyvsp[(6) - (8)].sValue)), new AST::SetVar(pp->setvars.size()));
  2113 + }
  2114 + if ((yyvsp[(8) - (8)].oArg)()) {
  2115 + AST::Node* arg = (yyvsp[(8) - (8)].oArg).some();
  2116 + if (arg->isSet()) {
  2117 + pp->setvars.push_back(varspec((yyvsp[(6) - (8)].sValue),
  2118 + new SetVarSpec(arg->getSet(),introduced)));
  2119 + } else if (arg->isSetVar()) {
  2120 + pp->setvars.push_back(varspec((yyvsp[(6) - (8)].sValue),
  2121 + new SetVarSpec(Alias(arg->getSetVar()),introduced)));
  2122 + delete arg;
  2123 + } else {
  2124 + yyassert(pp, false, "Invalid var set initializer.");
  2125 + delete arg;
  2126 + }
  2127 + if (!pp->hadError)
  2128 + addDomainConstraint(pp, "set_subset",
  2129 + new AST::SetVar(pp->setvars.size()-1), (yyvsp[(4) - (8)].oSet));
  2130 + } else {
  2131 + pp->setvars.push_back(varspec((yyvsp[(6) - (8)].sValue), new SetVarSpec((yyvsp[(4) - (8)].oSet),introduced)));
  2132 + }
  2133 + delete (yyvsp[(7) - (8)].argVec); free((yyvsp[(6) - (8)].sValue));
  2134 + ;}
  2135 + break;
  2136 +
  2137 + case 39:
  2138 +#line 597 "parser.yxx"
  2139 + {
  2140 + ParserState* pp = static_cast<ParserState*>(parm);
  2141 + yyassert(pp, (yyvsp[(6) - (6)].arg)->isInt(), "Invalid int initializer.");
  2142 + pp->intvals.put((yyvsp[(3) - (6)].sValue), (yyvsp[(6) - (6)].arg)->getInt());
  2143 + delete (yyvsp[(4) - (6)].argVec); free((yyvsp[(3) - (6)].sValue));
  2144 + ;}
  2145 + break;
  2146 +
  2147 + case 40:
  2148 +#line 604 "parser.yxx"
  2149 + {
  2150 + ParserState* pp = static_cast<ParserState*>(parm);
  2151 + yyassert(pp, (yyvsp[(6) - (6)].arg)->isBool(), "Invalid bool initializer.");
  2152 + pp->boolvals.put((yyvsp[(3) - (6)].sValue), (yyvsp[(6) - (6)].arg)->getBool());
  2153 + delete (yyvsp[(4) - (6)].argVec); free((yyvsp[(3) - (6)].sValue));
  2154 + ;}
  2155 + break;
  2156 +
  2157 + case 41:
  2158 +#line 611 "parser.yxx"
  2159 + {
  2160 + ParserState* pp = static_cast<ParserState*>(parm);
  2161 + yyassert(pp, (yyvsp[(8) - (8)].arg)->isSet(), "Invalid set initializer.");
  2162 + AST::SetLit* set = (yyvsp[(8) - (8)].arg)->getSet();
  2163 + pp->setvals.put((yyvsp[(5) - (8)].sValue), *set);
  2164 + delete set;
  2165 + delete (yyvsp[(6) - (8)].argVec); free((yyvsp[(5) - (8)].sValue));
  2166 + ;}
  2167 + break;
  2168 +
  2169 + case 42:
  2170 +#line 621 "parser.yxx"
  2171 + {
  2172 + ParserState* pp = static_cast<ParserState*>(parm);
  2173 + yyassert(pp, (yyvsp[(3) - (13)].iValue)==1, "Arrays must start at 1");
  2174 + if (!pp->hadError) {
  2175 + bool print = (yyvsp[(12) - (13)].argVec)->hasCall("output_array");
  2176 + vector<int> vars((yyvsp[(5) - (13)].iValue));
  2177 + if (!pp->hadError) {
  2178 + if ((yyvsp[(13) - (13)].oVarSpecVec)()) {
  2179 + vector<VarSpec*>* vsv = (yyvsp[(13) - (13)].oVarSpecVec).some();
  2180 + yyassert(pp, vsv->size() == static_cast<unsigned int>((yyvsp[(5) - (13)].iValue)),
  2181 + "Initializer size does not match array dimension");
  2182 + if (!pp->hadError) {
  2183 + for (int i=0; i<(yyvsp[(5) - (13)].iValue); i++) {
  2184 + IntVarSpec* ivsv = static_cast<IntVarSpec*>((*vsv)[i]);
  2185 + if (ivsv->alias) {
  2186 + vars[i] = ivsv->i;
  2187 + } else {
  2188 + vars[i] = pp->intvars.size();
  2189 + pp->intvars.push_back(varspec((yyvsp[(11) - (13)].sValue), ivsv));
  2190 + }
  2191 + if (!pp->hadError && (yyvsp[(9) - (13)].oSet)()) {
  2192 + Option<AST::SetLit*> opt =
  2193 + Option<AST::SetLit*>::some(new AST::SetLit(*(yyvsp[(9) - (13)].oSet).some()));
  2194 + addDomainConstraint(pp, "int_in",
  2195 + new AST::IntVar(vars[i]),
  2196 + opt);
  2197 + }
  2198 + }
  2199 + }
  2200 + delete vsv;
  2201 + } else {
  2202 + if ((yyvsp[(5) - (13)].iValue)>0) {
  2203 + IntVarSpec* ispec = new IntVarSpec((yyvsp[(9) - (13)].oSet),!print);
  2204 + string arrayname = "["; arrayname += (yyvsp[(11) - (13)].sValue);
  2205 + for (int i=0; i<(yyvsp[(5) - (13)].iValue)-1; i++) {
  2206 + vars[i] = pp->intvars.size();
  2207 + pp->intvars.push_back(varspec(arrayname, ispec));
  2208 + }
  2209 + vars[(yyvsp[(5) - (13)].iValue)-1] = pp->intvars.size();
  2210 + pp->intvars.push_back(varspec((yyvsp[(11) - (13)].sValue), ispec));
  2211 + }
  2212 + }
  2213 + }
  2214 + if (print) {
  2215 + AST::Array* a = new AST::Array();
  2216 + a->a.push_back(arrayOutput((yyvsp[(12) - (13)].argVec)->getCall("output_array")));
  2217 + AST::Array* output = new AST::Array();
  2218 + for (int i=0; i<(yyvsp[(5) - (13)].iValue); i++)
  2219 + output->a.push_back(new AST::IntVar(vars[i]));
  2220 + a->a.push_back(output);
  2221 + a->a.push_back(new AST::String(")"));
  2222 + pp->output(std::string((yyvsp[(11) - (13)].sValue)), a);
  2223 + }
  2224 + pp->intvararrays.put((yyvsp[(11) - (13)].sValue), vars);
  2225 + }
  2226 + delete (yyvsp[(12) - (13)].argVec); free((yyvsp[(11) - (13)].sValue));
  2227 + ;}
  2228 + break;
  2229 +
  2230 + case 43:
  2231 +#line 680 "parser.yxx"
  2232 + {
  2233 + ParserState* pp = static_cast<ParserState*>(parm);
  2234 + bool print = (yyvsp[(12) - (13)].argVec)->hasCall("output_array");
  2235 + yyassert(pp, (yyvsp[(3) - (13)].iValue)==1, "Arrays must start at 1");
  2236 + if (!pp->hadError) {
  2237 + vector<int> vars((yyvsp[(5) - (13)].iValue));
  2238 + if ((yyvsp[(13) - (13)].oVarSpecVec)()) {
  2239 + vector<VarSpec*>* vsv = (yyvsp[(13) - (13)].oVarSpecVec).some();
  2240 + yyassert(pp, vsv->size() == static_cast<unsigned int>((yyvsp[(5) - (13)].iValue)),
  2241 + "Initializer size does not match array dimension");
  2242 + if (!pp->hadError) {
  2243 + for (int i=0; i<(yyvsp[(5) - (13)].iValue); i++) {
  2244 + BoolVarSpec* bvsv = static_cast<BoolVarSpec*>((*vsv)[i]);
  2245 + if (bvsv->alias)
  2246 + vars[i] = bvsv->i;
  2247 + else {
  2248 + vars[i] = pp->boolvars.size();
  2249 + pp->boolvars.push_back(varspec((yyvsp[(11) - (13)].sValue), (*vsv)[i]));
  2250 + }
  2251 + if (!pp->hadError && (yyvsp[(9) - (13)].oSet)()) {
  2252 + Option<AST::SetLit*> opt =
  2253 + Option<AST::SetLit*>::some(new AST::SetLit(*(yyvsp[(9) - (13)].oSet).some()));
  2254 + addDomainConstraint(pp, "int_in",
  2255 + new AST::BoolVar(vars[i]),
  2256 + opt);
  2257 + }
  2258 + }
  2259 + }
  2260 + delete vsv;
  2261 + } else {
  2262 + for (int i=0; i<(yyvsp[(5) - (13)].iValue); i++) {
  2263 + vars[i] = pp->boolvars.size();
  2264 + pp->boolvars.push_back(varspec((yyvsp[(11) - (13)].sValue),
  2265 + new BoolVarSpec((yyvsp[(9) - (13)].oSet),!print)));
  2266 + }
  2267 + }
  2268 + if (print) {
  2269 + AST::Array* a = new AST::Array();
  2270 + a->a.push_back(arrayOutput((yyvsp[(12) - (13)].argVec)->getCall("output_array")));
  2271 + AST::Array* output = new AST::Array();
  2272 + for (int i=0; i<(yyvsp[(5) - (13)].iValue); i++)
  2273 + output->a.push_back(new AST::BoolVar(vars[i]));
  2274 + a->a.push_back(output);
  2275 + a->a.push_back(new AST::String(")"));
  2276 + pp->output(std::string((yyvsp[(11) - (13)].sValue)), a);
  2277 + }
  2278 + pp->boolvararrays.put((yyvsp[(11) - (13)].sValue), vars);
  2279 + }
  2280 + delete (yyvsp[(12) - (13)].argVec); free((yyvsp[(11) - (13)].sValue));
  2281 + ;}
  2282 + break;
  2283 +
  2284 + case 44:
  2285 +#line 732 "parser.yxx"
  2286 + {
  2287 + ParserState* pp = static_cast<ParserState*>(parm);
  2288 + yyassert(pp, false, "Floats not supported.");
  2289 + delete (yyvsp[(12) - (13)].argVec); free((yyvsp[(11) - (13)].sValue));
  2290 + ;}
  2291 + break;
  2292 +
  2293 + case 45:
  2294 +#line 739 "parser.yxx"
  2295 + {
  2296 + ParserState* pp = static_cast<ParserState*>(parm);
  2297 + bool print = (yyvsp[(14) - (15)].argVec)->hasCall("output_array");
  2298 + yyassert(pp, (yyvsp[(3) - (15)].iValue)==1, "Arrays must start at 1");
  2299 + if (!pp->hadError) {
  2300 + vector<int> vars((yyvsp[(5) - (15)].iValue));
  2301 + if ((yyvsp[(15) - (15)].oVarSpecVec)()) {
  2302 + vector<VarSpec*>* vsv = (yyvsp[(15) - (15)].oVarSpecVec).some();
  2303 + yyassert(pp, vsv->size() == static_cast<unsigned int>((yyvsp[(5) - (15)].iValue)),
  2304 + "Initializer size does not match array dimension");
  2305 + if (!pp->hadError) {
  2306 + for (int i=0; i<(yyvsp[(5) - (15)].iValue); i++) {
  2307 + SetVarSpec* svsv = static_cast<SetVarSpec*>((*vsv)[i]);
  2308 + if (svsv->alias)
  2309 + vars[i] = svsv->i;
  2310 + else {
  2311 + vars[i] = pp->setvars.size();
  2312 + pp->setvars.push_back(varspec((yyvsp[(13) - (15)].sValue), (*vsv)[i]));
  2313 + }
  2314 + if (!pp->hadError && (yyvsp[(11) - (15)].oSet)()) {
  2315 + Option<AST::SetLit*> opt =
  2316 + Option<AST::SetLit*>::some(new AST::SetLit(*(yyvsp[(11) - (15)].oSet).some()));
  2317 + addDomainConstraint(pp, "set_subset",
  2318 + new AST::SetVar(vars[i]),
  2319 + opt);
  2320 + }
  2321 + }
  2322 + }
  2323 + delete vsv;
  2324 + } else {
  2325 + if ((yyvsp[(5) - (15)].iValue)>0) {
  2326 + SetVarSpec* ispec = new SetVarSpec((yyvsp[(11) - (15)].oSet),!print);
  2327 + string arrayname = "["; arrayname += (yyvsp[(13) - (15)].sValue);
  2328 + for (int i=0; i<(yyvsp[(5) - (15)].iValue)-1; i++) {
  2329 + vars[i] = pp->setvars.size();
  2330 + pp->setvars.push_back(varspec(arrayname, ispec));
  2331 + }
  2332 + vars[(yyvsp[(5) - (15)].iValue)-1] = pp->setvars.size();
  2333 + pp->setvars.push_back(varspec((yyvsp[(13) - (15)].sValue), ispec));
  2334 + }
  2335 + }
  2336 + if (print) {
  2337 + AST::Array* a = new AST::Array();
  2338 + a->a.push_back(arrayOutput((yyvsp[(14) - (15)].argVec)->getCall("output_array")));
  2339 + AST::Array* output = new AST::Array();
  2340 + for (int i=0; i<(yyvsp[(5) - (15)].iValue); i++)
  2341 + output->a.push_back(new AST::SetVar(vars[i]));
  2342 + a->a.push_back(output);
  2343 + a->a.push_back(new AST::String(")"));
  2344 + pp->output(std::string((yyvsp[(13) - (15)].sValue)), a);
  2345 + }
  2346 + pp->setvararrays.put((yyvsp[(13) - (15)].sValue), vars);
  2347 + }
  2348 + delete (yyvsp[(14) - (15)].argVec); free((yyvsp[(13) - (15)].sValue));
  2349 + ;}
  2350 + break;
  2351 +
  2352 + case 46:
  2353 +#line 796 "parser.yxx"
  2354 + {
  2355 + ParserState* pp = static_cast<ParserState*>(parm);
  2356 + yyassert(pp, (yyvsp[(3) - (15)].iValue)==1, "Arrays must start at 1");
  2357 + yyassert(pp, (yyvsp[(14) - (15)].setValue)->size() == static_cast<unsigned int>((yyvsp[(5) - (15)].iValue)),
  2358 + "Initializer size does not match array dimension");
  2359 + if (!pp->hadError)
  2360 + pp->intvalarrays.put((yyvsp[(10) - (15)].sValue), *(yyvsp[(14) - (15)].setValue));
  2361 + delete (yyvsp[(14) - (15)].setValue);
  2362 + free((yyvsp[(10) - (15)].sValue));
  2363 + delete (yyvsp[(11) - (15)].argVec);
  2364 + ;}
  2365 + break;
  2366 +
  2367 + case 47:
  2368 +#line 809 "parser.yxx"
  2369 + {
  2370 + ParserState* pp = static_cast<ParserState*>(parm);
  2371 + yyassert(pp, (yyvsp[(3) - (15)].iValue)==1, "Arrays must start at 1");
  2372 + yyassert(pp, (yyvsp[(14) - (15)].setValue)->size() == static_cast<unsigned int>((yyvsp[(5) - (15)].iValue)),
  2373 + "Initializer size does not match array dimension");
  2374 + if (!pp->hadError)
  2375 + pp->boolvalarrays.put((yyvsp[(10) - (15)].sValue), *(yyvsp[(14) - (15)].setValue));
  2376 + delete (yyvsp[(14) - (15)].setValue);
  2377 + free((yyvsp[(10) - (15)].sValue));
  2378 + delete (yyvsp[(11) - (15)].argVec);
  2379 + ;}
  2380 + break;
  2381 +
  2382 + case 48:
  2383 +#line 822 "parser.yxx"
  2384 + {
  2385 + ParserState* pp = static_cast<ParserState*>(parm);
  2386 + yyassert(pp, false, "Floats not supported.");
  2387 + delete (yyvsp[(11) - (15)].argVec); free((yyvsp[(10) - (15)].sValue));
  2388 + ;}
  2389 + break;
  2390 +
  2391 + case 49:
  2392 +#line 829 "parser.yxx"
  2393 + {
  2394 + ParserState* pp = static_cast<ParserState*>(parm);
  2395 + yyassert(pp, (yyvsp[(3) - (17)].iValue)==1, "Arrays must start at 1");
  2396 + yyassert(pp, (yyvsp[(16) - (17)].setValueList)->size() == static_cast<unsigned int>((yyvsp[(5) - (17)].iValue)),
  2397 + "Initializer size does not match array dimension");
  2398 + if (!pp->hadError)
  2399 + pp->setvalarrays.put((yyvsp[(12) - (17)].sValue), *(yyvsp[(16) - (17)].setValueList));
  2400 + delete (yyvsp[(16) - (17)].setValueList);
  2401 + delete (yyvsp[(13) - (17)].argVec); free((yyvsp[(12) - (17)].sValue));
  2402 + ;}
  2403 + break;
  2404 +
  2405 + case 50:
  2406 +#line 842 "parser.yxx"
  2407 + {
  2408 + (yyval.varSpec) = new IntVarSpec((yyvsp[(1) - (1)].iValue),false);
  2409 + ;}
  2410 + break;
  2411 +
  2412 + case 51:
  2413 +#line 846 "parser.yxx"
  2414 + {
  2415 + int v = 0;
  2416 + ParserState* pp = static_cast<ParserState*>(parm);
  2417 + if (pp->intvarTable.get((yyvsp[(1) - (1)].sValue), v))
  2418 + (yyval.varSpec) = new IntVarSpec(Alias(v),false);
  2419 + else {
  2420 + pp->err << "Error: undefined identifier " << (yyvsp[(1) - (1)].sValue)
  2421 + << " in line no. "
  2422 + << yyget_lineno(pp->yyscanner) << std::endl;
  2423 + pp->hadError = true;
  2424 + (yyval.varSpec) = new IntVarSpec(0,false); // keep things consistent
  2425 + }
  2426 + free((yyvsp[(1) - (1)].sValue));
  2427 + ;}
  2428 + break;
  2429 +
  2430 + case 52:
  2431 +#line 861 "parser.yxx"
  2432 + {
  2433 + vector<int> v;
  2434 + ParserState* pp = static_cast<ParserState*>(parm);
  2435 + if (pp->intvararrays.get((yyvsp[(1) - (4)].sValue), v)) {
  2436 + yyassert(pp,static_cast<unsigned int>((yyvsp[(3) - (4)].iValue)) > 0 &&
  2437 + static_cast<unsigned int>((yyvsp[(3) - (4)].iValue)) <= v.size(),
  2438 + "array access out of bounds");
  2439 + if (!pp->hadError)
  2440 + (yyval.varSpec) = new IntVarSpec(Alias(v[(yyvsp[(3) - (4)].iValue)-1]),false);
  2441 + else
  2442 + (yyval.varSpec) = new IntVarSpec(0,false); // keep things consistent
  2443 + } else {
  2444 + pp->err << "Error: undefined array identifier " << (yyvsp[(1) - (4)].sValue)
  2445 + << " in line no. "
  2446 + << yyget_lineno(pp->yyscanner) << std::endl;
  2447 + pp->hadError = true;
  2448 + (yyval.varSpec) = new IntVarSpec(0,false); // keep things consistent
  2449 + }
  2450 + free((yyvsp[(1) - (4)].sValue));
  2451 + ;}
  2452 + break;
  2453 +
  2454 + case 53:
  2455 +#line 884 "parser.yxx"
  2456 + { (yyval.varSpecVec) = new vector<VarSpec*>(0); ;}
  2457 + break;
  2458 +
  2459 + case 54:
  2460 +#line 886 "parser.yxx"
  2461 + { (yyval.varSpecVec) = (yyvsp[(1) - (2)].varSpecVec); ;}
  2462 + break;
  2463 +
  2464 + case 55:
  2465 +#line 890 "parser.yxx"
  2466 + { (yyval.varSpecVec) = new vector<VarSpec*>(1); (*(yyval.varSpecVec))[0] = (yyvsp[(1) - (1)].varSpec); ;}
  2467 + break;
  2468 +
  2469 + case 56:
  2470 +#line 892 "parser.yxx"
  2471 + { (yyval.varSpecVec) = (yyvsp[(1) - (3)].varSpecVec); (yyval.varSpecVec)->push_back((yyvsp[(3) - (3)].varSpec)); ;}
  2472 + break;
  2473 +
  2474 + case 59:
  2475 +#line 897 "parser.yxx"
  2476 + { (yyval.varSpecVec) = (yyvsp[(2) - (3)].varSpecVec); ;}
  2477 + break;
  2478 +
  2479 + case 60:
  2480 +#line 901 "parser.yxx"
  2481 + { (yyval.varSpec) = new FloatVarSpec((yyvsp[(1) - (1)].dValue),false); ;}
  2482 + break;
  2483 +
  2484 + case 61:
  2485 +#line 903 "parser.yxx"
  2486 + {
  2487 + int v = 0;
  2488 + ParserState* pp = static_cast<ParserState*>(parm);
  2489 + if (pp->floatvarTable.get((yyvsp[(1) - (1)].sValue), v))
  2490 + (yyval.varSpec) = new FloatVarSpec(Alias(v),false);
  2491 + else {
  2492 + pp->err << "Error: undefined identifier " << (yyvsp[(1) - (1)].sValue)
  2493 + << " in line no. "
  2494 + << yyget_lineno(pp->yyscanner) << std::endl;
  2495 + pp->hadError = true;
  2496 + (yyval.varSpec) = new FloatVarSpec(0.0,false);
  2497 + }
  2498 + free((yyvsp[(1) - (1)].sValue));
  2499 + ;}
  2500 + break;
  2501 +
  2502 + case 62:
  2503 +#line 918 "parser.yxx"
  2504 + {
  2505 + vector<int> v;
  2506 + ParserState* pp = static_cast<ParserState*>(parm);
  2507 + if (pp->floatvararrays.get((yyvsp[(1) - (4)].sValue), v)) {
  2508 + yyassert(pp,static_cast<unsigned int>((yyvsp[(3) - (4)].iValue)) > 0 &&
  2509 + static_cast<unsigned int>((yyvsp[(3) - (4)].iValue)) <= v.size(),
  2510 + "array access out of bounds");
  2511 + if (!pp->hadError)
  2512 + (yyval.varSpec) = new FloatVarSpec(Alias(v[(yyvsp[(3) - (4)].iValue)-1]),false);
  2513 + else
  2514 + (yyval.varSpec) = new FloatVarSpec(0.0,false);
  2515 + } else {
  2516 + pp->err << "Error: undefined array identifier " << (yyvsp[(1) - (4)].sValue)
  2517 + << " in line no. "
  2518 + << yyget_lineno(pp->yyscanner) << std::endl;
  2519 + pp->hadError = true;
  2520 + (yyval.varSpec) = new FloatVarSpec(0.0,false);
  2521 + }
  2522 + free((yyvsp[(1) - (4)].sValue));
  2523 + ;}
  2524 + break;
  2525 +
  2526 + case 63:
  2527 +#line 941 "parser.yxx"
  2528 + { (yyval.varSpecVec) = new vector<VarSpec*>(0); ;}
  2529 + break;
  2530 +
  2531 + case 64:
  2532 +#line 943 "parser.yxx"
  2533 + { (yyval.varSpecVec) = (yyvsp[(1) - (2)].varSpecVec); ;}
  2534 + break;
  2535 +
  2536 + case 65:
  2537 +#line 947 "parser.yxx"
  2538 + { (yyval.varSpecVec) = new vector<VarSpec*>(1); (*(yyval.varSpecVec))[0] = (yyvsp[(1) - (1)].varSpec); ;}
  2539 + break;
  2540 +
  2541 + case 66:
  2542 +#line 949 "parser.yxx"
  2543 + { (yyval.varSpecVec) = (yyvsp[(1) - (3)].varSpecVec); (yyval.varSpecVec)->push_back((yyvsp[(3) - (3)].varSpec)); ;}
  2544 + break;
  2545 +
  2546 + case 67:
  2547 +#line 953 "parser.yxx"
  2548 + { (yyval.varSpecVec) = (yyvsp[(2) - (3)].varSpecVec); ;}
  2549 + break;
  2550 +
  2551 + case 68:
  2552 +#line 957 "parser.yxx"
  2553 + { (yyval.varSpec) = new BoolVarSpec((yyvsp[(1) - (1)].iValue),false); ;}
  2554 + break;
  2555 +
  2556 + case 69:
  2557 +#line 959 "parser.yxx"
  2558 + {
  2559 + int v = 0;
  2560 + ParserState* pp = static_cast<ParserState*>(parm);
  2561 + if (pp->boolvarTable.get((yyvsp[(1) - (1)].sValue), v))
  2562 + (yyval.varSpec) = new BoolVarSpec(Alias(v),false);
  2563 + else {
  2564 + pp->err << "Error: undefined identifier " << (yyvsp[(1) - (1)].sValue)
  2565 + << " in line no. "
  2566 + << yyget_lineno(pp->yyscanner) << std::endl;
  2567 + pp->hadError = true;
  2568 + (yyval.varSpec) = new BoolVarSpec(false,false);
  2569 + }
  2570 + free((yyvsp[(1) - (1)].sValue));
  2571 + ;}
  2572 + break;
  2573 +
  2574 + case 70:
  2575 +#line 974 "parser.yxx"
  2576 + {
  2577 + vector<int> v;
  2578 + ParserState* pp = static_cast<ParserState*>(parm);
  2579 + if (pp->boolvararrays.get((yyvsp[(1) - (4)].sValue), v)) {
  2580 + yyassert(pp,static_cast<unsigned int>((yyvsp[(3) - (4)].iValue)) > 0 &&
  2581 + static_cast<unsigned int>((yyvsp[(3) - (4)].iValue)) <= v.size(),
  2582 + "array access out of bounds");
  2583 + if (!pp->hadError)
  2584 + (yyval.varSpec) = new BoolVarSpec(Alias(v[(yyvsp[(3) - (4)].iValue)-1]),false);
  2585 + else
  2586 + (yyval.varSpec) = new BoolVarSpec(false,false);
  2587 + } else {
  2588 + pp->err << "Error: undefined array identifier " << (yyvsp[(1) - (4)].sValue)
  2589 + << " in line no. "
  2590 + << yyget_lineno(pp->yyscanner) << std::endl;
  2591 + pp->hadError = true;
  2592 + (yyval.varSpec) = new BoolVarSpec(false,false);
  2593 + }
  2594 + free((yyvsp[(1) - (4)].sValue));
  2595 + ;}
  2596 + break;
  2597 +
  2598 + case 71:
  2599 +#line 997 "parser.yxx"
  2600 + { (yyval.varSpecVec) = new vector<VarSpec*>(0); ;}
  2601 + break;
  2602 +
  2603 + case 72:
  2604 +#line 999 "parser.yxx"
  2605 + { (yyval.varSpecVec) = (yyvsp[(1) - (2)].varSpecVec); ;}
  2606 + break;
  2607 +
  2608 + case 73:
  2609 +#line 1003 "parser.yxx"
  2610 + { (yyval.varSpecVec) = new vector<VarSpec*>(1); (*(yyval.varSpecVec))[0] = (yyvsp[(1) - (1)].varSpec); ;}
  2611 + break;
  2612 +
  2613 + case 74:
  2614 +#line 1005 "parser.yxx"
  2615 + { (yyval.varSpecVec) = (yyvsp[(1) - (3)].varSpecVec); (yyval.varSpecVec)->push_back((yyvsp[(3) - (3)].varSpec)); ;}
  2616 + break;
  2617 +
  2618 + case 75:
  2619 +#line 1007 "parser.yxx"
  2620 + { (yyval.varSpecVec) = (yyvsp[(2) - (3)].varSpecVec); ;}
  2621 + break;
  2622 +
  2623 + case 76:
  2624 +#line 1011 "parser.yxx"
  2625 + { (yyval.varSpec) = new SetVarSpec((yyvsp[(1) - (1)].setLit),false); ;}
  2626 + break;
  2627 +
  2628 + case 77:
  2629 +#line 1013 "parser.yxx"
  2630 + {
  2631 + ParserState* pp = static_cast<ParserState*>(parm);
  2632 + int v = 0;
  2633 + if (pp->setvarTable.get((yyvsp[(1) - (1)].sValue), v))
  2634 + (yyval.varSpec) = new SetVarSpec(Alias(v),false);
  2635 + else {
  2636 + pp->err << "Error: undefined identifier " << (yyvsp[(1) - (1)].sValue)
  2637 + << " in line no. "
  2638 + << yyget_lineno(pp->yyscanner) << std::endl;
  2639 + pp->hadError = true;
  2640 + (yyval.varSpec) = new SetVarSpec(Alias(0),false);
  2641 + }
  2642 + free((yyvsp[(1) - (1)].sValue));
  2643 + ;}
  2644 + break;
  2645 +
  2646 + case 78:
  2647 +#line 1028 "parser.yxx"
  2648 + {
  2649 + vector<int> v;
  2650 + ParserState* pp = static_cast<ParserState*>(parm);
  2651 + if (pp->setvararrays.get((yyvsp[(1) - (4)].sValue), v)) {
  2652 + yyassert(pp,static_cast<unsigned int>((yyvsp[(3) - (4)].iValue)) > 0 &&
  2653 + static_cast<unsigned int>((yyvsp[(3) - (4)].iValue)) <= v.size(),
  2654 + "array access out of bounds");
  2655 + if (!pp->hadError)
  2656 + (yyval.varSpec) = new SetVarSpec(Alias(v[(yyvsp[(3) - (4)].iValue)-1]),false);
  2657 + else
  2658 + (yyval.varSpec) = new SetVarSpec(Alias(0),false);
  2659 + } else {
  2660 + pp->err << "Error: undefined array identifier " << (yyvsp[(1) - (4)].sValue)
  2661 + << " in line no. "
  2662 + << yyget_lineno(pp->yyscanner) << std::endl;
  2663 + pp->hadError = true;
  2664 + (yyval.varSpec) = new SetVarSpec(Alias(0),false);
  2665 + }
  2666 + free((yyvsp[(1) - (4)].sValue));
  2667 + ;}
  2668 + break;
  2669 +
  2670 + case 79:
  2671 +#line 1051 "parser.yxx"
  2672 + { (yyval.varSpecVec) = new vector<VarSpec*>(0); ;}
  2673 + break;
  2674 +
  2675 + case 80:
  2676 +#line 1053 "parser.yxx"
  2677 + { (yyval.varSpecVec) = (yyvsp[(1) - (2)].varSpecVec); ;}
  2678 + break;
  2679 +
  2680 + case 81:
  2681 +#line 1057 "parser.yxx"
  2682 + { (yyval.varSpecVec) = new vector<VarSpec*>(1); (*(yyval.varSpecVec))[0] = (yyvsp[(1) - (1)].varSpec); ;}
  2683 + break;
  2684 +
  2685 + case 82:
  2686 +#line 1059 "parser.yxx"
  2687 + { (yyval.varSpecVec) = (yyvsp[(1) - (3)].varSpecVec); (yyval.varSpecVec)->push_back((yyvsp[(3) - (3)].varSpec)); ;}
  2688 + break;
  2689 +
  2690 + case 83:
  2691 +#line 1062 "parser.yxx"
  2692 + { (yyval.varSpecVec) = (yyvsp[(2) - (3)].varSpecVec); ;}
  2693 + break;
  2694 +
  2695 + case 84:
  2696 +#line 1066 "parser.yxx"
  2697 + { (yyval.oVarSpecVec) = Option<vector<VarSpec*>* >::none(); ;}
  2698 + break;
  2699 +
  2700 + case 85:
  2701 +#line 1068 "parser.yxx"
  2702 + { (yyval.oVarSpecVec) = Option<vector<VarSpec*>* >::some((yyvsp[(2) - (2)].varSpecVec)); ;}
  2703 + break;
  2704 +
  2705 + case 86:
  2706 +#line 1072 "parser.yxx"
  2707 + { (yyval.oVarSpecVec) = Option<vector<VarSpec*>* >::none(); ;}
  2708 + break;
  2709 +
  2710 + case 87:
  2711 +#line 1074 "parser.yxx"
  2712 + { (yyval.oVarSpecVec) = Option<vector<VarSpec*>* >::some((yyvsp[(2) - (2)].varSpecVec)); ;}
  2713 + break;
  2714 +
  2715 + case 88:
  2716 +#line 1078 "parser.yxx"
  2717 + { (yyval.oVarSpecVec) = Option<vector<VarSpec*>* >::none(); ;}
  2718 + break;
  2719 +
  2720 + case 89:
  2721 +#line 1080 "parser.yxx"
  2722 + { (yyval.oVarSpecVec) = Option<vector<VarSpec*>* >::some((yyvsp[(2) - (2)].varSpecVec)); ;}
  2723 + break;
  2724 +
  2725 + case 90:
  2726 +#line 1084 "parser.yxx"
  2727 + { (yyval.oVarSpecVec) = Option<vector<VarSpec*>* >::none(); ;}
  2728 + break;
  2729 +
  2730 + case 91:
  2731 +#line 1086 "parser.yxx"
  2732 + { (yyval.oVarSpecVec) = Option<vector<VarSpec*>* >::some((yyvsp[(2) - (2)].varSpecVec)); ;}
  2733 + break;
  2734 +
  2735 + case 92:
  2736 +#line 1090 "parser.yxx"
  2737 + {
  2738 + ConExpr c((yyvsp[(2) - (6)].sValue), (yyvsp[(4) - (6)].argVec));
  2739 + ParserState *pp = static_cast<ParserState*>(parm);
  2740 + if (!pp->hadError) {
  2741 + try {
  2742 + pp->fg->postConstraint(c, (yyvsp[(6) - (6)].argVec));
  2743 + } catch (FlatZinc::Error& e) {
  2744 + yyerror(pp, e.toString().c_str());
  2745 + }
  2746 + }
  2747 + delete (yyvsp[(6) - (6)].argVec); free((yyvsp[(2) - (6)].sValue));
  2748 + ;}
  2749 + break;
  2750 +
  2751 + case 93:
  2752 +#line 1104 "parser.yxx"
  2753 + {
  2754 + ParserState *pp = static_cast<ParserState*>(parm);
  2755 + if (!pp->hadError) {
  2756 + try {
  2757 + pp->fg->solve((yyvsp[(2) - (3)].argVec));
  2758 + } catch (FlatZinc::Error& e) {
  2759 + yyerror(pp, e.toString().c_str());
  2760 + }
  2761 + } else {
  2762 + delete (yyvsp[(2) - (3)].argVec);
  2763 + }
  2764 + ;}
  2765 + break;
  2766 +
  2767 + case 94:
  2768 +#line 1117 "parser.yxx"
  2769 + {
  2770 + ParserState *pp = static_cast<ParserState*>(parm);
  2771 + if (!pp->hadError) {
  2772 + try {
  2773 + if ((yyvsp[(3) - (4)].bValue))
  2774 + pp->fg->minimize((yyvsp[(4) - (4)].iValue),(yyvsp[(2) - (4)].argVec));
  2775 + else
  2776 + pp->fg->maximize((yyvsp[(4) - (4)].iValue),(yyvsp[(2) - (4)].argVec));
  2777 + } catch (FlatZinc::Error& e) {
  2778 + yyerror(pp, e.toString().c_str());
  2779 + }
  2780 + } else {
  2781 + delete (yyvsp[(2) - (4)].argVec);
  2782 + }
  2783 + ;}
  2784 + break;
  2785 +
  2786 + case 95:
  2787 +#line 1139 "parser.yxx"
  2788 + { (yyval.oSet) = Option<AST::SetLit* >::none(); ;}
  2789 + break;
  2790 +
  2791 + case 96:
  2792 +#line 1141 "parser.yxx"
  2793 + { (yyval.oSet) = Option<AST::SetLit* >::some(new AST::SetLit(*(yyvsp[(2) - (3)].setValue))); ;}
  2794 + break;
  2795 +
  2796 + case 97:
  2797 +#line 1143 "parser.yxx"
  2798 + {
  2799 + (yyval.oSet) = Option<AST::SetLit* >::some(new AST::SetLit((yyvsp[(1) - (3)].iValue), (yyvsp[(3) - (3)].iValue)));
  2800 + ;}
  2801 + break;
  2802 +
  2803 + case 98:
  2804 +#line 1149 "parser.yxx"
  2805 + { (yyval.oSet) = Option<AST::SetLit* >::none(); ;}
  2806 + break;
  2807 +
  2808 + case 99:
  2809 +#line 1151 "parser.yxx"
  2810 + { bool haveTrue = false;
  2811 + bool haveFalse = false;
  2812 + for (int i=(yyvsp[(2) - (4)].setValue)->size(); i--;) {
  2813 + haveTrue |= ((*(yyvsp[(2) - (4)].setValue))[i] == 1);
  2814 + haveFalse |= ((*(yyvsp[(2) - (4)].setValue))[i] == 0);
  2815 + }
  2816 + delete (yyvsp[(2) - (4)].setValue);
  2817 + (yyval.oSet) = Option<AST::SetLit* >::some(
  2818 + new AST::SetLit(!haveFalse,haveTrue));
  2819 + ;}
  2820 + break;
  2821 +
  2822 + case 102:
  2823 +#line 1172 "parser.yxx"
  2824 + { (yyval.setLit) = new AST::SetLit(*(yyvsp[(2) - (3)].setValue)); ;}
  2825 + break;
  2826 +
  2827 + case 103:
  2828 +#line 1174 "parser.yxx"
  2829 + { (yyval.setLit) = new AST::SetLit((yyvsp[(1) - (3)].iValue), (yyvsp[(3) - (3)].iValue)); ;}
  2830 + break;
  2831 +
  2832 + case 104:
  2833 +#line 1180 "parser.yxx"
  2834 + { (yyval.setValue) = new vector<int>(0); ;}
  2835 + break;
  2836 +
  2837 + case 105:
  2838 +#line 1182 "parser.yxx"
  2839 + { (yyval.setValue) = (yyvsp[(1) - (2)].setValue); ;}
  2840 + break;
  2841 +
  2842 + case 106:
  2843 +#line 1186 "parser.yxx"
  2844 + { (yyval.setValue) = new vector<int>(1); (*(yyval.setValue))[0] = (yyvsp[(1) - (1)].iValue); ;}
  2845 + break;
  2846 +
  2847 + case 107:
  2848 +#line 1188 "parser.yxx"
  2849 + { (yyval.setValue) = (yyvsp[(1) - (3)].setValue); (yyval.setValue)->push_back((yyvsp[(3) - (3)].iValue)); ;}
  2850 + break;
  2851 +
  2852 + case 108:
  2853 +#line 1192 "parser.yxx"
  2854 + { (yyval.setValue) = new vector<int>(0); ;}
  2855 + break;
  2856 +
  2857 + case 109:
  2858 +#line 1194 "parser.yxx"
  2859 + { (yyval.setValue) = (yyvsp[(1) - (2)].setValue); ;}
  2860 + break;
  2861 +
  2862 + case 110:
  2863 +#line 1198 "parser.yxx"
  2864 + { (yyval.setValue) = new vector<int>(1); (*(yyval.setValue))[0] = (yyvsp[(1) - (1)].iValue); ;}
  2865 + break;
  2866 +
  2867 + case 111:
  2868 +#line 1200 "parser.yxx"
  2869 + { (yyval.setValue) = (yyvsp[(1) - (3)].setValue); (yyval.setValue)->push_back((yyvsp[(3) - (3)].iValue)); ;}
  2870 + break;
  2871 +
  2872 + case 112:
  2873 +#line 1204 "parser.yxx"
  2874 + { (yyval.floatSetValue) = new vector<double>(0); ;}
  2875 + break;
  2876 +
  2877 + case 113:
  2878 +#line 1206 "parser.yxx"
  2879 + { (yyval.floatSetValue) = (yyvsp[(1) - (2)].floatSetValue); ;}
  2880 + break;
  2881 +
  2882 + case 114:
  2883 +#line 1210 "parser.yxx"
  2884 + { (yyval.floatSetValue) = new vector<double>(1); (*(yyval.floatSetValue))[0] = (yyvsp[(1) - (1)].dValue); ;}
  2885 + break;
  2886 +
  2887 + case 115:
  2888 +#line 1212 "parser.yxx"
  2889 + { (yyval.floatSetValue) = (yyvsp[(1) - (3)].floatSetValue); (yyval.floatSetValue)->push_back((yyvsp[(3) - (3)].dValue)); ;}
  2890 + break;
  2891 +
  2892 + case 116:
  2893 +#line 1216 "parser.yxx"
  2894 + { (yyval.setValueList) = new vector<AST::SetLit>(0); ;}
  2895 + break;
  2896 +
  2897 + case 117:
  2898 +#line 1218 "parser.yxx"
  2899 + { (yyval.setValueList) = (yyvsp[(1) - (2)].setValueList); ;}
  2900 + break;
  2901 +
  2902 + case 118:
  2903 +#line 1222 "parser.yxx"
  2904 + { (yyval.setValueList) = new vector<AST::SetLit>(1); (*(yyval.setValueList))[0] = *(yyvsp[(1) - (1)].setLit); delete (yyvsp[(1) - (1)].setLit); ;}
  2905 + break;
  2906 +
  2907 + case 119:
  2908 +#line 1224 "parser.yxx"
  2909 + { (yyval.setValueList) = (yyvsp[(1) - (3)].setValueList); (yyval.setValueList)->push_back(*(yyvsp[(3) - (3)].setLit)); delete (yyvsp[(3) - (3)].setLit); ;}
  2910 + break;
  2911 +
  2912 + case 120:
  2913 +#line 1232 "parser.yxx"
  2914 + { (yyval.argVec) = new AST::Array((yyvsp[(1) - (1)].arg)); ;}
  2915 + break;
  2916 +
  2917 + case 121:
  2918 +#line 1234 "parser.yxx"
  2919 + { (yyval.argVec) = (yyvsp[(1) - (3)].argVec); (yyval.argVec)->append((yyvsp[(3) - (3)].arg)); ;}
  2920 + break;
  2921 +
  2922 + case 122:
  2923 +#line 1238 "parser.yxx"
  2924 + { (yyval.arg) = (yyvsp[(1) - (1)].arg); ;}
  2925 + break;
  2926 +
  2927 + case 123:
  2928 +#line 1240 "parser.yxx"
  2929 + { (yyval.arg) = (yyvsp[(2) - (3)].argVec); ;}
  2930 + break;
  2931 +
  2932 + case 124:
  2933 +#line 1244 "parser.yxx"
  2934 + { (yyval.oArg) = Option<AST::Node*>::none(); ;}
  2935 + break;
  2936 +
  2937 + case 125:
  2938 +#line 1246 "parser.yxx"
  2939 + { (yyval.oArg) = Option<AST::Node*>::some((yyvsp[(2) - (2)].arg)); ;}
  2940 + break;
  2941 +
  2942 + case 126:
  2943 +#line 1250 "parser.yxx"
  2944 + { (yyval.arg) = new AST::BoolLit((yyvsp[(1) - (1)].iValue)); ;}
  2945 + break;
  2946 +
  2947 + case 127:
  2948 +#line 1252 "parser.yxx"
  2949 + { (yyval.arg) = new AST::IntLit((yyvsp[(1) - (1)].iValue)); ;}
  2950 + break;
  2951 +
  2952 + case 128:
  2953 +#line 1254 "parser.yxx"
  2954 + { (yyval.arg) = new AST::FloatLit((yyvsp[(1) - (1)].dValue)); ;}
  2955 + break;
  2956 +
  2957 + case 129:
  2958 +#line 1256 "parser.yxx"
  2959 + { (yyval.arg) = (yyvsp[(1) - (1)].setLit); ;}
  2960 + break;
  2961 +
  2962 + case 130:
  2963 +#line 1258 "parser.yxx"
  2964 + {
  2965 + vector<int> as;
  2966 + ParserState* pp = static_cast<ParserState*>(parm);
  2967 + if (pp->intvararrays.get((yyvsp[(1) - (1)].sValue), as)) {
  2968 + AST::Array *ia = new AST::Array(as.size());
  2969 + for (int i=as.size(); i--;)
  2970 + ia->a[i] = new AST::IntVar(as[i]);
  2971 + (yyval.arg) = ia;
  2972 + } else if (pp->boolvararrays.get((yyvsp[(1) - (1)].sValue), as)) {
  2973 + AST::Array *ia = new AST::Array(as.size());
  2974 + for (int i=as.size(); i--;)
  2975 + ia->a[i] = new AST::BoolVar(as[i]);
  2976 + (yyval.arg) = ia;
  2977 + } else if (pp->setvararrays.get((yyvsp[(1) - (1)].sValue), as)) {
  2978 + AST::Array *ia = new AST::Array(as.size());
  2979 + for (int i=as.size(); i--;)
  2980 + ia->a[i] = new AST::SetVar(as[i]);
  2981 + (yyval.arg) = ia;
  2982 + } else {
  2983 + std::vector<int> is;
  2984 + std::vector<AST::SetLit> isS;
  2985 + int ival = 0;
  2986 + bool bval = false;
  2987 + if (pp->intvalarrays.get((yyvsp[(1) - (1)].sValue), is)) {
  2988 + AST::Array *v = new AST::Array(is.size());
  2989 + for (int i=is.size(); i--;)
  2990 + v->a[i] = new AST::IntLit(is[i]);
  2991 + (yyval.arg) = v;
  2992 + } else if (pp->boolvalarrays.get((yyvsp[(1) - (1)].sValue), is)) {
  2993 + AST::Array *v = new AST::Array(is.size());
  2994 + for (int i=is.size(); i--;)
  2995 + v->a[i] = new AST::BoolLit(is[i]);
  2996 + (yyval.arg) = v;
  2997 + } else if (pp->setvalarrays.get((yyvsp[(1) - (1)].sValue), isS)) {
  2998 + AST::Array *v = new AST::Array(isS.size());
  2999 + for (int i=isS.size(); i--;)
  3000 + v->a[i] = new AST::SetLit(isS[i]);
  3001 + (yyval.arg) = v;
  3002 + } else if (pp->intvals.get((yyvsp[(1) - (1)].sValue), ival)) {
  3003 + (yyval.arg) = new AST::IntLit(ival);
  3004 + } else if (pp->boolvals.get((yyvsp[(1) - (1)].sValue), bval)) {
  3005 + (yyval.arg) = new AST::BoolLit(bval);
  3006 + } else {
  3007 + (yyval.arg) = getVarRefArg(pp,(yyvsp[(1) - (1)].sValue));
  3008 + }
  3009 + }
  3010 + free((yyvsp[(1) - (1)].sValue));
  3011 + ;}
  3012 + break;
  3013 +
  3014 + case 131:
  3015 +#line 1307 "parser.yxx"
  3016 + {
  3017 + ParserState* pp = static_cast<ParserState*>(parm);
  3018 + int i = -1;
  3019 + yyassert(pp, (yyvsp[(3) - (4)].arg)->isInt(i), "Non-integer array index.");
  3020 + if (!pp->hadError)
  3021 + (yyval.arg) = getArrayElement(static_cast<ParserState*>(parm),(yyvsp[(1) - (4)].sValue),i);
  3022 + else
  3023 + (yyval.arg) = new AST::IntLit(0); // keep things consistent
  3024 + free((yyvsp[(1) - (4)].sValue));
  3025 + ;}
  3026 + break;
  3027 +
  3028 + case 132:
  3029 +#line 1320 "parser.yxx"
  3030 + { (yyval.argVec) = new AST::Array(0); ;}
  3031 + break;
  3032 +
  3033 + case 133:
  3034 +#line 1322 "parser.yxx"
  3035 + { (yyval.argVec) = (yyvsp[(1) - (2)].argVec); ;}
  3036 + break;
  3037 +
  3038 + case 134:
  3039 +#line 1326 "parser.yxx"
  3040 + { (yyval.argVec) = new AST::Array((yyvsp[(1) - (1)].arg)); ;}
  3041 + break;
  3042 +
  3043 + case 135:
  3044 +#line 1328 "parser.yxx"
  3045 + { (yyval.argVec) = (yyvsp[(1) - (3)].argVec); (yyval.argVec)->append((yyvsp[(3) - (3)].arg)); ;}
  3046 + break;
  3047 +
  3048 + case 136:
  3049 +#line 1336 "parser.yxx"
  3050 + {
  3051 + ParserState *pp = static_cast<ParserState*>(parm);
  3052 + if (!pp->intvarTable.get((yyvsp[(1) - (1)].sValue), (yyval.iValue))) {
  3053 + pp->err << "Error: unknown integer variable " << (yyvsp[(1) - (1)].sValue)
  3054 + << " in line no. "
  3055 + << yyget_lineno(pp->yyscanner) << std::endl;
  3056 + pp->hadError = true;
  3057 + }
  3058 + free((yyvsp[(1) - (1)].sValue));
  3059 + ;}
  3060 + break;
  3061 +
  3062 + case 137:
  3063 +#line 1347 "parser.yxx"
  3064 + {
  3065 + vector<int> tmp;
  3066 + ParserState *pp = static_cast<ParserState*>(parm);
  3067 + if (!pp->intvararrays.get((yyvsp[(1) - (4)].sValue), tmp)) {
  3068 + pp->err << "Error: unknown integer variable array " << (yyvsp[(1) - (4)].sValue)
  3069 + << " in line no. "
  3070 + << yyget_lineno(pp->yyscanner) << std::endl;
  3071 + pp->hadError = true;
  3072 + }
  3073 + if ((yyvsp[(3) - (4)].iValue) == 0 || static_cast<unsigned int>((yyvsp[(3) - (4)].iValue)) > tmp.size()) {
  3074 + pp->err << "Error: array index out of bounds for array " << (yyvsp[(1) - (4)].sValue)
  3075 + << " in line no. "
  3076 + << yyget_lineno(pp->yyscanner) << std::endl;
  3077 + pp->hadError = true;
  3078 + } else {
  3079 + (yyval.iValue) = tmp[(yyvsp[(3) - (4)].iValue)-1];
  3080 + }
  3081 + free((yyvsp[(1) - (4)].sValue));
  3082 + ;}
  3083 + break;
  3084 +
  3085 + case 140:
  3086 +#line 1377 "parser.yxx"
  3087 + { (yyval.argVec) = NULL; ;}
  3088 + break;
  3089 +
  3090 + case 141:
  3091 +#line 1379 "parser.yxx"
  3092 + { (yyval.argVec) = (yyvsp[(1) - (1)].argVec); ;}
  3093 + break;
  3094 +
  3095 + case 142:
  3096 +#line 1383 "parser.yxx"
  3097 + { (yyval.argVec) = new AST::Array((yyvsp[(2) - (2)].arg)); ;}
  3098 + break;
  3099 +
  3100 + case 143:
  3101 +#line 1385 "parser.yxx"
  3102 + { (yyval.argVec) = (yyvsp[(1) - (3)].argVec); (yyval.argVec)->append((yyvsp[(3) - (3)].arg)); ;}
  3103 + break;
  3104 +
  3105 + case 144:
  3106 +#line 1389 "parser.yxx"
  3107 + {
  3108 + (yyval.arg) = new AST::Call((yyvsp[(1) - (4)].sValue), AST::extractSingleton((yyvsp[(3) - (4)].arg))); free((yyvsp[(1) - (4)].sValue));
  3109 + ;}
  3110 + break;
  3111 +
  3112 + case 145:
  3113 +#line 1393 "parser.yxx"
  3114 + { (yyval.arg) = (yyvsp[(1) - (1)].arg); ;}
  3115 + break;
  3116 +
  3117 + case 146:
  3118 +#line 1397 "parser.yxx"
  3119 + { (yyval.arg) = new AST::Array((yyvsp[(1) - (1)].arg)); ;}
  3120 + break;
  3121 +
  3122 + case 147:
  3123 +#line 1399 "parser.yxx"
  3124 + { (yyval.arg) = (yyvsp[(1) - (3)].arg); (yyval.arg)->append((yyvsp[(3) - (3)].arg)); ;}
  3125 + break;
  3126 +
  3127 + case 148:
  3128 +#line 1403 "parser.yxx"
  3129 + { (yyval.arg) = (yyvsp[(1) - (1)].arg); ;}
  3130 + break;
  3131 +
  3132 + case 149:
  3133 +#line 1405 "parser.yxx"
  3134 + { (yyval.arg) = (yyvsp[(2) - (3)].arg); ;}
  3135 + break;
  3136 +
  3137 + case 150:
  3138 +#line 1409 "parser.yxx"
  3139 + { (yyval.arg) = new AST::BoolLit((yyvsp[(1) - (1)].iValue)); ;}
  3140 + break;
  3141 +
  3142 + case 151:
  3143 +#line 1411 "parser.yxx"
  3144 + { (yyval.arg) = new AST::IntLit((yyvsp[(1) - (1)].iValue)); ;}
  3145 + break;
  3146 +
  3147 + case 152:
  3148 +#line 1413 "parser.yxx"
  3149 + { (yyval.arg) = new AST::FloatLit((yyvsp[(1) - (1)].dValue)); ;}
  3150 + break;
  3151 +
  3152 + case 153:
  3153 +#line 1415 "parser.yxx"
  3154 + { (yyval.arg) = (yyvsp[(1) - (1)].setLit); ;}
  3155 + break;
  3156 +
  3157 + case 154:
  3158 +#line 1417 "parser.yxx"
  3159 + {
  3160 + vector<int> as;
  3161 + ParserState* pp = static_cast<ParserState*>(parm);
  3162 + if (pp->intvararrays.get((yyvsp[(1) - (1)].sValue), as)) {
  3163 + AST::Array *ia = new AST::Array(as.size());
  3164 + for (int i=as.size(); i--;)
  3165 + ia->a[i] = new AST::IntVar(as[i]);
  3166 + (yyval.arg) = ia;
  3167 + } else if (pp->boolvararrays.get((yyvsp[(1) - (1)].sValue), as)) {
  3168 + AST::Array *ia = new AST::Array(as.size());
  3169 + for (int i=as.size(); i--;)
  3170 + ia->a[i] = new AST::BoolVar(as[i]);
  3171 + (yyval.arg) = ia;
  3172 + } else if (pp->setvararrays.get((yyvsp[(1) - (1)].sValue), as)) {
  3173 + AST::Array *ia = new AST::Array(as.size());
  3174 + for (int i=as.size(); i--;)
  3175 + ia->a[i] = new AST::SetVar(as[i]);
  3176 + (yyval.arg) = ia;
  3177 + } else {
  3178 + std::vector<int> is;
  3179 + int ival = 0;
  3180 + bool bval = false;
  3181 + if (pp->intvalarrays.get((yyvsp[(1) - (1)].sValue), is)) {
  3182 + AST::Array *v = new AST::Array(is.size());
  3183 + for (int i=is.size(); i--;)
  3184 + v->a[i] = new AST::IntLit(is[i]);
  3185 + (yyval.arg) = v;
  3186 + } else if (pp->boolvalarrays.get((yyvsp[(1) - (1)].sValue), is)) {
  3187 + AST::Array *v = new AST::Array(is.size());
  3188 + for (int i=is.size(); i--;)
  3189 + v->a[i] = new AST::BoolLit(is[i]);
  3190 + (yyval.arg) = v;
  3191 + } else if (pp->intvals.get((yyvsp[(1) - (1)].sValue), ival)) {
  3192 + (yyval.arg) = new AST::IntLit(ival);
  3193 + } else if (pp->boolvals.get((yyvsp[(1) - (1)].sValue), bval)) {
  3194 + (yyval.arg) = new AST::BoolLit(bval);
  3195 + } else {
  3196 + (yyval.arg) = getVarRefArg(pp,(yyvsp[(1) - (1)].sValue),true);
  3197 + }
  3198 + }
  3199 + free((yyvsp[(1) - (1)].sValue));
  3200 + ;}
  3201 + break;
  3202 +
  3203 + case 155:
  3204 +#line 1460 "parser.yxx"
  3205 + {
  3206 + ParserState* pp = static_cast<ParserState*>(parm);
  3207 + int i = -1;
  3208 + yyassert(pp, (yyvsp[(3) - (4)].arg)->isInt(i), "Non-integer array index.");
  3209 + if (!pp->hadError)
  3210 + (yyval.arg) = getArrayElement(static_cast<ParserState*>(parm),(yyvsp[(1) - (4)].sValue),i);
  3211 + else
  3212 + (yyval.arg) = new AST::IntLit(0); // keep things consistent
  3213 + free((yyvsp[(1) - (4)].sValue));
  3214 + ;}
  3215 + break;
  3216 +
  3217 + case 156:
  3218 +#line 1471 "parser.yxx"
  3219 + {
  3220 + (yyval.arg) = new AST::String((yyvsp[(1) - (1)].sValue));
  3221 + free((yyvsp[(1) - (1)].sValue));
  3222 + ;}
  3223 + break;
  3224 +
  3225 +
  3226 +/* Line 1267 of yacc.c. */
  3227 +#line 3228 "parser.tab.cpp"
  3228 + default: break;
  3229 + }
  3230 + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
  3231 +
  3232 + YYPOPSTACK (yylen);
  3233 + yylen = 0;
  3234 + YY_STACK_PRINT (yyss, yyssp);
  3235 +
  3236 + *++yyvsp = yyval;
  3237 +
  3238 +
  3239 + /* Now `shift' the result of the reduction. Determine what state
  3240 + that goes to, based on the state we popped back to and the rule
  3241 + number reduced by. */
  3242 +
  3243 + yyn = yyr1[yyn];
  3244 +
  3245 + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  3246 + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  3247 + yystate = yytable[yystate];
  3248 + else
  3249 + yystate = yydefgoto[yyn - YYNTOKENS];
  3250 +
  3251 + goto yynewstate;
  3252 +
  3253 +
  3254 +/*------------------------------------.
  3255 +| yyerrlab -- here on detecting error |
  3256 +`------------------------------------*/
  3257 +yyerrlab:
  3258 + /* If not already recovering from an error, report this error. */
  3259 + if (!yyerrstatus)
  3260 + {
  3261 + ++yynerrs;
  3262 +#if ! YYERROR_VERBOSE
  3263 + yyerror (parm, YY_("syntax error"));
  3264 +#else
  3265 + {
  3266 + YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
  3267 + if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
  3268 + {
  3269 + YYSIZE_T yyalloc = 2 * yysize;
  3270 + if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
  3271 + yyalloc = YYSTACK_ALLOC_MAXIMUM;
  3272 + if (yymsg != yymsgbuf)
  3273 + YYSTACK_FREE (yymsg);
  3274 + yymsg = (char *) YYSTACK_ALLOC (yyalloc);
  3275 + if (yymsg)
  3276 + yymsg_alloc = yyalloc;
  3277 + else
  3278 + {
  3279 + yymsg = yymsgbuf;
  3280 + yymsg_alloc = sizeof yymsgbuf;
  3281 + }
  3282 + }
  3283 +
  3284 + if (0 < yysize && yysize <= yymsg_alloc)
  3285 + {
  3286 + (void) yysyntax_error (yymsg, yystate, yychar);
  3287 + yyerror (parm, yymsg);
  3288 + }
  3289 + else
  3290 + {
  3291 + yyerror (parm, YY_("syntax error"));
  3292 + if (yysize != 0)
  3293 + goto yyexhaustedlab;
  3294 + }
  3295 + }
  3296 +#endif
  3297 + }
  3298 +
  3299 +
  3300 +
  3301 + if (yyerrstatus == 3)
  3302 + {
  3303 + /* If just tried and failed to reuse look-ahead token after an
  3304 + error, discard it. */
  3305 +
  3306 + if (yychar <= YYEOF)
  3307 + {
  3308 + /* Return failure if at end of input. */
  3309 + if (yychar == YYEOF)
  3310 + YYABORT;
  3311 + }
  3312 + else
  3313 + {
  3314 + yydestruct ("Error: discarding",
  3315 + yytoken, &yylval, parm);
  3316 + yychar = YYEMPTY;
  3317 + }
  3318 + }
  3319 +
  3320 + /* Else will try to reuse look-ahead token after shifting the error
  3321 + token. */
  3322 + goto yyerrlab1;
  3323 +
  3324 +
  3325 +/*---------------------------------------------------.
  3326 +| yyerrorlab -- error raised explicitly by YYERROR. |
  3327 +`---------------------------------------------------*/
  3328 +yyerrorlab:
  3329 +
  3330 + /* Pacify compilers like GCC when the user code never invokes
  3331 + YYERROR and the label yyerrorlab therefore never appears in user
  3332 + code. */
  3333 + if (/*CONSTCOND*/ 0)
  3334 + goto yyerrorlab;
  3335 +
  3336 + /* Do not reclaim the symbols of the rule which action triggered
  3337 + this YYERROR. */
  3338 + YYPOPSTACK (yylen);
  3339 + yylen = 0;
  3340 + YY_STACK_PRINT (yyss, yyssp);
  3341 + yystate = *yyssp;
  3342 + goto yyerrlab1;
  3343 +
  3344 +
  3345 +/*-------------------------------------------------------------.
  3346 +| yyerrlab1 -- common code for both syntax error and YYERROR. |
  3347 +`-------------------------------------------------------------*/
  3348 +yyerrlab1:
  3349 + yyerrstatus = 3; /* Each real token shifted decrements this. */
  3350 +
  3351 + for (;;)
  3352 + {
  3353 + yyn = yypact[yystate];
  3354 + if (yyn != YYPACT_NINF)
  3355 + {
  3356 + yyn += YYTERROR;
  3357 + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  3358 + {
  3359 + yyn = yytable[yyn];
  3360 + if (0 < yyn)
  3361 + break;
  3362 + }
  3363 + }
  3364 +
  3365 + /* Pop the current state because it cannot handle the error token. */
  3366 + if (yyssp == yyss)
  3367 + YYABORT;
  3368 +
  3369 +
  3370 + yydestruct ("Error: popping",
  3371 + yystos[yystate], yyvsp, parm);
  3372 + YYPOPSTACK (1);
  3373 + yystate = *yyssp;
  3374 + YY_STACK_PRINT (yyss, yyssp);
  3375 + }
  3376 +
  3377 + if (yyn == YYFINAL)
  3378 + YYACCEPT;
  3379 +
  3380 + *++yyvsp = yylval;
  3381 +
  3382 +
  3383 + /* Shift the error token. */
  3384 + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
  3385 +
  3386 + yystate = yyn;
  3387 + goto yynewstate;
  3388 +
  3389 +
  3390 +/*-------------------------------------.
  3391 +| yyacceptlab -- YYACCEPT comes here. |
  3392 +`-------------------------------------*/
  3393 +yyacceptlab:
  3394 + yyresult = 0;
  3395 + goto yyreturn;
  3396 +
  3397 +/*-----------------------------------.
  3398 +| yyabortlab -- YYABORT comes here. |
  3399 +`-----------------------------------*/
  3400 +yyabortlab:
  3401 + yyresult = 1;
  3402 + goto yyreturn;
  3403 +
  3404 +#ifndef yyoverflow
  3405 +/*-------------------------------------------------.
  3406 +| yyexhaustedlab -- memory exhaustion comes here. |
  3407 +`-------------------------------------------------*/
  3408 +yyexhaustedlab:
  3409 + yyerror (parm, YY_("memory exhausted"));
  3410 + yyresult = 2;
  3411 + /* Fall through. */
  3412 +#endif
  3413 +
  3414 +yyreturn:
  3415 + if (yychar != YYEOF && yychar != YYEMPTY)
  3416 + yydestruct ("Cleanup: discarding lookahead",
  3417 + yytoken, &yylval, parm);
  3418 + /* Do not reclaim the symbols of the rule which action triggered
  3419 + this YYABORT or YYACCEPT. */
  3420 + YYPOPSTACK (yylen);
  3421 + YY_STACK_PRINT (yyss, yyssp);
  3422 + while (yyssp != yyss)
  3423 + {
  3424 + yydestruct ("Cleanup: popping",
  3425 + yystos[*yyssp], yyvsp, parm);
  3426 + YYPOPSTACK (1);
  3427 + }
  3428 +#ifndef yyoverflow
  3429 + if (yyss != yyssa)
  3430 + YYSTACK_FREE (yyss);
  3431 +#endif
  3432 +#if YYERROR_VERBOSE
  3433 + if (yymsg != yymsgbuf)
  3434 + YYSTACK_FREE (yymsg);
  3435 +#endif
  3436 + /* Make sure YYID is used. */
  3437 + return YYID (yyresult);
  3438 +}
  3439 +
  3440 +
  3441 +
... ...
fz/parser.tab.hh 0 → 100644
... ... @@ -0,0 +1,164 @@
  1 +/* A Bison parser, made by GNU Bison 2.3. */
  2 +
  3 +/* Skeleton interface for Bison's Yacc-like parsers in C
  4 +
  5 + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
  6 + Free Software Foundation, Inc.
  7 +
  8 + This program is free software; you can redistribute it and/or modify
  9 + it under the terms of the GNU General Public License as published by
  10 + the Free Software Foundation; either version 2, or (at your option)
  11 + any later version.
  12 +
  13 + This program is distributed in the hope that it will be useful,
  14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + GNU General Public License for more details.
  17 +
  18 + You should have received a copy of the GNU General Public License
  19 + along with this program; if not, write to the Free Software
  20 + Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21 + Boston, MA 02110-1301, USA. */
  22 +
  23 +/* As a special exception, you may create a larger work that contains
  24 + part or all of the Bison parser skeleton and distribute that work
  25 + under terms of your choice, so long as that work isn't itself a
  26 + parser generator using the skeleton or a modified version thereof
  27 + as a parser skeleton. Alternatively, if you modify or redistribute
  28 + the parser skeleton itself, you may (at your option) remove this
  29 + special exception, which will cause the skeleton and the resulting
  30 + Bison output files to be licensed under the GNU General Public
  31 + License without this special exception.
  32 +
  33 + This special exception was added by the Free Software Foundation in
  34 + version 2.2 of Bison. */
  35 +
  36 +/* Tokens. */
  37 +#ifndef YYTOKENTYPE
  38 +# define YYTOKENTYPE
  39 + /* Put the tokens into the symbol table, so that GDB and other debuggers
  40 + know about them. */
  41 + enum yytokentype {
  42 + FZ_INT_LIT = 258,
  43 + FZ_BOOL_LIT = 259,
  44 + FZ_FLOAT_LIT = 260,
  45 + FZ_ID = 261,
  46 + FZ_U_ID = 262,
  47 + FZ_STRING_LIT = 263,
  48 + FZ_VAR = 264,
  49 + FZ_PAR = 265,
  50 + FZ_ANNOTATION = 266,
  51 + FZ_ANY = 267,
  52 + FZ_ARRAY = 268,
  53 + FZ_BOOL = 269,
  54 + FZ_CASE = 270,
  55 + FZ_COLONCOLON = 271,
  56 + FZ_CONSTRAINT = 272,
  57 + FZ_DEFAULT = 273,
  58 + FZ_DOTDOT = 274,
  59 + FZ_ELSE = 275,
  60 + FZ_ELSEIF = 276,
  61 + FZ_ENDIF = 277,
  62 + FZ_ENUM = 278,
  63 + FZ_FLOAT = 279,
  64 + FZ_FUNCTION = 280,
  65 + FZ_IF = 281,
  66 + FZ_INCLUDE = 282,
  67 + FZ_INT = 283,
  68 + FZ_LET = 284,
  69 + FZ_MAXIMIZE = 285,
  70 + FZ_MINIMIZE = 286,
  71 + FZ_OF = 287,
  72 + FZ_SATISFY = 288,
  73 + FZ_OUTPUT = 289,
  74 + FZ_PREDICATE = 290,
  75 + FZ_RECORD = 291,
  76 + FZ_SET = 292,
  77 + FZ_SHOW = 293,
  78 + FZ_SHOWCOND = 294,
  79 + FZ_SOLVE = 295,
  80 + FZ_STRING = 296,
  81 + FZ_TEST = 297,
  82 + FZ_THEN = 298,
  83 + FZ_TUPLE = 299,
  84 + FZ_TYPE = 300,
  85 + FZ_VARIANT_RECORD = 301,
  86 + FZ_WHERE = 302
  87 + };
  88 +#endif
  89 +/* Tokens. */
  90 +#define FZ_INT_LIT 258
  91 +#define FZ_BOOL_LIT 259
  92 +#define FZ_FLOAT_LIT 260
  93 +#define FZ_ID 261
  94 +#define FZ_U_ID 262
  95 +#define FZ_STRING_LIT 263
  96 +#define FZ_VAR 264
  97 +#define FZ_PAR 265
  98 +#define FZ_ANNOTATION 266
  99 +#define FZ_ANY 267
  100 +#define FZ_ARRAY 268
  101 +#define FZ_BOOL 269
  102 +#define FZ_CASE 270
  103 +#define FZ_COLONCOLON 271
  104 +#define FZ_CONSTRAINT 272
  105 +#define FZ_DEFAULT 273
  106 +#define FZ_DOTDOT 274
  107 +#define FZ_ELSE 275
  108 +#define FZ_ELSEIF 276
  109 +#define FZ_ENDIF 277
  110 +#define FZ_ENUM 278
  111 +#define FZ_FLOAT 279
  112 +#define FZ_FUNCTION 280
  113 +#define FZ_IF 281
  114 +#define FZ_INCLUDE 282
  115 +#define FZ_INT 283
  116 +#define FZ_LET 284
  117 +#define FZ_MAXIMIZE 285
  118 +#define FZ_MINIMIZE 286
  119 +#define FZ_OF 287
  120 +#define FZ_SATISFY 288
  121 +#define FZ_OUTPUT 289
  122 +#define FZ_PREDICATE 290
  123 +#define FZ_RECORD 291
  124 +#define FZ_SET 292
  125 +#define FZ_SHOW 293
  126 +#define FZ_SHOWCOND 294
  127 +#define FZ_SOLVE 295
  128 +#define FZ_STRING 296
  129 +#define FZ_TEST 297
  130 +#define FZ_THEN 298
  131 +#define FZ_TUPLE 299
  132 +#define FZ_TYPE 300
  133 +#define FZ_VARIANT_RECORD 301
  134 +#define FZ_WHERE 302
  135 +
  136 +
  137 +
  138 +
  139 +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  140 +typedef union YYSTYPE
  141 +#line 330 "parser.yxx"
  142 +{ int iValue; char* sValue; bool bValue; double dValue;
  143 + std::vector<int>* setValue;
  144 + FlatZinc::AST::SetLit* setLit;
  145 + std::vector<double>* floatSetValue;
  146 + std::vector<FlatZinc::AST::SetLit>* setValueList;
  147 + FlatZinc::Option<FlatZinc::AST::SetLit* > oSet;
  148 + FlatZinc::VarSpec* varSpec;
  149 + FlatZinc::Option<FlatZinc::AST::Node*> oArg;
  150 + std::vector<FlatZinc::VarSpec*>* varSpecVec;
  151 + FlatZinc::Option<std::vector<FlatZinc::VarSpec*>* > oVarSpecVec;
  152 + FlatZinc::AST::Node* arg;
  153 + FlatZinc::AST::Array* argVec;
  154 + }
  155 +/* Line 1529 of yacc.c. */
  156 +#line 157 "parser.tab.hpp"
  157 + YYSTYPE;
  158 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */
  159 +# define YYSTYPE_IS_DECLARED 1
  160 +# define YYSTYPE_IS_TRIVIAL 1
  161 +#endif
  162 +
  163 +
  164 +
... ...
fz/parser.yxx 0 → 100644
... ... @@ -0,0 +1,1474 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2006-12-11 03:27:31 +1100 (Mon, 11 Dec 2006) $ by $Author: schulte $
  11 + * $Revision: 4024 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +%pure-parser
  39 +%parse-param {void *parm}
  40 +%{
  41 +#define YYPARSE_PARAM parm
  42 +#define YYLEX_PARAM static_cast<ParserState*>(parm)->yyscanner
  43 +#include "flatzinc.hh"
  44 +#include "parser.hh"
  45 +#include <iostream>
  46 +#include <fstream>
  47 +#include <sstream>
  48 +
  49 +#include <stdio.h>
  50 +#include <stdlib.h>
  51 +#include <fcntl.h>
  52 +#include <unistd.h>
  53 +#include <sys/types.h>
  54 +#include <sys/mman.h>
  55 +#include <sys/stat.h>
  56 +
  57 +using namespace std;
  58 +
  59 +int yyparse(void*);
  60 +int yylex(YYSTYPE*, void* scanner);
  61 +int yylex_init (void** scanner);
  62 +int yylex_destroy (void* scanner);
  63 +int yyget_lineno (void* scanner);
  64 +void yyset_extra (void* user_defined ,void* yyscanner );
  65 +
  66 +extern int yydebug;
  67 +
  68 +using namespace FlatZinc;
  69 +
  70 +void yyerror(void* parm, const char *str) {
  71 + ParserState* pp = static_cast<ParserState*>(parm);
  72 + pp->err << "Error: " << str
  73 + << " in line no. " << yyget_lineno(pp->yyscanner)
  74 + << std::endl;
  75 + pp->hadError = true;
  76 +}
  77 +
  78 +void yyassert(ParserState* pp, bool cond, const char* str)
  79 +{
  80 + if (!cond) {
  81 + pp->err << "Error: " << str
  82 + << " in line no. " << yyget_lineno(pp->yyscanner)
  83 + << std::endl;
  84 + pp->hadError = true;
  85 + }
  86 +}
  87 +
  88 +/*
  89 + * The symbol tables
  90 + *
  91 + */
  92 +
  93 +AST::Node* getArrayElement(ParserState* pp, string id, unsigned int offset) {
  94 + if (offset > 0) {
  95 + vector<int> tmp;
  96 + if (pp->intvararrays.get(id, tmp) && offset<=tmp.size())
  97 + return new AST::IntVar(tmp[offset-1]);
  98 + if (pp->boolvararrays.get(id, tmp) && offset<=tmp.size())
  99 + return new AST::BoolVar(tmp[offset-1]);
  100 + if (pp->setvararrays.get(id, tmp) && offset<=tmp.size())
  101 + return new AST::SetVar(tmp[offset-1]);
  102 +
  103 + if (pp->intvalarrays.get(id, tmp) && offset<=tmp.size())
  104 + return new AST::IntLit(tmp[offset-1]);
  105 + if (pp->boolvalarrays.get(id, tmp) && offset<=tmp.size())
  106 + return new AST::BoolLit(tmp[offset-1]);
  107 + vector<AST::SetLit> tmpS;
  108 + if (pp->setvalarrays.get(id, tmpS) && offset<=tmpS.size())
  109 + return new AST::SetLit(tmpS[offset-1]);
  110 + }
  111 +
  112 + pp->err << "Error: array access to " << id << " invalid"
  113 + << " in line no. "
  114 + << yyget_lineno(pp->yyscanner) << std::endl;
  115 + pp->hadError = true;
  116 + return new AST::IntVar(0); // keep things consistent
  117 +}
  118 +AST::Node* getVarRefArg(ParserState* pp, string id, bool annotation = false) {
  119 + int tmp;
  120 + if (pp->intvarTable.get(id, tmp))
  121 + return new AST::IntVar(tmp);
  122 + if (pp->boolvarTable.get(id, tmp))
  123 + return new AST::BoolVar(tmp);
  124 + if (pp->setvarTable.get(id, tmp))
  125 + return new AST::SetVar(tmp);
  126 + if (annotation)
  127 + return new AST::Atom(id);
  128 + pp->err << "Error: undefined variable " << id
  129 + << " in line no. "
  130 + << yyget_lineno(pp->yyscanner) << std::endl;
  131 + pp->hadError = true;
  132 + return new AST::IntVar(0); // keep things consistent
  133 +}
  134 +
  135 +void addDomainConstraint(ParserState* pp, std::string id, AST::Node* var,
  136 + Option<AST::SetLit* >& dom) {
  137 + if (!dom())
  138 + return;
  139 + AST::Array* args = new AST::Array(2);
  140 + args->a[0] = var;
  141 + args->a[1] = dom.some();
  142 + pp->domainConstraints.push_back(new ConExpr(id, args));
  143 +}
  144 +
  145 +/*
  146 + * Initialize the root gecode space
  147 + *
  148 + */
  149 +
  150 +void initfg(ParserState* pp) {
  151 + if (!pp->hadError)
  152 + pp->fg->init(pp->intvars.size(),
  153 + pp->boolvars.size(),
  154 + pp->setvars.size());
  155 +
  156 + for (unsigned int i=0; i<pp->intvars.size(); i++) {
  157 + if (!pp->hadError) {
  158 + try {
  159 + pp->fg->newIntVar(static_cast<IntVarSpec*>(pp->intvars[i].second));
  160 + } catch (FlatZinc::Error& e) {
  161 + yyerror(pp, e.toString().c_str());
  162 + }
  163 + }
  164 + if (pp->intvars[i].first[0] != '[') {
  165 + delete pp->intvars[i].second;
  166 + pp->intvars[i].second = NULL;
  167 + }
  168 + }
  169 + for (unsigned int i=0; i<pp->boolvars.size(); i++) {
  170 + if (!pp->hadError) {
  171 + try {
  172 + pp->fg->newBoolVar(
  173 + static_cast<BoolVarSpec*>(pp->boolvars[i].second));
  174 + } catch (FlatZinc::Error& e) {
  175 + yyerror(pp, e.toString().c_str());
  176 + }
  177 + }
  178 + if (pp->boolvars[i].first[0] != '[') {
  179 + delete pp->boolvars[i].second;
  180 + pp->boolvars[i].second = NULL;
  181 + }
  182 + }
  183 + for (unsigned int i=0; i<pp->setvars.size(); i++) {
  184 + if (!pp->hadError) {
  185 + try {
  186 + pp->fg->newSetVar(static_cast<SetVarSpec*>(pp->setvars[i].second));
  187 + } catch (FlatZinc::Error& e) {
  188 + yyerror(pp, e.toString().c_str());
  189 + }
  190 + }
  191 + if (pp->setvars[i].first[0] != '[') {
  192 + delete pp->setvars[i].second;
  193 + pp->setvars[i].second = NULL;
  194 + }
  195 + }
  196 + for (unsigned int i=pp->domainConstraints.size(); i--;) {
  197 + if (!pp->hadError) {
  198 + try {
  199 + assert(pp->domainConstraints[i]->args->a.size() == 2);
  200 + pp->fg->postConstraint(*pp->domainConstraints[i], NULL);
  201 + delete pp->domainConstraints[i];
  202 + } catch (FlatZinc::Error& e) {
  203 + yyerror(pp, e.toString().c_str());
  204 + }
  205 + }
  206 + }
  207 +}
  208 +
  209 +void fillPrinter(ParserState& pp, FlatZinc::Printer& p) {
  210 + p.init(pp.getOutput());
  211 +}
  212 +
  213 +AST::Node* arrayOutput(AST::Call* ann) {
  214 + AST::Array* a = NULL;
  215 +
  216 + if (ann->args->isArray()) {
  217 + a = ann->args->getArray();
  218 + } else {
  219 + a = new AST::Array(ann->args);
  220 + }
  221 +
  222 + std::ostringstream oss;
  223 +
  224 + oss << "array" << a->a.size() << "d(";
  225 + for (unsigned int i=0; i<a->a.size(); i++) {
  226 + AST::SetLit* s = a->a[i]->getSet();
  227 + if (s->empty())
  228 + oss << "{}, ";
  229 + else if (s->interval)
  230 + oss << s->min << ".." << s->max << ", ";
  231 + else {
  232 + oss << "{";
  233 + for (unsigned int j=0; j<s->s.size(); j++) {
  234 + oss << s->s[j];
  235 + if (j<s->s.size()-1)
  236 + oss << ",";
  237 + }
  238 + oss << "}, ";
  239 + }
  240 + }
  241 +
  242 + if (!ann->args->isArray()) {
  243 + a->a[0] = NULL;
  244 + delete a;
  245 + }
  246 + return new AST::String(oss.str());
  247 +}
  248 +
  249 +/*
  250 + * The main program
  251 + *
  252 + */
  253 +
  254 +namespace FlatZinc {
  255 +
  256 + FlatZincModel* parse(const std::string& filename, Printer& p, std::ostream& err,
  257 + FlatZincModel* fzs) {
  258 +#ifdef HAVE_MMAP
  259 + int fd;
  260 + char* data;
  261 + struct stat sbuf;
  262 + fd = open(filename.c_str(), O_RDONLY);
  263 + if (fd == -1) {
  264 + err << "Cannot open file " << filename << endl;
  265 + return NULL;
  266 + }
  267 + if (stat(filename.c_str(), &sbuf) == -1) {
  268 + err << "Cannot stat file " << filename << endl;
  269 + return NULL;
  270 + }
  271 + data = (char*)mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_SHARED, fd,0);
  272 + if (data == (caddr_t)(-1)) {
  273 + err << "Cannot mmap file " << filename << endl;
  274 + return NULL;
  275 + }
  276 +
  277 + if (fzs == NULL) {
  278 + fzs = new FlatZincModel();
  279 + }
  280 + ParserState pp(data, sbuf.st_size, err, fzs);
  281 +#else
  282 + std::ifstream file;
  283 + file.open(filename.c_str());
  284 + if (!file.is_open()) {
  285 + err << "Cannot open file " << filename << endl;
  286 + return NULL;
  287 + }
  288 + std::string s = string(istreambuf_iterator<char>(file),
  289 + istreambuf_iterator<char>());
  290 + if (fzs == NULL) {
  291 + fzs = new FlatZincModel();
  292 + }
  293 + ParserState pp(s, err, fzs);
  294 +#endif
  295 + yylex_init(&pp.yyscanner);
  296 + yyset_extra(&pp, pp.yyscanner);
  297 + // yydebug = 1;
  298 + yyparse(&pp);
  299 + fillPrinter(pp, p);
  300 +
  301 + if (pp.yyscanner)
  302 + yylex_destroy(pp.yyscanner);
  303 + return pp.hadError ? NULL : pp.fg;
  304 + }
  305 +
  306 + FlatZincModel* parse(std::istream& is, Printer& p, std::ostream& err,
  307 + FlatZincModel* fzs) {
  308 + std::string s = string(istreambuf_iterator<char>(is),
  309 + istreambuf_iterator<char>());
  310 +
  311 + if (fzs == NULL) {
  312 + fzs = new FlatZincModel();
  313 + }
  314 + ParserState pp(s, err, fzs);
  315 + yylex_init(&pp.yyscanner);
  316 + yyset_extra(&pp, pp.yyscanner);
  317 + // yydebug = 1;
  318 + yyparse(&pp);
  319 + fillPrinter(pp, p);
  320 +
  321 + if (pp.yyscanner)
  322 + yylex_destroy(pp.yyscanner);
  323 + return pp.hadError ? NULL : pp.fg;
  324 + }
  325 +
  326 +}
  327 +
  328 +%}
  329 +
  330 +%union { int iValue; char* sValue; bool bValue; double dValue;
  331 + std::vector<int>* setValue;
  332 + FlatZinc::AST::SetLit* setLit;
  333 + std::vector<double>* floatSetValue;
  334 + std::vector<FlatZinc::AST::SetLit>* setValueList;
  335 + FlatZinc::Option<FlatZinc::AST::SetLit* > oSet;
  336 + FlatZinc::VarSpec* varSpec;
  337 + FlatZinc::Option<FlatZinc::AST::Node*> oArg;
  338 + std::vector<FlatZinc::VarSpec*>* varSpecVec;
  339 + FlatZinc::Option<std::vector<FlatZinc::VarSpec*>* > oVarSpecVec;
  340 + FlatZinc::AST::Node* arg;
  341 + FlatZinc::AST::Array* argVec;
  342 + }
  343 +
  344 +%error-verbose
  345 +
  346 +%token <iValue> FZ_INT_LIT FZ_BOOL_LIT
  347 +%token <dValue> FZ_FLOAT_LIT
  348 +%token <sValue> FZ_ID FZ_U_ID FZ_STRING_LIT
  349 +
  350 +%token <bValue> FZ_VAR FZ_PAR
  351 +
  352 +%token FZ_ANNOTATION
  353 +%token FZ_ANY
  354 +%token FZ_ARRAY
  355 +%token FZ_BOOL
  356 +%token FZ_CASE
  357 +%token FZ_COLONCOLON
  358 +%token FZ_CONSTRAINT
  359 +%token FZ_DEFAULT
  360 +%token FZ_DOTDOT
  361 +%token FZ_ELSE
  362 +%token FZ_ELSEIF
  363 +%token FZ_ENDIF
  364 +%token FZ_ENUM
  365 +%token FZ_FLOAT
  366 +%token FZ_FUNCTION
  367 +%token FZ_IF
  368 +%token FZ_INCLUDE
  369 +%token FZ_INT
  370 +%token FZ_LET
  371 +%token <bValue> FZ_MAXIMIZE
  372 +%token <bValue> FZ_MINIMIZE
  373 +%token FZ_OF
  374 +%token FZ_SATISFY
  375 +%token FZ_OUTPUT
  376 +%token FZ_PREDICATE
  377 +%token FZ_RECORD
  378 +%token FZ_SET
  379 +%token FZ_SHOW
  380 +%token FZ_SHOWCOND
  381 +%token FZ_SOLVE
  382 +%token FZ_STRING
  383 +%token FZ_TEST
  384 +%token FZ_THEN
  385 +%token FZ_TUPLE
  386 +%token FZ_TYPE
  387 +%token FZ_VARIANT_RECORD
  388 +%token FZ_WHERE
  389 +
  390 +%type <sValue> var_par_id
  391 +%type <setLit> set_literal
  392 +
  393 +%type <varSpec> int_init bool_init set_init float_init
  394 +%type <oSet> int_ti_expr_tail bool_ti_expr_tail
  395 +
  396 +%type <oVarSpecVec> vardecl_int_var_array_init
  397 +%type <oVarSpecVec> vardecl_bool_var_array_init
  398 +%type <oVarSpecVec> vardecl_float_var_array_init
  399 +%type <oVarSpecVec> vardecl_set_var_array_init
  400 +%type <varSpecVec> int_var_array_literal
  401 +%type <varSpecVec> bool_var_array_literal
  402 +%type <varSpecVec> float_var_array_literal
  403 +%type <varSpecVec> set_var_array_literal
  404 +%type <varSpecVec> int_init_list int_init_list_head
  405 +%type <varSpecVec> bool_init_list bool_init_list_head
  406 +%type <varSpecVec> float_init_list float_init_list_head
  407 +%type <varSpecVec> set_init_list set_init_list_head
  408 +
  409 +%type <setValue> int_list int_list_head
  410 +%type <setValue> bool_list bool_list_head
  411 +%type <setValueList> set_literal_list set_literal_list_head
  412 +%type <floatSetValue> float_list float_list_head
  413 +
  414 +%type <arg> flat_expr non_array_expr annotation_expr ann_non_array_expr
  415 +%type <oArg> non_array_expr_opt
  416 +%type <argVec> flat_expr_list non_array_expr_list non_array_expr_list_head
  417 +
  418 +%type <iValue> solve_expr
  419 +%type <bValue> minmax
  420 +
  421 +%type <argVec> annotations annotations_head
  422 +%type <arg> annotation annotation_list
  423 +
  424 +%%
  425 +
  426 +/********************************/
  427 +/* main goal and item lists */
  428 +/********************************/
  429 +
  430 +model : preddecl_items vardecl_items constraint_items solve_item ';'
  431 +
  432 +preddecl_items:
  433 + /* empty */
  434 + | preddecl_items_head
  435 +
  436 +preddecl_items_head:
  437 + preddecl_item ';'
  438 + | preddecl_items_head preddecl_item ';'
  439 +
  440 +vardecl_items:
  441 + /* emtpy */
  442 + { initfg(static_cast<ParserState*>(parm)); }
  443 + | vardecl_items_head
  444 + { initfg(static_cast<ParserState*>(parm)); }
  445 +
  446 +vardecl_items_head:
  447 + vardecl_item ';'
  448 + | vardecl_items_head vardecl_item ';'
  449 +
  450 +constraint_items:
  451 + /* emtpy */
  452 + | constraint_items_head
  453 +
  454 +constraint_items_head:
  455 + constraint_item ';'
  456 + | constraint_items_head constraint_item ';'
  457 +
  458 +/********************************/
  459 +/* predicate declarations */
  460 +/********************************/
  461 +
  462 +preddecl_item:
  463 + FZ_PREDICATE FZ_ID '(' pred_arg_list ')'
  464 +
  465 +pred_arg_list:
  466 + /* empty */
  467 + | pred_arg_list_head list_tail
  468 +
  469 +pred_arg_list_head:
  470 + pred_arg
  471 + | pred_arg_list_head ',' pred_arg
  472 +
  473 +pred_arg:
  474 + pred_arg_type ':' FZ_ID
  475 +
  476 +pred_arg_type:
  477 + FZ_ARRAY '[' pred_array_init ']' FZ_OF pred_arg_simple_type
  478 + | FZ_ARRAY '[' pred_array_init ']' FZ_OF FZ_VAR pred_arg_simple_type
  479 + | FZ_VAR pred_arg_simple_type
  480 + | pred_arg_simple_type
  481 +
  482 +pred_arg_simple_type:
  483 + int_ti_expr_tail
  484 + | FZ_SET FZ_OF int_ti_expr_tail
  485 + | FZ_BOOL
  486 + | FZ_FLOAT
  487 +
  488 +pred_array_init:
  489 + pred_array_init_arg
  490 + | pred_array_init ',' pred_array_init_arg
  491 +
  492 +pred_array_init_arg:
  493 + FZ_INT
  494 + | FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT
  495 +
  496 +/********************************/
  497 +/* variable declarations */
  498 +/********************************/
  499 +
  500 +var_par_id : FZ_ID | FZ_U_ID
  501 +
  502 +vardecl_item:
  503 + FZ_VAR int_ti_expr_tail ':' var_par_id annotations non_array_expr_opt
  504 + {
  505 + ParserState* pp = static_cast<ParserState*>(parm);
  506 + bool print = $5->hasAtom("output_var");
  507 + bool introduced = $5->hasAtom("var_is_introduced");
  508 + pp->intvarTable.put($4, pp->intvars.size());
  509 + if (print) {
  510 + pp->output(std::string($4), new AST::IntVar(pp->intvars.size()));
  511 + }
  512 + if ($6()) {
  513 + AST::Node* arg = $6.some();
  514 + if (arg->isInt()) {
  515 + pp->intvars.push_back(varspec($4,
  516 + new IntVarSpec(arg->getInt(),introduced)));
  517 + } else if (arg->isIntVar()) {
  518 + pp->intvars.push_back(varspec($4,
  519 + new IntVarSpec(Alias(arg->getIntVar()),introduced)));
  520 + } else {
  521 + yyassert(pp, false, "Invalid var int initializer.");
  522 + }
  523 + if (!pp->hadError)
  524 + addDomainConstraint(pp, "int_in",
  525 + new AST::IntVar(pp->intvars.size()-1), $2);
  526 + delete arg;
  527 + } else {
  528 + pp->intvars.push_back(varspec($4, new IntVarSpec($2,introduced)));
  529 + }
  530 + delete $5; free($4);
  531 + }
  532 + | FZ_VAR bool_ti_expr_tail ':' var_par_id annotations non_array_expr_opt
  533 + {
  534 + ParserState* pp = static_cast<ParserState*>(parm);
  535 + bool print = $5->hasAtom("output_var");
  536 + bool introduced = $5->hasAtom("var_is_introduced");
  537 + pp->boolvarTable.put($4, pp->boolvars.size());
  538 + if (print) {
  539 + pp->output(std::string($4), new AST::BoolVar(pp->boolvars.size()));
  540 + }
  541 + if ($6()) {
  542 + AST::Node* arg = $6.some();
  543 + if (arg->isBool()) {
  544 + pp->boolvars.push_back(varspec($4,
  545 + new BoolVarSpec(arg->getBool(),introduced)));
  546 + } else if (arg->isBoolVar()) {
  547 + pp->boolvars.push_back(varspec($4,
  548 + new BoolVarSpec(Alias(arg->getBoolVar()),introduced)));
  549 + } else {
  550 + yyassert(pp, false, "Invalid var bool initializer.");
  551 + }
  552 + if (!pp->hadError)
  553 + addDomainConstraint(pp, "int_in",
  554 + new AST::BoolVar(pp->boolvars.size()-1), $2);
  555 + delete arg;
  556 + } else {
  557 + pp->boolvars.push_back(varspec($4, new BoolVarSpec($2,introduced)));
  558 + }
  559 + delete $5; free($4);
  560 + }
  561 + | FZ_VAR float_ti_expr_tail ':' var_par_id annotations non_array_expr_opt
  562 + { ParserState* pp = static_cast<ParserState*>(parm);
  563 + yyassert(pp, false, "Floats not supported.");
  564 + delete $5; free($4);
  565 + }
  566 + | FZ_VAR FZ_SET FZ_OF int_ti_expr_tail ':' var_par_id annotations non_array_expr_opt
  567 + {
  568 + ParserState* pp = static_cast<ParserState*>(parm);
  569 + bool print = $7->hasAtom("output_var");
  570 + bool introduced = $7->hasAtom("var_is_introduced");
  571 + pp->setvarTable.put($6, pp->setvars.size());
  572 + if (print) {
  573 + pp->output(std::string($6), new AST::SetVar(pp->setvars.size()));
  574 + }
  575 + if ($8()) {
  576 + AST::Node* arg = $8.some();
  577 + if (arg->isSet()) {
  578 + pp->setvars.push_back(varspec($6,
  579 + new SetVarSpec(arg->getSet(),introduced)));
  580 + } else if (arg->isSetVar()) {
  581 + pp->setvars.push_back(varspec($6,
  582 + new SetVarSpec(Alias(arg->getSetVar()),introduced)));
  583 + delete arg;
  584 + } else {
  585 + yyassert(pp, false, "Invalid var set initializer.");
  586 + delete arg;
  587 + }
  588 + if (!pp->hadError)
  589 + addDomainConstraint(pp, "set_subset",
  590 + new AST::SetVar(pp->setvars.size()-1), $4);
  591 + } else {
  592 + pp->setvars.push_back(varspec($6, new SetVarSpec($4,introduced)));
  593 + }
  594 + delete $7; free($6);
  595 + }
  596 + | FZ_INT ':' var_par_id annotations '=' non_array_expr
  597 + {
  598 + ParserState* pp = static_cast<ParserState*>(parm);
  599 + yyassert(pp, $6->isInt(), "Invalid int initializer.");
  600 + pp->intvals.put($3, $6->getInt());
  601 + delete $4; free($3);
  602 + }
  603 + | FZ_BOOL ':' var_par_id annotations '=' non_array_expr
  604 + {
  605 + ParserState* pp = static_cast<ParserState*>(parm);
  606 + yyassert(pp, $6->isBool(), "Invalid bool initializer.");
  607 + pp->boolvals.put($3, $6->getBool());
  608 + delete $4; free($3);
  609 + }
  610 + | FZ_SET FZ_OF FZ_INT ':' var_par_id annotations '=' non_array_expr
  611 + {
  612 + ParserState* pp = static_cast<ParserState*>(parm);
  613 + yyassert(pp, $8->isSet(), "Invalid set initializer.");
  614 + AST::SetLit* set = $8->getSet();
  615 + pp->setvals.put($5, *set);
  616 + delete set;
  617 + delete $6; free($5);
  618 + }
  619 + | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_VAR int_ti_expr_tail ':'
  620 + var_par_id annotations vardecl_int_var_array_init
  621 + {
  622 + ParserState* pp = static_cast<ParserState*>(parm);
  623 + yyassert(pp, $3==1, "Arrays must start at 1");
  624 + if (!pp->hadError) {
  625 + bool print = $12->hasCall("output_array");
  626 + vector<int> vars($5);
  627 + if (!pp->hadError) {
  628 + if ($13()) {
  629 + vector<VarSpec*>* vsv = $13.some();
  630 + yyassert(pp, vsv->size() == static_cast<unsigned int>($5),
  631 + "Initializer size does not match array dimension");
  632 + if (!pp->hadError) {
  633 + for (int i=0; i<$5; i++) {
  634 + IntVarSpec* ivsv = static_cast<IntVarSpec*>((*vsv)[i]);
  635 + if (ivsv->alias) {
  636 + vars[i] = ivsv->i;
  637 + } else {
  638 + vars[i] = pp->intvars.size();
  639 + pp->intvars.push_back(varspec($11, ivsv));
  640 + }
  641 + if (!pp->hadError && $9()) {
  642 + Option<AST::SetLit*> opt =
  643 + Option<AST::SetLit*>::some(new AST::SetLit(*$9.some()));
  644 + addDomainConstraint(pp, "int_in",
  645 + new AST::IntVar(vars[i]),
  646 + opt);
  647 + }
  648 + }
  649 + }
  650 + delete vsv;
  651 + } else {
  652 + if ($5>0) {
  653 + IntVarSpec* ispec = new IntVarSpec($9,!print);
  654 + string arrayname = "["; arrayname += $11;
  655 + for (int i=0; i<$5-1; i++) {
  656 + vars[i] = pp->intvars.size();
  657 + pp->intvars.push_back(varspec(arrayname, ispec));
  658 + }
  659 + vars[$5-1] = pp->intvars.size();
  660 + pp->intvars.push_back(varspec($11, ispec));
  661 + }
  662 + }
  663 + }
  664 + if (print) {
  665 + AST::Array* a = new AST::Array();
  666 + a->a.push_back(arrayOutput($12->getCall("output_array")));
  667 + AST::Array* output = new AST::Array();
  668 + for (int i=0; i<$5; i++)
  669 + output->a.push_back(new AST::IntVar(vars[i]));
  670 + a->a.push_back(output);
  671 + a->a.push_back(new AST::String(")"));
  672 + pp->output(std::string($11), a);
  673 + }
  674 + pp->intvararrays.put($11, vars);
  675 + }
  676 + delete $12; free($11);
  677 + }
  678 + | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_VAR bool_ti_expr_tail ':'
  679 + var_par_id annotations vardecl_bool_var_array_init
  680 + {
  681 + ParserState* pp = static_cast<ParserState*>(parm);
  682 + bool print = $12->hasCall("output_array");
  683 + yyassert(pp, $3==1, "Arrays must start at 1");
  684 + if (!pp->hadError) {
  685 + vector<int> vars($5);
  686 + if ($13()) {
  687 + vector<VarSpec*>* vsv = $13.some();
  688 + yyassert(pp, vsv->size() == static_cast<unsigned int>($5),
  689 + "Initializer size does not match array dimension");
  690 + if (!pp->hadError) {
  691 + for (int i=0; i<$5; i++) {
  692 + BoolVarSpec* bvsv = static_cast<BoolVarSpec*>((*vsv)[i]);
  693 + if (bvsv->alias)
  694 + vars[i] = bvsv->i;
  695 + else {
  696 + vars[i] = pp->boolvars.size();
  697 + pp->boolvars.push_back(varspec($11, (*vsv)[i]));
  698 + }
  699 + if (!pp->hadError && $9()) {
  700 + Option<AST::SetLit*> opt =
  701 + Option<AST::SetLit*>::some(new AST::SetLit(*$9.some()));
  702 + addDomainConstraint(pp, "int_in",
  703 + new AST::BoolVar(vars[i]),
  704 + opt);
  705 + }
  706 + }
  707 + }
  708 + delete vsv;
  709 + } else {
  710 + for (int i=0; i<$5; i++) {
  711 + vars[i] = pp->boolvars.size();
  712 + pp->boolvars.push_back(varspec($11,
  713 + new BoolVarSpec($9,!print)));
  714 + }
  715 + }
  716 + if (print) {
  717 + AST::Array* a = new AST::Array();
  718 + a->a.push_back(arrayOutput($12->getCall("output_array")));
  719 + AST::Array* output = new AST::Array();
  720 + for (int i=0; i<$5; i++)
  721 + output->a.push_back(new AST::BoolVar(vars[i]));
  722 + a->a.push_back(output);
  723 + a->a.push_back(new AST::String(")"));
  724 + pp->output(std::string($11), a);
  725 + }
  726 + pp->boolvararrays.put($11, vars);
  727 + }
  728 + delete $12; free($11);
  729 + }
  730 + | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_VAR float_ti_expr_tail ':'
  731 + var_par_id annotations vardecl_float_var_array_init
  732 + {
  733 + ParserState* pp = static_cast<ParserState*>(parm);
  734 + yyassert(pp, false, "Floats not supported.");
  735 + delete $12; free($11);
  736 + }
  737 + | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_VAR FZ_SET FZ_OF int_ti_expr_tail ':'
  738 + var_par_id annotations vardecl_set_var_array_init
  739 + {
  740 + ParserState* pp = static_cast<ParserState*>(parm);
  741 + bool print = $14->hasCall("output_array");
  742 + yyassert(pp, $3==1, "Arrays must start at 1");
  743 + if (!pp->hadError) {
  744 + vector<int> vars($5);
  745 + if ($15()) {
  746 + vector<VarSpec*>* vsv = $15.some();
  747 + yyassert(pp, vsv->size() == static_cast<unsigned int>($5),
  748 + "Initializer size does not match array dimension");
  749 + if (!pp->hadError) {
  750 + for (int i=0; i<$5; i++) {
  751 + SetVarSpec* svsv = static_cast<SetVarSpec*>((*vsv)[i]);
  752 + if (svsv->alias)
  753 + vars[i] = svsv->i;
  754 + else {
  755 + vars[i] = pp->setvars.size();
  756 + pp->setvars.push_back(varspec($13, (*vsv)[i]));
  757 + }
  758 + if (!pp->hadError && $11()) {
  759 + Option<AST::SetLit*> opt =
  760 + Option<AST::SetLit*>::some(new AST::SetLit(*$11.some()));
  761 + addDomainConstraint(pp, "set_subset",
  762 + new AST::SetVar(vars[i]),
  763 + opt);
  764 + }
  765 + }
  766 + }
  767 + delete vsv;
  768 + } else {
  769 + if ($5>0) {
  770 + SetVarSpec* ispec = new SetVarSpec($11,!print);
  771 + string arrayname = "["; arrayname += $13;
  772 + for (int i=0; i<$5-1; i++) {
  773 + vars[i] = pp->setvars.size();
  774 + pp->setvars.push_back(varspec(arrayname, ispec));
  775 + }
  776 + vars[$5-1] = pp->setvars.size();
  777 + pp->setvars.push_back(varspec($13, ispec));
  778 + }
  779 + }
  780 + if (print) {
  781 + AST::Array* a = new AST::Array();
  782 + a->a.push_back(arrayOutput($14->getCall("output_array")));
  783 + AST::Array* output = new AST::Array();
  784 + for (int i=0; i<$5; i++)
  785 + output->a.push_back(new AST::SetVar(vars[i]));
  786 + a->a.push_back(output);
  787 + a->a.push_back(new AST::String(")"));
  788 + pp->output(std::string($13), a);
  789 + }
  790 + pp->setvararrays.put($13, vars);
  791 + }
  792 + delete $14; free($13);
  793 + }
  794 + | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_INT ':'
  795 + var_par_id annotations '=' '[' int_list ']'
  796 + {
  797 + ParserState* pp = static_cast<ParserState*>(parm);
  798 + yyassert(pp, $3==1, "Arrays must start at 1");
  799 + yyassert(pp, $14->size() == static_cast<unsigned int>($5),
  800 + "Initializer size does not match array dimension");
  801 + if (!pp->hadError)
  802 + pp->intvalarrays.put($10, *$14);
  803 + delete $14;
  804 + free($10);
  805 + delete $11;
  806 + }
  807 + | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_BOOL ':'
  808 + var_par_id annotations '=' '[' bool_list ']'
  809 + {
  810 + ParserState* pp = static_cast<ParserState*>(parm);
  811 + yyassert(pp, $3==1, "Arrays must start at 1");
  812 + yyassert(pp, $14->size() == static_cast<unsigned int>($5),
  813 + "Initializer size does not match array dimension");
  814 + if (!pp->hadError)
  815 + pp->boolvalarrays.put($10, *$14);
  816 + delete $14;
  817 + free($10);
  818 + delete $11;
  819 + }
  820 + | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_FLOAT ':'
  821 + var_par_id annotations '=' '[' float_list ']'
  822 + {
  823 + ParserState* pp = static_cast<ParserState*>(parm);
  824 + yyassert(pp, false, "Floats not supported.");
  825 + delete $11; free($10);
  826 + }
  827 + | FZ_ARRAY '[' FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT ']' FZ_OF FZ_SET FZ_OF FZ_INT ':'
  828 + var_par_id annotations '=' '[' set_literal_list ']'
  829 + {
  830 + ParserState* pp = static_cast<ParserState*>(parm);
  831 + yyassert(pp, $3==1, "Arrays must start at 1");
  832 + yyassert(pp, $16->size() == static_cast<unsigned int>($5),
  833 + "Initializer size does not match array dimension");
  834 + if (!pp->hadError)
  835 + pp->setvalarrays.put($12, *$16);
  836 + delete $16;
  837 + delete $13; free($12);
  838 + }
  839 +
  840 +int_init :
  841 + FZ_INT_LIT
  842 + {
  843 + $$ = new IntVarSpec($1,false);
  844 + }
  845 + | var_par_id
  846 + {
  847 + int v = 0;
  848 + ParserState* pp = static_cast<ParserState*>(parm);
  849 + if (pp->intvarTable.get($1, v))
  850 + $$ = new IntVarSpec(Alias(v),false);
  851 + else {
  852 + pp->err << "Error: undefined identifier " << $1
  853 + << " in line no. "
  854 + << yyget_lineno(pp->yyscanner) << std::endl;
  855 + pp->hadError = true;
  856 + $$ = new IntVarSpec(0,false); // keep things consistent
  857 + }
  858 + free($1);
  859 + }
  860 + | var_par_id '[' FZ_INT_LIT ']'
  861 + {
  862 + vector<int> v;
  863 + ParserState* pp = static_cast<ParserState*>(parm);
  864 + if (pp->intvararrays.get($1, v)) {
  865 + yyassert(pp,static_cast<unsigned int>($3) > 0 &&
  866 + static_cast<unsigned int>($3) <= v.size(),
  867 + "array access out of bounds");
  868 + if (!pp->hadError)
  869 + $$ = new IntVarSpec(Alias(v[$3-1]),false);
  870 + else
  871 + $$ = new IntVarSpec(0,false); // keep things consistent
  872 + } else {
  873 + pp->err << "Error: undefined array identifier " << $1
  874 + << " in line no. "
  875 + << yyget_lineno(pp->yyscanner) << std::endl;
  876 + pp->hadError = true;
  877 + $$ = new IntVarSpec(0,false); // keep things consistent
  878 + }
  879 + free($1);
  880 + }
  881 +
  882 +int_init_list :
  883 + /* empty */
  884 + { $$ = new vector<VarSpec*>(0); }
  885 + | int_init_list_head list_tail
  886 + { $$ = $1; }
  887 +
  888 +int_init_list_head :
  889 + int_init
  890 + { $$ = new vector<VarSpec*>(1); (*$$)[0] = $1; }
  891 + | int_init_list_head ',' int_init
  892 + { $$ = $1; $$->push_back($3); }
  893 +
  894 +list_tail : | ','
  895 +
  896 +int_var_array_literal : '[' int_init_list ']'
  897 + { $$ = $2; }
  898 +
  899 +float_init :
  900 + FZ_FLOAT_LIT
  901 + { $$ = new FloatVarSpec($1,false); }
  902 + | var_par_id
  903 + {
  904 + int v = 0;
  905 + ParserState* pp = static_cast<ParserState*>(parm);
  906 + if (pp->floatvarTable.get($1, v))
  907 + $$ = new FloatVarSpec(Alias(v),false);
  908 + else {
  909 + pp->err << "Error: undefined identifier " << $1
  910 + << " in line no. "
  911 + << yyget_lineno(pp->yyscanner) << std::endl;
  912 + pp->hadError = true;
  913 + $$ = new FloatVarSpec(0.0,false);
  914 + }
  915 + free($1);
  916 + }
  917 + | var_par_id '[' FZ_INT_LIT ']'
  918 + {
  919 + vector<int> v;
  920 + ParserState* pp = static_cast<ParserState*>(parm);
  921 + if (pp->floatvararrays.get($1, v)) {
  922 + yyassert(pp,static_cast<unsigned int>($3) > 0 &&
  923 + static_cast<unsigned int>($3) <= v.size(),
  924 + "array access out of bounds");
  925 + if (!pp->hadError)
  926 + $$ = new FloatVarSpec(Alias(v[$3-1]),false);
  927 + else
  928 + $$ = new FloatVarSpec(0.0,false);
  929 + } else {
  930 + pp->err << "Error: undefined array identifier " << $1
  931 + << " in line no. "
  932 + << yyget_lineno(pp->yyscanner) << std::endl;
  933 + pp->hadError = true;
  934 + $$ = new FloatVarSpec(0.0,false);
  935 + }
  936 + free($1);
  937 + }
  938 +
  939 +float_init_list :
  940 + /* empty */
  941 + { $$ = new vector<VarSpec*>(0); }
  942 + | float_init_list_head list_tail
  943 + { $$ = $1; }
  944 +
  945 +float_init_list_head :
  946 + float_init
  947 + { $$ = new vector<VarSpec*>(1); (*$$)[0] = $1; }
  948 + | float_init_list_head ',' float_init
  949 + { $$ = $1; $$->push_back($3); }
  950 +
  951 +float_var_array_literal :
  952 + '[' float_init_list ']'
  953 + { $$ = $2; }
  954 +
  955 +bool_init :
  956 + FZ_BOOL_LIT
  957 + { $$ = new BoolVarSpec($1,false); }
  958 + | var_par_id
  959 + {
  960 + int v = 0;
  961 + ParserState* pp = static_cast<ParserState*>(parm);
  962 + if (pp->boolvarTable.get($1, v))
  963 + $$ = new BoolVarSpec(Alias(v),false);
  964 + else {
  965 + pp->err << "Error: undefined identifier " << $1
  966 + << " in line no. "
  967 + << yyget_lineno(pp->yyscanner) << std::endl;
  968 + pp->hadError = true;
  969 + $$ = new BoolVarSpec(false,false);
  970 + }
  971 + free($1);
  972 + }
  973 + | var_par_id '[' FZ_INT_LIT ']'
  974 + {
  975 + vector<int> v;
  976 + ParserState* pp = static_cast<ParserState*>(parm);
  977 + if (pp->boolvararrays.get($1, v)) {
  978 + yyassert(pp,static_cast<unsigned int>($3) > 0 &&
  979 + static_cast<unsigned int>($3) <= v.size(),
  980 + "array access out of bounds");
  981 + if (!pp->hadError)
  982 + $$ = new BoolVarSpec(Alias(v[$3-1]),false);
  983 + else
  984 + $$ = new BoolVarSpec(false,false);
  985 + } else {
  986 + pp->err << "Error: undefined array identifier " << $1
  987 + << " in line no. "
  988 + << yyget_lineno(pp->yyscanner) << std::endl;
  989 + pp->hadError = true;
  990 + $$ = new BoolVarSpec(false,false);
  991 + }
  992 + free($1);
  993 + }
  994 +
  995 +bool_init_list :
  996 + /* empty */
  997 + { $$ = new vector<VarSpec*>(0); }
  998 + | bool_init_list_head list_tail
  999 + { $$ = $1; }
  1000 +
  1001 +bool_init_list_head :
  1002 + bool_init
  1003 + { $$ = new vector<VarSpec*>(1); (*$$)[0] = $1; }
  1004 + | bool_init_list_head ',' bool_init
  1005 + { $$ = $1; $$->push_back($3); }
  1006 +
  1007 +bool_var_array_literal : '[' bool_init_list ']' { $$ = $2; }
  1008 +
  1009 +set_init :
  1010 + set_literal
  1011 + { $$ = new SetVarSpec($1,false); }
  1012 + | var_par_id
  1013 + {
  1014 + ParserState* pp = static_cast<ParserState*>(parm);
  1015 + int v = 0;
  1016 + if (pp->setvarTable.get($1, v))
  1017 + $$ = new SetVarSpec(Alias(v),false);
  1018 + else {
  1019 + pp->err << "Error: undefined identifier " << $1
  1020 + << " in line no. "
  1021 + << yyget_lineno(pp->yyscanner) << std::endl;
  1022 + pp->hadError = true;
  1023 + $$ = new SetVarSpec(Alias(0),false);
  1024 + }
  1025 + free($1);
  1026 + }
  1027 + | var_par_id '[' FZ_INT_LIT ']'
  1028 + {
  1029 + vector<int> v;
  1030 + ParserState* pp = static_cast<ParserState*>(parm);
  1031 + if (pp->setvararrays.get($1, v)) {
  1032 + yyassert(pp,static_cast<unsigned int>($3) > 0 &&
  1033 + static_cast<unsigned int>($3) <= v.size(),
  1034 + "array access out of bounds");
  1035 + if (!pp->hadError)
  1036 + $$ = new SetVarSpec(Alias(v[$3-1]),false);
  1037 + else
  1038 + $$ = new SetVarSpec(Alias(0),false);
  1039 + } else {
  1040 + pp->err << "Error: undefined array identifier " << $1
  1041 + << " in line no. "
  1042 + << yyget_lineno(pp->yyscanner) << std::endl;
  1043 + pp->hadError = true;
  1044 + $$ = new SetVarSpec(Alias(0),false);
  1045 + }
  1046 + free($1);
  1047 + }
  1048 +
  1049 +set_init_list :
  1050 + /* empty */
  1051 + { $$ = new vector<VarSpec*>(0); }
  1052 + | set_init_list_head list_tail
  1053 + { $$ = $1; }
  1054 +
  1055 +set_init_list_head :
  1056 + set_init
  1057 + { $$ = new vector<VarSpec*>(1); (*$$)[0] = $1; }
  1058 + | set_init_list_head ',' set_init
  1059 + { $$ = $1; $$->push_back($3); }
  1060 +
  1061 +set_var_array_literal : '[' set_init_list ']'
  1062 + { $$ = $2; }
  1063 +
  1064 +vardecl_int_var_array_init :
  1065 + /* empty */
  1066 + { $$ = Option<vector<VarSpec*>* >::none(); }
  1067 + | '=' int_var_array_literal
  1068 + { $$ = Option<vector<VarSpec*>* >::some($2); }
  1069 +
  1070 +vardecl_bool_var_array_init :
  1071 + /* empty */
  1072 + { $$ = Option<vector<VarSpec*>* >::none(); }
  1073 + | '=' bool_var_array_literal
  1074 + { $$ = Option<vector<VarSpec*>* >::some($2); }
  1075 +
  1076 +vardecl_float_var_array_init :
  1077 + /* empty */
  1078 + { $$ = Option<vector<VarSpec*>* >::none(); }
  1079 + | '=' float_var_array_literal
  1080 + { $$ = Option<vector<VarSpec*>* >::some($2); }
  1081 +
  1082 +vardecl_set_var_array_init :
  1083 + /* empty */
  1084 + { $$ = Option<vector<VarSpec*>* >::none(); }
  1085 + | '=' set_var_array_literal
  1086 + { $$ = Option<vector<VarSpec*>* >::some($2); }
  1087 +
  1088 +constraint_item :
  1089 + FZ_CONSTRAINT FZ_ID '(' flat_expr_list ')' annotations
  1090 + {
  1091 + ConExpr c($2, $4);
  1092 + ParserState *pp = static_cast<ParserState*>(parm);
  1093 + if (!pp->hadError) {
  1094 + try {
  1095 + pp->fg->postConstraint(c, $6);
  1096 + } catch (FlatZinc::Error& e) {
  1097 + yyerror(pp, e.toString().c_str());
  1098 + }
  1099 + }
  1100 + delete $6; free($2);
  1101 + }
  1102 +solve_item :
  1103 + FZ_SOLVE annotations FZ_SATISFY
  1104 + {
  1105 + ParserState *pp = static_cast<ParserState*>(parm);
  1106 + if (!pp->hadError) {
  1107 + try {
  1108 + pp->fg->solve($2);
  1109 + } catch (FlatZinc::Error& e) {
  1110 + yyerror(pp, e.toString().c_str());
  1111 + }
  1112 + } else {
  1113 + delete $2;
  1114 + }
  1115 + }
  1116 + | FZ_SOLVE annotations minmax solve_expr
  1117 + {
  1118 + ParserState *pp = static_cast<ParserState*>(parm);
  1119 + if (!pp->hadError) {
  1120 + try {
  1121 + if ($3)
  1122 + pp->fg->minimize($4,$2);
  1123 + else
  1124 + pp->fg->maximize($4,$2);
  1125 + } catch (FlatZinc::Error& e) {
  1126 + yyerror(pp, e.toString().c_str());
  1127 + }
  1128 + } else {
  1129 + delete $2;
  1130 + }
  1131 + }
  1132 +
  1133 +/********************************/
  1134 +/* type-insts */
  1135 +/********************************/
  1136 +
  1137 +int_ti_expr_tail :
  1138 + FZ_INT
  1139 + { $$ = Option<AST::SetLit* >::none(); }
  1140 + | '{' int_list '}'
  1141 + { $$ = Option<AST::SetLit* >::some(new AST::SetLit(*$2)); }
  1142 + | FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT
  1143 + {
  1144 + $$ = Option<AST::SetLit* >::some(new AST::SetLit($1, $3));
  1145 + }
  1146 +
  1147 +bool_ti_expr_tail :
  1148 + FZ_BOOL
  1149 + { $$ = Option<AST::SetLit* >::none(); }
  1150 + | '{' bool_list_head list_tail '}'
  1151 + { bool haveTrue = false;
  1152 + bool haveFalse = false;
  1153 + for (int i=$2->size(); i--;) {
  1154 + haveTrue |= ((*$2)[i] == 1);
  1155 + haveFalse |= ((*$2)[i] == 0);
  1156 + }
  1157 + delete $2;
  1158 + $$ = Option<AST::SetLit* >::some(
  1159 + new AST::SetLit(!haveFalse,haveTrue));
  1160 + }
  1161 +
  1162 +float_ti_expr_tail :
  1163 + FZ_FLOAT
  1164 + | '{' float_list_head list_tail '}'
  1165 +
  1166 +/********************************/
  1167 +/* literals */
  1168 +/********************************/
  1169 +
  1170 +set_literal :
  1171 + '{' int_list '}'
  1172 + { $$ = new AST::SetLit(*$2); }
  1173 + | FZ_INT_LIT FZ_DOTDOT FZ_INT_LIT
  1174 + { $$ = new AST::SetLit($1, $3); }
  1175 +
  1176 +/* list containing only primitive literals */
  1177 +
  1178 +int_list :
  1179 + /* empty */
  1180 + { $$ = new vector<int>(0); }
  1181 + | int_list_head list_tail
  1182 + { $$ = $1; }
  1183 +
  1184 +int_list_head :
  1185 + FZ_INT_LIT
  1186 + { $$ = new vector<int>(1); (*$$)[0] = $1; }
  1187 + | int_list_head ',' FZ_INT_LIT
  1188 + { $$ = $1; $$->push_back($3); }
  1189 +
  1190 +bool_list :
  1191 + /* empty */
  1192 + { $$ = new vector<int>(0); }
  1193 + | bool_list_head list_tail
  1194 + { $$ = $1; }
  1195 +
  1196 +bool_list_head :
  1197 + FZ_BOOL_LIT
  1198 + { $$ = new vector<int>(1); (*$$)[0] = $1; }
  1199 + | bool_list_head ',' FZ_BOOL_LIT
  1200 + { $$ = $1; $$->push_back($3); }
  1201 +
  1202 +float_list :
  1203 + /* empty */
  1204 + { $$ = new vector<double>(0); }
  1205 + | float_list_head list_tail
  1206 + { $$ = $1; }
  1207 +
  1208 +float_list_head:
  1209 + FZ_FLOAT_LIT
  1210 + { $$ = new vector<double>(1); (*$$)[0] = $1; }
  1211 + | float_list_head ',' FZ_FLOAT_LIT
  1212 + { $$ = $1; $$->push_back($3); }
  1213 +
  1214 +set_literal_list :
  1215 + /* empty */
  1216 + { $$ = new vector<AST::SetLit>(0); }
  1217 + | set_literal_list_head list_tail
  1218 + { $$ = $1; }
  1219 +
  1220 +set_literal_list_head :
  1221 + set_literal
  1222 + { $$ = new vector<AST::SetLit>(1); (*$$)[0] = *$1; delete $1; }
  1223 + | set_literal_list_head ',' set_literal
  1224 + { $$ = $1; $$->push_back(*$3); delete $3; }
  1225 +
  1226 +/********************************/
  1227 +/* constraint expressions */
  1228 +/********************************/
  1229 +
  1230 +flat_expr_list :
  1231 + flat_expr
  1232 + { $$ = new AST::Array($1); }
  1233 + | flat_expr_list ',' flat_expr
  1234 + { $$ = $1; $$->append($3); }
  1235 +
  1236 +flat_expr :
  1237 + non_array_expr
  1238 + { $$ = $1; }
  1239 + | '[' non_array_expr_list ']'
  1240 + { $$ = $2; }
  1241 +
  1242 +non_array_expr_opt :
  1243 + /* empty */
  1244 + { $$ = Option<AST::Node*>::none(); }
  1245 + | '=' non_array_expr
  1246 + { $$ = Option<AST::Node*>::some($2); }
  1247 +
  1248 +non_array_expr :
  1249 + FZ_BOOL_LIT
  1250 + { $$ = new AST::BoolLit($1); }
  1251 + | FZ_INT_LIT
  1252 + { $$ = new AST::IntLit($1); }
  1253 + | FZ_FLOAT_LIT
  1254 + { $$ = new AST::FloatLit($1); }
  1255 + | set_literal
  1256 + { $$ = $1; }
  1257 + | var_par_id /* variable, possibly array */
  1258 + {
  1259 + vector<int> as;
  1260 + ParserState* pp = static_cast<ParserState*>(parm);
  1261 + if (pp->intvararrays.get($1, as)) {
  1262 + AST::Array *ia = new AST::Array(as.size());
  1263 + for (int i=as.size(); i--;)
  1264 + ia->a[i] = new AST::IntVar(as[i]);
  1265 + $$ = ia;
  1266 + } else if (pp->boolvararrays.get($1, as)) {
  1267 + AST::Array *ia = new AST::Array(as.size());
  1268 + for (int i=as.size(); i--;)
  1269 + ia->a[i] = new AST::BoolVar(as[i]);
  1270 + $$ = ia;
  1271 + } else if (pp->setvararrays.get($1, as)) {
  1272 + AST::Array *ia = new AST::Array(as.size());
  1273 + for (int i=as.size(); i--;)
  1274 + ia->a[i] = new AST::SetVar(as[i]);
  1275 + $$ = ia;
  1276 + } else {
  1277 + std::vector<int> is;
  1278 + std::vector<AST::SetLit> isS;
  1279 + int ival = 0;
  1280 + bool bval = false;
  1281 + if (pp->intvalarrays.get($1, is)) {
  1282 + AST::Array *v = new AST::Array(is.size());
  1283 + for (int i=is.size(); i--;)
  1284 + v->a[i] = new AST::IntLit(is[i]);
  1285 + $$ = v;
  1286 + } else if (pp->boolvalarrays.get($1, is)) {
  1287 + AST::Array *v = new AST::Array(is.size());
  1288 + for (int i=is.size(); i--;)
  1289 + v->a[i] = new AST::BoolLit(is[i]);
  1290 + $$ = v;
  1291 + } else if (pp->setvalarrays.get($1, isS)) {
  1292 + AST::Array *v = new AST::Array(isS.size());
  1293 + for (int i=isS.size(); i--;)
  1294 + v->a[i] = new AST::SetLit(isS[i]);
  1295 + $$ = v;
  1296 + } else if (pp->intvals.get($1, ival)) {
  1297 + $$ = new AST::IntLit(ival);
  1298 + } else if (pp->boolvals.get($1, bval)) {
  1299 + $$ = new AST::BoolLit(bval);
  1300 + } else {
  1301 + $$ = getVarRefArg(pp,$1);
  1302 + }
  1303 + }
  1304 + free($1);
  1305 + }
  1306 + | var_par_id '[' non_array_expr ']' /* array access */
  1307 + {
  1308 + ParserState* pp = static_cast<ParserState*>(parm);
  1309 + int i = -1;
  1310 + yyassert(pp, $3->isInt(i), "Non-integer array index.");
  1311 + if (!pp->hadError)
  1312 + $$ = getArrayElement(static_cast<ParserState*>(parm),$1,i);
  1313 + else
  1314 + $$ = new AST::IntLit(0); // keep things consistent
  1315 + free($1);
  1316 + }
  1317 +
  1318 +non_array_expr_list :
  1319 + /* empty */
  1320 + { $$ = new AST::Array(0); }
  1321 + | non_array_expr_list_head list_tail
  1322 + { $$ = $1; }
  1323 +
  1324 +non_array_expr_list_head :
  1325 + non_array_expr
  1326 + { $$ = new AST::Array($1); }
  1327 + | non_array_expr_list_head ',' non_array_expr
  1328 + { $$ = $1; $$->append($3); }
  1329 +
  1330 +/********************************/
  1331 +/* solve expressions */
  1332 +/********************************/
  1333 +
  1334 +solve_expr:
  1335 + var_par_id
  1336 + {
  1337 + ParserState *pp = static_cast<ParserState*>(parm);
  1338 + if (!pp->intvarTable.get($1, $$)) {
  1339 + pp->err << "Error: unknown integer variable " << $1
  1340 + << " in line no. "
  1341 + << yyget_lineno(pp->yyscanner) << std::endl;
  1342 + pp->hadError = true;
  1343 + }
  1344 + free($1);
  1345 + }
  1346 + | var_par_id '[' FZ_INT_LIT ']'
  1347 + {
  1348 + vector<int> tmp;
  1349 + ParserState *pp = static_cast<ParserState*>(parm);
  1350 + if (!pp->intvararrays.get($1, tmp)) {
  1351 + pp->err << "Error: unknown integer variable array " << $1
  1352 + << " in line no. "
  1353 + << yyget_lineno(pp->yyscanner) << std::endl;
  1354 + pp->hadError = true;
  1355 + }
  1356 + if ($3 == 0 || static_cast<unsigned int>($3) > tmp.size()) {
  1357 + pp->err << "Error: array index out of bounds for array " << $1
  1358 + << " in line no. "
  1359 + << yyget_lineno(pp->yyscanner) << std::endl;
  1360 + pp->hadError = true;
  1361 + } else {
  1362 + $$ = tmp[$3-1];
  1363 + }
  1364 + free($1);
  1365 + }
  1366 +
  1367 +minmax:
  1368 + FZ_MINIMIZE
  1369 + | FZ_MAXIMIZE
  1370 +
  1371 +/********************************/
  1372 +/* annotation expresions */
  1373 +/********************************/
  1374 +
  1375 +annotations :
  1376 + /* empty */
  1377 + { $$ = NULL; }
  1378 + | annotations_head
  1379 + { $$ = $1; }
  1380 +
  1381 +annotations_head :
  1382 + FZ_COLONCOLON annotation
  1383 + { $$ = new AST::Array($2); }
  1384 + | annotations_head FZ_COLONCOLON annotation
  1385 + { $$ = $1; $$->append($3); }
  1386 +
  1387 +annotation :
  1388 + FZ_ID '(' annotation_list ')'
  1389 + {
  1390 + $$ = new AST::Call($1, AST::extractSingleton($3)); free($1);
  1391 + }
  1392 + | annotation_expr
  1393 + { $$ = $1; }
  1394 +
  1395 +annotation_list:
  1396 + annotation
  1397 + { $$ = new AST::Array($1); }
  1398 + | annotation_list ',' annotation
  1399 + { $$ = $1; $$->append($3); }
  1400 +
  1401 +annotation_expr :
  1402 + ann_non_array_expr
  1403 + { $$ = $1; }
  1404 + | '[' annotation_list ']'
  1405 + { $$ = $2; }
  1406 +
  1407 +ann_non_array_expr :
  1408 + FZ_BOOL_LIT
  1409 + { $$ = new AST::BoolLit($1); }
  1410 + | FZ_INT_LIT
  1411 + { $$ = new AST::IntLit($1); }
  1412 + | FZ_FLOAT_LIT
  1413 + { $$ = new AST::FloatLit($1); }
  1414 + | set_literal
  1415 + { $$ = $1; }
  1416 + | var_par_id /* variable, possibly array */
  1417 + {
  1418 + vector<int> as;
  1419 + ParserState* pp = static_cast<ParserState*>(parm);
  1420 + if (pp->intvararrays.get($1, as)) {
  1421 + AST::Array *ia = new AST::Array(as.size());
  1422 + for (int i=as.size(); i--;)
  1423 + ia->a[i] = new AST::IntVar(as[i]);
  1424 + $$ = ia;
  1425 + } else if (pp->boolvararrays.get($1, as)) {
  1426 + AST::Array *ia = new AST::Array(as.size());
  1427 + for (int i=as.size(); i--;)
  1428 + ia->a[i] = new AST::BoolVar(as[i]);
  1429 + $$ = ia;
  1430 + } else if (pp->setvararrays.get($1, as)) {
  1431 + AST::Array *ia = new AST::Array(as.size());
  1432 + for (int i=as.size(); i--;)
  1433 + ia->a[i] = new AST::SetVar(as[i]);
  1434 + $$ = ia;
  1435 + } else {
  1436 + std::vector<int> is;
  1437 + int ival = 0;
  1438 + bool bval = false;
  1439 + if (pp->intvalarrays.get($1, is)) {
  1440 + AST::Array *v = new AST::Array(is.size());
  1441 + for (int i=is.size(); i--;)
  1442 + v->a[i] = new AST::IntLit(is[i]);
  1443 + $$ = v;
  1444 + } else if (pp->boolvalarrays.get($1, is)) {
  1445 + AST::Array *v = new AST::Array(is.size());
  1446 + for (int i=is.size(); i--;)
  1447 + v->a[i] = new AST::BoolLit(is[i]);
  1448 + $$ = v;
  1449 + } else if (pp->intvals.get($1, ival)) {
  1450 + $$ = new AST::IntLit(ival);
  1451 + } else if (pp->boolvals.get($1, bval)) {
  1452 + $$ = new AST::BoolLit(bval);
  1453 + } else {
  1454 + $$ = getVarRefArg(pp,$1,true);
  1455 + }
  1456 + }
  1457 + free($1);
  1458 + }
  1459 + | var_par_id '[' ann_non_array_expr ']' /* array access */
  1460 + {
  1461 + ParserState* pp = static_cast<ParserState*>(parm);
  1462 + int i = -1;
  1463 + yyassert(pp, $3->isInt(i), "Non-integer array index.");
  1464 + if (!pp->hadError)
  1465 + $$ = getArrayElement(static_cast<ParserState*>(parm),$1,i);
  1466 + else
  1467 + $$ = new AST::IntLit(0); // keep things consistent
  1468 + free($1);
  1469 + }
  1470 + | FZ_STRING_LIT
  1471 + {
  1472 + $$ = new AST::String($1);
  1473 + free($1);
  1474 + }
... ...
fz/registry.cpp 0 → 100644
... ... @@ -0,0 +1,496 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Contributing authors:
  7 + * Mikael Lagerkvist <lagerkvist@gmail.com>
  8 + *
  9 + * Copyright:
  10 + * Guido Tack, 2007
  11 + * Mikael Lagerkvist, 2009
  12 + *
  13 + * Last modified:
  14 + * $Date: 2010-07-02 19:18:43 +1000 (Fri, 02 Jul 2010) $ by $Author: tack $
  15 + * $Revision: 11149 $
  16 + *
  17 + * This file is part of Gecode, the generic constraint
  18 + * development environment:
  19 + * http://www.gecode.org
  20 + *
  21 + * Permission is hereby granted, free of charge, to any person obtaining
  22 + * a copy of this software and associated documentation files (the
  23 + * "Software"), to deal in the Software without restriction, including
  24 + * without limitation the rights to use, copy, modify, merge, publish,
  25 + * distribute, sublicense, and/or sell copies of the Software, and to
  26 + * permit persons to whom the Software is furnished to do so, subject to
  27 + * the following conditions:
  28 + *
  29 + * The above copyright notice and this permission notice shall be
  30 + * included in all copies or substantial portions of the Software.
  31 + *
  32 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  33 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  34 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  35 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  36 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  37 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  38 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  39 + *
  40 + */
  41 +
  42 +#include "registry.hh"
  43 +#include "flatzinc.hh"
  44 +
  45 +namespace FlatZinc {
  46 +
  47 + Registry& registry(void) {
  48 + static Registry r;
  49 + return r;
  50 + }
  51 +
  52 + void
  53 + Registry::post(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  54 + std::map<std::string,poster>::iterator i = r.find(ce.id);
  55 + if (i == r.end()) {
  56 + throw FlatZinc::Error("Registry",
  57 + std::string("Constraint ")+ce.id+" not found");
  58 + }
  59 + i->second(s, ce, ann);
  60 + }
  61 +
  62 + void
  63 + Registry::add(const std::string& id, poster p) {
  64 + r[id] = p;
  65 + }
  66 +
  67 + namespace {
  68 +
  69 + void p_int_eq(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  70 + std::cerr << "int_eq("<<(*ce[0])<<","<<(*ce[1])<<")::"<<(*ann)<<"\n";
  71 + }
  72 + void p_int_ne(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  73 + std::cerr << "int_eq("<<(*ce[0])<<","<<(*ce[1])<<")::"<<(*ann)<<"\n";
  74 + }
  75 + void p_int_ge(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  76 + std::cerr << "int_ge("<<(*ce[0])<<","<<(*ce[1])<<")::"<<(*ann)<<"\n";
  77 + }
  78 + void p_int_gt(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  79 + std::cerr << "int_gt("<<(*ce[0])<<","<<(*ce[1])<<")::"<<(*ann)<<"\n";
  80 + }
  81 + void p_int_le(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  82 + std::cerr << "int_le("<<(*ce[0])<<","<<(*ce[1])<<")::"<<(*ann)<<"\n";
  83 + }
  84 + void p_int_lt(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  85 + std::cerr << "int_lt("<<(*ce[0])<<","<<(*ce[1])<<")::"<<(*ann)<<"\n";
  86 + }
  87 +
  88 + /* Comparisons */
  89 + void p_int_eq_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  90 + std::cerr << "int_eq_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  91 + <<")::"<<(*ann)<<"\n";
  92 + }
  93 + void p_int_ne_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  94 + std::cerr << "int_ne_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  95 + <<")::"<<(*ann)<<"\n";
  96 + }
  97 + void p_int_ge_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  98 + std::cerr << "int_ge_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  99 + <<")::"<<(*ann)<<"\n";
  100 + }
  101 + void p_int_gt_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  102 + std::cerr << "int_gt_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  103 + <<")::"<<(*ann)<<"\n";
  104 + }
  105 + void p_int_le_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  106 + std::cerr << "int_le_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  107 + <<")::"<<(*ann)<<"\n";
  108 + }
  109 + void p_int_lt_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  110 + std::cerr << "int_lt_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  111 + <<")::"<<(*ann)<<"\n";
  112 + }
  113 +
  114 + void p_int_lin_eq(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  115 + std::cerr << "int_lin_eq("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  116 + <<")::"<<(*ann)<<"\n";
  117 + }
  118 + void p_int_lin_eq_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  119 + std::cerr << "int_lin_eq_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  120 + <<","<<(*ce[3])<<")::"<<(*ann)<<"\n";
  121 + }
  122 + void p_int_lin_ne(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  123 + std::cerr << "int_lin_ne("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  124 + <<")::"<<(*ann)<<"\n";
  125 + }
  126 + void p_int_lin_ne_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  127 + std::cerr << "int_lin_ne_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  128 + <<","<<(*ce[3])<<")::"<<(*ann)<<"\n";
  129 + }
  130 + void p_int_lin_le(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  131 + std::cerr << "int_lin_le("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  132 + <<")::"<<(*ann)<<"\n";
  133 + }
  134 + void p_int_lin_le_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  135 + std::cerr << "int_lin_le_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  136 + <<","<<(*ce[3])<<")::"<<(*ann)<<"\n";
  137 + }
  138 + void p_int_lin_lt(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  139 + std::cerr << "int_lin_lt("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  140 + <<")::"<<(*ann)<<"\n";
  141 + }
  142 + void p_int_lin_lt_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  143 + std::cerr << "int_lin_lt_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  144 + <<","<<(*ce[3])<<")::"<<(*ann)<<"\n";
  145 + }
  146 + void p_int_lin_ge(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  147 + std::cerr << "int_lin_ge("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  148 + <<")::"<<(*ann)<<"\n";
  149 + }
  150 + void p_int_lin_ge_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  151 + std::cerr << "int_lin_ge_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  152 + <<","<<(*ce[3])<<")::"<<(*ann)<<"\n";
  153 + }
  154 + void p_int_lin_gt(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  155 + std::cerr << "int_lin_gt("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  156 + <<")::"<<(*ann)<<"\n";
  157 + }
  158 + void p_int_lin_gt_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  159 + std::cerr << "int_lin_gt_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  160 + <<","<<(*ce[3])<<")::"<<(*ann)<<"\n";
  161 + }
  162 +
  163 + /* arithmetic constraints */
  164 +
  165 + void p_int_plus(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  166 + std::cerr << "int_plus("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  167 + <<")::"<<(*ann)<<"\n";
  168 + }
  169 +
  170 + void p_int_minus(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  171 + std::cerr << "int_minus("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  172 + <<")::"<<(*ann)<<"\n";
  173 + }
  174 +
  175 + void p_int_times(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  176 + std::cerr << "int_times("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  177 + <<")::"<<(*ann)<<"\n";
  178 + }
  179 + void p_int_div(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  180 + std::cerr << "int_div("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  181 + <<")::"<<(*ann)<<"\n";
  182 + }
  183 + void p_int_mod(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  184 + std::cerr << "int_mod("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  185 + <<")::"<<(*ann)<<"\n";
  186 + }
  187 +
  188 + void p_int_min(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  189 + std::cerr << "int_min("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  190 + <<")::"<<(*ann)<<"\n";
  191 + }
  192 + void p_int_max(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  193 + std::cerr << "int_max("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  194 + <<")::"<<(*ann)<<"\n";
  195 + }
  196 + void p_int_negate(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  197 + std::cerr << "int_negate("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  198 + <<")::"<<(*ann)<<"\n";
  199 + }
  200 +
  201 + void p_bool_eq(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  202 + std::cerr << "bool_eq("<<(*ce[0])<<","<<(*ce[1])
  203 + <<")::"<<(*ann)<<"\n";
  204 + }
  205 + void p_bool_eq_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  206 + std::cerr << "bool_eq_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  207 + <<")::"<<(*ann)<<"\n";
  208 + }
  209 + void p_bool_ne(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  210 + std::cerr << "bool_ne("<<(*ce[0])<<","<<(*ce[1])
  211 + <<")::"<<(*ann)<<"\n";
  212 + }
  213 + void p_bool_ne_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  214 + std::cerr << "bool_ne_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  215 + <<")::"<<(*ann)<<"\n";
  216 + }
  217 + void p_bool_ge(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  218 + std::cerr << "bool_ge("<<(*ce[0])<<","<<(*ce[1])
  219 + <<")::"<<(*ann)<<"\n";
  220 + }
  221 + void p_bool_ge_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  222 + std::cerr << "bool_ge_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  223 + <<")::"<<(*ann)<<"\n";
  224 + }
  225 + void p_bool_le(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  226 + std::cerr << "bool_le("<<(*ce[0])<<","<<(*ce[1])
  227 + <<")::"<<(*ann)<<"\n";
  228 + }
  229 + void p_bool_le_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  230 + std::cerr << "bool_le_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  231 + <<")::"<<(*ann)<<"\n";
  232 + }
  233 + void p_bool_gt(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  234 + std::cerr << "bool_gt("<<(*ce[0])<<","<<(*ce[1])
  235 + <<")::"<<(*ann)<<"\n";
  236 + }
  237 + void p_bool_gt_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  238 + std::cerr << "bool_gt_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  239 + <<")::"<<(*ann)<<"\n";
  240 + }
  241 + void p_bool_lt(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  242 + std::cerr << "bool_lt("<<(*ce[0])<<","<<(*ce[1])
  243 + <<")::"<<(*ann)<<"\n";
  244 + }
  245 + void p_bool_lt_reif(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  246 + std::cerr << "bool_lt_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  247 + <<")::"<<(*ann)<<"\n";
  248 + }
  249 +
  250 + void p_bool_or(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  251 + std::cerr << "bool_or("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  252 + <<")::"<<(*ann)<<"\n";
  253 + }
  254 + void p_bool_and(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  255 + std::cerr << "bool_and("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  256 + <<")::"<<(*ann)<<"\n";
  257 + }
  258 + void p_array_bool_and(FlatZincModel& s, const ConExpr& ce, AST::Node* ann)
  259 + {
  260 + std::cerr << "array_bool_and("<<(*ce[0])<<","<<(*ce[1])
  261 + <<")::"<<(*ann)<<"\n";
  262 + }
  263 + void p_array_bool_or(FlatZincModel& s, const ConExpr& ce, AST::Node* ann)
  264 + {
  265 + std::cerr << "array_bool_or("<<(*ce[0])<<","<<(*ce[1])
  266 + <<")::"<<(*ann)<<"\n";
  267 + }
  268 + void p_array_bool_clause(FlatZincModel& s, const ConExpr& ce,
  269 + AST::Node* ann) {
  270 + std::cerr << "array_bool_clause("<<(*ce[0])<<","<<(*ce[1])
  271 + <<")::"<<(*ann)<<"\n";
  272 + }
  273 + void p_array_bool_clause_reif(FlatZincModel& s, const ConExpr& ce,
  274 + AST::Node* ann) {
  275 + std::cerr << "array_bool_clause_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  276 + <<")::"<<(*ann)<<"\n";
  277 + }
  278 + void p_bool_xor(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  279 + std::cerr << "bool_xor("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  280 + <<")::"<<(*ann)<<"\n";
  281 + }
  282 + void p_bool_l_imp(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  283 + std::cerr << "bool_l_imp("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  284 + <<")::"<<(*ann)<<"\n";
  285 + }
  286 + void p_bool_r_imp(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  287 + std::cerr << "bool_r_imp("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  288 + <<")::"<<(*ann)<<"\n";
  289 + }
  290 + void p_bool_not(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  291 + std::cerr << "bool_not("<<(*ce[0])<<","<<(*ce[1])
  292 + <<")::"<<(*ann)<<"\n";
  293 + }
  294 +
  295 + /* element constraints */
  296 + void p_array_int_element(FlatZincModel& s, const ConExpr& ce,
  297 + AST::Node* ann) {
  298 + std::cerr << "array_int_element("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  299 + <<")::"<<(*ann)<<"\n";
  300 + }
  301 + void p_array_bool_element(FlatZincModel& s, const ConExpr& ce,
  302 + AST::Node* ann) {
  303 + std::cerr << "array_bool_element("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  304 + <<")::"<<(*ann)<<"\n";
  305 + }
  306 +
  307 + /* coercion constraints */
  308 + void p_bool2int(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  309 + std::cerr << "bool2int("<<(*ce[0])<<","<<(*ce[1])
  310 + <<")::"<<(*ann)<<"\n";
  311 + }
  312 +
  313 + void p_int_in(FlatZincModel& s, const ConExpr& ce, AST::Node *ann) {
  314 + std::cerr << "int_in("<<(*ce[0])<<","<<(*ce[1])
  315 + <<")::"<<(*ann)<<"\n";
  316 + }
  317 +
  318 + void p_abs(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  319 + std::cerr << "abs("<<(*ce[0])<<","<<(*ce[1])<<")::"<<(*ann)<<"\n";
  320 + }
  321 +
  322 + class IntPoster {
  323 + public:
  324 + IntPoster(void) {
  325 + registry().add("int_eq", &p_int_eq);
  326 + registry().add("int_ne", &p_int_ne);
  327 + registry().add("int_ge", &p_int_ge);
  328 + registry().add("int_gt", &p_int_gt);
  329 + registry().add("int_le", &p_int_le);
  330 + registry().add("int_lt", &p_int_lt);
  331 + registry().add("int_eq_reif", &p_int_eq_reif);
  332 + registry().add("int_ne_reif", &p_int_ne_reif);
  333 + registry().add("int_ge_reif", &p_int_ge_reif);
  334 + registry().add("int_gt_reif", &p_int_gt_reif);
  335 + registry().add("int_le_reif", &p_int_le_reif);
  336 + registry().add("int_lt_reif", &p_int_lt_reif);
  337 + registry().add("int_lin_eq", &p_int_lin_eq);
  338 + registry().add("int_lin_eq_reif", &p_int_lin_eq_reif);
  339 + registry().add("int_lin_ne", &p_int_lin_ne);
  340 + registry().add("int_lin_ne_reif", &p_int_lin_ne_reif);
  341 + registry().add("int_lin_le", &p_int_lin_le);
  342 + registry().add("int_lin_le_reif", &p_int_lin_le_reif);
  343 + registry().add("int_lin_lt", &p_int_lin_lt);
  344 + registry().add("int_lin_lt_reif", &p_int_lin_lt_reif);
  345 + registry().add("int_lin_ge", &p_int_lin_ge);
  346 + registry().add("int_lin_ge_reif", &p_int_lin_ge_reif);
  347 + registry().add("int_lin_gt", &p_int_lin_gt);
  348 + registry().add("int_lin_gt_reif", &p_int_lin_gt_reif);
  349 + registry().add("int_plus", &p_int_plus);
  350 + registry().add("int_minus", &p_int_minus);
  351 + registry().add("int_times", &p_int_times);
  352 + registry().add("int_div", &p_int_div);
  353 + registry().add("int_mod", &p_int_mod);
  354 + registry().add("int_min", &p_int_min);
  355 + registry().add("int_max", &p_int_max);
  356 + registry().add("int_abs", &p_abs);
  357 + registry().add("int_negate", &p_int_negate);
  358 + registry().add("bool_eq", &p_bool_eq);
  359 + registry().add("bool_eq_reif", &p_bool_eq_reif);
  360 + registry().add("bool_ne", &p_bool_ne);
  361 + registry().add("bool_ne_reif", &p_bool_ne_reif);
  362 + registry().add("bool_ge", &p_bool_ge);
  363 + registry().add("bool_ge_reif", &p_bool_ge_reif);
  364 + registry().add("bool_le", &p_bool_le);
  365 + registry().add("bool_le_reif", &p_bool_le_reif);
  366 + registry().add("bool_gt", &p_bool_gt);
  367 + registry().add("bool_gt_reif", &p_bool_gt_reif);
  368 + registry().add("bool_lt", &p_bool_lt);
  369 + registry().add("bool_lt_reif", &p_bool_lt_reif);
  370 + registry().add("bool_or", &p_bool_or);
  371 + registry().add("bool_and", &p_bool_and);
  372 + registry().add("bool_xor", &p_bool_xor);
  373 + registry().add("array_bool_and", &p_array_bool_and);
  374 + registry().add("array_bool_or", &p_array_bool_or);
  375 + registry().add("bool_clause", &p_array_bool_clause);
  376 + registry().add("bool_clause_reif", &p_array_bool_clause_reif);
  377 + registry().add("bool_left_imp", &p_bool_l_imp);
  378 + registry().add("bool_right_imp", &p_bool_r_imp);
  379 + registry().add("bool_not", &p_bool_not);
  380 + registry().add("array_int_element", &p_array_int_element);
  381 + registry().add("array_var_int_element", &p_array_int_element);
  382 + registry().add("array_bool_element", &p_array_bool_element);
  383 + registry().add("array_var_bool_element", &p_array_bool_element);
  384 + registry().add("bool2int", &p_bool2int);
  385 + registry().add("int_in", &p_int_in);
  386 +
  387 + }
  388 + };
  389 + IntPoster __int_poster;
  390 +
  391 + void p_set_union(FlatZincModel& s, const ConExpr& ce, AST::Node *ann) {
  392 + std::cerr << "set_union("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  393 + <<")::"<<(*ann)<<"\n";
  394 + }
  395 + void p_set_intersect(FlatZincModel& s, const ConExpr& ce, AST::Node *ann) {
  396 + std::cerr << "set_intersect("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  397 + <<")::"<<(*ann)<<"\n";
  398 + }
  399 + void p_set_diff(FlatZincModel& s, const ConExpr& ce, AST::Node *ann) {
  400 + std::cerr << "set_diff("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  401 + <<")::"<<(*ann)<<"\n";
  402 + }
  403 +
  404 + void p_set_symdiff(FlatZincModel& s, const ConExpr& ce, AST::Node* ann) {
  405 + std::cerr << "set_symdiff("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  406 + <<")::"<<(*ann)<<"\n";
  407 + }
  408 +
  409 + void p_set_eq(FlatZincModel& s, const ConExpr& ce, AST::Node * ann) {
  410 + std::cerr << "set_eq("<<(*ce[0])<<","<<(*ce[1])
  411 + <<")::"<<(*ann)<<"\n";
  412 + }
  413 + void p_set_ne(FlatZincModel& s, const ConExpr& ce, AST::Node * ann) {
  414 + std::cerr << "set_ne("<<(*ce[0])<<","<<(*ce[1])
  415 + <<")::"<<(*ann)<<"\n";
  416 + }
  417 + void p_set_subset(FlatZincModel& s, const ConExpr& ce, AST::Node * ann) {
  418 + std::cerr << "set_subset("<<(*ce[0])<<","<<(*ce[1])
  419 + <<")::"<<(*ann)<<"\n";
  420 + }
  421 + void p_set_superset(FlatZincModel& s, const ConExpr& ce, AST::Node * ann) {
  422 + std::cerr << "set_superset("<<(*ce[0])<<","<<(*ce[1])
  423 + <<")::"<<(*ann)<<"\n";
  424 + }
  425 + void p_set_card(FlatZincModel& s, const ConExpr& ce, AST::Node * ann) {
  426 + std::cerr << "set_card("<<(*ce[0])<<","<<(*ce[1])
  427 + <<")::"<<(*ann)<<"\n";
  428 + }
  429 + void p_set_in(FlatZincModel& s, const ConExpr& ce, AST::Node * ann) {
  430 + std::cerr << "set_in("<<(*ce[0])<<","<<(*ce[1])
  431 + <<")::"<<(*ann)<<"\n";
  432 + }
  433 + void p_set_eq_reif(FlatZincModel& s, const ConExpr& ce, AST::Node * ann) {
  434 + std::cerr << "set_eq_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  435 + <<")::"<<(*ann)<<"\n";
  436 + }
  437 + void p_set_ne_reif(FlatZincModel& s, const ConExpr& ce, AST::Node * ann) {
  438 + std::cerr << "set_ne_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  439 + <<")::"<<(*ann)<<"\n";
  440 + }
  441 + void p_set_subset_reif(FlatZincModel& s, const ConExpr& ce,
  442 + AST::Node *ann) {
  443 + std::cerr << "set_subset_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  444 + <<")::"<<(*ann)<<"\n";
  445 + }
  446 + void p_set_superset_reif(FlatZincModel& s, const ConExpr& ce,
  447 + AST::Node *ann) {
  448 + std::cerr << "set_superset_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  449 + <<")::"<<(*ann)<<"\n";
  450 + }
  451 + void p_set_in_reif(FlatZincModel& s, const ConExpr& ce, AST::Node *ann) {
  452 + std::cerr << "set_in_reif("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  453 + <<")::"<<(*ann)<<"\n";
  454 + }
  455 + void p_set_disjoint(FlatZincModel& s, const ConExpr& ce, AST::Node *ann) {
  456 + std::cerr << "set_disjoint("<<(*ce[0])<<","<<(*ce[1])
  457 + <<")::"<<(*ann)<<"\n";
  458 + }
  459 +
  460 + void p_array_set_element(FlatZincModel& s, const ConExpr& ce,
  461 + AST::Node* ann) {
  462 + std::cerr << "array_set_element("<<(*ce[0])<<","<<(*ce[1])<<","<<(*ce[2])
  463 + <<")::"<<(*ann)<<"\n";
  464 + }
  465 +
  466 +
  467 + class SetPoster {
  468 + public:
  469 + SetPoster(void) {
  470 + registry().add("set_eq", &p_set_eq);
  471 + registry().add("set_ne", &p_set_ne);
  472 + registry().add("set_union", &p_set_union);
  473 + registry().add("array_set_element", &p_array_set_element);
  474 + registry().add("array_var_set_element", &p_array_set_element);
  475 + registry().add("set_intersect", &p_set_intersect);
  476 + registry().add("set_diff", &p_set_diff);
  477 + registry().add("set_symdiff", &p_set_symdiff);
  478 + registry().add("set_subset", &p_set_subset);
  479 + registry().add("set_superset", &p_set_superset);
  480 + registry().add("set_card", &p_set_card);
  481 + registry().add("set_in", &p_set_in);
  482 + registry().add("set_eq_reif", &p_set_eq_reif);
  483 + registry().add("equal_reif", &p_set_eq_reif);
  484 + registry().add("set_ne_reif", &p_set_ne_reif);
  485 + registry().add("set_subset_reif", &p_set_subset_reif);
  486 + registry().add("set_superset_reif", &p_set_superset_reif);
  487 + registry().add("set_in_reif", &p_set_in_reif);
  488 + registry().add("disjoint", &p_set_disjoint);
  489 + }
  490 + };
  491 + SetPoster __set_poster;
  492 +
  493 + }
  494 +}
  495 +
  496 +// STATISTICS: flatzinc-any
... ...
fz/registry.hh 0 → 100644
... ... @@ -0,0 +1,69 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2010-07-02 19:18:43 +1000 (Fri, 02 Jul 2010) $ by $Author: tack $
  11 + * $Revision: 11149 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#ifndef __GECODE_FLATZINC_REGISTRY_HH__
  39 +#define __GECODE_FLATZINC_REGISTRY_HH__
  40 +
  41 +#include "flatzinc.hh"
  42 +#include <string>
  43 +#include <map>
  44 +
  45 +namespace FlatZinc {
  46 +
  47 + /// Map from constraint identifier to constraint posting functions
  48 + class Registry {
  49 + public:
  50 + /// Type of constraint posting function
  51 + typedef void (*poster) (FlatZincModel&, const ConExpr&, AST::Node*);
  52 + /// Add posting function \a p with identifier \a id
  53 + void add(const std::string& id, poster p);
  54 + /// Post constraint specified by \a ce
  55 + void post(FlatZincModel& s, const ConExpr& ce, AST::Node* ann);
  56 +
  57 + private:
  58 + /// The actual registry
  59 + std::map<std::string,poster> r;
  60 + };
  61 +
  62 + /// Return global registry object
  63 + Registry& registry(void);
  64 +
  65 +}
  66 +
  67 +#endif
  68 +
  69 +// STATISTICS: flatzinc-any
... ...
fz/symboltable.hh 0 → 100644
... ... @@ -0,0 +1,78 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2010-07-02 19:18:43 +1000 (Fri, 02 Jul 2010) $ by $Author: tack $
  11 + * $Revision: 11149 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#ifndef __GECODE_FLATZINC_SYMBOLTABLE_HH__
  39 +#define __GECODE_FLATZINC_SYMBOLTABLE_HH__
  40 +
  41 +#include <map>
  42 +#include <vector>
  43 +
  44 +namespace FlatZinc {
  45 +
  46 + /// Symbol table mapping identifiers (strings) to values
  47 + template<class Val>
  48 + class SymbolTable {
  49 + private:
  50 + std::map<std::string,Val> m;
  51 + public:
  52 + /// Insert \a val with \a key
  53 + void put(const std::string& key, const Val& val);
  54 + /// Return whether \a key exists, and set \a val if it does exist
  55 + bool get(const std::string& key, Val& val) const;
  56 + };
  57 +
  58 + template<class Val>
  59 + void
  60 + SymbolTable<Val>::put(const std::string& key, const Val& val) {
  61 + m[key] = val;
  62 + }
  63 +
  64 + template<class Val>
  65 + bool
  66 + SymbolTable<Val>::get(const std::string& key, Val& val) const {
  67 + typename std::map<std::string,Val>::const_iterator i =
  68 + m.find(key);
  69 + if (i == m.end())
  70 + return false;
  71 + val = i->second;
  72 + return true;
  73 + }
  74 +
  75 +}
  76 +#endif
  77 +
  78 +// STATISTICS: flatzinc-any
... ...
fz/varspec.hh 0 → 100644
... ... @@ -0,0 +1,163 @@
  1 +/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
  2 +/*
  3 + * Main authors:
  4 + * Guido Tack <tack@gecode.org>
  5 + *
  6 + * Copyright:
  7 + * Guido Tack, 2007
  8 + *
  9 + * Last modified:
  10 + * $Date: 2010-07-02 19:18:43 +1000 (Fri, 02 Jul 2010) $ by $Author: tack $
  11 + * $Revision: 11149 $
  12 + *
  13 + * This file is part of Gecode, the generic constraint
  14 + * development environment:
  15 + * http://www.gecode.org
  16 + *
  17 + * Permission is hereby granted, free of charge, to any person obtaining
  18 + * a copy of this software and associated documentation files (the
  19 + * "Software"), to deal in the Software without restriction, including
  20 + * without limitation the rights to use, copy, modify, merge, publish,
  21 + * distribute, sublicense, and/or sell copies of the Software, and to
  22 + * permit persons to whom the Software is furnished to do so, subject to
  23 + * the following conditions:
  24 + *
  25 + * The above copyright notice and this permission notice shall be
  26 + * included in all copies or substantial portions of the Software.
  27 + *
  28 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32 + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33 + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34 + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35 + *
  36 + */
  37 +
  38 +#ifndef __GECODE_FLATZINC_VARSPEC__HH__
  39 +#define __GECODE_FLATZINC_VARSPEC__HH__
  40 +
  41 +#include "option.hh"
  42 +#include "ast.hh"
  43 +#include <vector>
  44 +#include <iostream>
  45 +
  46 +namespace FlatZinc {
  47 +
  48 + /// %Alias for a variable specification
  49 + class Alias {
  50 + public:
  51 + const int v;
  52 + Alias(int v0) : v(v0) {}
  53 + };
  54 +
  55 + /// Base class for variable specifications
  56 + class VarSpec {
  57 + public:
  58 + /// Whether the variable was introduced in the mzn2fzn translation
  59 + bool introduced;
  60 + /// Destructor
  61 + virtual ~VarSpec(void) {}
  62 + /// Variable index
  63 + int i;
  64 + /// Whether the variable aliases another variable
  65 + bool alias;
  66 + /// Whether the variable is assigned
  67 + bool assigned;
  68 + /// Constructor
  69 + VarSpec(bool introduced0) : introduced(introduced0) {}
  70 + };
  71 +
  72 + /// Specification for integer variables
  73 + class IntVarSpec : public VarSpec {
  74 + public:
  75 + Option<AST::SetLit* > domain;
  76 + IntVarSpec(const Option<AST::SetLit* >& d, bool introduced)
  77 + : VarSpec(introduced) {
  78 + alias = false;
  79 + assigned = false;
  80 + domain = d;
  81 + }
  82 + IntVarSpec(int i0, bool introduced) : VarSpec(introduced) {
  83 + alias = false; assigned = true; i = i0;
  84 + }
  85 + IntVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) {
  86 + alias = true; i = eq.v;
  87 + }
  88 + ~IntVarSpec(void) {
  89 + if (!alias && !assigned && domain())
  90 + delete domain.some();
  91 + }
  92 + };
  93 +
  94 + /// Specification for Boolean variables
  95 + class BoolVarSpec : public VarSpec {
  96 + public:
  97 + Option<AST::SetLit* > domain;
  98 + BoolVarSpec(Option<AST::SetLit* >& d, bool introduced)
  99 + : VarSpec(introduced) {
  100 + alias = false; assigned = false; domain = d;
  101 + }
  102 + BoolVarSpec(bool b, bool introduced) : VarSpec(introduced) {
  103 + alias = false; assigned = true; i = b;
  104 + }
  105 + BoolVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) {
  106 + alias = true; i = eq.v;
  107 + }
  108 + ~BoolVarSpec(void) {
  109 + if (!alias && !assigned && domain())
  110 + delete domain.some();
  111 + }
  112 + };
  113 +
  114 + /// Specification for floating point variables
  115 + class FloatVarSpec : public VarSpec {
  116 + public:
  117 + Option<std::vector<double>* > domain;
  118 + FloatVarSpec(Option<std::vector<double>* >& d, bool introduced)
  119 + : VarSpec(introduced) {
  120 + alias = false; assigned = false; domain = d;
  121 + }
  122 + FloatVarSpec(bool b, bool introduced) : VarSpec(introduced) {
  123 + alias = false; assigned = true; i = b;
  124 + }
  125 + FloatVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) {
  126 + alias = true; i = eq.v;
  127 + }
  128 + ~FloatVarSpec(void) {
  129 + if (!alias && !assigned && domain())
  130 + delete domain.some();
  131 + }
  132 + };
  133 +
  134 + /// Specification for set variables
  135 + class SetVarSpec : public VarSpec {
  136 + public:
  137 + Option<AST::SetLit*> upperBound;
  138 + SetVarSpec(bool introduced) : VarSpec(introduced) {
  139 + alias = false; assigned = false;
  140 + upperBound = Option<AST::SetLit* >::none();
  141 + }
  142 + SetVarSpec(const Option<AST::SetLit* >& v, bool introduced)
  143 + : VarSpec(introduced) {
  144 + alias = false; assigned = false; upperBound = v;
  145 + }
  146 + SetVarSpec(AST::SetLit* v, bool introduced) : VarSpec(introduced) {
  147 + alias = false; assigned = true;
  148 + upperBound = Option<AST::SetLit*>::some(v);
  149 + }
  150 + SetVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) {
  151 + alias = true; i = eq.v;
  152 + }
  153 + ~SetVarSpec(void) {
  154 + if (!alias && upperBound())
  155 + delete upperBound.some();
  156 + }
  157 + };
  158 +
  159 +}
  160 +
  161 +#endif
  162 +
  163 +// STATISTICS: flatzinc-any
... ...