Пример #1
0
void printStack(stack* s){

  if(emptyStack(s) == 1){

    printf("\nThe stack is empty.\n");
    return;
  }
  stack* tempS = createStack();
  dnode* tempN = frontStack(s);
  data* d = createData(tempN->d->i1,tempN->d->i2,tempN->d->f1);
  while(emptyStack(s) != 1){

    tempN = frontStack(s);
    printData(tempN->d);
    d = createData(tempN->d->i1,tempN->d->i2,tempN->d->f1);
    pushStack(tempS,d);
    popStack(s);
  }
  while(emptyStack(tempS) != 1){

    tempN = frontStack(tempS);
    d = createData(tempN->d->i1,tempN->d->i2,tempN->d->f1);
    pushStack(s,d);
    popStack(tempS);
  }
  return;
}
Пример #2
0
void codeGenVardec(symbol* variable, astNode* root, symTab* symtab) {
	if(variable == NULL)
		return;
	/* Global variables allocation */
	if(variable->scope == S_GLOBAL) {
		if(variable->type == T_INT) {
			// print word
			fprintf(yyoutasm, "%s:\t.word %d\n", variable->id+1, 0);	// 0 is the initialization
		} else if(variable->type == T_ARRAY) {
			// print words of size array
			fprintf(yyoutasm, "%s:\t.word 0", variable->id+1);
			for(int i = 0; i < variable->argNb-1; i++)
				fprintf(yyoutasm, ", 0");
			fprintf(yyoutasm, "\n");
		}
		if(root->rightSibling != NULL && root->rightSibling->type == NULLNODE) { // End of globals declaration
			fprintf(yyoutasm, "\t.text\n");
			fprintf(yyoutasm, "\tj main\t\t\t# Directly jump to label main -> where we usually enter the program\n");
			fprintf(yyoutasm, "\tnop\n");
		}
	} /* Local avriables allocation on stack */
	else if(variable->scope != S_ARG){ 
		if(variable->type == T_ARRAY)
			pushStack(variable->argNb, symtab);
		else
			pushStack(1, symtab);
	}
}
Пример #3
0
int main(void)
{
	int i, n, data;
	stack *s, *t;

	while (scanf("%d", &n) != EOF) {
		s = (stack *)malloc(sizeof(stack));
		s->top = 0;

		for (i = 0; i < n; i ++) {
			scanf("%d", &data);
			pushStack(s, data);
		}

		t = sortStack(s);

		while (t->top > 0) {
			printf("%d ", t->seq[-- t->top]);
		}
		printf("\n");
		free(s);
		free(t);
	}

	return 0;
}
char* simplifyPath(char* path) {
    int len = strlen(path);
    if (!path || len < 2)   return path;
    Stack stack;
    if (*(path + len - 1) == '/') {
        len--;
        *(path + len) = '\0';
    }
    char *str = (char *)malloc(sizeof(char)* (len + 1));
    initStack(&stack, len);
    int status;
    while (status = getElem(&path, str)) {
        if (status == 1) {
            pushStack(&stack, str);
        } else if(status == 2){
            popStack(&stack);
        }
    }
    if (stack.top == 0) {
        stack.elem[0] = '/';
        stack.top = 1;
        stack.pos[stack.top] = 1;
    }
    stack.elem[stack.pos[stack.top]] = '\0';
    return stack.elem;
}
Пример #5
0
    void AbstractXULParser::startElement(const Poco::XML::XMLString & uri,
                                         const Poco::XML::XMLString & localName,
                                         const Poco::XML::XMLString & qname,
                                         const Poco::XML::Attributes & attributes)
    {
        try
        {
            if (mIgnores > 0)
            {
                mIgnores++;
                return;
            }

            Element * parent = getCurrentParentElement();
            AttributesMapping attr;
            getAttributes(attributes, attr);
            ElementPtr element;
            if (createElement(localName, parent, attr, element))
            {
                pushStack(element);
            }
            else
            {
                mIgnores++;
                ReportError("Element is null and will be ignored.");
                return;
            }
        }
        catch (const Poco::Exception & inExc)
        {
            ReportError(inExc.displayText());
        }
    }
