473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Visual 2010 giving debug assertion error

I am unable to find that which line number is causing that error....
Mar 27 '16 #1
2 3113
//here is my code


#include<iostream>
#include<conio.h>
#include<string>
#include<fstream>
using namespace std;
ifstream ifs("input.txt");
ofstream ofs("output.txt");
ofstream efs("error.txt");

class token{ //THIS CLASS CONATINS TOKEN
private:

string ttype;
string tvalue;
public:
token(){
ttype = "error";
tvalue = "\0";
}
void settoken(string type, string val){
ttype = type;
tvalue = val;
}

string gettype(){
return ttype;
}
void print(){

cout << "\ntoken found :" << "\t" << tvalue << "\t" << "Token Type:" << "\t" << ttype << "\n";
ofs << "\ntoken found :" << "\t" << tvalue << "\t" << "Token Type:" << "\t" << ttype << "\n";
}

};
class lexical{ //THIS CLASS CONTAINS ALL FUNCTIONALITIES TO BE PERFORMED
private:
token tokn[100]; //ARRAY CONTAINING ALL TOKENS
string table1[100]; //HASH TABLE ARRAY
string ttypes[6]; //BASIC TOKEN TYPES
int ind ;

public:
lexical(){
ind=0;
ttypes[0] = "Keyword" ;
ttypes[1] = "Comments" ;
ttypes[2] = "Operators" ;
ttypes[3] = "Number" ;
ttypes[4] = "ID" ;
ttypes[5] = "Braket" ;
}

void setchunk(string ch){ //BASIC FUNCTION THAT CREATES TOKEN

int i = 0,j,tf=0;
static int f = 0; //FLAG FOR MULTI LINE COMMENTS END
static int ln = 0; //LINE NO
ln++;
string str = ""; //IT CONTAINS ANY ID OR ERROR
while (i < ch.size()){ //THIS LOOP CHECKS ALL TOKEN TYPES EXCEPT ID BECAUSE ID CONFLICTS WITH KEYWORD
if (f != 1){
str = "";
tf = 0;
for (; i < ch.size(); i++)
{
if (iskeyword(str)){
tf = 1; //this variable is used for token indexing problems
str = "";
break;
}
if (iscomment(&ch[i], &i, &f)){
tf = 1;
break;
}
else if (isoperator(&ch[i], &i)){
tf = 1;
break;
}
if (isbraket(&ch[i])){
tf = 1;
i++;
break;
}
else if (isnumber(&ch[i], &i)){
tf = 1;
break;
}

else if (ch[i] == ' ' || ch[i] == '\t'){
i++;
break;
}
str = str + ch[i];
}
j = 0;
while (1){ //THIS LOOP CHECKS AND SAPARATES THE ID AND ERROR
if (isID(str, &j,tf)){}
if (str != "" &&str[j] != '\n'&&j != str.size()){ //CHECKS FOR ERROR
efs << "\n" << str[j] << "\t invalid char at Line no :" << "\t" << ln << "\n"; //put error in error file
j++;
}
else
break; //EXITS WHILE LOOP WHEN STRING IS EMPTY
}
}
else{ //ELSE FOR MULTI LINE COMMENTS FLAG

if (ch[i] == '*'&&ch[i + 1] == '/'){
f=iscomment(&ch[i], &i, &f);
f = 0;
i++;
}
i++;
}
}


}

int hash(string st){ //SIMPLE HASH FUNCTION
int sum = 0,i;
for (i = 0; i < st.size(); i++){
sum = sum + st[i];
}
i=(sum % 100);
return i;

}
bool iscomment(char *ch, int *ij, int *f){ //CHECK FOR COMMENT SINGLE LINE + MULTI LINE
string st = "";
int i = 0;
int state = 0;
if (*f == 1){
state = 6;
}
while (1){
switch (state){
case 0:
if (ch[i] == '/'){
i++;
state = 1;
}
else
return false;

break;

case 1:

if (ch[i] == '/'){

i++;
state = 2;
}
else if (ch[i] == '*'){
state = 4;
i++;
}
else
return false;
break;
case 2:

while (ch[i] != '\n'){
i++;
}
if (ch[i] == '\n'){
i++;
state = 3;
}
else
return false;
break;
case 3:

tokn[ind].settoken("Comments ", "//--------");
ind++;
*ij = *ij + i;
return true;
break;
case 4:

while (ch[i] != '*' && ch[i] != '\n'){
i++;
}
if (ch[i] == '*'){

i++;
state = 5;
}
else if (ch[i] == '\n'){
*f = 1;
*ij = *ij + i;
return true;
}
else
return false;
break;
case 5:

if (ch[i] == '/'){

i++;
state = 6;
}
else
state = 4;
break;
case 6:

tokn[ind].settoken("Comments ML", "/*--------*/");
ind++;
*ij = *ij + i;
return true;
break;

}
}
}
void keytbl(){ //ADDS ALL KEYWORDS TO HASH TABLE
string keyword[] = { "CONST", "FLOAT", "INT", "DEAN", "BREAK", "CONTINUE", "ELSE", "FOR", "SWITCH", "VOID", "CASE", "ENUM", "SIZEOF", "TYPEDEF", "CHAR", "DO", "IF", "RETURN", "UNION", "WHILE", "UCP", "HOD", "and", "or" };
int j = 0;

for (int i = 0; i < 24; i++){
j = hash(keyword[i]);
while (table1[j] != "\0"){
j++;
}
table1[j] = keyword[i];
}
}
bool isoperator(char *ch, int *ij){ //CHECKS FOR OPERATOR MATCH
string st, c;
int j = 0, f = 0;

string operators[] = { ">>>", "<<<", "|&","&|", "++", "--", "&&", "!=", "<>", ":=", "==", "*", "+", "/", "<", ">", "-", "+=","-=", ";","||" };
for (int i = 0; i < 21; i++){
st = operators[i];

for (int im=0; im < st.size(); im++){
if (ch[im] != st[im]){
f = 0;
break;
}
else
f = 1;
}
if (f == 1){
tokn[ind].settoken("operator", st);
ind++;
*ij = *ij + st.size();
return true;
}
}
return false;
}
bool isbraket(char *ch){ //CHECKS BRACKET
string st = "";
st = st + *ch;
char brakets[] = { '{', '}', '(', ')', '[', ']' ,'"','"' };
for (int i = 0; i < 8; i++){
if (brakets[i] == *ch){
tokn[ind].settoken("Braket", st);
ind++;
return true;
}
}
return false;
}

bool isnumber(char *ch, int *ij){ //CHECKS FOR NUMBER
int i = 0, state = 0;
string st = "";
while (1){
switch (state){
case 0:
if (isdigit(ch[i])){
st = st + ch[i];
i++;
state = 2;
}
else if (ch[i] == '.')
{
st = st + ch[i];
i++;
state = 1;
}
else
return false;
break;
case 1:
while (isdigit(ch[i])){
st = st + ch[i];
i++;
}
if (ch[i] == '.')
{
return false;
}
else
state = 5;
break;
case 2:
while (isdigit(ch[i])){
st = st + ch[i];
i++;
}
if (ch[i] == '.')
{
st = st + ch[i];
i++;
state = 3;
}
else
state = 5;
break;
case 3:
if (isdigit(ch[i]))
{
st = st + ch[i];
i++;
state = 4;
}
else
return false;
break;
case 4:
while (isdigit(ch[i])){
st = st + ch[i];
i++;
}
if (ch[i] == '.')
{
return false;
}
else
state = 5;
break;
case 5:
tokn[ind].settoken("Number", st);
ind++;
*ij = *ij + st.size();
return true;
break;
}
}
}
void printtkn(int *n){ //PRINTS ALL TOKENS IN ONE LINE

int i = *n+1;
if (i==1){ i = i - 1; }


for (; i < (ind ); i++){
tokn[i].print();
}
*n = i-1;
cout << "\n\n";
}
int isID(string ch, int *j,int tf){ //CHECKS ID MATCH
int i = *j, state = 1;
bool f = 0;
int dc=0; //Checks if atleast one digit is present in the ID
string st = "";
while (1){
switch (state){
case 1:
if (isletter(ch[i])){
st = st + ch[i];
i++;
state = 2;
}
else if (ch[i] == '_'){
st = st + ch[i];
i++;
state = 3;
}
else if(isdigit(ch[i]))
{

dc=1;

st = st + ch[i];
i++;
state = 2;
}
else{
*j = i;
return false;
}
break;
case 2:
while (isletter(ch[i]) || isdigit(ch[i])){
if(isdigit(ch[i]))
{
dc=1;
}
st = st + ch[i];
i++;
}
if (ch[i] == '_'){
st = st + ch[i];
i++;
state == 3;
}
else{
state = 4;
break;
}
case 3:

if (isletter(ch[i]) || isdigit(ch[i])){
if(isdigit(ch[i]))
{
dc=1;
}
st = st + ch[i];
i++;
state = 2;
}
else if (ch[i] == '_'){
*j = i;
return false;
}
else
state = 4;
break;
case 4:
int check=ch.size();
if(ch[check] == '_'|| dc==0)
{
*j = i;
return false;
}
else
{

if (tf == 1){
tokn[ind] = tokn[ind - 1];
tokn[ind - 1].settoken("ID", st);
}
else
tokn[ind].settoken("ID", st);
ind++;
*j = i;
return true;
}
}
}
}
bool isletter(char ch){
if ((('z' >= ch) && ('a' <= ch)) || (('Z' >= ch) && ('A' <= ch))){
return true;
}

return false;
}
bool isdigit(char ch){
char number[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
for (int v = 0; v < 10; v++){
if (ch == number[v]){
return true;
}
}
return false;
}

bool iskeyword(string ch){ //CHECKS FOR KEYWORD
string st, c;
if (ch != ""){
int j = hash(ch);
for (int i = 0; i < 4; i++){
st = table1[j];
if (ch == st){
tokn[ind].settoken("Keyword", st);
ind++;
return true;
}
j++;

}

}
return false;
}
};


void main()
{
lexical le;
static int n = 0; //for line by line token printing
int line = 0;
string strline;
le.keytbl(); //add all keywords in hash table
while (!ifs.eof())
{

getline(ifs, strline, '\n'); //reading one line of file
line++;
ofs << "---------\n";
ofs << line << "\n"; //printing line no
strline = strline + "\n";
if (strline[0] != '\n'){ //checking that line isn,t empty
cout << strline << "\n";
le.setchunk(strline);
le.printtkn(&n);
}
}
}
Mar 27 '16 #2
weaknessforcats
9,208 Expert Mod 8TB
Have you stepped through this code using your debugger?
Mar 28 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ellieong | last post by:
When i try to run my program, i get this error "debug assertion failed!" and it's caused by this file called "afxtempl.h" at line 262. isn't this header file provided by c++? so how can i get rid...
0
by: lawrence | last post by:
Hi, I made a MFC ActiveX with a CwinThread Class in VC ++. Then i used it on Visual basic. When i try to make an exe i got this error : Debug Assertion Failed! Program: C:\PROGRAM...
2
by: karspy | last post by:
In my COM Server i have added Dialog Box. i have registered OCX file and added that Activex Control to my Project also. It has created 1 header file and 1 source file. After that i have created...
0
by: jpl78 | last post by:
Hi, I'm new in visual studio... I have an application that is running well in c++, using MFClasses. Now, I'm trying to design a windows form to start the code, but it gaves me a "debug assertion...
4
by: Mullai | last post by:
Hi , My program gives an error message like this Debug Assertion Failed! program:................ File: wincore.cpp Line: 958 Please can anyone help me out in this issue. I have to solve...
2
by: Pushpa | last post by:
Hi All, This my part of the c++ program using threads in windows : //modified by pushpa struct structExrdDoc { CExrdDoc* spDoc; LPCTSTR sstrFileName;
1
by: sanjeevani | last post by:
Hi guyz, i am new to c++ programming..and this forum ...i just hope that i am giving you all the information which will enable you to figure out the problem. My program uses c++ and image...
0
by: =?Utf-8?B?REx1ZWNr?= | last post by:
I am getting a debug assertion error that reads: Debug Assertion Failed! program E:\program files\internet explorer\iexplore,exe File: dbgheap.c Line: 1252 Expression:...
1
by: jarret | last post by:
Hello all. First off, I am not a programmer so this question is not related to a problem that I created myself. I am not quite sure what is going on, but I do know that C++ is screwing up. Now I...
8
by: Alex T | last post by:
Hello, I am having a problem running my program with libcurl, What puzzles me is that this program works on Visual Studio 2010 on my computer running Windows XP, however when I try to run the same...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.