Starting with Alhpa 6 release of the Dynamic Language Runtime and IronPython, the distribution includes a small sample language ToyScript. As the name suggests, rather than a serious 'real' language, it is a toy complex barely enough to deserve the label 'language'. The language is truly simple (for example it doesn't even support operator precedence or comments), but its simplicity allows us to focus on some of the design elements shared by the languages that currently target DLR.

Once you unzip the DLR distribution, ToyScript solution is easily found in the Src\ToyScript\ToyScript directory. The solution is all you need to get started since it includes reference to the DLR project (Microsoft.Scripting).

Like a traditional compiler, ToyScript has a tokenizer and parser (ToyTokenizer.cs and ToyParser.cs, both in the Parser directory) and an abstract syntax tree (in the Ast subdirectory). At the root of the AST hierarchy is a ToyNode from which Expression and Statement derive.

ToyScripts expressions are:

Assignment a = b
Constant 1, "Hello"
New new a(arg, ...)
Binary a + b
Index a[b]
Parenthesized (a)
Member a.b
Call a(b, ...)
Named a

And the statements:

If "if" statement
While "while" loop
Def Python-style function definition
Import Python-style import statement
Empty empty statement
Var Variable definition
Block Block of statements
Print Python-style "print"
ExpressionStatement  
Return  

So far, all of this is quite similar to the majority compilers out there. In the later stages of compilation the effects of targeting DLR will be visible. We'll talk about that in next chapter.