Пример #6
0
int main (int argc, char *argv[]) {

  int i = 0;
  Stack *myStack = createStack();
  Node *n = NULL;

  if (myStack == NULL) {
    printf("main: Cannot create stack. Exiting!\n");
    return 0;
  }

  for (i = 0; i < 10; i++) {
    n = createNode(i);
    pushStack(myStack, n);
  }

  printStack(myStack);

  for (i = 0; i < 11; i++) {
    n = popStack(myStack);
    if (n == NULL) {
      printf("main: popped NULL!\n");
      printStack(myStack);
      break;
    }
    printf("main: popped %d\n", n->data);
    free(n);
    n = NULL;
    printStack(myStack);
  }

  return 0;
}
int main(void){

	int i, x;
	char array[] = {'(','(','a','+','b',')','+','(','(',
					'c','+','d',')',')',')'};

	size_t tam = sizeof(array) / sizeof(array[0]);

	tStack stack;

	creatStack(&stack);

	for(i=0; i<tam; i++){
		if(array[i] == '('){
			x = pushStack(&stack, array[i]);
		}
		if((array[i] == ')') && (i>0)){
			x = popStack(&stack);
		}
	}

	if(stack.size == 0){
		printf("\nAccepted\n");
	}
	else{
		printf("\nRejected\n");
	}

	printStack(&stack);


	system("pause");

	return 0;
}
Пример #8
0
Файл: vm.c Проект: vangroan/gc
void pushPair(VM* vm) {
    Object* obj = newObject(vm, ObjPair);
    obj->head = popStack(vm);
    obj->tail = popStack(vm);

    pushStack(vm, obj);
}
Пример #9
0
	void LuaState::foreachKey(std::function<void(std::string, LuaState&)> fun) {
		pushStack();
		while (lua_next(_L, -2) != 0) {
			fun(pullStack<std::string>(-2), *this);
			popStack();
		}

	}
Пример #10
0
bool Interpreter::endBlock()
{
	if(!mInBlock) return(false);
	mInBlock=false;
	mBlockJump=0;
	pushStack(Data::pointer(new BoolData(mBlockSuccess)));
	return(true);
}
Пример #11
0
void fillAreaWithNumber(Point point, int number){
    stackIndex = -1;
    pushStack(point);
    while(stackIndex >= 0){
        point = popStack();
        map[point.x][point.y] = 0;
        sea[point.x][point.y] = number;
        if(visited[point.x][point.y]) continue;
        visited[point.x][point.y] = 1;
        int i;
        for(i = 0; i < 8; i++){
            Point next = nextPoint(point, i);
            if(isValidPoint(next) && map[next.x][next.y] < 0){
                pushStack(next);
            }
        }
    }
}
Пример #12
0
	void LuaState::foreachIndex(std::function<void(int, LuaState&)> fun) {

		pushStack();
		while (lua_next(_L, -2) != 0) {
			fun(pullStack<int>(-2), *this);
			popStack();
		}

	}
