Contact me only directly please:
hgn@catpool.com
and please NOT via these job sites, where we may have had first contact.

Abstract

Why Smalltalk for JavaScript?

Smalltalk references

Needed Smalltalk features

Tools, parsers, generators etc

 

 

 

 

Smalltalk to JavaScript translator (enhanced on 24.03.12)

Tools, parsers, generators etc

In order to save you time

This page is listing several links to pages that might be of interest for this project. The goal is to save you time and to present some good and perhaps interesting references. Please remember that the author is a layman in terms of compilers, parsers, languages and alike. Therefore, the comments presented here are only thoughts and assumptions but no directives.

Joose - object-oriented JavaScript

Please bear in mind that using Joose is a mandatory requirement. Joose uses just the standard JavaScript but it supports class definitions and inheritance, that very much resembles Smalltalk. We want JavaScript to be "as much object-oriented as possible" and Joose was developed after Smalltalk originally by the German Smalltalker Malte Ubl and it is now maintained and enhanced by Nickolay Platonov in Russia. Thanks to both for this great work!

Some well suited tools: Jison, PetitParser, CoffeeScript

Jison and CoffeeShop are probably best suited to support this venture and presumably PetitParser, written in Smalltalk, could deliver the grammar specifications. A list of other and probably less helpful tools can be found further below.

JavaScript parser generator Jison

It seems that Jison is the most appropriate tool to use. It was used to generate the CoffeeScript JavaScript meta language that is mentioned in the next chapter.

I cite the Jison website: "Jison takes a context-free grammar as input and outputs a JavaScript file capable of parsing the language described by that grammar. You can then use the generated script to parse inputs and accept, reject, or perform actions based on the input. If you’re familiar with Bison or Yacc, or other clones, you’re almost ready to roll."

The open question is whether the needed grammar for parsing Smalltalk can be generated by PetitParser (see further below).

CoffeeScript

Please also consider the use of CoffeeScript, a language that transcompiles to JavaScript, that simplifies the syntax and reduces the amount of code. Maybe that's simpler to translate to.

In any case, I am strongly considering to use CoffeeScript for my already existing but not yet final generator in Smalltalk that creates user interface definitions for EXT JS (Sencha) from Smalltalk code. It is embedded in the existing configuration and versioning code in Smalltalk.

Perhaps translating to CoffeScripts is much easier to achieve, because CoffeeScript avoids much of the hassle with JavaScript's awkward syntax, braces and semicolon requirements.
It were those parts that drove me, a very experianced Smalltalker, mad when learning JavaScript. I always asked myself why the fuck do I have to care about such stupid details in JS?! Smalltalk does not require any of this nonsense either. Well, the world often steps backwards....!

Thoughts on Jison and CoffeeScript

With Jison it should also be possible to generate plain JavaScript directly. Perhaps this is the better solution as this avoids trouble from the fact that CoffeeScript may (?) cause problems with the Joose class declaratoin syntax, which is plain JavaScript but still very special. Again: I am a layman in language and grammar subjects, thus I am only giving my thoughts but no directives.

PetitParser written in Smalltalk

It's not fully clear to me what this really is. It looks as though this is only a tool to generate parser syntax but I found nothing mentioned that any Smalltalk syntax is already available. So to me this seems to be the right but empty box. Probably, the right theory but failing in practice, I don't know.

Unfortunately, as so often in the Smalltalk world, documentation and explanation are very sparse. This is how some Smalltalkers love to express their eliteness.

You find some explanations here, and here is the website and here is the Smalltalk version mentioned that I am using (although I am using an older release but that is less of a problem).

A warning: I do not know to what extent this tool can be used for real-life projects. Quite often these university guys just start some projects that sound brilliant but most are stopped half-way before ever reaching any state near what can be called industrial strength. I feat that this is also the case here, but I am not certain. Please read this and also this. But it also seems that it was be used successfully for smaller projects: please read this.

Despite all of this, I think it would be worth evaluating this approach. Keep in mind, that we only need a partial syntax translation of Smalltalk code and perhaps this is still the best approach.

Currently preferred solution

It would probably be the preferred solution to parse Smalltalk in and by itself, inside the Smalltalk development environment, rather than delegating this to some foreign tool.

More details would be under direct and immediate control. I would also expect better debugging and simpler enhancements over the lifecycle of this project - and this will be decades.

Therefore, at this moment and with my limited knowledge of these matters, my currently preferred solution looks like this (but again, no directive, just my thoughts):

Smalltalk code and class declarations

Model and UI definitions in data

Original code is Smalltalk; limited syntax and limited use of blocks, no rarely used constructs; code specially written for translation to JS Original data is held in Smalltalk code; used to generate data for run-time; extensive versioning and configuration aids are available
a) Preferred solution
Use PetitParser to generate JS code from Smalltalk
Existing and partially working code generatior will be changed to support CoffeeScript; has simpler syntax, no hassle with braces
b) Alternative solution
Use Jison to parse and translate the exported Smalltalk code to JavaScript
Part of this code generation are also "make files" and XML definitions for the JS code compression and obfuscation tool in use

Other tools

Here is a list of additional tools that might be helpful to implement a Smalltalk to JavaScript translation.

ANTLR Smalltalk parser grammar

Can be found here.

YACC in Smalltalk?

Download GNU Smalltalk, it has a yacc grammar for its compiler:
(start at www.gnu.org/directory) Maybe that could help to produce the grammar definitions needed by Jison?!

JavaScript grammar / syntax

Link 1 and Link 2 Could these be used for Jison?

Smalltalk parser for translation to Objective-C (“Producer”)

Producer is implemented in Objective-C and other Unix tools. Its lexical analyzer, written in Lex, composes characters into tokens and delivers them to the parser, written in YACC. The parser recognizes syntactic components of the Smalltalk-80 language and executes Objective-C statements that build a syntax tree bottom-up as instances of syntactic classes like Method, Message, and Identifier. …….

The primary conclusion that can be drawn from the results to date is that small Smalltalk applications that do not lean heavily on complex features of the Smalltalk environment can be translated to Objective-C with remarkably little trouble. This professional work could probably be re-used.

PCCTS and ANTLR generate JavsScript code

ANTLR 1 and ANTLR 2 - org and especially this page

ANTLR Grammar for Smalltalk80

Grammar is here and here is a Smalltalk parser for making Smalltalk run on the Java VM.

This above uses ANTLR and it's ofd December 2011. Maybe parts could be helpful.

Smalltalk parser written in Pharo Smalltalk PetitParser

Here is another parser written in Pharo Smalltalk. Note that out of the many "exotic" Smalltalk dialects, Pharo is for us by far the preferred one. There is even a detailed tutorial video here.

Another Smalltalk grammar

Smalltalk parser written in Vista Smalltalk We are rather sceptical about this Smalltalk dialect. It seems more an academic toy than a real production system.

"Vista Smalltalk uses an Antlr generated parser. For Silver Smalltalk, they have adapted a lightweight hand coded parser that they developed for GWT-Smalltalk last year."

YACC and LEX

Please not that it's only a proposal to use these proven and powerful tools. The author has no own experiance and if you prefer to use other tools, that's ok for us. True is what works. Note that ASFAIK YACC only produces C code and therefore is probably not first choice.

Is YACC still used?

Some comments.

Chrome VM "V8 " in Smalltalk

Perhaps this could be another interesting solution. It is little known that the JavaScript VM of Google Chrome was designed and architectured based on Smalltalk (though it's written in C++). The Smalltalk dialect is called Strongtalk. More about V8 can be found here.

The other pages

Smalltalk references
Needed Smalltalk features
Grammar and syntax etc