• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ push函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中push函数的典型用法代码示例。如果您正苦于以下问题:C++ push函数的具体用法?C++ push怎么用?C++ push使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了push函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: display

//Called to update the display.
//You should call glutSwapBuffers after all of your rendering to display what you rendered.
//If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
void display()
{
	g_lights.UpdateTime();

	glm::vec4 bkg = g_lights.GetBackgroundColor();

	glClearColor(bkg[0], bkg[1], bkg[2], bkg[3]);
	glClearDepth(1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glutil::MatrixStack modelMatrix;
	modelMatrix.SetMatrix(g_viewPole.CalcMatrix());

	const glm::mat4 &worldToCamMat = modelMatrix.Top();
	LightBlock lightData = g_lights.GetLightInformation(worldToCamMat);

	glBindBuffer(GL_UNIFORM_BUFFER, g_lightUniformBuffer);
	glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(lightData), &lightData);
	glBindBuffer(GL_UNIFORM_BUFFER, 0);

	if(g_pScene)
	{
		glutil::PushStack push(modelMatrix);

		g_pScene->Draw(modelMatrix, g_materialBlockIndex, g_lights.GetTimerValue("tetra"));
	}

	{
		glutil::PushStack push(modelMatrix);
		//Render the sun
		{
			glutil::PushStack push(modelMatrix);

			glm::vec3 sunlightDir(g_lights.GetSunlightDirection());
			modelMatrix.Translate(sunlightDir * 500.0f);
			modelMatrix.Scale(30.0f, 30.0f, 30.0f);

			glUseProgram(g_Unlit.theProgram);
			glUniformMatrix4fv(g_Unlit.modelToCameraMatrixUnif, 1, GL_FALSE,
				glm::value_ptr(modelMatrix.Top()));

			glm::vec4 lightColor = g_lights.GetSunlightIntensity();
			glUniform4fv(g_Unlit.objectColorUnif, 1, glm::value_ptr(lightColor));
			g_pScene->GetSphereMesh()->Render("flat");
		}

		//Render the lights
		if(g_bDrawLights)
		{
			for(int light = 0; light < g_lights.GetNumberOfPointLights(); light++)
			{
				glutil::PushStack push(modelMatrix);

				modelMatrix.Translate(g_lights.GetWorldLightPosition(light));

				glUseProgram(g_Unlit.theProgram);
				glUniformMatrix4fv(g_Unlit.modelToCameraMatrixUnif, 1, GL_FALSE,
					glm::value_ptr(modelMatrix.Top()));

				glm::vec4 lightColor = g_lights.GetPointLightIntensity(light);
				glUniform4fv(g_Unlit.objectColorUnif, 1, glm::value_ptr(lightColor));
				g_pScene->GetCubeMesh()->Render("flat");
			}
		}

		if(g_bDrawCameraPos)
		{
			glutil::PushStack push(modelMatrix);

			modelMatrix.SetIdentity();
			modelMatrix.Translate(glm::vec3(0.0f, 0.0f, -g_viewPole.GetView().radius));

			glDisable(GL_DEPTH_TEST);
			glDepthMask(GL_FALSE);
			glUseProgram(g_Unlit.theProgram);
			glUniformMatrix4fv(g_Unlit.modelToCameraMatrixUnif, 1, GL_FALSE,
				glm::value_ptr(modelMatrix.Top()));
			glUniform4f(g_Unlit.objectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f);
			g_pScene->GetCubeMesh()->Render("flat");
			glDepthMask(GL_TRUE);
			glEnable(GL_DEPTH_TEST);
			glUniform4f(g_Unlit.objectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f);
			g_pScene->GetCubeMesh()->Render("flat");
		}
	}

	glutPostRedisplay();
	glutSwapBuffers();
}
开发者ID:Sand3r-,项目名称:gltut,代码行数:92,代码来源:Scene+Lighting.cpp


示例2: modify

 void
 modify(const_reference r_old, const_reference r_new)
 {
   erase(r_old);
   push(r_new);
 }
