#include <iostream>
#include <string>

#include "scanner.h"

using namespace std;

void program(string &sym);

void body(string &sym);
void stmt(string &sym);

string sym;

int main()
{
openfile();
sym = getsym();
program(sym);

return 0;

}

void program(string &sym)
{
	stmt(sym);
	//cout << sym;
	if(sym!="$")
	{
		cout << "Parser failed" << endl;
	}
	else
	{
		cout << "PARSE COMPLETED" << endl;
		return;
	}
}

void stmt(string &sym)
{
	//cout << sym;
	if(sym == "RWread" || sym == "RWwrite")
	{
		sym = getsym();
		if(sym == ";")
		{
			//cout << sym;
			cout << "end of that expression" << endl;
			sym = getsym();
			program(sym);
		}
	}
	else
return;
}

in the text file from what its reading is as follows:
read ;
$

i get the output "end of that expression" which is fine, but then I get 2 "PARSER COMPLTED" , but I only want one of them. I can't understand why I get two and not one? :sad:

void program(string &sym)
{
	stmt(sym);
	//cout << sym;
	if(sym!="$")
	{
		cout << "Parser failed" << endl;
	}
	else
	{
		cout << "PARSE COMPLETED" << endl;
		return;
	}
}

in the text file from what its reading is as follows:
read ;
$

so the input is $ and so read your if else condition properly in the function program..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.