Пример #13
0
int _delayExec( char *inActionCall, char *recoveryActionCall,
                char *delayCondition,  ruleExecInfo_t *rei ) {

    char *args[MAX_NUM_OF_ARGS_IN_ACTION];
    int i, argc;
    ruleExecSubmitInp_t *ruleSubmitInfo;
    /* char action[MAX_ACTION_SIZE]; */
    char tmpStr[NAME_LEN];
    bytesBuf_t *packedReiAndArgBBuf = NULL;
    char *ruleExecId;
    char *actionCall;


    RE_TEST_MACRO( "    Calling _delayExec" );

    actionCall = inActionCall;
    /* Get Arguments */
    actionCall = ( char * ) malloc( strlen( inActionCall ) + strlen( recoveryActionCall ) + 3 );
    sprintf( actionCall, "%s|%s", inActionCall, recoveryActionCall );
    args[1] = NULL;
    argc = 0;
    /* Pack Rei and Args */
    i = packReiAndArg( rei->rsComm, rei, args, argc, &packedReiAndArgBBuf );
    if ( i < 0 ) {
        if ( actionCall != inActionCall ) {
            free( actionCall );
        }
        return( i );
    }
    /* fill Conditions into Submit Struct */
    ruleSubmitInfo = ( ruleExecSubmitInp_t * ) mallocAndZero( sizeof( ruleExecSubmitInp_t ) );
    i  = fillSubmitConditions( actionCall, delayCondition, packedReiAndArgBBuf, ruleSubmitInfo, rei );
    if ( actionCall != inActionCall ) {
        free( actionCall );
    }
    if ( i < 0 ) {
        free( ruleSubmitInfo );
        return( i );
    }

    /* Store ReiArgs Struct in a File */
    i = rsRuleExecSubmit( rei->rsComm, ruleSubmitInfo, &ruleExecId );
    if ( packedReiAndArgBBuf != NULL ) {
        clearBBuf( packedReiAndArgBBuf );
        free( packedReiAndArgBBuf );
    }

    free( ruleSubmitInfo );
    if ( i < 0 ) {
        return( i );
    }
    free( ruleExecId );
    snprintf( tmpStr, NAME_LEN, "%d", i );
    i = pushStack( &delayStack, tmpStr );
    return( i );
}
Пример #14
0
void Java_java_lang_Object_hashCode(void)
{
    /* The following must be two lines:
     * objectHashCode can GC, and a compiler is allowed to assume that the
     * value of sp hasn't changed if it is all on one line.
     */
    OBJECT object = popStackAsType(OBJECT);
    long result = objectHashCode(object); /* this may GC */
    pushStack(result);
}
Пример #15
0
/* transforms the values string in a binary tree */
void createTree(char *values, int size)
{
    for (int i=0; i<size; i++)
    {
        NodeT *aux = createNode(*(values+i));
        if (isalpha(aux->value) || (aux->value=='#'))
        {
            pushStack(aux);
        }
        else if (strchr("+-*/", aux->value))
        {
            NodeT *node = createNode(aux->value);
            node->right = popStack();
            node->left = popStack();

            pushStack(node);
        }
    }
}
Пример #16
0
int main()
{
    StackT stack1;
    StackT *stackPtr1 = &stack1;
    initStack(stackPtr1);
    
    printf("Pushing 'A' 'B' 'C' 'D' onto stack1\n");
    pushStack(stackPtr1, 'A');
    pushStack(stackPtr1, 'B');
    pushStack(stackPtr1, 'C');
    pushStack(stackPtr1, 'D');
    
    printf("Popping and displaying all items from stack 1.\n");
    while(!isEmptyStack(stackPtr1))
        printf("%c ", popStack(stackPtr1));
    printf("\n\n");

    return 0;
}
Пример #17
0
/* make a stack of file and dir names with full path recursively out of the dirname given */
Stack makeDirStack(char *dirname, Stack stack)
{
    Stack stk = stack;
    DIR *dp;
    struct dirent *entry;
    if ((dp = opendir(dirname)) == NULL)          // Open the directory
    {
    	//dirname is fullpath to a file..add file to stack
    	if(!existsInStack(stk,dirname))
    	{
    		stk = pushStack(stk,dirname);
    	}
    	closedir(dp);
    	return stk;
	}
	else
	{
		//go through each file/dir in the opened directory
		//if dir empty -> return
		//if dir is a file -> add to stack
		//if dir -> recursively add to stack
		while ((entry = readdir(dp)))
		{
			if(strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0)
			{
				//add the directory path to the stack if it doesn't already exist
				if(!existsInStack(stk,dirname))
				{
					stk = pushStack(stk,dirname);
				}
				
				//recursively go into any directory except . or ..
				char directory[PATH_MAX];
				strcpy(directory,dirname);
				strcat(directory,"/");
				strcat(directory,entry->d_name);
				stk = makeDirStack(directory,stk);
			}
		}
		closedir(dp);
		return stk;
	}
}
Пример #18
0
bool isSameTree(TreeNode* p, TreeNode* q) {
    Stack stack_sp, stack_sq, *stack_p = &stack_sp, *stack_q = &stack_sq;
    initStack(stack_p);
    initStack(stack_q);
    while ((p || stack_p->top) && (q || stack_q)) {
        if (p && q) {
            pushStack(stack_p, p);
            pushStack(stack_q, q);
            p = p->left;
            q = q->left;
        } else if (!p && !q) {
            p = popStack(stack_p);
            q = popStack(stack_q);
            if (p->val != q->val)   return false;
            p = p->right;
            q = q->right;
        } else return false;
    }
    return (p == q) && (stack_p->top == stack_q->top);
}
Пример #19
0
JSValue Function::callFromC(JSValue* argsBegin, JSValue* argsEnd) {
    JSValue r;
    auto vm = JSVM::instance();
    auto frame = vm->topFrame();
    JSValue *ret = vm->pushStack(argsBegin, argsEnd);
    callFromVM(ret, ret + (argsEnd - argsBegin));
    execute(frame);
    r = *ret;
    vm->popStack(int(argsEnd - argsBegin));
    return r;
}
Пример #20
0
 yy_extra_type() {
   lineno = 1;
   terminated = false;
   used = false;
   short_tags = true;
   asp_tags = false;
   idx_expr = false;
   include_debug = false;
   has_doc_block = false;
   expecting_xhp_class_statements = false;
   pushStack();
 }