开发者ID:5432935,项目名称:crossbridge,代码行数:6,代码来源:native_priority_queue.hpp


示例3: Dijkstra

/** 
 * Constructor
 * 
 * @param n Node to start
 * @param is_min Whether this algorithm will search for min or max distance
 */
  Dijkstra(const Node &n, const bool is_min=true):
    m_min(is_min) { 
    push(n, n, 0); 
  }
开发者ID:Plantain,项目名称:XCSoar,代码行数:10,代码来源:Dijkstra.hpp


示例4: link

  /**
   * Add an edge (node-node-distance) to the search
   *
   * @param n Destination node to add
   * @param pn Predecessor of destination node
   * @param e Edge distance
   */
  void link(const Node &node, const Node &parent, const unsigned &edge_value = 1) {
#ifdef INSTRUMENT_TASK
    count_dijkstra_links++;
#endif
    push(node, parent, cur->second + adjust_edge_value(edge_value)); 
  }
开发者ID:galippi,项目名称:xcsoar,代码行数:13,代码来源:Dijkstra.hpp


示例5: restart

 /**
  * Resets as if constructed afresh
  *
  * @param n Node to start
  */
 void restart(const Node &node) {
   clear();
   push(node, node, 0);
 }
开发者ID:galippi,项目名称:xcsoar,代码行数:9,代码来源:Dijkstra.hpp


示例6: Counter

 // 'name' is the unique name for the instance of Counter being constructed.
 // This is what will be used as the key in the JSON endpoint.
 // 'window' is the amount of history to keep for this Metric.
 Counter(const std::string& name, const Option<Duration>& window = None())
   : Metric(name, window),
     data(new Data())
 {
   push(data->v);
 }
开发者ID:flixster,项目名称:mesos,代码行数:9,代码来源:counter.hpp


示例7: push

 Counter& operator += (int64_t v)
 {
   push(__sync_add_and_fetch(&data->v, v));
   return *this;
 }
开发者ID:flixster,项目名称:mesos,代码行数:5,代码来源:counter.hpp


示例8: main

/* reverse Polish calculator */
int main()
{
    int type;
    double op2;
    char s[MAXOP];

    while ((type = getop(s)) != EOF)
    {
        switch(type)
        {
            case NUMBER:
                push(atof(s));
                break;
            case NEGATIVE_NUMBER:
                push(-1 * atof(s));
                break;
            case '+':
                push(pop() + pop());
                break;
            case '*':
                push(pop() * pop());
                break;
            case '-':
                op2 = pop();
                push(pop() - op2);
                break;
            case '/':
                op2 = pop();
                if (op2 != 0.0)
                    push(pop() / op2);
                else
                    printf("error: zero divisor\n");
                break;
            case '%':
                op2 = pop();
                push((int)pop() % (int)op2);
                break;
            case '\n':
                //do nothing
                break;
            case POP:
                printf("\t%.8g\n", pop());
                break;
            case PEEK:
                printf("\t%.8g\n", peek());
                break;
            case DUPLICATE:
                dup();
                break;
            case SWAP:
                swap();
                break;
            case CLEAR:
                clear();
                break;
            default:
                printf("error: unknown command %s\n", s);
                break;  
        }
    }

    return 0; //return SUCCESS
}
开发者ID:AskDrCatcher,项目名称:kernighanC,代码行数:64,代码来源:ex4-4.c


示例9: mg_write

int mg_write(struct mg_connection *conn, const void *buf, size_t len) {
  return (int) push(NULL, conn->client.sock, (const char *) buf, (int64_t) len);
}
开发者ID:Metrological,项目名称:dial-reference,代码行数:3,代码来源:mongoose.c


示例10: dup

/* dup : duplicate top element and push it in the stack */
void dup(void)
{
    push(peek());
}
开发者ID:AskDrCatcher,项目名称:kernighanC,代码行数:5,代码来源:ex4-4.c


示例11: split_quoted

