hi everyone,
I'm working on a project for one of my classes that parses a given grammar. I'm pretty sure I have coded it correctly but I keep getting the following list of linker errors:
[Linker error] undefined reference to `assign(char)'
[Linker error] undefined reference to `integer(char)'
[Linker error] undefined reference to `literal(char)'
[Linker error] undefined reference to `expr(char)'
[Linker error] undefined reference to `primary(char)'
[Linker error] undefined reference to `term(char)'
[Linker error] undefined reference to `term(char)'
[Linker error] undefined reference to `expr(char)'
[Linker error] undefined reference to `integer(char)'
[Linker error] undefined reference to `expr(char)'
ld returned 1 exit status
If anyone has any idea why this is happening or what I can do to fix it I would appreciate it immensely !!!! Thanks in advance : )
Here is my code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool assign(char);
bool expr(char);
bool term(char);
bool primary(char);
bool integer(char);
bool literal(char);
int main()
{
ifstream inFile;
inFile.open("parser.txt");
string stringToTest;
inFile >> stringToTest;
char *c;
*c = stringToTest[0];
cout << "c : " << c << endl;
if (assign(*c) && *c == '\0')
cout << "The string: " << stringToTest << "is in the language" << endl;
else
cout << "The string: " << stringToTest << "is not in the language" << endl;
inFile.close();
system("Pause");
return 0;
}
bool literal(char *c)
{
cout << "in literal" << endl;
if (*c == 0 || *c == 1 || *c == 2 || *c == 3 || *c == 4 || *c == 5 || *c == 6 || *c == 7 || *c == 8 || *c == 9)
{
++c;
return true;
}
else
return false;
}
bool integer (char *c)
{
cout <<"in integer" << endl;
if (*c == 'a' || *c == 'b' || *c == 'c' || *c == 'd' || *c == 'e' || *c == 'f' || *c == 'g' || *c == 'h' || *c == 'i' || *c == 'j' || *c == 'k' || *c == 'l' || *c == 'm' || *c == 'n' || *c == 'o' || *c == 'p' || *c == 'q' || *c == 'r' || *c == 's' || *c == 't' || *c == 'u' || *c == 'v' || *c == 'w' || *c == 'x' || *c == 'y' || *c == 'z')
{
++c;
return true;
}
else
return false;
}
bool primary (char *c)
{
cout << "in primary" << endl;
if(integer(*c))
return true;
else if (literal(*c))
return true;
else if (*c == '(')
++c;
if (expr(*c))
if (*c == ')')
{
++c;
return true;
}
else
return false;
}
bool term (char *c)
{
cout << "in term" << endl;
if (primary(*c))
{
++c;
if (*c == '*' || *c == '/')
++c;
if (term(*c))
{
++c;
return true;
}
else
return false;
}
else
return false;
}
bool expr (char *c)
{
cout << "in expression" << endl;
if (term(*c))
{
if (*c == '+' || *c == '-')
++c;
if (*c == expr(*c))
return true;
else
return false;
}
else
return false;
}
bool assign (char *c)
{
cout << "in assign" << endl;
if (integer(*c))
{
if (*c == '=')
++c;
if (expr(*c))
return true;
else
return false;
}
else
return false;
}