Wednesday, January 27, 2010

SLANG4.net is now a .net Compiler

Hi all ,

I have updated SLANG4.net site ( http://slangfordotnet.codeplex.com ) with a new release. Now the software is a compiler which generates .net IL code...here are some samples

Let us how our compiler has generated code for some script....
/////////////////////////////
// Mul.sl
//
//
//
PRINTLINE 2*(3+4);

Using the ILDASM utility , here is what we get from our compiler...


.method public static void Main() cil managed
{
.entrypoint
// Code size 35 (0x23)
.maxstack 3
IL_0000: ldc.r8 2.
IL_0009: ldc.r8 3.
IL_0012: ldc.r8 4.
IL_001b: add
IL_001c: mul
IL_001d: call void [mscorlib]System.Console::WriteLine(float64)
IL_0022: ret
} // end of method MainClass::Main



///////////////////////////////////
//
// A simple SLANG script
//
// Sample #1
//
NUMERIC a; // Declare a Numeric variable
a = 2*3+5* 30 + -(4*5+3); // Assign
PRINTLINE a; // Dump a
//----- String concatenation
PRINT "Hello " + "World";
//-------------- Write a new line
PRINTLINE "";
//-------------- string data type
STRING c;
c = "Hello "; // assignment to string
//---------------- assignment and concatenation
C = C + "World";
PRINTLINE c;
//-------------- boolean variable
BOOLEAN d;
d= TRUE;
PRINTLINE d;
d= FALSE;
PRINTLINE d;


The output is


.method public static void Main() cil managed
{
.entrypoint
// Code size 156 (0x9c)
.maxstack 4
.locals init (float64 V_0,
string V_1,
bool V_2)
IL_0000: ldc.r8 2.
IL_0009: ldc.r8 3.
IL_0012: mul
IL_0013: ldc.r8 5.
IL_001c: ldc.r8 30.
IL_0025: mul
IL_0026: ldc.r8 4.
IL_002f: ldc.r8 5.
IL_0038: mul
IL_0039: ldc.r8 3.
IL_0042: add
IL_0043: neg
IL_0044: add
IL_0045: add
IL_0046: stloc.0
IL_0047: ldloc.0
IL_0048: call void [mscorlib]System.Console::WriteLine(float64)
IL_004d: ldstr "Hello "
IL_0052: ldstr "World"
IL_0057: call string [mscorlib]System.String::Concat(string,
string)
IL_005c: call void [mscorlib]System.Console::Write(string)
IL_0061: ldstr ""
IL_0066: call void [mscorlib]System.Console::WriteLine(string)
IL_006b: ldstr "Hello "
IL_0070: stloc.1
IL_0071: ldloc.1
IL_0072: ldstr "World"
IL_0077: call string [mscorlib]System.String::Concat(string,
string)
IL_007c: stloc.1
IL_007d: ldloc.1
IL_007e: call void [mscorlib]System.Console::WriteLine(string)
IL_0083: ldc.i4 0x1
IL_0088: stloc.2
IL_0089: ldloc.2
IL_008a: call void [mscorlib]System.Console::WriteLine(bool)
IL_008f: ldc.i4 0x0
IL_0094: stloc.2
IL_0095: ldloc.2
IL_0096: call void [mscorlib]System.Console::WriteLine(bool)
IL_009b: ret
} // end of method MainClass::Main

0 comments: