My code generation project AjGenesis uses a interpreted language to execute tasks and expand templates. The language was named AjBasic. It’s used in all the examples I wrote with AjGenesis (more info at AjGenesis posts). Years ago, I had separated the interpreter code from the mother project. This weekend, I was refactoring the code. The result is now published at:
In my opinion, Google Code is easy to manage. Contrary to SourceForge and CodePlex, they are using Subversion as code repository. I use the Tortoise SVN client to checking the changes. Google people are gentle: I can create many projects, until now:
More info in previous posts:
The solution AjBasicWithTests is composed by the projects:
AjBasic: It implements the compiler and tokenizer. The tokenizer separates the incoming text in tokens. The compiler makes abstract trees from such input.
AjInterpreter: A new project, not present in AjGenesis. It contains all the support for the abstract tree, its nodes, the environment for values, and an evaluator of programs. The management of .NET objects, and dynamic objects, are in this project, too. My intention is to continue to use this project to support other interpreted languages.
AjBasic.Console: A simple console to test the interpreter.
AjBasic.GUI: A simple (and ugly) WinForm to test the interpreter.
AjBasic.Test: Some test fixtures, using NUnit (there is another solution AjBasic that not includes the tests)
All the projects are written using Visual Basic .NET. The solution was compiled using Visual Studio 2005. The console and GUI project could be used as a base that explains how to use the interpreter from your own application.
There are many points to discuss about the implementation: they would deserve future posts. By now, let’s explore some of the main features of the project, at its current status. Then, I’ll write down some ideas to explore in future versions.
So, you can write code like this:
You don’t have to declare the variable. You can create the object and add the property FirstName in one command (this automatic creation of object is not supported in AjGenesis, yet).
You can test the existence of a property:
If the variable a has no assigned value, or if it has no LastName property, the above condition is evaluated to false. You can test something like foo.bar.anything and no exception is raised. The result value would be a nothing, what is evaluated as a false in a condition.
The solution was not developed using TDD (Test-driven development). Instead, I wrote the tests after the code, only to be sure the core functionality were well implemented, according to my expectations. I didn’t use descriptive names, but they were useful when I refactored the full solution:
You can try the language from the console AjBasic.Console:
and from the WinForm AjBasic.GUI
None of the above is the “ultimate app”, but they work…😉
There are many ideas flying near my remaining neuron, and I have to put order on them. Some points, for the record:
– Now the interpreter core is separated from compiler, I could write AjSharp, an interpreter with C# syntax. Then, it could be added to AjGenesis, to write templates in a language more palatable to die-hard C# programmers.
– Add support to dynamic classes and prototypes.
– Refactor the tests
– Write down a minimal manual, explaining the language and its features
– Extend the language to support delayed values and delayed evaluation
– The internal form of this interpreter could be rewritten in Java
– The option to write an AST related to DLR support doesn’t attract me, it could be a lot of work. But it could be interesting to learn more about .NET DLR.
– Use the language as the basis for programming distributed agents (an ambitious point, that deserves more evaluation).
As usual, I had fun written this software.
Angel “Java” Lopez