Re: The signs of literals

"Matt Timmermans" <mtimmerm@microstar.no-spam.com>
12 Dec 1997 14:57:20 -0500

          From comp.compilers

Related articles
The signs of literals lin@cs.monash.edu.au (Hung-Ta Lin) (1997-12-07)
Re: The signs of literals dlmoore@ix.netcom.com (David L Moore) (1997-12-10)
Re: The signs of literals clark@quarry.zk3.dec.com (Chris Clark USG) (1997-12-10)
Re: The signs of literals hbaker@netcom.com (1997-12-12)
Re: The signs of literals tim@wagner.Princeton.EDU (1997-12-12)
Re: The signs of literals mtimmerm@microstar.no-spam.com (Matt Timmermans) (1997-12-12)
Re: The signs of literals dlmoore@ix.netcom.com (David L Moore) (1997-12-13)
| List of all articles for this month |

From: "Matt Timmermans" <mtimmerm@microstar.no-spam.com>
Newsgroups: comp.compilers
Date: 12 Dec 1997 14:57:20 -0500
Organization: IGS - Information Gateway Services
References: 97-12-053
Keywords: lex

Hung-Ta Lin wrote in message 97-12-053...
> ...
>Would it be okay to change that grammar to:
>
> exp5 ::= [+|-] exp6
> exp6 ::= integer_literal | ...
>
> integer_literal ::= digit {digit}


This works just fine if you use:


exp5 ::= [+|-] exp5


You really have to think about the semantic meaning of these expressions,
though.


It would probably be odd to have "-32768" and "- 32768" mean different
things, but as another poster mentioned, if -32768 is the most negative
value you can put in an integer_literal, then 32767 is probably the highest
value you can put in an integer_literal, -(32768) would overflow.


If don't want to catch overflows of literals as errors, then you do not have
a problem if you do everything in the naive way:


3276*10 -> 32760
32760 + 8 -> -32768 //wrapped around here
-(-32768) -> -32768 //negating this value has no effect


so 32768 will wrap around to zero and - 32768 will evaluate to zero


--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.