Angel \”Java\” Lopez on Blog

March 8, 2011

AjGenesis and Language Workbench Competition 2011

Filed under: AjGenesis, Code Generation, Lwc2011 — ajlopez @ 5:33 pm

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:

http://www.languageworkbenches.net/LWCTask-1.0.pdf

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:

http://ajgenesis.codeplex.com/SourceControl/list/changesets

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
    Entities
	Entity Person
	    Properties
		Property Name Type="Text"
		Property FirstName Type="Text"
		Property BirthDate Type="Date"
		Property OwnedCar Type="Car"
	    End Properties
	End Entity
	
	Entity Car
	    Properties
		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:

GenerateCSharp.cmd

GenerateJava.cmd

GenerateVbNet.cmd

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

<Technology>
	<Name>VbNet</Name>
</Technology>

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

http://www.ajlopez.com

http://twitter.com/ajlopez

2 Comments »

  1. Great to see this happen, Angel! I’ll be back for more.

    Comment by Angelo — March 9, 2011 @ 9:28 pm

  2. [...] my previous post I described my initial work for Language Workbench Competition 2011, using AjGenesis. Now, it’s [...]

    Pingback by More Language Workbench Competition 2011 with AjGenesis « Angel “Java” Lopez on Blog — March 14, 2011 @ 9:03 am


RSS feed for comments on this post. TrackBack URI

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Theme: Shocking Blue Green. Get a free blog at WordPress.com

Follow

Get every new post delivered to your Inbox.

Join 67 other followers

%d bloggers like this: