Best experienced with Microsoft® Internet Explorer 3.0 and a 64K High-Color driver (or better) |
The Home of dCG (draft) Code Generator dCG Scripting Guide A general purpose source code generator for Microsoft WindowsTM
by Rui Nuno Capela
Contents | dCG Home | dCG Download | dCG Mailing List | dCG Survey Form |
Member of the Internet Link Exchange |
|
ContentsIntroductionSubstitution Mechanism and Variables Data Types and Expressions User defined Objects User defined Functions User defined Dialogs User Code Protection List of Statements List of Functions We're talking about:
dCG (draft) Code Generator !
|
Have a starting point... |
IntroductionThe dCG scripting language is a procedural high-level interpreted language that can be used to create template driven text files. The dCG scripts are considered source code templates in its own nature. These templates - the source scripts - consist in interpreted statements and expressions that are embedded in literal text portions. The aim is to produce one or more output text files that have the same image of that of the literal text portions and tailored by the interpretation and substitution of the variable portions - driven by language statements, variable and function expressions. Statements have crucial role in flow control, I/O and user interaction. There can be only one statement per line. Statements don't produce any direct output (with the unique exception of the PRINT statement in special cases) but do control how output is to be performed. However, can be more than one expression within one line and expressions are considered the main output agents of the dCG scripting. They are ruled by the dCG substitution mechanism. |
Who's the substitute?... |
Substitution Mechanism and VariablesThe essential feature of dCG is the scripting substitution mechanism. All scripting statements and expressions are inscribed within the output text (just like a template) and can be recognized by its delimiter markers. By default, the script delimiter markers are $[ and ]$, respectively for the start and end of the script statement or expression portion. Therefore, every text that isn't delimited between these markers is considered literal text, and will be transferred to output without modification. All source text that is found between the scripting markers are to be processed by the script interpreter and will result in some action depending if it's a statement or a simple expression. In this later case, the expression is evaluated and if the result is a character string or a numeric value, it will be transferred to current output in the same position occupied by the marked up script portion. If one or more expressions in one single line leads to an empty or blank output line, no output is made, that is, the output line is suppressed. For example, the following script line: $[UserName = "John Doe"]$is an assignment statement, where a variable called UserName is assigned a character string. No declaration is needed to the variable. Variables are typeless, that is, they can hold whatever data type in one time. Further in the source we could write the line: Authorized user: $[UserName]$where there's some literal text with an embedded script portion. The script portion contains the variable name that has been assigned before. It is treated as an expression that leads to a character string result. After processing, the corresponding output should be: Authorized user: John DoeVariable names can have any reasonable length. Can be codified with any alphanumeric (A-Z; 0-9) or the underscore character (_). However, variable names cannot start with a numeric digit, they must begin with an alphabetic (A-Z) or the underscore character (_). As the whole language, including statements and function names, variable names identifiers are not case sensitive. A little more elaborated script (and almost as useless) can be exemplified by the following source lines: $[OUTPUT "colors.out"]$ $[Colors = LIST ("Red", "Green", "Blue")]$ $[Intensities = LIST ("Light", "Dark")]$ $[Count = 0]$ Available colors: $[FOR EACH Color IN Colors]$ $[FOR EACH Intensity IN Intensities]$ $[Count = Count + 1]$ Color $[Count]$: $[Intensity + "-" + Color]$ $[END FOR]$ $[END FOR]$ There are $[Count]$ colors available.this will create an output file named colors.out with the following contents: Available colors: Color 1: Light-Red Color 2: Dark-Red Color 3: Light-Green Color 4: Dark-Green Color 5: Light-Blue Color 6: Dark-Blue There are 6 colors available. |
Now we're getting serious... |
Data Types and ExpressionsThe dCG Scripting language supports four basic data types:
Expressions are constructed by applying standard operators to one or more operands. Operands can be any literal value, variable, object member (that is treated just like a special case of a variable) or function return values. The defined operators are shown below, in precedence order:
|
dCGScript is not yet another OOP language!... |
User defined ObjectsObjects are just static data structures. The dCG script language is not an object-oriented language so don't start looking for any inheritance mechanism or any methods associated to dCG objects. It's just a way to aggregate data items that have a common relationship. Nothing more simple than that. An example of an object variable declaration within a script is shown below: $[OBJECT MyApplication]$ $[Name = "MyApp"]$ $[Dir = "C:\USR\MYAPP"]$ $[System = LISTIDH_LIST("Windows 3.x", "Win32")]$ $[END OBJECT]$This will result in declaring an object variable named MyApplication with three data members. The first member, entitled Name, is defined as a character string with default value "MyApp". The second member, named Dir, is also a string with initial value "C:\USR\MYAPP". The third and last member, identified by System, is defined as a list of two strings. After definition the MyApplication object and any of its members can be used as individual variables. Object member names have the same restrictions applicable to stand-alone variable names, and are not case sensitive. An object member is accessed by using a dot character followed by the member name identifier. They can also be the target (left hand operand) of an assignment statement. For example, for the following script lines: Application Name.....: $[MyApplication.Name]$ Application Directory: $[MyApplication.Dir]$ Application Platform.: $[MyApplication.System[0]]$the corresponding output should be: Application Name.....: MyApp Application Directory: C:\USR\MYAPP Application Platform.: Windows 3.xNotice the way one can access a list item by index, as it is done in MyApplication.System[0] to retrieve the first list item. Object members can be of any data type, determined by the initial value expression on the declaration (right side of the equal character). Assigning one object variable to another is just a way to make an object clone (member-wise copy). |
If you're functional!... |
User defined FunctionsOther than the pre-defined functions, the definition of new functions is supported at script level. The following example is a simple example of the definition of an user function named MyFunc that calculates the mean value of its two arguments: $[PROCEDURE MyFunc ( Arg1, Arg2 )]$ $[Result = (Arg1 + Arg2) / 2]$ $[RETURN Result]$ $[END PROC]$After this definition, the script: Half-way value: $[MyFunc(100,200)]$will have the following output: Half-way value: 150Functions have a single return value that can be of any defined data type and may be part of any consistent expression. A function must be defined before it is called and may have any number of arguments. Every function that accept one or more parameter (arguments), including predefined ones, may be called in two different forms. The usual way is passing all arguments between parenthesis and separated by commas, like MyFunc(X,200). The second way is by attaching the function name to a variable identifier, using the dot character, like X.MyFunc(200). This means that the variable value is to be passed as if it were the first argument in regular form. If the affected variable is of the same type as the function return value, it will be assigned the later. This is the only way one can mimic a parameter passing by reference. In all other cases, all parameter passing is done by value (except for internal functions). This means that MyFunc(X,200) and X.MyFunc(200) are equivalent function calls, but the later will also set the value of X to the function's return value. In the following examples both forms of calling a function are shown. Regular calling form: $[X = MyFunc(100,200)]$ The result is: $[X]$Dot calling form: $[X = 100]$ The result is: $[X.MyFunc(200)]$Both ways are functionally equivalent and would result in the same output: The result is: 150 |
Let's talk!... |
User defined DialogsThe dCG Scripting language supports the definition of dynamic dialog boxes to let the user interact with the interpretation and generation process. Each in-line defined dialog is mapped to an object variable whose members can be accessed as any other data value in a statement or expression. This is an example of an in-line dialog definition, that would be mapped to an object variable named MyDialog: $[DIALOG MyDialog, "Name Entry Example", 30, 40, 140, 40]$ $[CONTROL Prompt, Text, "Enter Your Name:", 4, 4, 80, 8]$ $[CONTROL Name, Edit, "", 4, 14, 80, 12]$ $[CONTROL Ok, OkButton, "Ok", 90, 4, 46, 14]$ $[CONTROL Cancel, CancelButton, "Cancel", 90, 22, 46, 14]$ $[END DIALOG]$In this dialog there is declared four child window controls: one static text control (Prompt), one edit box (Name) and two standard push-buttons (Ok and Cancel). The following script lines will display the dialog and process the data the user has entered in it: $[DIALOG MyDialog]$ $[IF MyDialog.Result]$ My name is $[MyDialog.Name.Text]$! $[ELSE]$ I have no name. $[END IF]$Supposing the user had typed "John Doe" in the dialog edit box control (which contents referenced as MyDialog.Name.Text) and chose the Ok button (yielding the dialog's object member MyDialog.Result to a non-zero value) the output would be: My name is John Doe!If the Cancel button had been chosen (or the user had closed the dialog by selecting the control menu or hitting the Escape key) the script output would certainly be: I have no name.That is, MyDialog.Result now has a 0 (zero) value. |
Where did this come from?... |
User Code ProtectionEach time a script is interpreted any output files are completely overwritten. However there is the possibility to mark a code block as being protected, that is, not overwritten upon script interpretation, preserving any modification the user had made after a previous generation. This is called user code protection and the following example shows how a protect block can be defined within a script: // $[PROTECT "ProtectTag1"]$ // Some first-time generation text... pstrText = "Default text"; // $[END PROTECT]$After generation, the corresponding output file would look like: // %PROTECT ProtectTag1 // Some first-time generation text... pstrText = "Default text"; // %ENDPROTECTAny text that falls between the %PROTECT/%ENDPROTECT pair may be freely modified and is known to be a protected code block. Next time the same output file is generated all modifications made within this block will stay intact. Normally the %PROTECT/%ENDPROTECT marks should be coded as part of a comment area. In the example above, C/C++ is the target language; if it were a COBOL example one would use an asterisk '*' on 7th column; in PASCAL the curly brace '{...}' pair would lead the same purpose. |
Look familiar?... |
List of Statements
|
Call me!... |
List of Functions
|
I use dCG to make this webs!... |
If you're interested in dCG, please give me a call,
or you can fill an available dCG survey form.
Above Destruction!Please note that this is one of my early attempts to produce a web page, just a glimpse from myself to the world. This is in constant destruction and it will be a new tiny world for you to explore. |
This web has been last updated on May 9, 1999, and brought to reality thanks to CompuServe. http://ourworld.compuserve.com/homepages/rncbc/dCG2.htm |
|
Commonwealth Network |
|
Home sweet home... |
|