Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
6.7 kB · 170 lines
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Main authors: * Guido Tack <tack@gecode.org> * * Copyright: * Guido Tack, 2007 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */%option reentrant%option bison-bridge%option noyywrap%option yylineno%{#if defined __GNUC__#pragma GCC diagnostic ignored "-Wunused-function"#pragma GCC diagnostic ignored "-Wunused-parameter"#pragma GCC diagnostic ignored "-Wsign-compare"#elif defined _MSC_VER#pragma warning(push, 1)#endifvoid yyerror(void*, const char*);#define yyerror(s) yyerror(yyextra, s)#include <errno.h>#include <stdlib.h>#include <gecode/flatzinc/parser.hh>const char* stringbuf;int stringbuflen;int stringbufpos;bool parseInt(const char* text, int& value) { long int result = strtol(text,NULL,0); if ( (result == LONG_MAX || result == LONG_MIN) && errno == ERANGE ) return false; if (result < Gecode::Int::Limits::min || result > Gecode::Int::Limits::max) return false; value = static_cast<int>(result); return true;}int yy_input_proc(char* buf, int size, yyscan_t yyscanner);#define YY_INPUT(buf, result, max_size) \ result = yy_input_proc(buf, max_size, yyscanner);%}%%\n { /*yylineno++;*/ /* ignore EOL */ }[ \t\r] { /* ignore whitespace */ }%.* { /* ignore comments */ }"true" { yylval->iValue = 1; return FZ_BOOL_LIT; }"false" { yylval->iValue = 0; return FZ_BOOL_LIT; }-?[0-9]+ { if (parseInt(yytext,yylval->iValue)) return FZ_INT_LIT; else yyerror(("The literal '" + std::string(yytext) + "' of the type int is out of range (" + std::to_string(Gecode::Int::Limits::min) + ".." + std::to_string(Gecode::Int::Limits::max) + ")").c_str()); }-?0x[0-9A-Fa-f]+ { if (parseInt(yytext,yylval->iValue)) return FZ_INT_LIT; else yyerror(("The literal '" + std::string(yytext) + "' of the type int is out of range (" + std::to_string(Gecode::Int::Limits::min) + ".." + std::to_string(Gecode::Int::Limits::max) + ")").c_str()); }-?0o[0-7]+ { if (parseInt(yytext,yylval->iValue)) return FZ_INT_LIT; else yyerror(("The literal '" + std::string(yytext) + "' of the type int is out of range (" + std::to_string(Gecode::Int::Limits::min) + ".." + std::to_string(Gecode::Int::Limits::max) + ")").c_str()); }-?[0-9]+\.[0-9]+ { yylval->dValue = strtod(yytext,NULL); return FZ_FLOAT_LIT; }-?[0-9]+\.[0-9]+[Ee][+-]?[0-9]+ { yylval->dValue = strtod(yytext,NULL); return FZ_FLOAT_LIT; }-?[0-9]+[Ee][+-]?[0-9]+ { yylval->dValue = strtod(yytext,NULL); return FZ_FLOAT_LIT; }[=:;{}(),\[\]\.] { return *yytext; }\.\. { return FZ_DOTDOT; }:: { return FZ_COLONCOLON; }"annotation" { return FZ_ANNOTATION; }"any" { return FZ_ANY; }"array" { return FZ_ARRAY; }"bool" { return FZ_BOOL; }"case" { return FZ_CASE; }"constraint" { return FZ_CONSTRAINT; }"default" { return FZ_DEFAULT; }"else" { return FZ_ELSE; }"elseif" { return FZ_ELSEIF; }"endif" { return FZ_ENDIF; }"enum" { return FZ_ENUM; }"float" { return FZ_FLOAT; }"function" { return FZ_FUNCTION; }"if" { return FZ_IF; }"include" { return FZ_INCLUDE; }"int" { return FZ_INT; }"let" { return FZ_LET; }"maximize" { yylval->bValue = false; return FZ_MAXIMIZE; }"minimize" { yylval->bValue = true; return FZ_MINIMIZE; }"of" { return FZ_OF; }"satisfy" { return FZ_SATISFY; }"output" { return FZ_OUTPUT; }"par" { yylval->bValue = false; return FZ_PAR; }"predicate" { return FZ_PREDICATE; }"record" { return FZ_RECORD; }"set" { return FZ_SET; }"show_cond" { return FZ_SHOWCOND; }"show" { return FZ_SHOW; }"solve" { return FZ_SOLVE; }"string" { return FZ_STRING; }"test" { return FZ_TEST; }"then" { return FZ_THEN; }"tuple" { return FZ_TUPLE; }"type" { return FZ_TYPE; }"var" { yylval->bValue = true; return FZ_VAR; }"variant_record" { return FZ_VARIANT_RECORD; }"where" { return FZ_WHERE; }[A-Za-z][A-Za-z0-9_]* { yylval->sValue = strdup(yytext); return FZ_ID; }_[_]*[A-Za-z][A-Za-z0-9_]* { yylval->sValue = strdup(yytext); return FZ_U_ID; }\"[^"\n]*\" { yylval->sValue = strdup(yytext+1); yylval->sValue[strlen(yytext)-2] = 0; return FZ_STRING_LIT; }. { yyerror("Unknown character"); }%%int yy_input_proc(char* buf, int size, yyscan_t yyscanner) { Gecode::FlatZinc::ParserState* parm = static_cast<Gecode::FlatZinc::ParserState*>(yyget_extra(yyscanner)); return parm->fillBuffer(buf, size); // work around warning that yyunput is unused yyunput (0,buf,yyscanner);}