Home Page   We Generate Your Software.
Products Services Company Technology Demo Contact Site Map Search
Please note: this document is currently under revision.
The information herein contained, while still valid, does not reflect the latest state of the described technology.
The Somusar/SoProTech[tm] Booklet Series
Volume IV

"somusar/Tefigel: A Tutorial Introduction"

Printer friendly


Contents
1. Introduction
2. Language Summary
3. Text File Components
3.1 Text Files and Text Lines
3.2 Commands and Instructions
3.3 Comments
3.4 Markers
3.5 Special Characters
3.6 Variables
3.7 Name Spaces
4. Text File Processing
5. Modularity
6. Multilanguage Applicability
7. Generating Object-oriented Languages
8. Generating Internet-oriented Languages and Protocols
9. Generating Procedural Languages
10. Generating Scripting or Special-purpose Languages
11. Advanced Features and Topics
12. A More Extensive Example
13. Further Reading

Chapter 3 - Text File Components

The basic unit of work of Tefigel is the text file: the concept of Tefigel program or script is in fact purposely not clearly defined by the language, so that the translator can process any type of text file, independently of its contents and name or suffix. Nevertheless, usual programming concepts like instructions, comments and variables are clearly defined, as explained in the next paragraphs of this chapter.

3.1 - Text Files and Text Lines        top

Traditionally, the first code example of a computer language has always been a "Hello, world!" program. Tefigel copies most of its input to its output, apart from variables substitution and execution of instructions. Thus, Tefigel allows such a "Hello" program to be written in its simplest form as follows.

Code Example 1 - Hello world
The simplest Somusar/Tefigel[tm] program: the traditional one-line greeting message. No actual processing takes place: input is copied to output.
Source code - File "hello_world"
    1      Hello, world!
	       
Output of "/opt/somusar/bin/tefigel hello_world"
    1      Hello, world!
	       

A slightly more complex implementation of this example involves a variable and an instruction, namely ECHO, as follows.

Code Example 2 - Hello world II
Set a variable and write it out with an instruction. Note that contents of variable "greeting" is accessed by simply naming it where required, even between double quotes ".
Source code - File "hello_world.2"
    1      @ set greeting=Hello, world!
    2      @ echo greeting
    3      Here it comes once again: greeting, and again: "greeting".
	       
Output of "/opt/somusar/bin/tefigel hello_world.2"
    1      Hello, world!
    2      Here it comes once again: Hello, world!, and again: "Hello, world!".
	       

3.2 - Commands and Instructions        top

Tefigel commands consist of either lines beginning with a Tefigel instruction (that is, a recognized uppercase word), or lines beginning with the current command marker, as shown in the following example.

Code Example 3 - Commands and variables
Short example introducing command lines, variables and the concept of command marker.
Source code - File "plain_cmd"
    1      Text lines, not to be altered by tefigel, as they contain neither
    2      tefigel variables, nor tefigel commands.
    3      @ echo Command line, echo message.
    4      @ set MESSAGE="Hello!"
    5      % echo Not a command line (yet), but contains a variable: MESSAGE.
    6      @ mark CMD %
    7      % echo Now a command line, due to command mark CMD. Variable: MESSAGE.
    8      % unset MESSAGE
    9      % echo After unset, variable MESSAGE is no longer a variable.
   10      % mark CMD
   11      % echo '%' is no longer the command line marker.
   12        Some more text lines, not to be altered by tefigel, as they contain
   13        neither tefigel variables, nor tefigel commands. Note that white
   14        s p a c e s   within text lines     are     left           untouched.    
	       
Output of "/opt/somusar/bin/tefigel plain_cmd"
    1      Text lines, not to be altered by tefigel, as they contain neither
    2      tefigel variables, nor tefigel commands.
    3      Command line, echo message.
    4      % echo Not a command line (yet), but contains a variable: "Hello!".
    5      Now a command line, due to command mark CMD. Variable: "Hello!".
    6      After unset, variable MESSAGE is no longer a variable.
    7      % echo '%' is no longer the command line marker.
    8        Some more text lines, not to be altered by tefigel, as they contain
    9        neither tefigel variables, nor tefigel commands. Note that white
   10        s p a c e s   within text lines     are     left           untouched.    
	       

The variable command marker plays an important role in making Tefigel more widely usable. In fact, several computer languages define a constant command marker, such as # in C/C++ preprocessing, or * in RPG comments, or C in Fortran comments: Tefigel's variable command marker allows Tefigel instructions to be intermixed with, and easily recognizable within, virtually any textual computer language. The default command marker is the character @, but it can be set to any other character, as shown in the previous example.

3.3 - Comments        top

