ExpertCoder   ExpertCoder is a toolkit that supports the creation of code generators based on expert systems.
What is Expert Coder?

ExpertCoder is a toolkit for the .NET platform that supports the creation of code generators based on expert systems. It's not a generator of code generators, but rather a set of libraries useful to write generators.

The traditional way of writing code generators is by simply writing a computer program with a series of print-like commands.
The problem with this approach is that it makes it very difficult, even for the generator's author, to alter the design of the generated code because the later is not similar to the code of the generator.

There are other, more advanced, alternatives, such as using XSLT stylesheets to transform XML documents into source code. With these alternatives you gain in clarity, because the code of the generator (the stylesheet) looks like the generated code; however, these methods expose their disadvantages when you need to add intelligence to the generator, because the set of tools and libraries accessible from a template is fairly small.

The purpose of this project is to build a toolset that provides the code generator writer with the best of both worlds:

  • The clarity that results from using templates for code generation.
  • The flexibility provided by the power of the .NET platform, along with its huge class library.

Besides, as it's based on the principles of expert systems, the resulting generators are easily extensible, modular, and their structure is more declarative than imperative.

How it works?

The basic idea is to create an expert system, to write a set of rules and then to specify the distinct precedences between them.

This rules are evaluated by an execution engine who determines, based on the precedencies and every rule's activation state, which rule must be executed.

The execution engine provides an environment, which provides three sources of information:

  • Parameters: this are stored in configuration files.
  • Input model: the model to be converted.
  • Infered knowledge: the expert system is able to modify its active memory. By using this you can implement an indirect interaction mechanism for rules.

The environment keeps references to:

  • The input model.
  • The current element from the input model.
  • The output model.
  • The current element from the output model.

A typical generator is composed by two kinds of rules: navigation rules and production rules.
Navigation rules are activated in presence of a given element type at the input, and procedes to "navigate" that element's relationships, changing the current element from the input model.
Production rules, when get active in presence of an input element (and maybe also certain kind of element at the output,) apply a developer-written algorithm in order to generate nodes at the output, using the information currently available at the input and in the active memory.