hello guys,
i have been stuck with some right now on my design on paser for a simple grammer which is given bellow
L -> ( C )
C -> idC'
C' -> , id C' | E
for the expression
( a , b , c )
the problem with the code is when i return from the function C' to the C the token 'sym' which i read in C' is not the same in C. its true that u can say that all the local varables will destroyed when the control comes out of the function. but in my case i have declared sym variable as globle so that it can be acessed by all the function. and here us code
Code:
char *sym;
void L(char *sym)
{
if(strcmp(sym,"(")==0)
{
sym=getsym();
C(sym);
printf("%s",sym); // so if i print the sym here it has to print ')'but it prints the old which was read by this function first that was id
if(strcmp(sym,")")!=0)
{
printf("Error: closing para missing\n");
getchar();
exit(1);
}
}
else
{
printf("Error: opening para missing\n");
getchar();
exit(1);
}
}
void C(char *sym)
{
if(strcmp(sym,"id")==0)
{
sym=getsym();
C1(sym);
}
else
{
printf("Error: Identifier missing\n");
getchar();
exit(1);
}
}
void C1(char *sym)
{
if(strcmp(sym,",")==0)
{
sym=getsym();
if(strcmp(sym,"id")==0)
{
sym=getsym();
C1(sym);
}
else
{
printf("Error: Identifier missing\n");
getchar();
exit(1);
}
}
}
any help would be appriciated
ssharish2005