Hi guys

I have programming language project to write parser for grammar

and i found this source code in the net and it's really worked with out error

but the problem is

the program should take the input from text file called "f.txt" and check it's syntax

if ok the program says "SUCCESS" if not will says "PARSER ERROR"

and my program when I compile it, always says "PARSER ERROR"

My QUESTION is how to make the program says "SUCCESS"

my code below

Code:
#include "stdafx.h"
#include <fstream>
#include <iostream>
using namespace std;
#include <ctype.h>
#include <stdio.h>
#include <cstring>

int counter;
char word[20], x;


typedef enum {UNDEF, TYPE, START, ELSE ,EOI, LEFTSET, RIGHTSET, OR, NOT, AND, TRUE, FALSE, ANDSYMBOL, RETURN, COMME, NOTEQUAL, GREATEREQUAL, LESSEQUAL, GREATER, LESS, PLUS, TIMES, EQUAL, COMMA, DIVISION, MINUS, LPAREN, RPAREN, EOL, NUMBER, ERROR, IDENTIFIER, SEMICOLON, IF, WHILE} TokenType;
int numval;
bool retflag = false;
char curr_char = '#';
fstream f, out;


TokenType Token;
TokenType Token2 = UNDEF;
void Parameterlist();
void Parameterlist2();
void Nexpr();
void Term();
void Factor();
void Bcond();
void Bterm();
void Bfactor();
void Whilestat();
void Ifstat();
void Stat();
void Statlist();
TokenType getToken( fstream& f)
{
	int co = 0;
	bool num, chr, done;
	if ( curr_char == '#' || curr_char == ' ' || curr_char == '\n' || curr_char == 9)
	{
		do{
			f.get(curr_char);
		}while( (curr_char == 10 && !f.eof()) || (  curr_char == 9 && !f.eof() ) );
		/*while(  curr_char == 9 && !f.eof() ){
			f.get(curr_char);
		}*/
	}
	done = false;
	
	
	while (  curr_char != '!' && curr_char != ' ' && curr_char != '=' && curr_char != ';' && curr_char != '+' && curr_char != '-' && curr_char != '/' && curr_char != '*' && curr_char != '(' && curr_char != ')' && curr_char != '&' && curr_char != '|' && curr_char != ',' && curr_char != '<' && curr_char != '>' && curr_char != '{' && curr_char != '}' && !f.eof() && (curr_char != '\n'))
	{
		word[co] = curr_char;
		co++;
		f.get(curr_char);
	}
	if ( co == 0 )
	{
		x = curr_char;
		counter = 0;
		f.get(curr_char);
	}
	else
		word[co] = '\0';
		counter = 1;
	num = true;
	if ( (word[0] >= 48) && (word[0] <= 57) )
	{
		for (int i=0; i < co; i++)
			if ( (word[i] < 48) || (word[i] > 57) ) 
				num = false;
	}
	else
		num = false;
	if ( num == true )
	{
		done = true;
		return NUMBER;
	}
	if ( strcmp(word,"START") == 0)
	{
		done = true;
		return START;
	}
	
	
	
	if ( (strcmp(word,"int") == 0) || (strcmp(word,"char") == 0) || (strcmp(word,"double") == 0) || 
										(strcmp(word,"string") == 0) || (strcmp(word,"bool") == 0	)  )
	{
		done = true;
		return TYPE;
	}
	if ( (strcmp(word,"if") == 0))
	{
		done = true;
		return IF;
	}
	if ( (strcmp(word,"while") == 0))
	{
		done = true;
		return WHILE;
	}
	if ( (strcmp(word,"else") == 0)  )
	{
		done = true;
		return ELSE;
	}
	if ( (strcmp(word,"true") == 0)   )
	{
		done = true;
		return TRUE;
	}
	if ( (strcmp(word,"false") == 0)  )
	{
		done = true;
		return FALSE;
	}
if ( (strcmp(word,"return") == 0)  )
	{
		done = true;
		return RETURN;
	}
	if ( (word[0] >= 97) && (word[0] <= 122) )
	{
		chr = true;
		for (int i=1; i<co; i++)
			if ( ispunct(word[i])== true )
				chr = false;
		if ( chr == true )
		{
			done = true;
			return IDENTIFIER;
		}
	}
	switch(x)
	{
	case '(':
		done = true;
		return LPAREN;
		break;
	case ')':
		done = true;
		return RPAREN;
		break;
	case '<':
		if ( curr_char == '=' )
		{
			f.get(curr_char);
			done = true;
			return LESSEQUAL;
		}
		else
		{	
			done = true;
			return LESS;
		}
		break;
	case '>':
		if ( curr_char == '=' )
		{
			f.get(curr_char);
			done = true;
			return GREATEREQUAL;
		}
		else
		{	
			done = true;
			return GREATER;
		}
		break;
	case ';': 
		done = true;
		return SEMICOLON;
		break;
	case '+': 
		done = true;
		return PLUS;
		break;
	case '-':
		done = true;
		return MINUS;
		break;
	case '*': 
		done = true;
		return TIMES;
		break;
	case '/':
		done = true;
		return DIVISION;
		break;
	case '=':
		done = true;
		return EQUAL;
		break;
	/*case 10:
		done = true;
		return EOL;
		break;*/
	case '{':
		done = true;
		return LEFTSET;
		break;
	case '}':
		done = true;
		return RIGHTSET;
		break;
	case ',':
		done = true;
		return COMME;
		break;
	case '&':
		done = true;
		return AND;
		break;
	case '|':
		done = true;
		return OR;
		break;
	case '!':
		if ( curr_char == '=' )
		{
			f.get(curr_char);
			done = true;
			return NOTEQUAL;
		}
		else
		{	
			done = true;
			return NOT;
		}
		break;
	default: break;
	}
	if ( done == false && !f.eof())
		return ERROR;
	else
		return EOI;
}

