|
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.
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!".
|
|
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.
|
|
|
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.
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.
|
|
|
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.
|
|
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.
|
|
|
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>.
|
|
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.
|
|
|
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 -----------
|
|
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.
|
|
|
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.
|
|
|
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.
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.
|
|
|
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]
|