cant reove the shift reduce conflict..

N

None

%token NUMBER
%token CD
%token CD..
%token SHOWAVAILABLEINTERFACE
%token LOCKPORT
%token RELEASEPORT
%token LISTSTDPACKET
%token SHOWPACKET
%token MODIFYPACKET
%token LOAD
%token MODIFYTRANSMITNFO
%token SENDPACKET
%token SETCAPTURECOUNT
%token SETCAPTURETIME
%token SETFILTERMAC
%token STARTCAPTURE
%token HELP

%%

cmd: /*Blank*/ {printf("blank command entered ");}
| cmd_name args_list { char str[80];
strcpy (str,$1);
strcat (str,'(');
strcat (str,$2);
strcat (str,')');
$$ = str;
}
;

cmd_name: CD {$$ = $1;}
| CD.. {$$ = $1;}
| SHOWAVAILABLEINTERFACE {$$ = $1;}
| LOCKPORT {$$ = $1;}
| RELEASEPORT {$$ = $1;}
| LISTSTDPACKET {$$ = $1;}
| SHOWPACKET {$$ = $1;}
| MODIFYPACKET {$$ = $1;}
| LOAD {$$ = $1;}
| MODIFYTRANSMITNFO {$$ = $1;}
| SENDPACKET {$$ = $1;}
| SETCAPTURECOUNT {$$ = $1;}
| SETCAPTURETIME {$$ = $1;}
| SETFILTERMAC {$$ = $1;}
| STARTCAPTURE {$$ = $1;}
| HELP {$$ = $1;}
;

args_list: /*Blank*/ {$$= ' ';}
| args args_list { char str[80];
strcpy (str,$1);
strcat (str,',');
strcat (str,$2);
$$ = str;
}
;

args: int_number {$$ = $1;}
| float_number {$$ = $1;}
| ip_address {$$ = $1;}
| mac_address {$$ = $1;}
;

int_number: NUMBER {$$ = $1;}
| NUMBER int_number { char str[80];
strcpy (str,$1);
strcat (str,$2);
$$ = str;
}
;

float_number: int_number'.'int_number { char str[80];
strcpy (str,$1);
strcat (str,".");
strcat (str,$3);
$$ = str;
}
;

ip_address: int_number '.' int_number '.' int_number '.'
int_number { char str[80];

strcpy (str,$1);

strcat (str,".");

strcat (str,$3);

strcat (str,".");

strcat (str,$5);

strcat (str,".");

strcat (str,$7);

$$ = str;
}
;

mac_address: int_number ':' int_number ':' int_number ':'
int_number ':' int_number ':' int_number { char str[80];

strcpy (str,$1);

strcat (str,":");

strcat (str,$3);

strcat (str,":");

strcat (str,$5);

strcat (str,":");

strcat (str,$7);

strcat (str,":");

strcat (str,$9);

strcat (str,":");

strcat (str,$11);

$$ = str;
}
;





Hey,


I have been stuck on this Grammar for some time..

Can any one please help me remove the S/R conflict???

Also are the strcat and stcpy statements valid???
 
J

Jens Thoms Toerring

First of all, please put your question into the message itself, not
just into the subject line. Second, "cant reove the shift reduce
conflict.." isn't a question about C but looks like some problem
you have with yacc or bison. The group comp.compilers is probably
where you should ask for help.

But there's also a serious C problem hidden there:
cmd: /*Blank*/ {printf("blank command entered ");}
| cmd_name args_list { char str[80];
strcpy (str,$1);
strcat (str,'(');
strcat (str,$2);
strcat (str,')');
$$ = str;
}

The action (the part in curly braces will be copied into the
output C code by yacc or bison _including_ the curly braces.
So you end up with a block and the 'str' array you defined
there will go out of scope at th end of the block. But you
still hold a pointer to that array, which gets passed on to
somewhere outside of the block. If it's ever used (and using
it is what '$$' is exists for) you created undefined behaviour,
i.e. it might seem to work some of the time but may crash at
any moment.

This is not a special case with actions in yacc or bison at all
but a general rule: never use a variable after it's gone out of
scope, also not via a pointer you may still hold to the variable
- this pointer has no useful value any more once you left the
block (be it a function or something just enclosed in curly
braces) the variable it pointed to was defined in.

Regards, Jens
 
I

Ian Collins

aman said:
Don't quote signatures.

Mr Genius.. u dint solve the prob..
u doesn't post here any more. Assuming 'prob' should be problem, show
me the C problem in the post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top