Esempio n. 1
0
int main() {

	stack<string> myStack;

	if (myStack.isEmpty())
		cout << "int stack is empty" << endl << endl;
	else
		cout << "int stack is not empty" << endl << endl;
	
	myStack.push("roy");
	myStack.push("randy");
	myStack.push("justin");
	
	if (myStack.isEmpty())
		cout << "int stack is empty" << endl << endl;
	else
		cout << "int stack is not empty" << endl << endl;
	
	stack<string> myStack2 = myStack;
	
	cout << "test pops from original int stack" << endl;
	myStack.pop();
	showStack(myStack);
	
	cout << "show copied Stack, tests copy constructor" << endl;
	showStack(myStack2);

	myStack2.makeEmpty();
	showStack(myStack2);
	
	return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	int N = (argc < 2) ? 20 : atoi(argv[1]);
	if (N < 20) N = 20;
	Stack s = newStack();
	int i;
	char x[50];
	for (i = 0; i < N; i++) {
		if (random()%10 > 5) {
			if (!emptyStack(s)) {
				char *str = popFrom(s);
				printf("Remove %s\n",str);
				free(str);
			}
		}
		else {
			randomString(x);
			pushOnto(s,x);
			printf("Insert %s\n",x);
		}
		showStack(s);
	}
	disposeStack(s);
	return 0;
}
Esempio n. 3
0
int scripting_GetIntegerResult(int *i) {
	if(lua_isnumber(L, -1)) {
    *i = (int)lua_tonumber(L, -1);
		lua_pop(L, 1); /* restore stack */
		return 0;
	} else {
		showStack();
		return 1;
	}
}  
Esempio n. 4
0
int scripting_GetFloatResult(float *f) {
	if(lua_isnumber(L, -1)) {
    *f = (float) lua_tonumber(L, -1);
		lua_pop(L, 1); /* restore stack */
		return 0;
	} else {
		showStack();
    return 1;
	}
}  
Esempio n. 5
0
File: debug.c Progetto: fmccabe/cafe
static DebugWaitFor dbgShowStack(char *line, processPo p, termPo loc, insWord ins, void *cl) {
  methodPo mtd = p->prog;
  framePo fp = p->fp;
  ptrPo sp = p->sp;

  if (line[0] == '\n') {
    showAllStack(debugOutChnnl, p, mtd, fp, sp);
  } else
    showStack(debugOutChnnl, p, mtd, cmdCount(line, 1), fp, sp);

  resetDeflt("n");
  return moreDebug;
}
Esempio n. 6
0
void menu() {
	
	int option, input;
	
	printf("\n1. Push\n2. Pop\n3. Show Stack\n4. Exit\n\n");
	scanf("%d", &option);
	
	switch (option) {
		case 1: printf("\n\nInput: ");
			scanf("%d", &input);
			push(input);
			break;
		case 2: pop();
			break;
		case 3: showStack();	
			break;
		case 4: exit(0);
		default: printf("\nError: Please enter a valid option.\n");
	}

}
Esempio n. 7
0
	bool debugNext(Aggregate& a,Word& n,Word& i){
		if(debugLevel>=nestLevel && a){
l:		print(toString(a,tsAlsoName,i));
			showStack();
			tString s=getLine();
			for(obj c:s){
				switch(tolower(c.w)){
					case 'e':
						if(debugLevel<=nestLevel) ++debugLevel;break;
					case 'n':
						break;
					case 'x':
						--debugLevel;break;
					case 'b':
						if(i)--i;goto l;
					default:
						break;
				}
			}
		}
		return true;
	}
