fransvo@maestro.htsa.aha.nl (Frans van Otten) (06/15/89)
In Modula-2, a valid subrange is [5 .. 10]. But would [5..10] also be a valid subrange ? I mean, how should this be interpreted ? [ 5 .. 10 ] = "[" integer doubledot integer "]" or [ 5. . 10 ] = "[" real dot integer "]" What is the "common" interpretation ? -- Frans van Otten | fransvo@maestro.htsa.aha.nl or Algemene Hogeschool Amsterdam | fransvo@htsa.uucp or Technische en Maritieme Faculteit | [[...!]backbone!]htsa!fransvo
djsalomon@watdragon.waterloo.edu (Daniel J. Salomon) (06/16/89)
In article <983@maestro.htsa.aha.nl> fransvo@maestro.htsa.aha.nl (Frans van Otten) writes: > In Modula-2, a valid subrange is [5 .. 10]. But would [5..10] also > be a valid subrange ? I mean, how should this be interpreted ? > > [ 5 .. 10 ] = "[" integer doubledot integer "]" > > or > > [ 5. . 10 ] = "[" real dot integer "]" > > What is the "common" interpretation ? > -- > Frans van Otten | fransvo@maestro.htsa.aha.nl or > Algemene Hogeschool Amsterdam | fransvo@htsa.uucp or > Technische en Maritieme Faculteit | [[...!]backbone!]htsa!fransvo You have just encountered one of the rocky scanning/parsing problems of Modula-2. Pascal has a similar problem. The sequence "[5..10]" is a valid subrange in Modula-2. The reason is that it can be generated by the Modula-2 grammar, whereas the sequence "[ real dot integer ]" cannot. The reason that it is a rocky problem is that you need two-character lookahead in your scanner to recognize it. A possible alternative is to have your scanner recognize only integers and have your parser assemble real constants from component integer fields. Then your scanner one needs only one-character lookahead. If you use the second method be sure to pass up all the characters of the integers rather than just their values, otherwise the fractional part of a real number may be interpreted incorrectly if it had leading zeros.
george@sequent.UUCP (George Emery) (06/17/89)
In article <983@maestro.htsa.aha.nl> fransvo@maestro.htsa.aha.nl (Frans van Otten) writes: >In Modula-2, a valid subrange is [5 .. 10]. But would [5..10] also >be a valid subrange ? I mean, how should this be interpreted ? Someone's already answered this with the technically correct answer, so I'll add that in the real world all the compilers I've used (not many: 3) will accept [5..10]. George Emery ...!tektronix!sequent!crg3!george (503) 257-9731 (voice, home)