this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 3/* 4 * Main authors: 5 * Guido Tack <guido.tack@monash.edu> 6 */ 7 8/* This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 11 12%option reentrant 13%option bison-bridge bison-locations 14%option noyywrap 15%option stack 16 17%{ 18#if defined __GNUC__ 19#pragma GCC diagnostic ignored "-Wunused-function" 20#pragma GCC diagnostic ignored "-Wunused-parameter" 21#pragma GCC diagnostic ignored "-Wsign-compare" 22#pragma GCC diagnostic ignored "-Wdeprecated" 23#elif defined _MSC_VER 24#pragma warning(push, 1) 25#endif 26 27namespace MiniZinc{ class ParserLocation; } 28#define YYLTYPE MiniZinc::ParserLocation 29#define YYLTYPE_IS_DECLARED 1 30#define YYLTYPE_IS_TRIVIAL 0 31 32#include <minizinc/parser.hh> 33 34namespace MiniZinc { 35 36 int utf8len(const char* s) { 37 int l=0; 38 for (int i=0; s[i] != '\0'; i++) 39 if ((s[i] & 0xc0) != 0x80) 40 l++; 41 return l; 42 } 43 44 int yy_input_proc(char* buf, int size, yyscan_t yyscanner); 45} 46 47#define YY_INPUT(buf, result, max_size) \ 48 result = ::MiniZinc::yy_input_proc(buf, max_size, yyscanner); 49 50#define YY_USER_ACTION \ 51 { MiniZinc::ParserState* parm = \ 52 static_cast<MiniZinc::ParserState*>(yyget_extra(yyscanner)); \ 53 yylloc->firstLine(yylloc->lastLine()); \ 54 yylloc->firstColumn(yylloc->lastColumn()+1); \ 55 if(parm->hadNewline) { \ 56 parm->hadNewline=false; \ 57 parm->lineStartPos += parm->nTokenNextStart; \ 58 parm->nTokenNextStart=1; \ 59 yylloc->lastLine(yylloc->lastLine()+1); \ 60 yylloc->firstLine(yylloc->lastLine()); \ 61 yylloc->firstColumn(1); \ 62 } \ 63 if(yytext[0] == '\n') { \ 64 parm->hadNewline=true; \ 65 parm->nTokenNextStart+=0; \ 66 } else { \ 67 parm->nTokenNextStart+=yyleng; \ 68 } \ 69 yylloc->lastColumn(yylloc->firstColumn()+::MiniZinc::utf8len(yytext)-1); \ 70 } 71 72namespace MiniZinc { 73 74 bool hexstrtointval(const char* s, long long int& v) { 75 std::istringstream iss(s); 76 iss >> std::hex >> v; 77 return !iss.fail(); 78 } 79 80 bool octstrtointval(const char* s, long long int& v) { 81 std::istringstream iss(s); 82 iss >> std::oct >> v; 83 return !iss.fail(); 84 } 85 86 bool fast_strtointval(const char* s, long long int& v) { 87 MiniZinc::IntVal x = 0; 88 try { 89 for (; *s != '\0'; ++s) { 90 x = (x*10) + (*s - '0'); 91 } 92 } catch (MiniZinc::ArithmeticError&) { 93 return false; 94 } 95 v = x.toInt(); 96 return true; 97 } 98 99 bool strtofloatval(const char* s, double& v) { 100 std::istringstream iss(s); 101 iss >> v; 102 return !iss.fail(); 103 } 104 105 void clearBuffer(void* parm) { 106 MiniZinc::ParserState* pp = 107 static_cast<MiniZinc::ParserState*>(parm); 108 pp->stringBuffer = ""; 109 } 110 111 void appendBufferString(void* parm, const char* s) { 112 MiniZinc::ParserState* pp = 113 static_cast<MiniZinc::ParserState*>(parm); 114 pp->stringBuffer += s; 115 } 116 117 void appendBufferChar(void* parm, char s) { 118 MiniZinc::ParserState* pp = 119 static_cast<MiniZinc::ParserState*>(parm); 120 pp->stringBuffer += s; 121 } 122 123 char* bufferData(void* parm) { 124 MiniZinc::ParserState* pp = 125 static_cast<MiniZinc::ParserState*>(parm); 126 return strdup(pp->stringBuffer.c_str()); 127 } 128} 129 130%} 131 132%x string 133%x string_quote 134%x multilinecomment 135%x doccomment 136%x doccomment_file 137%s bracket_exp 138%s quoted_exp 139 140%% 141 142<*>\x0 { return MZN_INVALID_NULL; } 143 144\xa { } 145[ \f\xd\t] { /* ignore whitespace */ } 146 147"/**" { yy_push_state(doccomment,yyscanner); ::MiniZinc::clearBuffer(yyget_extra(yyscanner)); } 148<doccomment>{ 149 "*/" { yylval->sValue = ::MiniZinc::bufferData(yyget_extra(yyscanner)); 150 yy_pop_state(yyscanner); return MZN_DOC_COMMENT; } 151 [^*\xa]+ { ::MiniZinc::appendBufferString(yyget_extra(yyscanner), yytext); } 152 "*" { ::MiniZinc::appendBufferString(yyget_extra(yyscanner), yytext); } 153 \xa { ::MiniZinc::appendBufferString(yyget_extra(yyscanner), yytext); } 154} 155 156"/***" { yy_push_state(doccomment_file,yyscanner); ::MiniZinc::clearBuffer(yyget_extra(yyscanner)); } 157<doccomment_file>{ 158 "*/" { yylval->sValue = ::MiniZinc::bufferData(yyget_extra(yyscanner)); 159 yy_pop_state(yyscanner); return MZN_DOC_FILE_COMMENT; } 160 [^*\xa]+ { ::MiniZinc::appendBufferString(yyget_extra(yyscanner), yytext); } 161 "*" { ::MiniZinc::appendBufferString(yyget_extra(yyscanner), yytext); } 162 \xa { ::MiniZinc::appendBufferString(yyget_extra(yyscanner), yytext); } 163} 164 165"/*" { yy_push_state(multilinecomment,yyscanner); } 166<multilinecomment>{ 167 "*/" { yy_pop_state(yyscanner); } 168 [^*\xa]+ { } 169 "*" { } 170 \xa { } 171} 172 173 174"[" { return MZN_LEFT_BRACKET; } 175"[|" { return MZN_LEFT_2D_BRACKET; } 176"]" { return MZN_RIGHT_BRACKET; } 177"|]" { return MZN_RIGHT_2D_BRACKET; } 178%[^\xa]* { /* ignore comments */ } 179 180"true" { yylval->iValue = 1; return MZN_BOOL_LITERAL; } 181"false" { yylval->iValue = 0; return MZN_BOOL_LITERAL; } 182 1830[xX]([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.)([pP][+-]?[0-9]+)|(0[xX][0-9a-fA-F]+[pP][+-]?[0-9]+) { 184 if (::MiniZinc::strtofloatval(yytext, yylval->dValue)) 185 return MZN_FLOAT_LITERAL; 186 else 187 return MZN_INVALID_FLOAT_LITERAL; 188 } 189 1900[xX][0-9A-Fa-f]+ { 191 if (::MiniZinc::hexstrtointval(yytext+2, yylval->iValue)) 192 return MZN_INTEGER_LITERAL; 193 else 194 return MZN_INVALID_INTEGER_LITERAL; 195 } 1960o[0-7]+ { 197 if (::MiniZinc::octstrtointval(yytext+2, yylval->iValue)) 198 return MZN_INTEGER_LITERAL; 199 else 200 return MZN_INVALID_INTEGER_LITERAL; 201 } 202[0-9]+ { 203 if (::MiniZinc::fast_strtointval(yytext, yylval->iValue)) 204 return MZN_INTEGER_LITERAL; 205 else 206 return MZN_INVALID_INTEGER_LITERAL; 207 } 208 209[0-9]+\.[0-9]+ { 210 if (::MiniZinc::strtofloatval(yytext, yylval->dValue)) 211 return MZN_FLOAT_LITERAL; 212 else 213 return MZN_INVALID_FLOAT_LITERAL; 214 } 215[0-9]+\.[0-9]+[Ee][+-]?[0-9]+ { 216 if (::MiniZinc::strtofloatval(yytext, yylval->dValue)) 217 return MZN_FLOAT_LITERAL; 218 else 219 return MZN_INVALID_FLOAT_LITERAL; 220 } 221[0-9]+[Ee][+-]?[0-9]+ { 222 if (::MiniZinc::strtofloatval(yytext, yylval->dValue)) 223 return MZN_FLOAT_LITERAL; 224 else 225 return MZN_INVALID_FLOAT_LITERAL; 226 } 227[:;|{},\[\]\.] { 228 return *yytext; } 229\.\. { return MZN_DOTDOT; } 230"'\.\.'" { return MZN_DOTDOT_QUOTED; } 231:: { return MZN_COLONCOLON; } 232_ { return MZN_UNDERSCORE; } 233"ann" { return MZN_ANN; } 234"annotation" { return MZN_ANNOTATION; } 235"any" { return MZN_ANY; } 236"array" { return MZN_ARRAY; } 237"bool" { return MZN_BOOL; } 238"case" { return MZN_CASE; } 239"constraint" { return MZN_CONSTRAINT; } 240"default" { return MZN_DEFAULT; } 241"div" { return MZN_IDIV; } 242"'div'" { return MZN_IDIV_QUOTED; } 243"diff" { return MZN_DIFF; } 244"'diff'" { return MZN_DIFF_QUOTED; } 245"else" { return MZN_ELSE; } 246"elseif" { return MZN_ELSEIF; } 247"endif" { return MZN_ENDIF; } 248"enum" { return MZN_ENUM; } 249"float" { return MZN_FLOAT; } 250"function" { return MZN_FUNCTION; } 251"if" { return MZN_IF; } 252"include" { return MZN_INCLUDE; } 253"infinity" { return MZN_INFINITY; } 254"intersect" { return MZN_INTERSECT; } 255"'intersect'" { return MZN_INTERSECT_QUOTED; } 256"in" { return MZN_IN; } 257"'in'" { return MZN_IN_QUOTED; } 258"int" { return MZN_INT; } 259"let" { return MZN_LET; } 260"list" { return MZN_LIST; } 261"maximize" { yylval->bValue = false; return MZN_MAXIMIZE; } 262"minimize" { yylval->bValue = true; return MZN_MINIMIZE; } 263"mod" { return MZN_MOD; } 264"'mod'" { return MZN_MOD_QUOTED; } 265"not" { return MZN_NOT; } 266"'not'" { return MZN_NOT_QUOTED; } 267"of" { return MZN_OF; } 268"output" { return MZN_OUTPUT; } 269"opt" { return MZN_OPT; } 270"par" { return MZN_PAR; } 271"predicate" { return MZN_PREDICATE; } 272"record" { return MZN_RECORD; } 273"satisfy" { return MZN_SATISFY; } 274"set" { return MZN_SET; } 275"solve" { return MZN_SOLVE; } 276"string" { return MZN_STRING; } 277"subset" { return MZN_SUBSET; } 278"'subset'" { return MZN_SUBSET_QUOTED; } 279"superset" { return MZN_SUPERSET; } 280"'superset'" { return MZN_SUPERSET_QUOTED; } 281"symdiff" { return MZN_SYMDIFF; } 282"'symdiff'" { return MZN_SYMDIFF_QUOTED; } 283"test" { return MZN_TEST; } 284"then" { return MZN_THEN; } 285"tuple" { return MZN_TUPLE; } 286"type" { return MZN_TYPE; } 287"union" { return MZN_UNION; } 288"'union'" { return MZN_UNION_QUOTED; } 289"var" { return MZN_VAR; } 290"variant_record" { return MZN_VARIANT_RECORD; } 291"where" { return MZN_WHERE; } 292"xor" { return MZN_XOR; } 293"'xor'" { return MZN_XOR_QUOTED; } 294"+" { return MZN_PLUS; } 295"'+'" { return MZN_PLUS_QUOTED; } 296"-" { return MZN_MINUS; } 297"'-'" { return MZN_MINUS_QUOTED; } 298"*" { return MZN_MULT; } 299"'*'" { return MZN_MULT_QUOTED; } 300"/" { return MZN_DIV; } 301"'/'" { return MZN_DIV_QUOTED; } 302"^-1" { return MZN_POW_MINUS1; } 303"^" { return MZN_POW; } 304"'^'" { return MZN_POW_QUOTED; } 305"++" { return MZN_PLUSPLUS; } 306"'++'" { return MZN_PLUSPLUS_QUOTED; } 307"<>" { return MZN_ABSENT; } 308"<" { return MZN_LE; } 309"'<'" { return MZN_LE_QUOTED; } 310"<=" { return MZN_LQ; } 311"'<='" { return MZN_LQ_QUOTED; } 312">" { return MZN_GR; } 313"'>'" { return MZN_GR_QUOTED; } 314">=" { return MZN_GQ; } 315"'>='" { return MZN_GQ_QUOTED; } 316"==" { return MZN_EQ; } 317"'=='" { return MZN_EQ_QUOTED; } 318"=" { return MZN_EQ; } 319"'='" { return MZN_EQ_QUOTED; } 320"!=" { return MZN_NQ; } 321"'!='" { return MZN_NQ_QUOTED; } 322"->" { return MZN_IMPL; } 323"'->'" { return MZN_IMPL_QUOTED; } 324"<-" { return MZN_RIMPL; } 325"'<-'" { return MZN_RIMPL_QUOTED; } 326"<->" { return MZN_EQUIV; } 327"'<->'" { return MZN_EQUIV_QUOTED; } 328"\\/" { return MZN_OR; } 329"'\\/'" { return MZN_OR_QUOTED; } 330"/\\" { return MZN_AND; } 331"'/\\'" { return MZN_AND_QUOTED; } 332 333"~+" { return MZN_WEAK_PLUS; } 334"~*" { return MZN_WEAK_MULT; } 335"~=" { return MZN_WEAK_EQ; } 336"~-" { return MZN_WEAK_MINUS; } 337 338"'~"[+*=-]"'" { 339 yylval->sValue = strdup(yytext+1); 340 yylval->sValue[strlen(yytext)-2] = 0; 341 return MZN_IDENTIFIER; } 342 343"_objective" { yylval->sValue = strdup(yytext); return MZN_IDENTIFIER; } 344 345[A-Za-z][A-Za-z0-9_]* { 346 yylval->sValue = strdup(yytext); return MZN_IDENTIFIER; } 347"'"[^\\'\xa\xd\x0]*"'" { 348 yylval->sValue = strdup(yytext); return MZN_IDENTIFIER; } 349_[A-Za-z][A-Za-z0-9_]* { 350 MiniZinc::ParserState* parm = 351 static_cast<MiniZinc::ParserState*>(yyget_extra(yyscanner)); 352 if (parm->isFlatZinc) { 353 yylval->sValue = strdup(yytext); return MZN_IDENTIFIER; 354 } else { 355 return FLATZINC_IDENTIFIER; 356 } 357 } 358 359"\xE2\x88\x80" { yylval->sValue = strdup("forall"); return MZN_IDENTIFIER; } 360"\xE2\x88\x83" { yylval->sValue = strdup("exists"); return MZN_IDENTIFIER; } 361"\xE2\x88\x88" { return MZN_IN; } 362"\xE2\x8A\x86" { return MZN_SUBSET; } 363"\xE2\x8A\x87" { return MZN_SUPERSET; } 364"\xE2\x88\x9E" { return MZN_INFINITY; } 365"\xC2\xAC" { return MZN_NOT; } 366"\xE2\x86\x90" { return MZN_RIMPL; } 367"\xE2\x86\x92" { return MZN_IMPL; } 368"\xE2\x86\x94" { return MZN_EQUIV; } 369"\xE2\x88\xA7" { return MZN_AND; } 370"\xE2\x88\xA8" { return MZN_OR; } 371"\xE2\x89\xA0" { return MZN_NQ; } 372"\xE2\x89\xA4" { return MZN_LQ; } 373"\xE2\x89\xA5" { return MZN_GQ; } 374"\xE2\x88\xAA" { return MZN_UNION; } 375"\xE2\x88\xA9" { return MZN_INTERSECT; } 376"\xE2\x81\xBB\xC2\xB9" { return MZN_POW_MINUS1; } 377 378$$[A-Za-z][A-Za-z0-9_]* { 379 yylval->sValue = strdup(yytext+1); return MZN_TI_ENUM_IDENTIFIER; } 380 381$[A-Za-z][A-Za-z0-9_]* { 382 yylval->sValue = strdup(yytext+1); return MZN_TI_IDENTIFIER; } 383 384"(" { yy_push_state(bracket_exp,yyscanner); return *yytext; } 385<bracket_exp>")" { yy_pop_state(yyscanner); return *yytext; } 386<quoted_exp>")" { yy_pop_state(yyscanner); yy_pop_state(yyscanner); yy_push_state(string_quote,yyscanner); 387 ::MiniZinc::clearBuffer(yyget_extra(yyscanner)); } 388 389\" { yy_push_state(string,yyscanner); ::MiniZinc::clearBuffer(yyget_extra(yyscanner)); } 390<string,string_quote>[^\\"\xa\xd\x0]* { ::MiniZinc::appendBufferString(yyget_extra(yyscanner), yytext); } 391<string,string_quote>\\n { ::MiniZinc::appendBufferChar(yyget_extra(yyscanner), '\n'); } 392<string,string_quote>\\t { ::MiniZinc::appendBufferChar(yyget_extra(yyscanner), '\t'); } 393<string,string_quote>\\[\\'] { ::MiniZinc::appendBufferChar(yyget_extra(yyscanner), yytext[1]); } 394<string,string_quote>\\[\\"] { ::MiniZinc::appendBufferChar(yyget_extra(yyscanner), yytext[1]); } 395<string>\\"(" { yylval->sValue = ::MiniZinc::bufferData(yyget_extra(yyscanner)); 396 yy_push_state(quoted_exp,yyscanner); return MZN_STRING_QUOTE_START; } 397<string_quote>\\"(" { yylval->sValue = ::MiniZinc::bufferData(yyget_extra(yyscanner)); 398 yy_push_state(quoted_exp,yyscanner); return MZN_STRING_QUOTE_MID; } 399<string>\" { yylval->sValue = ::MiniZinc::bufferData(yyget_extra(yyscanner)); 400 yy_pop_state(yyscanner); return MZN_STRING_LITERAL; } 401<string_quote>\" { yylval->sValue = ::MiniZinc::bufferData(yyget_extra(yyscanner)); 402 yy_pop_state(yyscanner); return MZN_STRING_QUOTE_END; } 403<string,string_quote>. { return (unsigned char)yytext[0]; } 404<string,string_quote>[\xa\xd\x0] { return MZN_END_OF_LINE_IN_STRING; } 405<string,string_quote><<EOF>> { yy_pop_state(yyscanner); return MZN_UNTERMINATED_STRING; } 406 407`[A-Za-z][A-Za-z0-9_]*` { 408 yylval->sValue = strdup(yytext+1); 409 yylval->sValue[strlen(yytext)-2] = 0; 410 return MZN_QUOTED_IDENTIFIER; } 411 412. { return (unsigned char)yytext[0]; } 413 414%% 415namespace MiniZinc { 416 int yy_input_proc(char* buf, int size, yyscan_t yyscanner) { 417 MiniZinc::ParserState* parm = 418 static_cast<MiniZinc::ParserState*>(yyget_extra(yyscanner)); 419 return parm->fillBuffer(buf, size); 420 // work around warning that yyunput is unused 421 yyunput (0,buf,yyscanner); 422 } 423}