git-subtree-dir: software/gecode_on_replay git-subtree-split: 8051d92b9c89e49cccfbd1c201371580d7703ab4
171 lines
6.6 KiB
Plaintext
Executable File
171 lines
6.6 KiB
Plaintext
Executable File
/* -*- 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)
|
|
#endif
|
|
|
|
void 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);
|
|
}
|