/** Translation script, reading a MLC file (Mini-Langage Conditionel) and generating the corresponding .h and .c files. Strange points to check: - there is no 'pourtout' statement, able to iterate multiple columns such as 'ORG', - what about 'Pointillés'? - display functions are restrained to columns only; why not to apply it on an expression, like the following: Titre ( NOM + Pointillés + PAGE_DEB) To run the example, type the following command line in the console: codeworker -translate MLC.cwp script1.mlc script1.c Nota: "script1.mlc" is the display strategy, written in the 'Mini-Langage Conditionel' DSL (*.mlc). **/ DSL ::= #ignore(C++) #continue => { local sFileRadical = rsubString(getOutputFilename(), 2); local sShortName = getShortFilename(sFileRadical); generate({#ifndef _@this@_h_ #define _@this@_h_ void affiche_@this@(DBLigne* r); #endif @ }, sShortName, sFileRadical + ".h"); @#include "@sFileRadical@.h" void affiche_@sShortName@(DBLigne* r) { @ incrementIndentLevel(); } [statement]* #empty => { decrementIndentLevel(); @} @ } ; statement ::= #readIdentifier:sID => local sFirstLetter = sID.charAt(0); [ // id starts with a capital letter? // So, it is a display statement #check(sFirstLetter == sFirstLetter.toUpperString()) #continue display_function | // id is compulsory an instruction #continue keyword ] ; display_function<"Titre"> ::= #continue '(' column:sField ')' => local args; [ '+' #continue => pushItem args; #generatedString(args#back) display_literal ]* => { @printf("%s@repeatString(" %s", args.size())@\n", Titre(r->@sField@)@ foreach i in args { @, @i@@ } @); @ } ; display_function<"Ligne"> ::= #continue '(' column:sField ')' => local args; [ '+' #continue => pushItem args; #generatedString(args#back) display_literal ]* => { @printf("%s@repeatString(" %s", args.size())@\n", Ligne(r->@sField@)@ foreach i in args { @, @i@@ } @); @ } ; display_function<"Sous_Ligne"> ::= #continue '(' column:sField ')' => local args; [ '+' #continue => pushItem args; #generatedString(args#back) display_literal ]* => { @printf("%s@repeatString(" %s", args.size())@\n", Sous_Ligne(r->@sField@)@ foreach i in args { @, @i@@ } @); @ } ; display_literal ::= #readCString | "Pointillés" => {@Pointilles@} | column:sCol => {@r->@sCol@@} ; keyword<"si"> ::= #continue => { @if (@ } '(' condition ')' #readIdentifier:"alors" => { @) { @ incrementIndentLevel(); } '(' [statement]* ')' [ #readIdentifier:"sinon" #continue '(' => { decrementIndentLevel(); @} else { @ } [statement]* ')' ]? => { decrementIndentLevel(); @} @ } ; keyword<"tantque"> ::= #continue => { @while (@ } '(' condition ')' #readIdentifier:"alors" => { @) { @ incrementIndentLevel(); } '(' [statement]* ')' => { decrementIndentLevel(); @} @ } ; condition ::= comparison_expression; comparison_expression ::= => local iPosition = getOutputLocation(); literal_expression => local sOp; [ ["<>" | "<=" | "<" | ">=" | ">" | "="]:sOp #continue => { if sOp == "<>" sOp = "!="; @, @ } literal_expression ]? => if sOp { insertText(iPosition, "strcmp("); @) @sOp@ 0@ } ; literal_expression ::= "'" #continue ->(:sText)"'" => {@"@sText@"@} | column:sCol => {@r->@sCol@@} ; column ::= #readIdentifier:{"NOM", "PAGE_DEB", "ADR_L1", "ADR_L2", "ORG"};