Som language

This document is now available in e-book form.

Quick introduction

Som is a simple language that is complete enough to be self-hosting, that is, its compiler and its virtual machine are written in Som.  It is small, the whole package is around 2,000 lines of code written in Som so it can be read and understood by one person in a short time. Som language has been used in teaching computer architecture, compiler and machine language in my classes for the past 10 years.  Its compiler front end is driven by an automatically generated parser.  (The parser generator in Som is provided). The back end is easily retarget to different machine langauges.

Here is a sample of the language.

Som's virtual machine has an interesting development.  It started the life as a zero-address (stack-based) instruction set and evolved through one-address and then three-address formats.  In fact, the history of Som's virtual machine read like a study in instruction set evolution.  Read Som's birthday report to know more. Som's environment includes a batch-mode compiler and an interactive one. An expression can be typed in and is evaluated immediately. Here is an example of an interactive sesssion:

> print 2 + 3 nl
5
> to sq x = x * x
> print sq 4 nl
16
>

If you are curious about language design, compiler construction or virtual machine instructions, then you are welcome to try Som.  The package is extremely small.  All source files and the executable virtual machine plus the compiler object is under 200K bytes. Because of its smallness, it can be use as an embedded language, or it can be modify for a domain-specific language (through the change of grammar) easily. Hope you enjoy playing with Som.

PS. “Som” is usually a nickname of a girl in Thai language.  “Som” is translated to English as a colour “orange” or a fruit “orange” or “tangerine”.

Important Milestones

Earlier versions
Release history
Happy birthday Som  2008

Code Release

The release includes all source of compiler system (in Som) and the virtual machine (in C) and the executable vm compiled on Windows XP platform, Vista and Windows 7 and 8.  It also contains a bit of test file and examples.  The whole package is very small 100K-600K bytes (zip).

10 November 2012
Som v 5.2  10-11-12 release
 readme
25 December 2010
Som v 5.1  Christmas release  t2-64
 readme
5 December 2009 Som v 5.0   new t2-code vm  readme
22 September 2009 Som v 4.2a  new parser generator  readme
9 September 2009 Som v 4.2  Triple 9 release  readme
9 August 2008 Som v 4.1  Birthday release  readme
2 July 2007 Som v 4.0  fast u-code vm  readme
19 August 2007 Som v 3.1  fast sx-code vm  readme

 Language Manual

Part I  The language

motivation
syntax
examples
design decision
string
macro

Part II   Internals

s-code
lexical generator
compiler
parser generator
parser generator v 2
parse tree
code generation
optimisation
optimisation for macro and/or (in Som v 4.0)
optimisation  in Som 5.0

Part III VM

Object file format
System call
S-code virtual machine
T-code       som v 1.7
Sx-code     som v 3.0
U-code      som v 4.0
U-code  improved    som v.4.1
T2-code     som v 5.0
T2-64-code  som v 5.1

Appendix

the origin of Som
conveniences
indentation as block

How to get Som   

Som v1.0   (Som in C)  the origin of Som
Som v2.0   (Som-in-Som)  readme
Som v1.5  (with macro)    readme
Som v1.7   (t-code vm)     readme
Som v1.8  (bug fixed v 1.7)   readme
Som v2.4  (Som-in-Som for 2007)    readme   (it achieved self-compiling!)
Som v3.0  (Som-in Som with new sx-code VM)   readme
Som v3.1  (fast sx-code VM)   readme
Som v4.0  (u-code VM)   readme
Som v4.1  (improved u-code and compiler)  bug fixed  (18 Aug 2008)   readme   
Som v4.2   (lex as built-in function)  readme
Som v4.2a  (new parser gen)  readme   
Som v5.0    (new t2-code vm)  readme
Som v5.1   (t2-code 64-bit)  readme
Som v5.2   (10-11-12, vm in som)  readme

Document

Old introduction
How to compile Som suite
How to generate som.obj  (for som v 2.4)
Example session
Happy birthday Som (2008)

Publications

related to Som language, stack-processors and virtual machines

last update  10 Nov 2012