473,513 Members | 4,116 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cant reove the shift reduce conflict..

%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???

Apr 5 '07 #1
5 1910
None wrote:
%token NUMBER
Is there a full moon tonight?

--
Ian Collins.
Apr 5 '07 #2
None <am****@gmail.comwrote:

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
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Apr 5 '07 #3
On Apr 5, 4:16 pm, Ian Collins <ian-n...@hotmail.comwrote:
None wrote:
%token NUMBER

Is there a full moon tonight?

--
Ian Collins.

Mr Genius.. u dint solve the prob..

Apr 5 '07 #4
Op Thu, 05 Apr 2007 23:16:18 +1200 schreef Ian Collins:
None wrote:
>%token NUMBER

Is there a full moon tonight?
Practically, yes. A few days ago, April 2, 17.14 UT ;-)
--
Coos
Apr 5 '07 #5
aman wrote:
On Apr 5, 4:16 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>None wrote:
>>>%token NUMBER

Is there a full moon tonight?
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.

--
Ian Collins.
Apr 5 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2338
by: berehneh | last post by:
i can install apache in windows 2000 professional but when i was to install it in a LAN it cant run correctly when i type http://localhost/ in browser i recieve The page can not find why?
226
12320
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d1 = {'a':1} >>> d2 = {'b':2} >>> d3 = {'c':3}
22
1968
by: Cameron Laird | last post by:
QOTW: "... and to my utter surprise it worked." - Andrew Nagel on his move from wxPython to programming Tkinter in desperation "Python has more web application frameworks than keywords." - Skip Montanaro (but probably others going back years) Frithiof Andreas Jensen writes frankly on use of SNMP and netconf:...
56
15293
by: Christian Christmann | last post by:
Hi, in the header of my class I've a constant static const int a = ( 1 << 32 ) - 1; When compiling the code, g++ issues the warning "warning: left shift count >= width of type" Why? And how can I get rid of that?
29
1226
by: Dustan | last post by:
According to the following page on Wikipedia: http://en.wikipedia.org/wiki/Python_%28programming_language%29#Future_development reduce is going to be removed in python 3.0. It talks of an accumulation loop; I have no idea what that's supposed to mean. So, =============================== , , ]
7
1173
by: Bint | last post by:
Hi, What is a simple way to shift the elements in an array, circularly? Is there a way to do it so that you don't need a separate storage array? IE I want to shift array A{1,2,3,4,5,6,7,8} by 3 to the right. The result would be B{6,7,8,1,2,3,4,5) Thanks! B
14
3518
lotus18
by: lotus18 | last post by:
Hello World I have a problem in detecting the conflict schedule (Day and Time). Day 1. M 2. T 3. W 4. TH 5. F
14
6869
lotus18
by: lotus18 | last post by:
Hello all I have these records on my Day Table for my complete database table please click here 1. M 2. T 3. W 4. TH 5. F 6. S
1
3819
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt worked. Dates of particular year,month not displayed in that calender grids. i have collected that coding from online free resources. Here i have...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7563
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7125
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4757
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.