Tefigel comments can be written in two ways, as the next example shows:

  • Using instruction REM;

  • Using a variable comment marker as the first character of a line, in the same way as for the command marker explained above.

Code Example 4 - Comments
Tefigel comments using instruction REM or a variable comment marker.
Source code - File "comments"
    1      ------------ Commenting via default "#" -------------------------------
    2      Plain text before the first comment.
    3      # This is a tefigel comment, and will be ignored
    4      # by the tefigel translator
    5      Plain text after the first comment.
    6      ------------ Commenting via a new comment marker (1: use "|") -------
    7      @ mark rem |
    8      Plain text before the second comment.
    9      | After command mark rem above, lines starting with a |
   10      | are treated as comments.
   11      Plain text after the second comment.
   12      ------------ Commenting via a different comment marker (2: use "%") -------
   13      @ mark rem %
   14      Plain text before the third comment.
   15      % After command mark rem above, lines starting with a %
   16      % are treated as comments.
   17      Plain text after the third comment.
   18      |    Note that lines starting with a | are no longer
   19      |    treated as comments.
	       
Output of "/opt/somusar/bin/tefigel comments"
    1      ------------ Commenting via default "#" -------------------------------
    2      Plain text before the first comment.
    3      Plain text after the first comment.
    4      ------------ Commenting via a new comment marker (1: use "|") -------
    5      Plain text before the second comment.
    6      Plain text after the second comment.
    7      ------------ Commenting via a different comment marker (2: use "%") -------
    8      Plain text before the third comment.
    9      Plain text after the third comment.
   10      |    Note that lines starting with a | are no longer
   11      |    treated as comments.
	       

3.4 - Markers        top

As shortly introduced above, Tefigel features an enhanced preprocessor-like approach: the first character in an input text line may have a special function, such as being a command or comment marker. The definition of a marker is achieved using instruction MARK, which allows to define several types of markers: beyond commands and comments, also function/subroutine CALLs can be associated with a marker.

Code Example 5 - Markers
Use of Tefigel markers.
Source code - File "markers"
    1      @ rem Plain comment
    2      @ echo Plain command with default command marker '@'
    3      @ mark rem |
    4      @ mark CMD %
    5      | Comment with new comment marker '|'
    6      % echo Command with new command marker '%'
    7      Plain text line with placeholder.
    8      % set placeholder=<some text>
    9      Plain text line with placeholder.
	       
Output of "/opt/somusar/bin/tefigel markers"
    1      Plain command with default command marker '@'
    2      Command with new command marker '%'
    3      Plain text line with placeholder.
    4      Plain text line with <some text>.
	       

3.5 - Special Characters        top

Another dynamic syntax construct of Tefigel consists in its set of special characters, which are special-purpose operators that can be used within normal text lines and dynamically changed using appropriate instructions.

Special characters include a DASH operator - explained in a following paragraph - to concatenate strings and create name-value contents association; a LINEBREAK operator, to split one input logical line across two or more physical lines; a CALLKEY operator, to issue function calls from within text lines; and a few more.

Code Example 6 - Special Characters
Split a logical line on two physical lines, and concatenate strings using the current dash operator.
Source code - File "special_chars"
    1      Text on two physical lines %
    2      separated by a '%'
    3      @ linebreak %
    4      Text on two physical lines %
    5      separated by a '%'
    6      -----------
    7      Line with a bro-ken word
    8      @ dash -
    9      Line with a bro-ken word
   10      -----------
	       
Output of "/opt/somusar/bin/tefigel special_chars"
    1      Text on two physical lines %
    2      separated by a '%'
    3      Text on two physical lines separated by a '%'
    4      -----------
    5      Line with a bro-ken word
    6      Line with a broken word
    7      -----------
	       

3.6 - Variables        top

Tefigel variables are basically placeholders for character strings, although basic arithmetic and boolean operations can be performed on them, if the value that they hold allows such operations. The next example briefly shows how Tefigel variables can be used.