void Error()
{
	cout << " PARSER ERROR \n";
	exit(1);
}


void match(TokenType t) {
	if ( Token2 != UNDEF ){
		Token = Token2;
		Token2 = UNDEF;
		if (Token != t)
		{
		    Error();
			return;
		}
	}
	else 
		if (Token == t)
	{
/////////////////////////////////////
	
		if (counter ==1)
		{

			if(Token == TYPE)
			{
				if(strcmp(word,"int"))
				out<<"int";
				else if(strcmp(word,"char"))
				out<<"char";
			else if(strcmp(word,"double"))
				out<<"double";
			else if(strcmp(word,"string"))
				out<<"string";
			else if(strcmp(word,"bool"))
				out<<"bool";
			}
			else if(Token == START)
				out<<"void main()";
			else if(Token == ELSE)
				out<<"else";
			else if(Token == LEFTSET)
				out<<"{";
			else if(Token == RIGHTSET)
				out<<"}";
			else if(Token == OR)
				out<<"||";
			else if(Token == NOT)
				out<<"!";
			else if(Token == AND)
				out<<"&&";
			else if(Token == TRUE)
				out<<"true";
			else if(Token == FALSE)
				out<<"false";
			else if(Token == ANDSYMBOL)
				out<<"&";
			else if(Token == RETURN)
				out<<"return";
			else if(Token == COMME)
				out<<",";
			else if(Token == NOTEQUAL)
				out<<"!=";
			else if(Token == GREATEREQUAL)
				out<<">=";
			else if(Token == LESSEQUAL)
				out<<"<=";
			else if(Token == GREATER)
				out<<">";
			else if(Token == LESS)
				out<<"<";
			else if(Token == PLUS)
				out<<"+";
			else if(Token == TIMES)
				out<<"*";
			else if(Token == EQUAL)
				out<<"=";
			else if(Token == DIVISION)
				out<<"/";
			else if(Token == MINUS)
				out<<"-";
			else if(Token == LPAREN)
				out<<"(";
			else if(Token == RPAREN)
				out<<")";
			else if(Token == EOL)
				out<<"cout<<endl;";
			else if(Token == NUMBER)
				out<<word;
			else if(Token == IDENTIFIER)
				out<<word;
			else if(Token == SEMICOLON)
				out<<";";
			else if(Token == IF)
				out<<"if";
			else if(Token == WHILE)
				out<<"while";			
		}
/////////////////////////////////////////
		else
			if(counter == 0)
			{
				out<<x;
			}


		do {
		Token = getToken(f);
		}while ( Token == EOL );
	}
	else  
		Error();
} 

void initscanner() 
{


ofstream out;
out.open ("out.txt");


	f.open("f.txt");
	if ( f.fail())
	{
		cout << "File not loaded\n";
		exit(1);
	}

}
void finish() 
{
	f.close();

}
void Dec() 
{
	match(TYPE);
	match(IDENTIFIER);
	match(SEMICOLON);
}

void Declist() 
{
	Dec(); 
	while ( Token == TYPE )
		Dec();
}

