Example #1
0
void queens::range::RangeParser::parse() {
  YYStack  yystack;
  yystack.push(0);

  // Fetch until error (throw) or accept (return)
  while(true) {
    // Current lookahead
    YYSVal          yysval;
    unsigned short  yytok = nextToken(yysval);

    if(yytok <  YYINTERN)  yytok = yyintern[yytok];
    if(yytok >= YYINTERN)  error("Unknown Token");
#ifdef TRACE
    std::cerr << "Read " << yyterms[yytok] << std::endl;
#endif

    // Reduce until shift
    while(true) {
      signed short const  yyact = yyaction[*yystack][yytok];
      if(yyact == 0) {
        std::string                yymsg("Expecting (");
        signed short const *const  yyrow = yyaction[*yystack];
        for(unsigned  i = 0; i < 16; i++) {
          if(yyrow[i])  yymsg.append(yyterms[i]) += '|';
        }
        *yymsg.rbegin() = ')';
        error(yymsg.append(" instead of ").append(yyterms[yytok]));
        return;
      }
      if(yyact >  1) { // shift
#ifdef TRACE
        std::cerr << "Push " << yyterms[yytok] << std::endl;
#endif
        yystack.push(yyact, yysval);
        break;
      }
      else {           // reduce (includes accept)
        YYSVal                yylval;
        unsigned short const  yyrno = (yyact < 0)? -yyact : 0;
        unsigned short const  yylen = yylength[yyrno];
        
#ifdef TRACE
        std::cerr << "Reduce by " << yyrules[yyrno] << std::endl;
#endif
        switch(yyrno) { // do semantic actions
        case 0:         // accept
          return;
case 1: {
#line 166 "RangeParser.ypp"

          m_range = SRange::create(
	              std::static_pointer_cast<SAddress>(yystack[yylen - 1]),
		      std::static_pointer_cast<SAddress>(yystack[yylen - 1])
		    );
        
#line 371 "RangeParser.cpp"
break;
}
case 2: {
#line 172 "RangeParser.ypp"

          m_range = SRange::create(
	              std::static_pointer_cast<SAddress>(yystack[yylen - 1]),
		      std::static_pointer_cast<SAddress>(yystack[yylen - 3])
		    );
	
#line 382 "RangeParser.cpp"
break;
}
case 3: {
#line 178 "RangeParser.ypp"

          m_range = SRange::createSpan(
	              std::static_pointer_cast<SAddress>(yystack[yylen - 1]),
		      static_cast<SNumber const&>(*yystack[yylen - 4])
		    );
	
#line 393 "RangeParser.cpp"
break;
}
case 4: {
#line 184 "RangeParser.ypp"

          m_range = SRange::createSpan(
	              std::static_pointer_cast<SAddress>(yystack[yylen - 1]),
		      -static_cast<SNumber const&>(*yystack[yylen - 4])
		    );
	
#line 404 "RangeParser.cpp"
break;
}
case 5: {
#line 190 "RangeParser.ypp"

          m_range = SRange::createBiSpan(
	              std::static_pointer_cast<SAddress>(yystack[yylen - 1]),
		      static_cast<SNumber const&>(*yystack[yylen - 4])
		    );
        
#line 415 "RangeParser.cpp"
break;
}
case 6: {
#line 197 "RangeParser.ypp"

        yylval = SAddress::createFirst(SPredicate::TRUE);
       
#line 423 "RangeParser.cpp"
break;
}
case 7: {
#line 200 "RangeParser.ypp"

	yylval = SAddress::createFirst(std::static_pointer_cast<SPredicate>(yystack[yylen - 3]));
       
#line 431 "RangeParser.cpp"
break;
}
case 8: {
#line 203 "RangeParser.ypp"

	yylval = SAddress::createLast(SPredicate::TRUE);
       
#line 439 "RangeParser.cpp"
break;
}
case 9: {
#line 206 "RangeParser.ypp"

	yylval = SAddress::createLast(std::static_pointer_cast<SPredicate>(yystack[yylen - 3]));
       
#line 447 "RangeParser.cpp"
break;
}
case 10: {
#line 209 "RangeParser.ypp"

         uint64_t  spec = 0L;
	 unsigned  wild = 0;
	 buildSpec(spec, wild, *yystack[yylen - 2]);
	 buildSpec(spec, wild, *yystack[yylen - 4]);
	 buildSpec(spec, wild, *yystack[yylen - 7]);
	 buildSpec(spec, wild, *yystack[yylen - 9]);
	 buildSpec(spec, wild, *yystack[yylen - 12]);
	 buildSpec(spec, wild, *yystack[yylen - 14]);
	 buildSpec(spec, wild, *yystack[yylen - 17]);
	 buildSpec(spec, wild, *yystack[yylen - 19]);
	 yylval = SAddress::create(spec, wild);
       
#line 465 "RangeParser.cpp"
break;
}
case 11: {
#line 222 "RangeParser.ypp"

         yylval = SAddress::createOffset(SAddress::createFirst(SPredicate::TRUE),
				     static_cast<SNumber const&>(*yystack[yylen - 2]));
       
#line 474 "RangeParser.cpp"
break;
}
case 12: {
#line 226 "RangeParser.ypp"

         yylval = SAddress::createOffset(std::static_pointer_cast<SAddress>(yystack[yylen - 1]),
		                     static_cast<SNumber const&>(*yystack[yylen - 3]));
       
#line 483 "RangeParser.cpp"
break;
}
case 13: {
#line 230 "RangeParser.ypp"

         yylval = SAddress::createOffset(std::static_pointer_cast<SAddress>(yystack[yylen - 1]),
		                     -static_cast<SNumber const&>(*yystack[yylen - 3]));
       
#line 492 "RangeParser.cpp"
break;
}
case 14: {
#line 235 "RangeParser.ypp"
 yylval = SPredicate::TAKEN; 
#line 498 "RangeParser.cpp"
break;
}
case 15: {
#line 236 "RangeParser.ypp"
 yylval = SPredicate::SOLVED; 
#line 504 "RangeParser.cpp"
break;
}
case 16: {
#line 237 "RangeParser.ypp"

	yylval = SPredicate::createInverted(std::static_pointer_cast<SPredicate>(yystack[yylen - 2]));
       
#line 512 "RangeParser.cpp"
break;
}
case 17: {
#line 241 "RangeParser.ypp"

        int const  v = static_cast<SNumber const&>(*yystack[yylen - 1]);
	if((v < 0) || (26 < v)) {
	  error("Absolute position must be in the range [0, 27)");
	}
        yylval = yystack[yylen - 1];
      
#line 524 "RangeParser.cpp"
break;
}
case 18: {
#line 248 "RangeParser.ypp"
 yylval = std::make_shared<SNumber>(-1); 
#line 530 "RangeParser.cpp"
break;
}
        }
        
        yystack.pop(yylen);
        yystack.push(yygoto[*yystack][yylhs[yyrno]], yylval);
      }
    }
  }
}
Example #2
0
void q2d::quantor::Quantorizer::parse() {
  YYStack  yystack;
  yystack.push(0);

  // Fetch until error (throw) or accept (return)
  while(true) {
    // Current lookahead
    YYSVal          yysval;
    unsigned short  yytok = nextToken(yysval);

    if(yytok <  YYINTERN)  yytok = yyintern[yytok];
    if(yytok >= YYINTERN)  error("Unknown Token");
#ifdef TRACE
    std::cerr << "Read " << yyterms[yytok] << std::endl;
#endif

    // Reduce until shift
    while(true) {
      signed short const  yyact = yyaction[*yystack][yytok];
      if(yyact == 0) {
        std::string                yymsg("Expecting (");
        signed short const *const  yyrow = yyaction[*yystack];
        for(unsigned  i = 0; i < 15; i++) {
          if(yyrow[i])  yymsg.append(yyterms[i]) += '|';
        }
        *yymsg.rbegin() = ')';
        error(yymsg.append(" instead of ").append(yyterms[yytok]));
        return;
      }
      if(yyact >  1) { // shift
#ifdef TRACE
        std::cerr << "Push " << yyterms[yytok] << std::endl;
#endif
        yystack.push(yyact, yysval);
        break;
      }
      else {           // reduce (includes accept)
        YYSVal                yylval;
        unsigned short const  yyrno = (yyact < 0)? -yyact : 0;
        unsigned short const  yylen = yylength[yyrno];
        
#ifdef TRACE
        std::cerr << "Reduce by " << yyrules[yyrno] << std::endl;
#endif
        switch(yyrno) { // do semantic actions
        case 0:         // accept
          return;
case 1: {
#line 282 "Quantorizer.ypp"
 addClause((int)yystack[yylen - 1]); 
#line 423 "Quantorizer.cpp"
break;
}
case 2: {
#line 283 "Quantorizer.ypp"

        addClause( yystack[yylen - 1], -yystack[yylen - 3]);
        addClause(-yystack[yylen - 1],  yystack[yylen - 3]);
       
#line 432 "Quantorizer.cpp"
break;
}
case 3: {
#line 287 "Quantorizer.ypp"
 addClause(yystack[yylen - 2]); 
#line 438 "Quantorizer.cpp"
break;
}
case 4: {
#line 288 "Quantorizer.ypp"
 yylval = yystack[yylen - 1]; 
#line 444 "Quantorizer.cpp"
break;
}
case 5: {
#line 289 "Quantorizer.ypp"
 yylval = yystack[yylen - 1]; yylval.add(yystack[yylen - 3]); 
#line 450 "Quantorizer.cpp"
break;
}
case 6: {
#line 291 "Quantorizer.ypp"

        unsigned const  res = makeAuxiliary();
        addClause( res, -yystack[yylen - 1], -yystack[yylen - 3]);
        addClause(-res,  yystack[yylen - 1]);
        addClause(-res,  yystack[yylen - 3]);
        yylval = res;
       
#line 462 "Quantorizer.cpp"
break;
}
case 7: {
#line 298 "Quantorizer.ypp"

        unsigned const  res = makeAuxiliary();
        addClause(-res,  yystack[yylen - 1], yystack[yylen - 3]);
        addClause( res, -yystack[yylen - 1]);
        addClause( res, -yystack[yylen - 3]);
        yylval = res;
       
#line 474 "Quantorizer.cpp"
break;
}
case 8: {
#line 305 "Quantorizer.ypp"

        unsigned const  res = makeAuxiliary();
        addClause(-res, -yystack[yylen - 1], -yystack[yylen - 3]);
        addClause(-res,  yystack[yylen - 1],  yystack[yylen - 3]);
        addClause( res, -yystack[yylen - 1],  yystack[yylen - 3]);
        addClause( res,  yystack[yylen - 1], -yystack[yylen - 3]);
        yylval = res;
       
#line 487 "Quantorizer.cpp"
break;
}
case 9: {
#line 313 "Quantorizer.ypp"

        unsigned const  res = makeAuxiliary();
        addClause(-res, -yystack[yylen - 1], -yystack[yylen - 3]);
        addClause( res,  yystack[yylen - 1]);
        addClause( res,  yystack[yylen - 3]);
        yylval = res;
       
#line 499 "Quantorizer.cpp"
break;
}
case 10: {
#line 320 "Quantorizer.ypp"

        unsigned const  res = makeAuxiliary();
        addClause( res,  yystack[yylen - 1], yystack[yylen - 3]);
        addClause(-res, -yystack[yylen - 1]);
        addClause(-res, -yystack[yylen - 3]);
        yylval = res;
       
#line 511 "Quantorizer.cpp"
break;
}
case 11: {
#line 327 "Quantorizer.ypp"

        unsigned const  res = makeAuxiliary();
        addClause( res, -yystack[yylen - 1], -yystack[yylen - 3]);
        addClause( res,  yystack[yylen - 1],  yystack[yylen - 3]);
        addClause(-res, -yystack[yylen - 1],  yystack[yylen - 3]);
        addClause(-res,  yystack[yylen - 1], -yystack[yylen - 3]);
        yylval = res;
       
#line 524 "Quantorizer.cpp"
break;
}
case 12: {
#line 335 "Quantorizer.ypp"
 yylval = yystack[yylen - 1]; 
#line 530 "Quantorizer.cpp"
break;
}
case 13: {
#line 337 "Quantorizer.ypp"
 yylval =  yystack[yylen - 1]; 
#line 536 "Quantorizer.cpp"
break;
}
case 14: {
#line 338 "Quantorizer.ypp"
 yylval = -yystack[yylen - 2]; 
#line 542 "Quantorizer.cpp"
break;
}
case 15: {
#line 339 "Quantorizer.ypp"
 yylval =  yystack[yylen - 2]; 
#line 548 "Quantorizer.cpp"
break;
}
        }
        
        yystack.pop(yylen);
        yystack.push(yygoto[*yystack][yylhs[yyrno]], yylval);
      }
    }
  }
}