hi , this is my first post here . I've wrote a program that uses <stack> header and I need to use a while operation in my code . the problem is when I use stack header operations like stack.pop() in the while it gives me errors when I run the program(it compiles without errors) . for example the code below gives me error :
"Debug assertion failed!
Expression: deque empty before pop"
the code that gives me this error is:
while(true){
stack.pop();
break;
}
anyone knows what's the problem .
thanks
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
#include <stack>
using namespace std;
#include <cctype>
#include <ctype.h>
//--------------------------------------------------------
//--------------------------------------------------------
char Action[6][6];
char Action2[6][6];
//----Grammer Rules
char arr1[]={'S','E','E'};
char arr2[]={'E','(','q'};
int Numfunc(char a){
int c;
switch(a){
case '0':
c=0;break;
case '1':
c=1;break;
case '2':
c=2;break;
case '3':
c=3;break;
case '4':
c=4;break;
case '5':
c=5;break;
}
return c;
}
char actionfunc(char a,char b){
int c;
int d;
switch(b){
case 'q':
c=0;break;
case '(':
c=1;break;
case ')':
c=2;break;
case '$':
c=3;break;
case 'S':
c=4;break;
case 'E':
c=5;break;
}
switch(a){
case '0':
d=0;break;
case '1':
d=1;break;
case '2':
d=2;break;
case '3':
d=3;break;
case '4':
d=4;break;
case '5':
d=5;break;
}
return Action[d][c];
}
char actionfunc2(char a,char b){
int d;
int c;
switch(b){
case 'q':
c=0;break;
case '(':
c=1;break;
case ')':
c=2;break;
case '$':
c=3;break;
case 'S':
c=4;break;
case 'E':
c=5;break;
}
switch(a){
case '0':
d=0;break;
case '1':
d=1;break;
case '2':
d=2;break;
case '3':
d=3;break;
case '4':
d=4;break;
case '5':
d=5;break;
}
return Action2[d][c];
}
and when I run the complete code it gives me no error in the compilation but gives me another error in the run :
"Debug Assertion Failed!
Program:f:\C++\test5\test4\Debug\test4.exe
File:j\program files\microsoft visual studio 9.0\vc\include\deque
Line: 202
Expression: ("_Myoff + _Off <= ((_Mydeque*)(this->Getmycont()))->_Myoff+((_Mydeque*)(this->_Getmycont()))->_Mysize&&_Myoff+ _Off >= ((_Mydeque*)(this->_Getmycont()))-> _Myoff",0)
Here is the first question that the program asked.
inter your lexeme: hello
I entered hello. I have no idea what a lexeme is so I don't have the slightest clue what to enter. So I just entered hello. The following while loop crashes because you are searching for a ; that obviously does not exist within the string. What are you trying to do here and how do you know that the user will enter a ';'?
Look at line 185. Now why would you call the top member function on a stack (mystack) that you just finished emptying? What do you think will happen when you call top on an empty stack object?