Beispiel #1
0
    bool Expr::parseUnaryExpression() {
        PARSER_FLOW_TRACER();
        /* left associative */

        switch (ahead().type()) {
        case T_AT_SIGN:
            emitError("addr-of-operator unsupported");
            // ### @foo (addr-of operator)
            return false;

        case T_MINUS:
        case T_PLUS:
        case T_NOT: {
            Model::ExprUnary::Ptr result = new Model::ExprUnary;
            result->setUnaryOperator(tokenToUnary(ahead().type()));
            next();
            FAIL_IF_NOT(parsePrimaryExpression());
            result->setOperand(model());
            setModel(result);
            return true; }

        default:
            return parsePrimaryExpression();
        }
    }
Beispiel #2
0
    bool Expr::parseRelationalExpression() {
        PARSER_FLOW_TRACER();
        /* right associative */

        FAIL_IF_NOT(parseAdditiveExpression());

        switch(ahead().type()) {
        case T_LESS_THAN_EQUAL:
        case T_GREATER_THAN_EQUAL:
        case T_LEFT_ANGLE:
        case T_RIGHT_ANGLE:
        case T_EQUAL:
        case T_INEQUAL: {
            Model::ExprBinary::Ptr result = new Model::ExprBinary;
            result->setLeftOperand(model());
            result->setBinaryOperator(tokenToBinary(ahead().type()));

            next();
            FAIL_IF_NOT(parseAdditiveExpression());
            result->setRightOperand(model());

            setModel(result); }
        }

        return true;
    }
Beispiel #3
0
    bool Expr::parsePrimaryExpression() {
        PARSER_FLOW_TRACER();

        switch(ahead().type()) {
        case T_LEFT_PAREN: {
            REQUIRE_TOKEN(T_LEFT_PAREN);
            FAIL_IF_NOT(parseExpression());
            REQUIRE_TOKEN(T_RIGHT_PAREN);
            return true; }

        case T__NUMBER: {
            next();
            setModel(new Model::ExprConstNumber(current().number()));
            return true; }

        case T__STRING: {
            next();
            setModel(new Model::ExprConstString(QString::fromUtf8(current().text().constData())));
            return true; }

        case T__FLOAT:
            next();
            setModel(new Model::ExprConstDouble(current().numberFloat()));
            return true;

        case T__IDENTIFIER: {

            Model::Decl::Ptr decl = curCtx()->lookup(ahead().identifier());
            if (!decl) {
                emitError(QLatin1Literal("Unknown identifier: ") %
                          Model::Identifier(ahead().identifier()).toString());
                return false;
            }

            if (decl->type() == Model::oDeclConst) {
                next();

                Model::ExprConstConst::Ptr ecc = new Model::ExprConstConst;
                ecc->setDecl(decl.scast<Model::DeclConst>());
                setModel(ecc);

                return true;
            }

            LValue lvp(this);
            lvp.setOptions(LValue::AllowFunctionCall);
            FAIL_IF_NOT(lvp());

            Model::ExprLValue::Ptr elv = new Model::ExprLValue;
            elv->setLValue(lvp.model());
            setModel(elv);
            return true; }

        default:
            return false;
        }
    }
