[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lexical syntax for numbers



A proposed lexical syntax for Scheme numbers.


The draft of the Revised Revised Report did not specify a lexical
syntax for numbers.  This proposal is consistent with the draft
but it incorporates a large number of rather arbitrary decisions
that are likely to be controversial.  Feel free to controverse.

Actually there are two proposals.  The first proposal is for full
(optional) Scheme and the second is for essential Scheme.
(Implementations would be free to implement anything in between
or to extend the syntax so long as the extended syntax didn't
conflict with the optional syntax, right?)

x* means zero or more occurrences of x.
Spaces never appear inside a number, so all spaces in the syntax
are for legibility.
<empty> is the empty string.


bit -->  0  |  1

oct -->  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7

dit -->  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9

hit -->  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9
      |  a  |  b  |  c  |  d  |  e  |  f  
      |  A  |  B  |  C  |  D  |  E  |  F

radix2  -->  #b  |  #B

radix8  -->  #o  |  #O

radix10  -->  <empty>  |  #d  |  #D

radix16  -->  #h  |  #H

exactness  -->  <empty>  |  #i  |  #I  |  #e  |  #E

precision  -->  <empty>  |  #s  |  #S  |  #l  |  #L

prefix2  -->  radix2 exactness precision  |  radix2 precision exactness
           |  exactness radix2 precision  |  exactness precision radix2
	   |  precision radix2 exactness  |  precision exactness radix2

prefix8  -->  radix8 exactness precision  |  radix8 precision exactness
           |  exactness radix8 precision  |  exactness precision radix8
	   |  precision radix8 exactness  |  precision exactness radix8

prefix10  -->  radix10 exactness precision  |  radix10 precision exactness
            |  exactness radix10 precision  |  exactness precision radix10
	    |  precision radix10 exactness  |  precision exactness radix10

prefix16  -->  radix16 exactness precision  |  radix16 precision exactness
            |  exactness radix16 precision  |  exactness precision radix16
	    |  precision radix16 exactness  |  precision exactness radix16

sign  -->  <empty>  |  +  |  -

suffix  -->  <empty>  |  e d d*  |  E d d*  |  e - d d*  |  E - d d*

ureal  -->  prefix2 bit bit* #* suffix
	 |  prefix2 bit bit* #* / bit bit* #* suffix
         |  prefix2 . bit bit* #* suffix
	 |  prefix2 bit bit* . bit* #* suffix
	 |  prefix2 bit bit* #* . #* suffix

         |  prefix8 oct oct* #* suffix
	 |  prefix8 oct oct* #* / oct oct* #* suffix
         |  prefix8 . oct oct* #* suffix
	 |  prefix8 oct oct* . oct* #* suffix
	 |  prefix8 oct oct* #* . #* suffix

         |  prefix10 dit dit* #* suffix
	 |  prefix10 dit dit* #* / dit dit* #* suffix
         |  prefix10 . dit dit* #* suffix
	 |  prefix10 dit dit* . dit* #* suffix
	 |  prefix10 dit dit* #* . #* suffix

         |  prefix16 hit hit* #* suffix
	 |  prefix16 hit hit* #* / hit hit* #* suffix
         |  prefix16 . hit hit* #* suffix
	 |  prefix16 hit hit* . hit* #* suffix
	 |  prefix16 hit hit* #* . #* suffix

real  -->  sign ureal

number  -->  real  |  real + ureal i  |  real - ureal i  |  real @ real


Some consequences of this syntax are reported below.  Please keep
in mind that when I say a syntax is "illegal", I mean that it is
not generated by the syntax above and is therefore not a number
in (full optional) Scheme.  The syntax could represent a legal
symbol or even a legal number in an extended Scheme.

Consequences:

Exponents are always in base 10.
Exponents may not have explicit + signs.

	e+4			is illegal
	1E+3			is illegal
	#d+3 			is illegal
	4-+5i			is illegal
	4#.5			is illegal
	#d5/#o10		is illegal
	-4/-5			is illegal
	#o5/10			is .625
	#s4			is legal
	#s#i#b.10##-#x#L#Ea.bi	is legal



The proposal for essential Scheme:


dit -->  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9

sign  -->  <empty>  |  +  |  -

number  -->  sign dit dit*




Question about exactness:  In an implementation that doesn't keep
track of exactness, the exact? predicate should always return
#!false.  Right?

				William Clinger
				willc@indiana
	after 1 May:		willc@tektronix