Code Example 7 - Variables and basic operations
Variables can be of different types (strings, numbers and boolean), although they are all internally treated as strings, and function as placeholders.
Source code - File "plain_var"
    1      Following variables:
    2       -  "Number"
    3       -  "Class"
    4       -  "BoolCondition"
    5       -  "String"
    6       -  "Identifier"
    7       -  "Empty"
    8      are currently not set.
    9      @ set  Number=256
   10      @ set  Class=Customer
   11      @ set  Identifier=some_id
   12      @ eval BoolCondition Number>0
   13      @ set  String= plain string with some blanks and various quotes ("'`)
   14      @ set  Empty=
   15      @ add  Number Number
   16      ------------------ After set and eval:
   17      Following variables are now placeholders:
   18       -  "Number"
   19       -  "Class"
   20       -  "BoolCondition"
   21       -  "String"
   22       -  "Identifier"
   23       -  "Empty"
	       
Output of "/opt/somusar/bin/tefigel plain_var"
    1      Following variables:
    2       -  "Number"
    3       -  "Class"
    4       -  "BoolCondition"
    5       -  "String"
    6       -  "Identifier"
    7       -  "Empty"
    8      are currently not set.
    9      ------------------ After set and eval:
   10      Following variables are now placeholders:
   11       -  "512"
   12       -  "Customer"
   13       -  "1"
   14       -  " plain string with some blanks and various quotes ("'`)"
   15       -  "some_id"
   16       -  ""
	       

Two very important operations that can be applied to Tefigel variables via the current dash are string concatenation, shown in the next example, and contents association stored into so-called associative variables; the latter topic requires a more complex example and is described later in the document.

Code Example 8 - String concatenation via DASH
Usage of string concatenation via DASH to generate a Java set method.
Source code - File "string_cat"
    1      @ dash $
    2      @ set MEMBER=Quantity
    3      @ set MEMBERTYPE=int
    4          public void set$MEMBER(MEMBERTYPE a$MEMBER) {
    5              this.MEMBER = a$MEMBER;
    6          }
	       
Output of "/opt/somusar/bin/tefigel string_cat"
    1          public void setQuantity(int aQuantity) {
    2              this.Quantity = aQuantity;
    3          }
	       

String concatenation and contents association allow Tefigel users to group Tefigel variables in aggregates like records, lists, mappings and arrays, which are globally referred to as associative variables.

The dash operator is also variable as the command and comment markers previously discussed, to allow Tefigel to flexibly deal with the variety of syntax rules and tokens of as many computer languages as possible.

3.7 - Name Spaces        top

Tefigel variables are grouped in nested name spaces, or scopes, which are created and deleted either implicitly when a CALL to a subroutine or function is issued, or explicitly by means of PUSH and POP, as shown in the following example.

Code Example 9 - Name spaces
Three nested variables namespaces.
Source code - File "namespaces"
    1      Namespace 1) Variable "eks" currently evaluates to 'X'.
    2      @ set X=
    3      Namespace 1) Variable "eks" now evaluates to 'X'.
    4      @ set X=namespace 1
    5      Namespace 1) Variable "eks" now evaluates to 'X'.
    6      @ push
    7          Namespace 2) Variable "eks" now evaluates to 'X'.
    8      @ set X=namespace 2
    9          Namespace 2) Variable "eks" now evaluates to 'X'.
   10      @ push
   11              Namespace 3) Variable "eks" now evaluates to 'X'.
   12      @ set X=namespace 3
   13              Namespace 3) Variable "eks" now evaluates to 'X'.
   14      @ pop
   15          Namespace 2) Variable "eks" now evaluates to 'X'.
   16      @ set X=namespace 2, second value
   17          Namespace 2) Variable "eks" now evaluates to 'X'.
   18      @ pop
   19      Namespace 1) Variable "eks" now evaluates to 'X'.
   20      @ unset X
   21      Namespace 1) Variable "eks" now evaluates to 'X'.
	       
Output of "/opt/somusar/bin/tefigel namespaces"
    1      Namespace 1) Variable "eks" currently evaluates to 'X'.
    2      Namespace 1) Variable "eks" now evaluates to ''.
    3      Namespace 1) Variable "eks" now evaluates to 'namespace 1'.
    4          Namespace 2) Variable "eks" now evaluates to 'namespace 1'.
    5          Namespace 2) Variable "eks" now evaluates to 'namespace 2'.
    6              Namespace 3) Variable "eks" now evaluates to 'namespace 2'.
    7              Namespace 3) Variable "eks" now evaluates to 'namespace 3'.
    8          Namespace 2) Variable "eks" now evaluates to 'namespace 2'.
    9          Namespace 2) Variable "eks" now evaluates to 'namespace 2, second value'.
   10      Namespace 1) Variable "eks" now evaluates to 'namespace 1'.
   11      Namespace 1) Variable "eks" now evaluates to 'X'.
	       

A global name space is also always available via the instruction GLOBSET, which is useful for example to preserve context across subsequent CALLs to the same subroutine. Name spaces are actually very seldom used explicitly via PUSH and POP; in fact, they are internally used by Tefigel to save/restore context before and after subroutine CALLs.

[Previous chapter]    [Next chapter]    [Back to top]

http:// www.somusar.com  / doc  / booklets  / tefigel_tut  - Powered by SoProMach
Copyright © 2003-2012 Somusar - Trademarks - Legal - Privacy - Webmaster