Saturday, November 11, 2006

No keywords

Ever wondered why languages have keywords? Well, they even fight over it -- some smalltalk proponent argued that smalltalk having just five keywords is way better than ruby having thirtysome. But special cases are usually only zero, one or infinity, and in this case one is out, too.

So indeed a language should at best not have any keywords at all. But the only that manage to do so are from the lisp family. In the others you sometimes get the really strange error. In C it is perfectly legal to say int class;, and thus the X11 people did exactly that (in a structure declaration). Use that header from C++, and you get a rather unexpected syntax error. A reserved keyword is not an identifier, and thus raises the syntax error. Also the C++ community continues inventing new keywords while C goes to strange things like long long to avoid that.

The solution is to make keywords into regular entries in the global symbol table with special values. That way any other scope could use any identifier it likes without fear of clashes with esoteric or future 'keywords'. There is one disadvantage: Parsing is affected by semantic analysis, but then that is no news, remember typedef which is explicit in C and implicit in C++ class declarations. But then, since gloop is to have macros, this is no additional disadvantage.

And to answer the question: Keywords are most easily handled directly as special tokens, and they have been invented waaay before the concept of namespace pollution.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home