Re: Calculating expressions with several types

"Chris Locke" <>
13 Dec 2000 15:04:07 -0500

          From comp.compilers

Related articles
Calculating expressions with several types (=?koi8-r?B?4c7Uz84=?=) (2000-12-11)
Re: Calculating expressions with several types (Fairbairn Family) (2000-12-13)
Re: Calculating expressions with several types (Chris Locke) (2000-12-13)
Re: Calculating expressions with several types (Jean Pariseau) (2000-12-18)
| List of all articles for this month |

From: "Chris Locke" <>
Newsgroups: comp.compilers
Date: 13 Dec 2000 15:04:07 -0500
Organization: Compilers Central
References: 00-12-044
Keywords: types
Posted-Date: 13 Dec 2000 15:04:07 EST

You may find the ECMAscript (Javascript) standard interesting. seek
out ECMA-262 at

It gives procedural semantics for evaluation of expressions. It
defines (in its own odd way!) what conversions should be applied at a
particular time when parsing and evaluating expressions.

I'm not a fan of JavaScript or its type system. But if you have never
looked at implementing this sort of stuff before it might be
interesting to see what's involved.

Javascript uses what some term a 'Variant' type system where objects
are fairly type anonymous until an explicit value type is required, at
which time type conversion is carried out. Fom your original post it
sounded as if this is the sort of thing you are after. Internally,
objects are carried around in a union with a tag indicating the active
type and corresponding field of the union. New objects are created
with a nul type and value, with appropriate conversion rules. (e.g
nul type converts to the empty string)

Once you get into the area of converting to/from strings you have to
start defining a whole bunch of supported notations e.g. do you
support hexadecimal numbers in String -> Number conversions? What is
the format? Will round-trip conversions (e.g. String -> Number ->
String) yield consistent results. The ECMA-262 standard has to go
into those sorts of details! Depending on what your language is for,
you may not have too go into such detail.


Post a followup to this message

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