I have the following production rule
E -> (EX)|Y
X -> vE|^E|>E
Y -> -E|p|q|r
and I have the following code
int i;
int j;
int count;
char l;
void match(char t);
void E();
void X();
void Y();
void match(char t)
{
if (l == t) {
count += 1;
}
else{
printf("Error");
}
}
void E()
{
if(l == '('){
match('(');
E();
X();
if(l == ')'){
match(')');
return;
}
}
else{
Y();
}
return;
}
void Y()
{
if(l == '-'){
match('-');
E();
}
else if(l == 'p'){
match('p');
return;
}
else if(l == 'q'){
match('q');
return;
}
else if(l == 'r'){
match('r');
return;
}
}
void X()
{
if(l == 'v'){
match('v');
E();
}
else if(l == '^'){
match('^');
E();
}
else if(l == '>'){
match('>');
E();
}
return;
}
int parse(char* g){
count = 0;
//int k = strlen(g);
l = g[count];
//sprintf("%c",l);
E();
if(l == '$'){
printf("Parsing successful");
return 1;
}
else{
printf("Parsing unsuccessful");
return 0;
}
}
which doesnt seem to work. The program crashes without printing anything. What is the problem in the code? The code runs inititally but nothing happens and then the program just exits. I dont think there is a segmentation fault but could someone please advise and help
lis not updated during the recursion.