Пример #21
0
/* makes a stack for extract with all the argv provided */
Stack getExtractStack(int argc, char **argv, Stack stk)
{
	int i;
	for(i = 1; i < argc - ARCHIVE; i++)
	{
		char *path;
		path = stripSlashes(argv[i+ARCHIVE]);
		stk = pushStack(stk,path);
		free(path);
	}
	return stk;
}
Пример #22
0
//print stack.  You have to print from the stack. You can not call a print function from dlinklist
void printStack(struct stack *s)
{
//	struct data* tDta = NULL;
	struct stack *tS = createStack();

	while(!isEmptyStack(s))
	{
		struct data* tDta = top(s);
		printData(tDta);
		pushStack(tS,createData(tDta->v1,tDta->v2));
		popStack(s);
	}

	while(!isEmptyStack(tS))
	{
		struct data* tDta = top(tS);
		pushStack(s,createData(tDta->v1,tDta->v2));
                popStack(tS);
	}
	cleanStack(tS);
}
Пример #23
0
void pushStackAtIndex(void* val,size_t index, stack* s){
    assert(s!=NULL);
    if (index > s->length) {
        pushStack(val, s);
        return;
    }
    if (s->length == s->capacity) {
        expendeStack(s);
    }
    memmove((char*)s->value+(index+1)*s->elemSize, (char*)s->value+index*s->elemSize, (s->length-index)*s->elemSize);
    memcpy((char*)s->value+index*s->elemSize, val, s->elemSize);
    s->length++;
}
Пример #24
0
void
parallel_mandelbrot(struct mandelbrot_thread *args, struct mandelbrot_param *parameters)
{
#if LOADBALANCE == 1 // Use a stack
	
	if(args -> id == 0)
	{
		initStack();
	}
	pthread_barrier_wait(&thread_para_barrier);
	
	int i;
	int RowsPerThread = ROWS_PER_TASK;
	float threadsInv = (float)ROWS_PER_TASK / (float)mandelbrot_param.height;
	float irange = mandelbrot_param.upper_i - mandelbrot_param.lower_i;
	int tasksPerThread = (mandelbrot_param.height / ROWS_PER_TASK) / NB_THREADS;
	
	for(i = tasksPerThread * args -> id; i < tasksPerThread * (args -> id + 1); i ++)
	{
		struct mandelbrot_param tempParam = mandelbrot_param;
		tempParam.height = ROWS_PER_TASK;
		tempParam.lower_i = irange * threadsInv * (float)i + mandelbrot_param.lower_i;
		tempParam.upper_i = irange * threadsInv * (float)(i + 1) + mandelbrot_param.lower_i;
		pushStack(&tempParam, ROWS_PER_TASK * i);
	}
#endif
	
#if LOADBALANCE == 0
	int RowsPerThread = parameters -> height / NB_THREADS;
	float range = (float)RowsPerThread / (float)parameters -> height;
	
	float threadsInv = 1.0f / (float)NB_THREADS;
	float irange = parameters -> upper_i - parameters -> lower_i;
	
	struct mandelbrot_param tempParam = *parameters;
	tempParam.height = parameters -> height / NB_THREADS;
	tempParam.lower_i = irange * threadsInv * (float)args -> id + parameters -> lower_i;
	tempParam.upper_i = irange * threadsInv * (float)(args -> id + 1) + parameters -> lower_i;
	
	compute_chunk(&tempParam, RowsPerThread * args -> id, 0);
#endif
#if LOADBALANCE == 1
	while (1)
	{
		struct mandelbrot_param_offset* theParamOffset = popStack();
		if(theParamOffset == NULL)
			break;
		compute_chunk(&(theParamOffset -> theParam), theParamOffset -> heightOffset, 0);
	}
#endif
}
void akAnimationBlender::push(akAnimationPlayer* action, const akScalar& frames, int mode, int priority)
{
	akAnimationBlend act;
	act.setAnimationPlayer(action);

	if (m_stack.find(act) == UT_NPOS)
	{
		act.enable(true);
		act.setBlendFrames(frames);
		act.setMode(mode);
		act.setPriority(priority);
		pushStack(act);
	}
}
Пример #26
0
    void CPU::interrupt(InterruptType type)
    {
        if (f_I && type != NMI && type != BRK_)
            return;

        if (type == BRK_) //Add one if BRK, a quirk of 6502
            ++r_PC;

        pushStack(r_PC >> 8);
        pushStack(r_PC);

        Byte flags = f_N << 7 |
                     f_V << 6 |
                       1 << 5 | //unused bit, supposed to be always 1
          (type == BRK_) << 4 | //B flag set if BRK
                     f_D << 3 |
                     f_I << 2 |
                     f_Z << 1 |
                     f_C;
        pushStack(flags);

        f_I = true;

        switch (type)
        {
            case IRQ:
            case BRK_:
                r_PC = readAddress(IRQVector);
                break;
            case NMI:
                r_PC = readAddress(NMIVector);
                break;
        }

        m_skipCycles += 7;
    }