void Factor() 
{
	if ( Token == NUMBER )
		match(NUMBER);
	else if ( Token == TRUE )
		match(TRUE);
	else if ( Token == FALSE )
		match(FALSE);
	else{
		match(IDENTIFIER);
		if ( Token == LPAREN )
		{
			match(LPAREN);
			Parameterlist();
			match(RPAREN);
		}
		
	}
}

void Term() 
{
	Factor();
	while( Token == TIMES || Token == DIVISION )
	{
		match(Token);
		Factor();
	}
}

void Nexpr() 
{
	Term();
	while ( Token == PLUS || Token == MINUS )
	{
		match(Token);
		Term();
	}
}
void Parameterlist() 
{
	Nexpr();
	while( Token == COMME )
	{
		match(COMME);
		Nexpr();
	}
		
}
void Relation() 
{
	if ( Token == NOTEQUAL )
		match(NOTEQUAL);
	else
		if (Token == EQUAL )
			match(EQUAL);
		else
			if (Token == GREATEREQUAL )
				match(GREATEREQUAL);
			else
				if (Token == LESSEQUAL)
					match(LESSEQUAL);
				else
					if (Token == GREATER)
						match(GREATER);
					else
						match(LESS);
}
void Bexpr() 
{
	Nexpr();
	Relation();
	Nexpr();
}
void Bfactor() 
{
	if ( Token == TRUE )
		match(TRUE);
	else if ( Token == FALSE)
			match (FALSE);
	else if ( Token == LPAREN)
			{
				Bcond();
				match(RPAREN);
			}
	else  {
			Nexpr();
			Relation();
			Nexpr();
	}
}

void Bterm() 
{
	if ( Token == NOT)
	{
		match(NOT);
		Bterm();
	}
	else
	{
		Bfactor();
		while ( Token == AND )
		{
			match(AND);
			Bfactor();
		}
	}
}
void Bcond() 
{
	Bterm();
	while( Token == OR )
	{
		match(OR);
		Bterm();
	}
}

void Ifstat() 
{
	match(IF);
	match(LPAREN);
	Bcond();
	match(RPAREN);
	match(LEFTSET);
	Statlist();
	match(RIGHTSET);
	if ( Token == ELSE )
	{
		match(ELSE);
		match(LEFTSET);
		Statlist();
		match(RIGHTSET);
	}
}
void AssignmentStat() 
{
	match(IDENTIFIER);
	match(EQUAL);
	Nexpr();
	match(SEMICOLON);
}
void Whilestat() 
{
	match(WHILE);
	match(LPAREN);
	Bcond();
	match(RPAREN);
	match(LEFTSET);
	Statlist();
	match(RIGHTSET);
}
void Stat() 
{
	retflag = false;
	if ( Token == IF )
		Ifstat();
	else if ( Token == WHILE )
			Whilestat();
	else if (Token == IDENTIFIER )
			AssignmentStat();
	else
	{
		match(RETURN);
		Nexpr();
		match(SEMICOLON);
		retflag = true;
	}
}
void Statlist() 
{
	Stat();
	while ( Token == IF || Token == WHILE || Token == RETURN ||  Token == IDENTIFIER )
		Stat();
}
void Funbody() 
{
	Declist();
	Statlist();
}
void Function() 
{
	match(TYPE);
	match(IDENTIFIER);
	match(LPAREN);
	Parameterlist2();
	match(RPAREN);
	match(LEFTSET);
	Funbody();
	if (retflag != true)
		Error();
	match(RIGHTSET);
}
void Parameterlist2() 
{
	match(TYPE);
	Nexpr();
	while( Token == COMME )
	{
		match(COMME);
		match(TYPE);
		Nexpr();
	}
}
void Funlist() 
{
	Function();
	while ( Token == TYPE )
		Function();
}
void Start() {
	match(START);
	match(LEFTSET);
	Funbody();
	match(RIGHTSET);
	if ( retflag != true )
		Error();
	if ( Token == TYPE )
		Funlist();
	match(EOI);
}

void parser() {
	Start();
}

int _tmain(int argc, _TCHAR* argv[])
{
	int x=0;
	initscanner();
	Token = getToken(f);
	parser();
	finish();
	cout << "SUCCESS!!!\n";
	return 0;
}
and this text for "f.txt"

Code:
START
{
	int x ;  
	x = false;
	return d;


};
i think the problem in text file should be edited to make it success

but I don't know how to fix it??