SimpleScript (1) First ideas

The latest two week, I was busy writing CobolScript, my COBOL compiler to JavaScript (see my posts). I have console sample programs, and dynamic pages samples running on Node.js (see samples). The web samples are using the simple http node.js module, or my new SimpleWeb module, a simple middleware layer a la Connect. I started to write a Python to JavaScript compiler, see Py2Script, too. But now, after those training projecs (my first ones that are compiling to JavaScript using JavaScript), I want to push the envelope and write a simple script compiler, I named SimpleScript (see repo).

The key points:

– It compiles to JavaScript, so, it’s JavaScript-oriented. It’s not a script language to be implemented in different technologies (.NET, Java, JavaScript). It’s totally oriented to JavaScript semantic.

– I love C programming language tradition, but this time, I want no semicolons and curly braces. I want a syntax more Python/Ruby oriented.

– No indentation “hell”. Ok, I like Python, but indentation as part of the syntax, it’s not my preferred way.

– No command separator (no semicolon or something else) except new line or syntax. That is, I could write

if a < 1 a = 1


if a < 1
   a = 1

Notice the use of end.

You CANNOT write (semicolon is not a separator):

if a < 1 a=1; b=2

You MUST write:

if a < 1
  a = 1
  b = 2

– No parenthesis around conditions (see the above if example).

– Only for … in , to be discussed. I want to have for-in as in JavaScript, but with some variant to access directly the values instead the names/indexes of an object or array. Something like

for k in myarray

iterates over myarray indexes.

for k in myarray values

iterates over myarray values, directly. Range expression will be supported:

for k in 0..n

– Loops with continue, break. The main loop construction is the while.

– Functions as first class citizens.

function keyword will be used to define anonymous functions. Maybe (to be discussed) I will use define keyword to define named functions.

– Function invocation with explicit parenthesis (forget Ruby convention, go for something like Python 3.x).

– Array access with [] (forget Basic programming convention of using parenthesis).

– External variables. I learnt this from my CobolScript work: the linkage section is useful. An external variable is something injected at runtime (not a global one), and it can be provided in the call to the program. For example, print function could be an external one, so the calling program could redirect the print to the console, or to a buffer or to the web response. at will.

– Global variables should be declared explicitly. All non-declared variable is considered local (to the function, unit where it is used).

– Functions has closures as in JavaScript. In contrast, AFAIK, Python use explicit declaration to access outer variables in a function. I like JavaScript automatic access to outer variables, so I will keep it.

– Async constructions. I added this to CobolScript, and I found it useful. It’s something like the await/async in C# 5.0

– Run on the browser and on Node.js.

– Class support: to be discussed (the only key use case I have, is the game client coding for my game project).

I know, there are other implementations, like CofeeScript. But I want to training me, on JavaScript, Node.js and TDD.

Keep tuned!

Angel “Java” Lopez

2 thoughts on “SimpleScript (1) First ideas

  1. Pingback: Mass Programming Language (1) Inception | Angel "Java" Lopez on Blog

  2. Pingback: SimpleScript (2) The Lexer | Angel "Java" Lopez on Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s