AjGenesis and Language Workbench Competition 2011

Last week, thanks to a @pmolinam, I met

Language Workbench Competition 2011

Molina had sent me the info last year, but I forget the challenge. It is mentioned in InfoQ:

Language Workbench Competition 2011 Submissions

You can read the task list at:


I don’t sure if AjGenesis could qualify as a Language Workbench: it’s more oriented to be a free-model code generation tool. It has no IDE integration, but it is flexible and language-independent. It doesn’t produce any DSL: instead, it has a free model that can be use in many ways, to describe the concepts you have to model, without attached domain specific language. @pmolinam asked if I could complete the tasks using AjGenesis, my open source codegeneration tool. My answer: Yes!

Then, some messages appeared at twitter:

Today, I started to write Phase 0, points 0.1-0.2. The example is at AjGenesis trunk, at:


under examples/Lcw2011

The first point 0.1 is:

0.1 Simple (structural) DSL without any fancy expression language or such. Build a simple data definition language to define entities with properties. Properties have a name and a type. It should be possible to use primitive types for properties, as well as other Entities.

entity Person { 
    string name
    string firstname
    date bithdate
    Car ownedCar

entity Car { 
    string make
    string model

I wrote a simple Project.txt (note that I’m using the textual model instead the XML one, see Models for AjGenesis and Textual model for Code Generation in AjGenesis ).

Project Lwc2011
	Entity Person
		Property Name Type="Text"
		Property FirstName Type="Text"
		Property BirthDate Type="Date"
		Property OwnedCar Type="Car"
	    End Properties
	End Entity
	Entity Car
		Property Make Type="Text"
		Property Model Type="Text"
	    End Properties
	End Entity
    End Entities
End Project

The Phase 0-0.2:

0.2 Code generation to GPL such as Java, C#, C++ or XML Generate Java Beans (or some equivalent data structure in C#, Scala, etc.) with setters, getters and fields for the properties.

Using assets from my post Building An Application using AjGenesis (Part 4), I wrote the commands:




I’m using additional model files for describing technology. This is my VbNet technology model:


Simple! This time, I’m using the XML model (in memory, textual and XML have the same features; it’s only a serialization option).

Look at GenerateCSharp.cmd:

AjGenesis.Console Project\Project.txt Project\Technologies\CSharp.xml Tasks\Complete.ajg Tasks\Generate.ajg

It loads the Project.txt, the corresponding technology model, loads and executes the Complete.ajg task, and then loads and executes the Generate.ajg task. The Complete.task (see the mentioned post Building An Application using AjGenesis (Part 4)) it’s used for complete the model: one thing it dows is to translate abstract types like “Text”, to the corresponding final language type, like “string” in C#, or “String” in Java.

The Generate.ajg takes the enriched model and generate the code for each entity, using templates. This is the template for C#:

// Entity Class, generated with AjGenesis (http://ajgenesis.codeplex.com)
namespace ${Project.CSharp.Namespace} {
	public class ${Entity.Name}
	for each Property in Entity.Properties
		public ${Property.CSharp.Type} ${Property.Name} { get; set; }
	end for

The generated code for Person entity:

// Entity Class, generated with AjGenesis (http://ajgenesis.codeplex.com)
namespace Lwc2011 {
	public class Person
		public string Name { get; set; }
		public string FirstName { get; set; }
		public DateTime BirthDate { get; set; }
		public Car OwnedCar { get; set; }

Next steps: complete 0.3, 0.4 tasks, and then, solve Phase 1. I could complete the assignment in two weeks. I will publish the advance in upcoming posts.

Keep tuned!

Angel “Java” Lopez



2 thoughts on “AjGenesis and Language Workbench Competition 2011

  1. Pingback: More Language Workbench Competition 2011 with AjGenesis « Angel “Java” Lopez on Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s