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 Javascript-like syntax with noticeable loans to other popular scripting languages. However, when it comes to OOP, AddyScript has a radically different approach than the function-based approach of Javascript.
Main features
- byref and variably sized arrays of parameters (with a syntax borrowed to C#).
- Dynamic typing and dynamically declared variables (declared just as they are assigned a value).
- Closures (in the form of anonymous functions, lambda expressions and references to functions).
- A Structured error handling mechanism.
- Array and object initializers.
- The ability to import an existing script from another.
- The ability to instantiate and manipulate .Net Framework (or Mono) and COM classes.
- The ability to invoke native DLL functions.
Why is it different?
Unlike many other scripting engines, AddyScript does not use a language recognition tool. Rather, 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.
When could it be useful?
- When you want to give to the end-user of your application the ability to edit and execute formulas at runtime.
- When you want to evaluate certain expressions typed by end-users at runtime.
- When you want to teach programming to your younger boy/girl with a not constraining language.
How to use it?
- First, add a reference to AddyScript.dll in your project.
- Then import the AddyScript and AddyScript.Parsers namespaces.
- You could additionally import any namespace in the AddyScript.dll assembly depending on what you want to do with it.
- Type your script somewhere (either in a file or in an in-memory string).
- Finally, add a code snippet like this:
var parser = new Parser(new Lexer(new StringReader(myScriptCode)));
// Alternatively : var parser = new Parser(new Lexer(new StreamReader(myScriptFile)));
var program = parser.Program();
var context = new ScriptContext();
context.Variables["stringVar"] = "John Doe";
context.Variables["doubleVar"] = 18.5;
ScriptEngine.Interpret(program, context);
Remarks
- There is also an Evaluate method in the ScriptEngine class for quickly evaluating expressions.
- The small help file provided with the demo application explains the usage of AddyScript with more details.
About the demo
The test form uses the ScintillaNet control. So, it has some nice features like syntax highlighting, auto-completion, line numbers and call tips. A few samples are provided in the
Scripts subdirectory of the solution folder. All that is made to help you getting started.
What has been recently added?
- Date and decimal types (ver. 0.7)
- OOP support (ver. 0.8)
- try-catch-finally (ver. 0.8)
- reflection (ver. 0.8)
- import directive (ver. 0.8)
- date, string and array arithmetic (ver. 0.8)
- function references and in-line function declarations (ver. 0.8)
- localized error messages (ver. 0.9. From vesion 0.9.2, french language support has been added)
- a C-like conversion syntax (ver. 0.9)
- a better management of assignment and byref parameters (ver. 0.9)
- an empty for loop is now equivalent to an infinite loop (ver. 0.9)
- a better support of the foreach loop including an iterator protocol for user defined classes (demonstrated in the xrange.add sample script) (ver. 0.9)
- a goto statement and labels management (ver. 0.9)
- a better control on the usage of the continue, break, this, super and return keywords (ver. 0.9)
- a totally redesigned GUI for the demo application, with the ability of simultaneously loading several scripts (ver. 0.9)
- a small help file for the demo application (ver. 0.9)
- an additional demo application named Plotter (the name is self explanatory) 100% compatible with mono 2.6.3 and higher (ver. 0.9)
- a demo application for the mono platform (ver 0.9; improved in version 0.9.3)
- the possibility to export the syntax tree to XML format (ver 0.9)
- the possibility to regenerate the source-code from the syntax tree (essentially used to allow automatic code formatting) (ver. 0.9.1. Improved in version 0.9.2)
- improved try-catch-finally statement : no return in the finally block; no jump out of the finally block; jumps invoked from the try or catch blocks are well remembered after the execution of the finally block. (ver. 0.9.1)
- ability to create instances of .Net and COM types and invoke their members (ver. 0.9.4)
- ability to convert a closure to a delegate and attach it as a handler for a .Net object's event (ver 0.9.4)
- redesigned external functions feature (now target native functions; ver 0.9.4.1)
Important!
AddyScript is now released under the GNU LGPL License. So, you can now use it without being obliged to publish your source-code.
What's next?
- More improvement on the GTK# demo.
- The ability to compile a script to a managed executable via CodeDom (or Reflection.Emit; continuously delayed because improving the interpreter is the priority).
- Additional localized UI resources (It's up to you to do that).
- User defined constants.
- A probable replacement of the actual array type by a list and a dictionary type.
- A probable redesign of the date type and its related functions.
- Maybe more OOP related features like properties, indexers and operators overload.
- Maybe the ability to subclass a CLR type from AddyScript.
- Maybe a variant number of strongly typed catch clause in the try-catch-finally statement.
Well, that's all. Hope you'll enjoy. Waiting for your feedback.