Hi,
I was able to a config file containing the following input
name > me,name < me,talk = we
using the following bison recursive code
Code:
property_list:
alpha_list
{
}
;
alpha_list:
alpha_list ALPHANAME OPERATION ALPHANAME
{
t = (struct table *) malloc(sizeof(struct table));
if (t == NULL){
printf("Error on malloc `table'.\n");
exit(-1);
}
else{
t->table_name = strdup($2);
printf("%s\n",t->table_name);
t->next = tl;
tl = t;
}
}
| ALPHANAME OPERATION ALPHANAME
{
tl = (struct table *) malloc(sizeof(struct table));
if (tl == NULL){
printf("Error on malloc `table'.\n");
exit(-1);
}
else{
tl->table_name = strdup($1);
printf("%s\n",tl->table_name);
tl->next = NULL;
}
}
;
Note: Alphaname is for the name and me and operation for <>=
But when i wanted to parser the following
name > me,name < me,talk = we me
As the string on the others side of the operand (ie <>=) can have infinity amount spaces so i planned to used another recrsion case to fix that case
Here is the code
Code:
property_list:
alpha_list val_list
{
}
;
alpha_list:
alpha_list ALPHANAME OPERATION val_list
{
t = (struct table *) malloc(sizeof(struct table));
if (t == NULL){
printf("Error on malloc `table'.\n");
exit(-1);
}
else{
t->table_name = strdup($2);
printf("%s\n",t->table_name);
t->next = tl;
tl = t;
}
}
| ALPHANAME OPERATION val_list
{
tl = (struct table *) malloc(sizeof(struct table));
if (tl == NULL){
printf("Error on malloc `table'.\n");
exit(-1);
}
else{
tl->table_name = strdup($1);
printf("%s\n",tl->table_name);
tl->next = NULL;
}
}
;
val_list:
val_list ALPHANAME
{
t = (struct table *) malloc(sizeof(struct table));
if (t == NULL){
printf("Error on malloc `table'.\n");
exit(-1);
}
else{
t->table_name = strdup($2);
printf("%s\n",t->table_name);
t->next = tl;
tl = t;
}
}
| ALPHANAME
{
tl = (struct table *) malloc(sizeof(struct table));
if (tl == NULL){
printf("Error on malloc `table'.\n");
exit(-1);
}
else{
tl->table_name = strdup($1);
printf("%s\n",tl->table_name);
tl->next = NULL;
}
}
;
But it keeps on complaining about syntax error and doesnt read even the following case
name > me,
Let alone the case with more spaces. How do I fix this?