What is it?

AddyScript is a scripting engine for the .Net and Mono platforms. It can be used to add scripting capabilities to business applications or simply as a learning tool for younger people.

Syntax overview

AddyScript has a straightforward C-like syntax (or JavaScript-like or PHP-like) with noticeable loans to popular scripting languages like JavaScript, PHP, Python and Ruby. It can be summarized as an interpreted dynamically typed version of the C language with OOP features.

Main features

Why is it different?

Unlike many other scripting languages, AddyScript does not rely on a language recognition tool for its lexer and parsers. Rather than that, its lexer and parser are entirely hand-coded. This makes it easier for anyone who knows C# (and has some compilation rudiments) to edit the code without needing to learn another stuff (However, it's quite easy to regenerate those classes with tools like Irony or ANTL). Also note that at this stage, AddyScript is not built on top of the DLR. For some features like dynamic typing, this may seam like re-inventing the wheel. Not at all, The real goal is to keep the engine easy to migrate on other (even native) platforms.

When could it be useful?

How to use it?

There are several usage scenarios for AddyScript.

Suppose that you simply want to parse and run a script from your program. Then simply proceed as follows:
  1. First, add a reference to AddyScript.dll to your project.
  2. Then import the AddyScript namespace.
  3. You could additionally import any namespace from the AddyScript.dll assembly depending on what you want to do with it.
  4. Type your script somewhere (either in a file or in an in-memory string).
  5. Finally, add a code snippet like this:
var program = ScriptEngine.ParseFile(path_to_your_script);
// Alternatively: var program = ScriptEngine.ParseString(string_containing_your_script);
var context = new ScriptContext();
context.Variables["stringVar"] = "John Doe";
context.Variables["floatVar"] = 18.5;
ScriptEngine.Interpret(program, context);
Console.WriteLine(context.Variables["stringVar"]);
Console.WriteLine(context.Variables["floatVar"]);


Now, suppose that you want to evaluate a formula contained in a string. Here is how to do:
  1. Add a reference to AddyScript.dll to your project.
  2. Import the AddyScript and any other namespaces from the AddyScript.dll assembly depending on what you want to do with it.
  3. I suppose that the formula to evaluate is store in a string called strFormula and expects a parameter named x; successive values for parameter x are stored in a collection named inputValues.
  4. Add a code snippet like this:
var formula = ScriptEngine.ParseExpression(strFormula);
var context = new ScriptContext();

foreach (var value in inputValues)
{
    context.Variables["x"] = value;
    double result = ScriptEngine.Evaluate(formula, context).AsDouble;
    Console.WriteLine(result);
}


The last stuff is about how to invoke parts of a script from C# or VB.Net (or any other language) code:
  1. Add a reference to AddyScript.dll to your project.
  2. Import the AddyScript and any other namespaces from the AddyScript.dll assembly.
  3. The rest is like it follows:
delegate double DummyDelegate(double x);

var context = new ScriptContext();
var engine = new ScriptEngine(context);

// Declare a dummy function in the script; note that this one matches the prototype of DummyDelegate
engine.Evaluate("function dummy (x) { return 2 * x + 5;}");

// Invoke dummy from the client code
var res1 = engine.Invoke("dummy", -7);
Console.WriteLine(res1.AsDouble);

// Create a delegate that wraps dummy and invoke it
var dummy = (DummyDelegate) engine.GetDelegate("dummy", typeof(DummyDelegate));
var res2 = dummy(4);
Console.WriteLine(res2);

About the demo

The editor window uses the ScintillaNet control. So, it has some nice features like syntax highlighting, auto-completion, line numbers and call tips. It's also shipped with a small help manual in CHM format. A few samples are provided in the Examples subdirectory of the solution's folder. All that is made to help you getting started.

What has been recently added?

What's still to come?


Well, that's all. Hope you'll enjoy. Waiting for your feedback.