Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!iuvax!watmath!watdragon!djsalomon From: djsalomon@watdragon.waterloo.edu (Daniel J. Salomon) Newsgroups: comp.lang.modula2 Subject: Re: Subranges and doubledots Message-ID: <14516@watdragon.waterloo.edu> Date: 16 Jun 89 02:42:23 GMT References: <983@maestro.htsa.aha.nl> Reply-To: djsalomon@watdragon.waterloo.edu (Daniel J. Salomon) Organization: U. of Waterloo, Ontario Lines: 31 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.