hey, for a class project I have to write a parser for a grammar that my professor is giving us. I have broken it down into a very small part and want to get that working before parsing an entire string. In this bit of code, the string to be parsed is "a=" . Which is in the file read.txt
This is my code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool test(char *);
int main ()
{
ifstream inFile;
inFile.open("read.txt");
string line;
inFile >> line;
char *c;
*c = line [0];
if (test(c) && *c == '\0')
cout << "The string: " << line << "is in the language" << endl;
else
cout << "The string: " << line << "is not in the language" << endl;
system("Pause");
return 0;
}
bool test(char *c)
{
if (*c == 'a' || *c == '-')
++*c;
if(*c == '=' || *c == '-')
return true;
}
The problem I am having is in the test function. The string to be parsed is 'a=' . The function gets past the first if test because c is set to a, but then after '++*c' c is somehow incremented to b instead of the equal sign. I have no idea how to change this and any input/advice would be greatly appreciated!!!