Esempio n. 8
0
void ET::interpretLoop(){	
	int cnt=0;
	while(!postClear(exitInterpretLoop)){
		//exS.print(L"exLvl: "+to_wstring(E.execution.l)+L":"+to_wstring(E.paren.l)+L" cnt:"+to_wstring(E.counter.l)+L" EX: "+to_wstring(exS.elements()));
		//stack.print(L"Stacks:"+to_wstring(stacks.elements())+L"  Stack:"+to_wstring(stack.elements())+L" ");
		//tracked(String,cmd,=NAPL( ));
		
		String s=getLine();
		
		if(s.elements()==0) 
			break;
		if(isHttpRequest(s))
			write("http request");
		interpret(s);
		std::stringstream ss;
			showStack(ss);
			ss<<std::dec<<"\n"<<std::setw(4)<<cnt++<<" E:"<<execution.l<<" P:"<<paren.l<<" C:"<<counter.l;
			ss<<" charL:"<<charLevel<<" charCounter:"<<charCounter;
			ss<<" exS:"<<exS.elements()<<" stacks:"<<stacks.elements()<<" \t"<<"n:"<<stack().elements()<<" "<<toString(stack())<<" || ";
			for(auto i:stack()) ss<<std::hex<<i<<" ";ss<<std::endl;
			//ss<<std::dec<<" freeMem="<<freeMem()<<" freeVectors="<<freeVectorsLU(freeObj)<<std::endl;
		write(ss);
	}
}
Esempio n. 9
0
File: vm.cpp Progetto: pangc/pvm
void VMachine::Execute(){
	int step=0;
	int index = -1;
	int index1,index2;
	ip = 0;
    void *op_lables[13];
    goto PREPARE;
LABEL_NOP:
    goto NEXT_INSTR;
LABEL_PUSH:
    operstack.push(instr[ip]._operand);
    goto NEXT_INSTR;
LABEL_POP:
     index = operstack.top();
     operstack.pop();
     FreeIndex.insert(index);
    goto NEXT_INSTR;
LABEL_GETTOP:
    index = operstack.top();
    goto NEXT_INSTR;
LABEL_JMP:
    step = instr[ip]._operand;
    goto NEXT_INSTR;
LABEL_IFJMP:
    index= operstack.top();
    operstack.pop();
    if(ObjTable[index].t == BOOLEAN)
        if(ObjTable[index].v.b ==1)
            step = instr[ip]._operand;
    goto NEXT_INSTR;
LABEL_ADD:
    index1 = operstack.top();
    operstack.pop();
    index2 = operstack.top();
    operstack.pop();
    if(ObjTable[index1].t != ObjTable[index2].t)
        vmerror("diffrent type to add\n");
    else{
        if(ObjTable[index1].t == NUMBER){
            ObjTable[index1].v.num = ObjTable[index1].v.num + ObjTable[index2].v.num;
            operstack.push(index1);
            FreeIndex.insert(index2);
        }
        else if(ObjTable[index1].t = STRING){
            ObjTable[index1].v.str = strcat(ObjTable[index1].v.str,ObjTable[index2].v.str);
            operstack.push(index1);
            FreeIndex.insert(index2);
        }
        else{
            vmerror("can not add this type\n");
        }
    }
    goto NEXT_INSTR;
LABEL_SUB:
    index1 = operstack.top();
    operstack.pop();
    index2 = operstack.top();
    operstack.pop();
    if(ObjTable[index1].t != ObjTable[index2].t)
        vmerror("diffrent type to add\n");
    else{
        if(ObjTable[index1].t == NUMBER){
            ObjTable[index1].v.num = ObjTable[index1].v.num + ObjTable[index2].v.num;
            operstack.push(index1);
            FreeIndex.insert(index2);
        }
        else{
            vmerror("can not add this type\n");
        }
    }
    goto NEXT_INSTR;
LABEL_MUL:
    index1 = operstack.top();
    operstack.pop();
    index2 = operstack.top();
    operstack.pop();
    if(ObjTable[index1].t != ObjTable[index2].t)
        vmerror("diffrent type to mul\n");
    else if(ObjTable[index1].t != NUMBER)
        vmerror("can not multiply non-numeric\n");
    else{
        ObjTable[index1].v.num = ObjTable[index1].v.num * ObjTable[index2].v.num;
        operstack.push(index1);
        FreeIndex.insert(index2);
    }
    goto NEXT_INSTR;
LABEL_DIV:
    index1 = operstack.top();
    operstack.pop();
    index2 = operstack.top();
    operstack.pop();
    if(ObjTable[index1].t != ObjTable[index2].t)
        vmerror("diffrent type to mul\n");
    else if(ObjTable[index1].t != NUMBER)
        vmerror("can not multiply non-numeric\n");
    else{
        ObjTable[index1].v.num = ObjTable[index1].v.num / ObjTable[index2].v.num;
        operstack.push(index1);
        FreeIndex.insert(index2);
    }
    goto NEXT_INSTR;
LABEL_EQ:
    index1 = operstack.top();
    operstack.pop();
    index2 = operstack.top();
    operstack.pop();
    if(ObjTable[index1].t != ObjTable[index2].t){
           vmerror("diffrent type");
    }
    else{
        switch(ObjTable[index1].t){
            case NUMBER:
                if(ObjTable[index1].v.num == ObjTable[index1].v.num)
                    PushBoolean(1);         //1表示真,压入栈vmstark
                else
                    PushBoolean(0);           //0表示假
                break;
            case STRING:
                if(strcmp(ObjTable[index1].v.str,ObjTable[index2].v.str)==0)
                    PushBoolean(1);
                else
                    PushBoolean(0);
                break;
            case BOOLEAN:
                if(ObjTable[index1].v.b == ObjTable[index1].v.b)
                    PushBoolean(1);         //1表示真,压入栈vmstark
                else
                    PushBoolean(0);           //0表示假
                break;
        }
    }
    goto NEXT_INSTR;
LABEL_LT:
    index1 = operstack.top();
    operstack.pop();
    index2 = operstack.top();
    operstack.pop();
    if(ObjTable[index1].t != ObjTable[index2].t){
           vmerror("diffrent type");
    }
    else{
        switch(ObjTable[index1].t){
            case NUMBER:
                if(ObjTable[index1].v.num < ObjTable[index1].v.num)
                    PushBoolean(1);         //1表示真,压入栈vmstark
                else
                    PushBoolean(0);           //0表示假
                break;
            case STRING:
                if(strcmp(ObjTable[index1].v.str,ObjTable[index2].v.str)<0)
                    PushBoolean(1);
                else
                    PushBoolean(0);
                break;
            case BOOLEAN:
                PushNil();
                break;
        }
    }
    goto NEXT_INSTR;
LABEL_GT:
    index1 = operstack.top();
    operstack.pop();
    index2 = operstack.top();
    operstack.pop();
    if(ObjTable[index1].t != ObjTable[index2].t){
           vmerror("diffrent type");
    }
    else{
        switch(ObjTable[index1].t){
            case NUMBER:
                if(ObjTable[index1].v.num > ObjTable[index1].v.num)
                    PushBoolean(1);         //1表示真,压入栈vmstark
                else
                    PushBoolean(0);           //0表示假
                break;
            case STRING:
                if(strcmp(ObjTable[index1].v.str,ObjTable[index2].v.str)>0)
                    PushBoolean(1);
                else
                    PushBoolean(0);
                break;
            case BOOLEAN:
                PushNil();
                break;
        }
    }
    goto NEXT_INSTR;
LABLE_UNKNOWN:
    vmerror("unknown opcode");
    goto NEXT_INSTR;
PREPARE:
    op_lables[0] = &&LABEL_NOP;
    op_lables[1] = &&LABEL_PUSH;
    op_lables[2] = &&LABEL_POP;
    op_lables[3] = &&LABEL_GETTOP;
    op_lables[4] = &&LABEL_JMP;
    op_lables[5] = &&LABEL_IFJMP;
    op_lables[6] = &&LABEL_ADD;
    op_lables[7] = &&LABEL_SUB;
    op_lables[8] = &&LABEL_MUL;
    op_lables[9] = &&LABEL_DIV;
    op_lables[10] = &&LABEL_EQ;
    op_lables[11] = &&LABEL_LT;
    op_lables[12] = &&LABEL_GT;
NEXT_INSTR:
    if(ip > 14) goto END;
    ip = ip+step;
    step = 1;
  //  showFree();
    showStack();
//    showObj();
    if(instr[ip]._opcode<256 || instr[ip]._opcode>(257+13)) goto LABLE_UNKNOWN;
    goto *op_lables[instr[ip]._opcode-257];
END:
	getchar();
}