Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
31 Jan 2006 12:47:46 -0500

          From comp.compilers

Related articles
1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 devriese@cs.tcd.ie (Edsko de Vries) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 torbenm@app-0.diku.dk (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 rsc@swtch.com (Russ Cox) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 jm@bourguet.org (Jean-Marc Bourguet) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 gneuner2@comcast.net (George Neuner) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 rivers@dignus.com (Thomas David Rivers) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 david@tribble.com (David R Tribble) (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 henry@spsystems.net (2006-01-31)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-02-02)
Re: 1 - 1, 1 -1, 1-1, 1 - -1 and -2147483648 DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2006-02-02)
[1 later articles]
| List of all articles for this month |

From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups: comp.compilers
Date: 31 Jan 2006 12:47:46 -0500
Organization: cbb software GmbH
References: 06-01-131
Keywords: lex, arithmetic
Posted-Date: 31 Jan 2006 12:47:46 EST

On 31 Jan 2006 09:57:37 -0500, Edsko de Vries wrote:


[...]
> Is there a good solution that solves both problems? At the moment, I
> have added a new rule to the lexer that matches this exact number,
> which solves the problem - but it's a hack.. (actually, there are two
> rules, one for 32-bit machines, one for 64-bit machines..)


In Ada all literals are considered of some indefinite numeric type
[Universal_Integer]. The compiler evaluates all expressions exactly and
generates error when the result is converted to the target [finite] type.
So, for example, if Int_8 has range -128..127, nevertheless the following
is legal Ada:


      X : Int_8 := 1000 - 900; -- The result is in the range


With this approach, literals are unsigned and unary minus works just fine.


Of course, you will not be able to compile something like


      2**98756466 - 2**98756466


which is also legal. But it is not a big loss. (:-))


--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



Post a followup to this message

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