MSS Code Factory: A Fractal Programming System    Get MSS Code Factory at SourceForge.net. Fast, secure and Free Open Source software downloads

Prev Documentation Home Next

Generic Expansion Language

The Generic Expansion Language (GEL) is the meta-language grammar and built in modifiers and keywords provided by the MssCFGenContext GEL interpreter from the 1.9 CFCore implementation. When GEL is adapted to a business application model by specifying ExtendCFCore="true" for a schema, a SchemaMssCF package is produced containing a SchemaMssCFEngine implementation that binds the specific names of the business language to the core expert systems engine technology provided by CFCore.

While the manufactured GEL implementation is not an artificial intelligence in and of itself, it is based on the same expert systems technology that allowed MSS Code Factory to achieve a level of technology that could be legitimately called genetic artificial intelligence. It is the sum of parts that garners the factory with intelligence and its ability to produce a customized GEL implementation which qualifies it as a genetic algorithm.

GEL is used in the $-delimited expansions specified for the GenRule, GenFile, and GenTrunc definitions contained by an application's set of knowledge configuration cartridges, which use the same syntax and file structure as the factory's own knowledge base.

When GEL is extended by the engine to produce a SchemaMssCF binding layer, it establishes the binding, iterator, and reference names that are valid within the context of the manufactured application. The specific meaning of the language that results is derived from the business application model itself, providing a very naturally flowing syntax for navigating the model in rules defined to be processed by your customized SchemaMssCFEngine implementation.

This is the heart of the genetic learning that happens when MSS Code Factory adapts itself to a new business model, and results in a customized knowledge engineering language tailored to the needs of your business.

This document defines the common components of GEL which apply to all business knowledge engineering languages that result.

The syntax of a GEL statement

A GEL expansion statement appears anywhere in the body text of a GenRule, GenFile, or GenTrunc expansion rule and is delimited by enclosing it in $ characters. To embed a literal dollar sign in expansion text, use two dollar signs, as in "$$".

The ScopeDef and GenDef names you use for the expansion rules in your cartridges are the same names you specified for the tables which comprise your business model. They are not in any way restricted to the names used by the MSS Code Factory itself for its MSSBam models.

What names are bound by a GEL specialization?

The SchemaMssCFEngine for a schema binds the following names to the GEL specialization:

empty

The empty expansion produces an empty string.

iterate

$iterate RelationSuffix(
  [before ExpandBefore]
  [first ExpandFirst]
  [each ExpandEach]
  [last ExpandLast]
  [after ExpandAfter]
  [lone ExpandLone]
  [empty ExpandEmpty] )$

An iterate directive specifies which expansions to perform before/after the iteration expansion, for the first and last elements in the expansion set, and for each and lone elements of the expansion set. Finally there is the empty expansion, which often expands to empty in order to prevent a warning being issued if an iteration expands to an empty set.

spread

$spread RelationSuffix(
  [between ExpandBetween]
  [before ExpandBefore]
  [first ExpandFirst]
  [each ExpandEach]
  [last ExpandLast]
  [after ExpandAfter]
  [lone ExpandLone]
  [empty ExpandEmpty] )$

A spread directive is a special form of iterator that evaluates a series of iterations over the result of expanding the RelationSuffix to obtain the iteration list. Given an iteration list of n elements, n, n-1, n-2...1 elements are processed by each pass, skipping the tail of the previous iteration each time. So far this construct is only used to evaluate the where clauses for comparing composite keys in the page data stored procedures.

reference

$reference RelationSuffix GELStatement$

The reference directive resolves the singleton reference named Suffix within the current context. After expanding the reference, a new GenContext is pushed with the reference as the top GenDef, and the remaining GELStatement is expanded within that new context. This provides a left-to-right reading of the overall expansion syntax.

switch

$switch ValMacro Key1 Macro1 Key2 Macro2 [nil NilMacro] [empty EmptyMacro] default MacroDefault$

The switch directive is followed by a sequence of literal matching string names and the expansions to apply if the ValMacro expands to the specified string name. If none of the specified string names applies, the required default expansion is applied.

The special tag nil is expanded if the value of the ValMacro expansion is null, and the empty expansion applies if ValMacro expands to an empty string.

Stack unwinding: popto, poptop, and poponefromtop

$popto GenDefName GELStatement$

Expansion of a popto directive temporarily unwinds the expansion stack to the first instance of a GenDefName object as the GenDef of the context. A new context is pushed which clones the popped context, so the actual context stack isn't really unwound in reality.

$poptop GenDefName GELStatement$

Expansion of a poptop directive pushes a clone of the topmost GenDef derived from the specified GenDefName.

$poponefromtop GenDefName GELStatement$

Expansion of a poponefromtop directive pushes a clone of the secondmost GenDef derived from the specified GenDefName. This is rarely used, but critical when it's needed.

Case Manipulation: upper, lower, leadlower, and mixed

The verbs upper, lower, leadlower, and mixed are used to manipulate the case of the subsequent GELStatement expansion as specified.

$upper GELStatement$

Convert the expansion of GELStatement to uppercase.

$lower GELStatement$

Convert the expansion of GELStatement to lowercase.

$leadlower GELStatement$

Convert the first character expansion of the GELStatement expansion to lowercase.

$mixed GELStatement$

Kind of a pointless keyword, as it means to pass the expansion of the GELStatement without modification. Its use is primarily as syntactic sugar for the pedantic knowledge engineer.

counter

$counter CounterName new$

Define a new counter named CounterName and initialize it to 0, expanding this directive to an empty string.

$counter CounterName increment$

Increment the counter, expanding this directive to an empty string.

$counter CounterName decrement$

Decrement the counter, expanding this directive to an empty string.

$counter CounterName value$

Expands to the value of the counter.

constrainMin and constrainMax

$constrainMax MaxValue MacroName$
$constrainMin MinValue MacroName$

Each expands MacroName, and converts the result to Long.

MaxValue and MinValue can be numeric values or MacroNames. If they are numeric values, they're converted to Long If they are macro names, the macro is expanded and the result is converted to Long.

Once all values are converted, inclusive comparisons are made, and the resulting maximum or minimum value is converted to a string and resturned as the result of the expansion.

This means you can do range constraints like:

$constrainMin 4 MaxLen$
$constrainMax 100 MaxLen$

You can easily nest one within the other by using an injected expansion name to pass the results of one expansion to further evaluation by the invoker.

prefixline

$prefixline ValueMacro BodyMacro$

The ValueMacro is expanded to get the string which is to be inserted as a line prefix.

The BodyMacro is expanded, and the beginning of every line in the expansion is prefixed by the expansion of ValueMacro.

This makes it possible to embed the license text within a comment block of source code.

Builtin Expansions

The following pre-defined expansions are built into the MssCFEngine:

GeneratorName

GeneratorVersion

GenDate

GenTime

GenTimestamp

GenSerializableUID

GenFileFullName

Expands to the fully pathed name of the currently open file.

GenFileName

Expands to the name of the file without any directory specs, including any file-type suffixes.

GenFileBaseName

Expands to the name of the file without any directory specs, and without the file-type suffix.

GenPackage

Expands to the name of the package being generated.

GenPackageDir

Expands to the subdirectory part of the package converted to a directory (with forward slashes.) The generation root directory is not included.

GenPackageFullDir

expands to include the generation root directory as well as the package directory. No processing is done on the root directory, so on DOS-derived file systems there may be backslashes included.

GeneratingClass

GenSubPackage

SourceBundle

SourcePackage