Пример #27
0
int main(int argc, char const *argv[])
{
	initStack(); //Set stack pointers
	int i;
	for (i = 0; i < MAX_STACK_SIZE; i++) //Fill stack from 0 to 4
		pushStack(i);

	int *popValue = popStack(); //Set pop value (first one in, last one out) (Again, it's 4 because we use ints, otherwise, we'd use index values)
	while(popValue != NULL) //Starting at newest value, pop value out to screen
	{
		printf("%d\n", *popValue);
		popValue = popStack();
	}
	return 0;
}
Пример #28
0
 yy_extra_type() {
   lineno = 1;
   terminated = false;
   used = false;
   short_tags = true;
   idx_expr = false;
   include_debug = false;
   has_doc_block = false;
   force_global_namespace = false;
   expecting_xhp_class_statements = false;
   hh_tags = false;
   return_all_tokens = false;
   insert_token = 0;
   pushStack();
 }
Пример #29
0
void codeGenFuncCall(astNode* root, symTab* symtab, char* id) {
	astNode* child = root->leftMostChild;
	short argNb = 0;
	pushStack(1, symtab); 	// Word reserved on the stack for return value 

	while(child->rightSibling != NULL) {
		if(child->rightSibling->type == EXPR) {	// Evaluate expressions of each parameter and push them onto the stack 
			computeExpression(child->rightSibling, symtab);
			argNb++;
		}
		child = child->rightSibling;
	}

	fprintf(yyoutasm, "\tjal %s\t\t# Jump to function %s and return address is next instruction\n", id, id);	// Inconditional jump to callee function
	fprintf(yyoutasm, "\tnop\n");
	popStack(argNb, symtab);	// Remove arguments. Top of the stack is now returned value
}
Пример #30
0
//非递归先序遍历
void peorder(csTree root) {
	stackStor s;
	csTree p;
	Initstack(&s);//初始化时如果是void 类型则要用二级指针 
	p=root;
	while(p!=NULL || IsEmpty(s)!=0) {
		
		if(p!=NULL) {
			printf("%c",p->data);
			pushStack(s,p);
			p=p->Firstchild;
		}
		 else {
		 	//中序非递归 printf("%c",p->data);
			p=popstack(s);
			p=p->Nextsibling;
		}
	}
}