Syntax in Languages

posted on 2005-09-23

Following the post about NekoML syntax, I replied to a post on LtU with the following message.

[…] We all now here that while syntax does matters, it’s far from being the most important point in a programming language.

A language design is divided into the following categories (please tell me if I forget some) :

  • the syntax
  • the semantics
  • the type system
  • the features

While the syntax is pure “style”, each of them having its proponents, the semantics is independant from the syntax and describe how the language is evaluated.

At this point we can say that what makes Ruby is not only the syntax, which can be easily changed using a “translator” but its semantics which can hardly be changed without breaking a lot of things.

The type system assists the semantics since except Bash which have only one type “string”, most of the languages have a more-or-less rich, more-or-less extensible type system featuring several “basic” types. The semantics of the language specify also if and how types are checked. Basicly dynamicly-typed languages have a type system, sometimes very rich, but the whole check is delayed at runtime. OTOH static type systems will check a lot of things at compile time and can (but not always do) eliminate a lot of checks at runtime. To be precise, some dynamicly typed language will add some checks at compile time that will enable them to skip some runtime checks if satisfied.

And then comes the features. Class systems are a possible feature when the language have objects in its type system. First class functions and closures are also features. Same for “generators” or continuations, same for embedded regular expressions (which are more a syntax feature - called syntactic “sugar”), and more…

All of theses things together are making a programming language, and syntax is far from being the most important point in language design since it’s the most easy to change. However, it shouldn’t be underestimated since a lot of programmers will judge a language from its syntax only before even starting playing with its semantics, type system, and features.

As a conclusion, it’s funny to see that language “wars” are mostly focused on two points : syntax and type checking (not type system itself), maybe because “original” shift between Lisp and Fortran.

Leave a Reply

You must be logged in to post a comment.