Beispiel #4
0
static bool scanFor(std::istream &in, const uint8_t * bytes, const unsigned len)
{
   std::vector<uint8_t> ahead(len); // the bytes matched
   
   in.read((char*)&ahead.front(), len);
   unsigned count = in.gcount();
   if (count < len) return false;
   
   unsigned offset=0; // the index mod len which we're in ahead
   
   do
   {
      bool found=true;
      for (unsigned i=0; i < len; i++)
      {
         if (ahead[(i+offset)%len] != bytes[i])
         {
            found=false;
            break;
         }
      }
      if (found)
         return true;
      
      ahead[offset++%len] = in.get();
      
   } while (!in.eof());
   return false;
}
Beispiel #5
0
void
MSEdge::initialize(const std::vector<MSLane*>* lanes) {
    assert(lanes != 0);
    myLanes = lanes;
    if (!lanes->empty()) {
        recalcCache();
    }
    if (myFunction == EDGEFUNCTION_DISTRICT) {
        myCombinedPermissions = SVCAll;
    }
    for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
        myWidth += (*i)->getWidth();
    }
    if (MSGlobals::gLateralResolution > 0 || MSGlobals::gLaneChangeDuration > 0) {
        SUMOReal widthBefore = 0;
        for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
            (*i)->setRightSideOnEdge(widthBefore, (int)mySublaneSides.size());
            MSLeaderInfo ahead(*i);
            for (int j = 0; j < ahead.numSublanes(); ++j) {
                mySublaneSides.push_back(widthBefore + j * MSGlobals::gLateralResolution);
            }
            widthBefore += (*i)->getWidth();
        }
    }
}
Beispiel #6
0
bool dfs(Node node, int step) {
  visited[node.x][node.y] = true;
  route[step] = mark[node.x][node.y];

  if (step == SIZE - 1) {
    for (int i = 0; i < SIZE; i++)
        printf("%d%c", route[i], i == SIZE - 1 ? '\n' : ' ');
    return true;
  } else {
    std::vector<Node> v;
    for (int i = 0; i < NEIGHBOR; i++) {
      Node cur(node.x + dx[i], node.y + dy[i]);
      if (valid(cur)) {
        for (int j = 0; j < NEIGHBOR; j++) {
          Node ahead(cur.x + dx[j], cur.y + dy[j]);
          if (valid(ahead))
            cur.next++;
        }
        v.push_back(cur);
      }
    }

    std::sort(v.begin(), v.end(), cmp);

    for (int i = 0; i < v.size(); i++) {
      visited[v[i].x][v[i].y] = true;
      if (dfs(v[i], step + 1))
        return true;
      visited[v[i].x][v[i].y] = false;
    }
    return false;
  }
}
Beispiel #7
0
    bool Expr::parseMultiplicativeExpression() {
        PARSER_FLOW_TRACER();
        /* right associative */

        FAIL_IF_NOT(parseUnaryExpression());

        while (IS_MULTI_EXPR_OPER(ahead().type())) {
            Model::ExprBinary::Ptr result = new Model::ExprBinary;
            result->setLeftOperand(model());
            result->setBinaryOperator(tokenToBinary(ahead().type()));

            next();
            FAIL_IF_NOT(parseUnaryExpression());
            result->setRightOperand(model());

            setModel(result);
        }

        return true;
    }
double_vector vavImage::GetRingB(double x, double y, double radius, int div)
{
	double_vector ans;
	double step = 360.0 / div;
	Vector2 ahead(0, -radius);
	for (int i = 0; i < div; ++i)
	{
		Vector2 move = Quaternion::GetRotation(ahead, i * step);
		ans.push_back(GetBilinearB(x + move.x, y + move.y));
	}
	return ans;
}
Beispiel #9
0
int main()
{
	int i;
	
	setup_movement();
	
	ahead();
	
	turn_right();

	turn_left();
}
double_vector vavImage::GetLineB(double x1, double y1, double x2, double y2,
								 int div)
{
	double_vector ans;
	double step = 1.0 / (div - 1);
	Vector2 ahead(x2 - x1, y2 - y1);
	ahead *= step;
	for (int i = 0; i < div; ++i)
	{
		ans.push_back(GetBilinearB(x1 +  ahead.x * i, y1 +  ahead.y * i));
	}
	return ans;
}
// Apply the camera's transformations to the world:
void Camera::applyTransform() {

    // Move world to match camera:
    GL::rotatePitch(-pitch);
    GL::rotateYaw(-yaw);
    GL::translate(-location);

    // Setup lighting:
    vec3 a = ahead(), l = location-40.*a-50.*vec3::Y();
    a-=vec3(0,a.y*0.2,0);
    X_SPOT_LT(1, RGB(240,240,200), l.x, l.y, l.z, a.x, a.y*0.5, a.z, 57);
    X_SPOT_LT(2, RGB(40,50,60), l.x, l.y, l.z, a.x, a.y*0.5, a.z, 70);
    X_FOG(RGB(0,0,0), true, 0.00045, 0);
}