this repo has no description
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 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34%option reentrant 35%option bison-bridge 36%option noyywrap 37%option yylineno 38 39%{ 40#if defined __GNUC__ 41#pragma GCC diagnostic ignored "-Wunused-function" 42#pragma GCC diagnostic ignored "-Wunused-parameter" 43#pragma GCC diagnostic ignored "-Wsign-compare" 44#elif defined _MSC_VER 45#pragma warning(push, 1) 46#endif 47 48void yyerror(void*, const char*); 49#define yyerror(s) yyerror(yyextra, s) 50 51#include <errno.h> 52#include <stdlib.h> 53 54#include <gecode/flatzinc/parser.hh> 55 56const char* stringbuf; 57int stringbuflen; 58int stringbufpos; 59 60bool parseInt(const char* text, int& value) { 61 long int result = strtol(text,NULL,0); 62 if ( (result == LONG_MAX || result == LONG_MIN) && errno == ERANGE ) 63 return false; 64 if (result < Gecode::Int::Limits::min || result > Gecode::Int::Limits::max) 65 return false; 66 value = static_cast<int>(result); 67 return true; 68} 69 70int yy_input_proc(char* buf, int size, yyscan_t yyscanner); 71#define YY_INPUT(buf, result, max_size) \ 72 result = yy_input_proc(buf, max_size, yyscanner); 73%} 74 75%% 76 77\n { /*yylineno++;*/ /* ignore EOL */ } 78[ \t\r] { /* ignore whitespace */ } 79%.* { /* ignore comments */ } 80 81"true" { yylval->iValue = 1; return FZ_BOOL_LIT; } 82"false" { yylval->iValue = 0; return FZ_BOOL_LIT; } 83-?[0-9]+ { if (parseInt(yytext,yylval->iValue)) 84 return FZ_INT_LIT; 85 else 86 yyerror(("The literal '" + std::string(yytext) 87 + "' of the type int is out of range (" 88 + std::to_string(Gecode::Int::Limits::min) 89 + ".." + std::to_string(Gecode::Int::Limits::max) 90 + ")").c_str()); 91 } 92-?0x[0-9A-Fa-f]+ { if (parseInt(yytext,yylval->iValue)) 93 return FZ_INT_LIT; 94 else 95 yyerror(("The literal '" + std::string(yytext) 96 + "' of the type int is out of range (" 97 + std::to_string(Gecode::Int::Limits::min) 98 + ".." + std::to_string(Gecode::Int::Limits::max) 99 + ")").c_str()); 100 } 101-?0o[0-7]+ { if (parseInt(yytext,yylval->iValue)) 102 return FZ_INT_LIT; 103 else 104 yyerror(("The literal '" + std::string(yytext) 105 + "' of the type int is out of range (" 106 + std::to_string(Gecode::Int::Limits::min) 107 + ".." + std::to_string(Gecode::Int::Limits::max) 108 + ")").c_str()); 109 } 110-?[0-9]+\.[0-9]+ { yylval->dValue = strtod(yytext,NULL); 111 return FZ_FLOAT_LIT; } 112-?[0-9]+\.[0-9]+[Ee][+-]?[0-9]+ { yylval->dValue = strtod(yytext,NULL); 113 return FZ_FLOAT_LIT; } 114-?[0-9]+[Ee][+-]?[0-9]+ { yylval->dValue = strtod(yytext,NULL); 115 return FZ_FLOAT_LIT; } 116[=:;{}(),\[\]\.] { return *yytext; } 117\.\. { return FZ_DOTDOT; } 118:: { return FZ_COLONCOLON; } 119"annotation" { return FZ_ANNOTATION; } 120"any" { return FZ_ANY; } 121"array" { return FZ_ARRAY; } 122"bool" { return FZ_BOOL; } 123"case" { return FZ_CASE; } 124"constraint" { return FZ_CONSTRAINT; } 125"default" { return FZ_DEFAULT; } 126"else" { return FZ_ELSE; } 127"elseif" { return FZ_ELSEIF; } 128"endif" { return FZ_ENDIF; } 129"enum" { return FZ_ENUM; } 130"float" { return FZ_FLOAT; } 131"function" { return FZ_FUNCTION; } 132"if" { return FZ_IF; } 133"include" { return FZ_INCLUDE; } 134"int" { return FZ_INT; } 135"let" { return FZ_LET; } 136"maximize" { yylval->bValue = false; return FZ_MAXIMIZE; } 137"minimize" { yylval->bValue = true; return FZ_MINIMIZE; } 138"of" { return FZ_OF; } 139"satisfy" { return FZ_SATISFY; } 140"output" { return FZ_OUTPUT; } 141"par" { yylval->bValue = false; return FZ_PAR; } 142"predicate" { return FZ_PREDICATE; } 143"record" { return FZ_RECORD; } 144"set" { return FZ_SET; } 145"show_cond" { return FZ_SHOWCOND; } 146"show" { return FZ_SHOW; } 147"solve" { return FZ_SOLVE; } 148"string" { return FZ_STRING; } 149"test" { return FZ_TEST; } 150"then" { return FZ_THEN; } 151"tuple" { return FZ_TUPLE; } 152"type" { return FZ_TYPE; } 153"var" { yylval->bValue = true; return FZ_VAR; } 154"variant_record" { return FZ_VARIANT_RECORD; } 155"where" { return FZ_WHERE; } 156[A-Za-z][A-Za-z0-9_]* { yylval->sValue = strdup(yytext); return FZ_ID; } 157_[_]*[A-Za-z][A-Za-z0-9_]* { yylval->sValue = strdup(yytext); return FZ_U_ID; } 158\"[^"\n]*\" { 159 yylval->sValue = strdup(yytext+1); 160 yylval->sValue[strlen(yytext)-2] = 0; 161 return FZ_STRING_LIT; } 162. { yyerror("Unknown character"); } 163%% 164int yy_input_proc(char* buf, int size, yyscan_t yyscanner) { 165 Gecode::FlatZinc::ParserState* parm = 166 static_cast<Gecode::FlatZinc::ParserState*>(yyget_extra(yyscanner)); 167 return parm->fillBuffer(buf, size); 168 // work around warning that yyunput is unused 169 yyunput (0,buf,yyscanner); 170}