int
split_quoted (const char *s, int *argc, char *argv[], int argv_sz)
{
    char arg_buff[MAX_ARG_LEN]; /* current argument buffer */
    char *ap, *ae;              /* arg_buff current ptr & end-guard */
    const char *c;              /* current input charcter ptr */
    char qc;                    /* current quote character */
    enum states state;          /* current state */
    enum err_codes err;         /* error end-code */
    int flags;                  /* warning flags */

    ap = &arg_buff[0];
    ae = &arg_buff[MAX_ARG_LEN - 1];
    c = &s[0];
    state = ST_DELIM;
    err = ERR_OK;
    flags = 0;
    qc = SQ; /* silence compiler waring */

    while ( state != ST_END ) {
        switch (state) {
        case ST_DELIM:
            while ( is_delim(*c) ) c++;
            if ( *c == SQ || *c == DQ ) {
                qc = *c; c++; state = ST_QUOTE; 
                break;
            }
            if ( *c == EOS ) {
                state = ST_END;
                break;
            }
            if ( *c == BS ) {
                c++;
                if ( *c == NL ) {
                    c++;
                    break;
                }
                if ( *c == EOS ) {
                    state = ST_END; err = ERR_BS_AT_EOS;
                    break;
                }
            }
            /* All other cases incl. character after BS */
            save(); c++; state = ST_ARG;
            break;
        case ST_QUOTE:
            while ( *c != qc && ( *c != BS || qc == SQ ) && *c != EOS ) {
                save(); c++;
            }
            if ( *c == qc ) {
                c++; state = ST_ARG;
                break;
            }
            if ( *c == BS ) {
                assert (qc == DQ);
                c++;
                if ( *c == NL) {
                    c++;
                    break;
                }
                if (*c == EOS) {
                    state = ST_END; err = ERR_BS_AT_EOS;
                    break;
                }
                if ( ! is_dq_escapable(*c) ) {
                    c--; save(); c++;
                }
                save(); c++;
                break;
            }
            if ( *c == EOS ) {
                state = ST_END; err = ERR_SQ_OPEN_AT_EOS;
                break;
            }
            assert(0);
        case ST_ARG:
            if ( *c == SQ || *c == DQ ) {
                qc = *c; c++; state = ST_QUOTE;
                break;
            }
            if ( is_delim(*c) || *c == EOS ) {
                push();
                state = (*c == EOS) ? ST_END : ST_DELIM;
                c++;
                break;
            }
            if ( *c == BS ) {
                c++;
                if ( *c == NL ) {
                    c++;
                    break;
                }
                if ( *c == EOS ) {
                    state = ST_END; err = ERR_BS_AT_EOS;
                    break;
                }
            }
            /* All other cases, incl. character after BS */
            save(); c++;
            break;
//.........这里部分代码省略.........
开发者ID:JamesLinus,项目名称:LiteBSD-Ports,代码行数:101,代码来源:split.c


示例12: push

void Scene::Draw( glutil::MatrixStack &modelMatrix, int materialBlockIndex, float alphaTetra )
{
	//Render the ground plane.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.RotateX(-90);

		DrawObject(m_pTerrainMesh.get(), GetProgram(LP_VERT_COLOR_DIFFUSE), materialBlockIndex, 0,
			modelMatrix);
	}

	//Render the tetrahedron object.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(75.0f, 5.0f, 75.0f);
		modelMatrix.RotateY(360.0f * alphaTetra);
		modelMatrix.Scale(10.0f, 10.0f, 10.0f);
		modelMatrix.Translate(0.0f, sqrtf(2.0f), 0.0f);
		modelMatrix.Rotate(glm::vec3(-0.707f, 0.0f, -0.707f), 54.735f);

		DrawObject(m_pTetraMesh.get(), "lit-color", GetProgram(LP_VERT_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 1, modelMatrix);
	}

	//Render the monolith object.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(88.0f, 5.0f, -80.0f);
		modelMatrix.Scale(4.0f, 4.0f, 4.0f);
		modelMatrix.Scale(4.0f, 9.0f, 1.0f);
		modelMatrix.Translate(0.0f, 0.5f, 0.0f);

		DrawObject(m_pCubeMesh.get(), "lit", GetProgram(LP_MTL_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 2, modelMatrix);
	}

	//Render the cube object.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(-52.5f, 14.0f, 65.0f);
		modelMatrix.RotateZ(50.0f);
		modelMatrix.RotateY(-10.0f);
		modelMatrix.Scale(20.0f, 20.0f, 20.0f);

		DrawObject(m_pCubeMesh.get(), "lit-color", GetProgram(LP_VERT_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 3, modelMatrix);
	}

	//Render the cylinder.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(-7.0f, 30.0f, -14.0f);
		modelMatrix.Scale(15.0f, 55.0f, 15.0f);
		modelMatrix.Translate(0.0f, 0.5f, 0.0f);

		DrawObject(m_pCylMesh.get(), "lit-color", GetProgram(LP_VERT_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 4, modelMatrix);
	}

	//Render the sphere.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(-83.0f, 14.0f, -77.0f);
		modelMatrix.Scale(20.0f, 20.0f, 20.0f);

		DrawObject(m_pSphereMesh.get(), "lit", GetProgram(LP_MTL_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 5, modelMatrix);
	}
}
开发者ID:Sand3r-,项目名称:gltut,代码行数:69,代码来源:Scene.cpp


示例13: main

int main()
{
    int type;
    double op1, op2;
    char s[MAXOP];

    while ((type = getop(s)) != EOF) {
        switch (type) {
        case NUMBER:
            push(atof(s));
            break;
        case '+':
            push(pop() + pop());
            break;
        case '*':
            push(pop() * pop());
            break;
        case '-':
            op2 = pop();
            op1 = pop();
            if (op1 == 0.0)
                push(op2 * -1);
            else
                push(op1 - op2);
            break;
        case '/':
            op2 = pop();
            if (op2 != 0.0)
                push(pop() / op2);
            else
                printf("error: zero divisor\n");
            break;
        case '%':
            op2 = pop();
            push(fmod(pop(), op2));
            break;
        case 'c':
            op2 = pop();
            op1 = pop();
/**********************************************/
            v = op2;
/**********************************************/
            printf("%f\n", op2);
            push(op2);
            push(op1);
            break;
        case 's':
            push(sin(pop())); 
            break;
        case 'e':
            push(exp(pop()));
            break;
        case 'p':
            op2 = pop();
            push(pow(pop(), op2));
            break;
/*****************************************************/
        case 'v':
            push(v);
            break;
        case '\n':
            v = pop();
            printf("\t%.8g\n", v);
            break;
/*****************************************************/
        default:
            printf("error: unknown command %s\n", s);
            break;
        }
    }
    return 0;
}
开发者ID:kokosabu,项目名称:exercises,代码行数:72,代码来源:e06.c


示例14: DrawParthenon

void DrawParthenon(glutil::MatrixStack &modelMatrix)
{
	//Draw base.
	{
		glutil::PushStack push(modelMatrix);

		modelMatrix.Scale(glm::vec3(g_fParthenonWidth, g_fParthenonBaseHeight, g_fParthenonLength));
		modelMatrix.Translate(glm::vec3(0.0f, 0.5f, 0.0f));

		glUseProgram(UniformColorTint.theProgram);
		glUniformMatrix4fv(UniformColorTint.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
		glUniform4f(UniformColorTint.baseColorUnif, 0.9f, 0.9f, 0.9f, 0.9f);
		g_pCubeTintMesh->Render();
		glUseProgram(0);
	}

	//Draw top.
	{
		glutil::PushStack push(modelMatrix);

		modelMatrix.Translate(glm::vec3(0.0f, g_fParthenonColumnHeight + g_fParthenonBaseHeight, 0.0f));
		modelMatrix.Scale(glm::vec3(g_fParthenonWidth, g_fParthenonTopHeight, g_fParthenonLength));
		modelMatrix.Translate(glm::vec3(0.0f, 0.5f, 0.0f));

		glUseProgram(UniformColorTint.theProgram);
		glUniformMatrix4fv(UniformColorTint.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
		glUniform4f(UniformColorTint.baseColorUnif, 0.9f, 0.9f, 0.9f, 0.9f);
		g_pCubeTintMesh->Render();
		glUseProgram(0);
	}

	//Draw columns.
	const float fFrontZVal = (g_fParthenonLength / 2.0f) - 1.0f;
	const float fRightXVal = (g_fParthenonWidth / 2.0f) - 1.0f;

	for(int iColumnNum = 0; iColumnNum < int(g_fParthenonWidth / 2.0f); iColumnNum++)
	{
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3((2.0f * iColumnNum) - (g_fParthenonWidth / 2.0f) + 1.0f,
				g_fParthenonBaseHeight, fFrontZVal));

			DrawColumn(modelMatrix, g_fParthenonColumnHeight);
		}
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3((2.0f * iColumnNum) - (g_fParthenonWidth / 2.0f) + 1.0f,
				g_fParthenonBaseHeight, -fFrontZVal));

			DrawColumn(modelMatrix, g_fParthenonColumnHeight);
		}
	}

	//Don't draw the first or last columns, since they've been drawn already.
	for(int iColumnNum = 1; iColumnNum < int((g_fParthenonLength - 2.0f) / 2.0f); iColumnNum++)
	{
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3(fRightXVal,
				g_fParthenonBaseHeight, (2.0f * iColumnNum) - (g_fParthenonLength / 2.0f) + 1.0f));

			DrawColumn(modelMatrix, g_fParthenonColumnHeight);
		}
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3(-fRightXVal,
				g_fParthenonBaseHeight, (2.0f * iColumnNum) - (g_fParthenonLength / 2.0f) + 1.0f));

			DrawColumn(modelMatrix, g_fParthenonColumnHeight);
		}
	}

	//Draw interior.
	{
		glutil::PushStack push(modelMatrix);

		modelMatrix.Translate(glm::vec3(0.0f, 1.0f, 0.0f));
		modelMatrix.Scale(glm::vec3(g_fParthenonWidth - 6.0f, g_fParthenonColumnHeight,
			g_fParthenonLength - 6.0f));
		modelMatrix.Translate(glm::vec3(0.0f, 0.5f, 0.0f));

		glUseProgram(ObjectColor.theProgram);
		glUniformMatrix4fv(ObjectColor.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
		g_pCubeColorMesh->Render();
		glUseProgram(0);
	}

	//Draw headpiece.
	{
		glutil::PushStack push(modelMatrix);

		modelMatrix.Translate(glm::vec3(
			0.0f,
			g_fParthenonColumnHeight + g_fParthenonBaseHeight + (g_fParthenonTopHeight / 2.0f),
			g_fParthenonLength / 2.0f));
		modelMatrix.RotateX(-135.0f);
		modelMatrix.RotateY(45.0f);

		glUseProgram(ObjectColor.theProgram);
		glUniformMatrix4fv(ObjectColor.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
//.........这里部分代码省略.........
开发者ID:dustin-biser,项目名称:OpenGLTutorials,代码行数:101,代码来源:World+Scene.cpp


示例15: push

	void FloatAttributeUpdater::push(const float *value)
	{
		push(value,1);
	}
开发者ID:Frontier789,项目名称:Flib,代码行数:4,代码来源:FloatAttributeUpdater.cpp


示例16: display

//Called to update the display.
//You should call glutSwapBuffers after all of your rendering to display what you rendered.
//If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
void display()
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepth(1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if(g_pConeMesh && g_pCylinderMesh && g_pCubeTintMesh && g_pCubeColorMesh && g_pPlaneMesh)
	{
		const glm::vec3 &camPos = ResolveCamPosition();

		glutil::MatrixStack camMatrix;
		camMatrix.SetMatrix(CalcLookAtMatrix(camPos, g_camTarget, glm::vec3(0.0f, 1.0f, 0.0f)));

		glUseProgram(UniformColor.theProgram);
		glUniformMatrix4fv(UniformColor.worldToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(camMatrix.Top()));
		glUseProgram(ObjectColor.theProgram);
		glUniformMatrix4fv(ObjectColor.worldToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(camMatrix.Top()));
		glUseProgram(UniformColorTint.theProgram);
		glUniformMatrix4fv(UniformColorTint.worldToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(camMatrix.Top()));
		glUseProgram(0);

		glutil::MatrixStack modelMatrix;

		//Render the ground plane.
		{
			glutil::PushStack push(modelMatrix);

			modelMatrix.Scale(glm::vec3(100.0f, 1.0f, 100.0f));

			glUseProgram(UniformColor.theProgram);
			glUniformMatrix4fv(UniformColor.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
			glUniform4f(UniformColor.baseColorUnif, 0.302f, 0.416f, 0.0589f, 1.0f);
			g_pPlaneMesh->Render();
			glUseProgram(0);
		}

		//Draw the trees
		DrawForest(modelMatrix);

		//Draw the building.
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3(20.0f, 0.0f, -10.0f));

			DrawParthenon(modelMatrix);
		}

		if(g_bDrawLookatPoint)
		{
			glDisable(GL_DEPTH_TEST);
			glm::mat4 idenity(1.0f);

			glutil::PushStack push(modelMatrix);

			glm::vec3 cameraAimVec = g_camTarget - camPos;
			modelMatrix.Translate(0.0f, 0.0, -glm::length(cameraAimVec));
			modelMatrix.Scale(1.0f, 1.0f, 1.0f);
		
			glUseProgram(ObjectColor.theProgram);
			glUniformMatrix4fv(ObjectColor.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
			glUniformMatrix4fv(ObjectColor.worldToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(idenity));
			g_pCubeColorMesh->Render();
			glUseProgram(0);
			glEnable(GL_DEPTH_TEST);
		}
	}

	glutSwapBuffers();
}
开发者ID:dustin-biser,项目名称:OpenGLTutorials,代码行数:72,代码来源:World+Scene.cpp


示例17: main

/* reverse Polish calculator */
main()
{
	int type;
	double op2,temp;
	char s[MAXOP];
	while ((type = getop(s)) != EOF) {
		switch (type) {
			case NUMBER:
				push(atof(s));
				break;
			case '+':
				push(pop() + pop());
				break;
			case '*':
				push(pop() * pop());
				break;
			case '-':
				op2 = pop();
				push(pop() - op2);
				break;
			case '/':
				op2 = pop();
				if (op2 != 0.0)
					push(pop() / op2);
				else
					printf("error: zero divisor\n");
				break;
			case '%':
				op2=pop();
				if(op2!=0.0)
					push(fmod(pop(), op2));
				else
					printf("error :zero diviser\n");
				break;
			case '?':
				op2=pop();
				printf("the top value of the stack is: %g\n ",op2);
				push(op2);
				break;
			case 'd':
				op2=pop();
				push(op2);
				push(op2);
				break;
			case 's':
				op2=pop();
				temp=pop();
				push(op2);
				push(temp);
				break;
			case 'c':
				clear();
				break;
			case '\n':
				printf("\t%.8g\n", pop());
				break;
			default:
				printf("error: unknown command %s\n", s);
				break;
		}
	}
	return 0;
}
开发者ID:sirajmuneer123,项目名称:k-and-r,代码行数:64,代码来源:4-4.c


示例18: reset

 void reset()
 {
   push(__sync_and_and_fetch(&data->v, 0));
 }
开发者ID:flixster,项目名称:mesos,代码行数:4,代码来源:counter.hpp


示例19: getCommand

	bool Compiler::compile(std::istream& input)
	{
		mInput = &input;
		mInstructions.clear();

		std::stack<int> loopStack;
		char command;

		command = getCommand();
		while(command) {
			int move = 0;
			while(command and isMove(command)) {
				if(command == '>') {
					move++;
				} else {
					move--;
				}
				command = getCommand();
			}
			if(move != 0) {
				push(op_move);
				push(move);
			}

			int change = 0;
			while(command and isChange(command)) {
				if(command == '+') {
					change++;
				} else {
					change--;
				}
				command = getCommand();
			}
			if(change != 0) {
				push(op_change);
				push(change);
			}

			while(command and isIO(command)) {
				if(command == '.') {
					push(op_output);
				} else {
					push(op_input);
				}
				command = getCommand();
			}

			while(command and isLoop(command)) {
				if(command == '[') {
					loopStack.push(mInstructions.size());

					push(op_loop_begin);
					push(-1);
				} else {
					if(loopStack.empty()) {
						mError = "unopened ]";
						return false;
					} else {
						push(op_loop_end);
						mInstructions[loopStack.top() + 1].param = mInstructions.size();
						loopStack.pop();
					}
				}
				command = getCommand();
			}
		}

		if(not loopStack.empty()) {
			mError = "unclosed [";
			return false;
		}

		push(op_stop);

		return true;
	}
开发者ID:honzasp,项目名称:brainfuck,代码行数:76,代码来源:compiler.cpp


示例20: makeCommandStreamUtil

command_t
makeCommandStreamUtil(int (*get_next_byte) (void *),
		      void *get_next_byte_argument,
		      STATE *state)
{
  char **tokenPTR = checked_malloc(sizeof(char**));
  char *token = NULL;
  int len = 0;
  TOKENTYPE type;
  command_t command = NULL;
  char *input = NULL, *output = NULL;

  type = readNextToken(tokenPTR, &len, get_next_byte, get_next_byte_argument);
  if (type == NOT_DEFINED) {
    free(tokenPTR);
    return NULL;
  } else if (type == O_PAR) {
    token = "(";
  } else {
    token = *tokenPTR;
  }

  command = AllocateCommand();
  if (!command) {
    return NULL;
  }


  if (!strncmp(token, "then", 4)) {
    if (!(pop() == IF)) {
      printErr();
    }
    push(THEN);
    *state = THEN;
    goto ret_null;
  } else if (!strncmp(token, "done", 4)) {
    if (!(pop() == DO)) {
      printErr();
    }
    *state = DONE;
    CScount--;
    goto ret_null;
  } else if (!strncmp(token, "do", 4)) {
    STATE tmp = pop();
    if (!((tmp == WHILE) || (tmp == UNTIL))) {
      printErr();
    }
    push(DO);
    *state = DO;
    goto ret_null;
  } else if (!strncmp(token, "else", 4)) {
    if (!(pop() == THEN)) {
      printErr();
    }
    push(ELSE);
    *state = ELSE;
    goto ret_null;
  } else if (!strncmp(token, "fi", 4)) {
    STATE tmp = pop();
    if (!((tmp == THEN) || (tmp == ELSE))) {
      printErr();
    }
    CScount--;
    *state = FI;
    goto ret_null;
  } else if (!strncmp(token, ")", 1)) {
    CScount--;
    *state = CLOSE_PAR;
    goto ret_null;
  } else if (!strncmp(token, "if", 2)) {
    push(IF);
    CScount++;
    command = makeCommand(command, NULL, IF_COMMAND, input, output);
    free(tokenPTR);
    command->u.command[0] = makeCommandStreamUtil(get_next_byte,
						  get_next_byte_argument,
						  state);
    while (*state != THEN) {
      if (!makeCommandStreamUtil(get_next_byte,
				 get_next_byte_argument,
				 state)) {
	type = NOT_DEFINED;
	break;
      }
    }

    if (type == NOT_DEFINED && *state != THEN) {
      return NULL;
    }

    command->u.command[1] = makeCommandStreamUtil(get_next_byte,
						  get_next_byte_argument,
						  state);
    if (*state != ELSE && *state != FI) {
      // HANDLE error;
      ;
    } else if (*state == ELSE || (*state == FI && CScount)) {
	command->u.command[2] = makeCommandStreamUtil(get_next_byte,
						      get_next_byte_argument,
						      state);
//.........这里部分代码省略.........
开发者ID:robertabbott,项目名称:CS_111,代码行数:101,代码来源:read-command.c



注:本文中的push函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pushAddress函数代码示例发布时间:2022-05-30
下一篇:
C++ purple_url_encode函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap