Tefigel provides all the basic tools usually available
in most, if not all, procedural languages to enable
the implementation of sequential algorithms and to convert
an input flow into an output flow, namely
computation of arithmetic and logical - or boolean -
expressions, language structures to control the processing flow,
and input/output instructions to manage the inbound and
outbound data flows.
Tefigel has been designed mainly for generating text files and
not for complex, general-purpose software systems. Its set of
arithmetic instructions comprises thus very basic operations,
such as ADD, SUB, MUL, DIV, TRUNC, NEG,
as shown by the next example. All computations are performed
in floating point, as for a pocket calculator.
|
Source code - File "arith"
|
1 # Sample arithmetic computation
2 @ set A=3
3 @ set B=6
4 @ set C=B
5 @ div C A
6 B divided by A yields C
7 @ sub B 1
8 @ set C=B
9 @ div C A
10 B divided by A yields C
|
|
Output of
"/opt/somusar/bin/tefigel arith"
|
1 6 divided by 3 yields 2
2 5 divided by 3 yields 1.666666666666667
|
|
Control flow in Tefigel is supported by traditional constructs,
such as IF..ELSE..ENDIF and WHILE..ENDWHILE. Additionally,
instructions LABEL, JUMP, and JUMPCOND allow
conditional and unconditional branching. A simple loop
is illustrated by the next example.
|
Source code - File "loop"
|
1 ---- Begin loop
2 @ loop I=0,2
3 loop #I
4 @ endloop
5 ---- End loop
|
|
Output of
"/opt/somusar/bin/tefigel loop"
|
1 ---- Begin loop
2 loop #0
3 loop #1
4 loop #2
5 ---- End loop
|
|
As for arithmetic computation, the language constructs for
boolean computation are very primitive in Tefigel: the set
of boolean instructions consists of instructions
EVAL, AND, OR and NOT, whereas the set
of boolean test operators consists of:
- = for "equal";
- # for "not equal";
- > for "greater than";
- < for "less than";
- } for "greater or equal";
- { for "less or equal";
- ~ (pronounced like) for "similar to".
The following example shows a typical application of boolean computation
to control flow.
Code Example 12 - Boolean computation and control flow
|
An example of logical computation is given on lines 6 and 7.
Conditional control flow (IF..ELSE..ENDIF) is illustrated
on lines 8-10-12 and 14-16-18. An example of
unconditional branching (goto) is provided on lines 4 and 19.
|
|
Source code - File "logical"
|
1 @ set A=true
2 @ set B=false
3 @ set C=unknown
4 @ label back
5 ---- Begin logical expression evaluation
6 @ eval expr A#B
7 @ and expr A#C
8 @ if expr=1
9 A, B, C are all different
10 @ else
11 A, B, C are not all different
12 @ endif
13 ---- End logical expression evaluation
14 @ if C=true
15 @ quit
16 @ else
17 @ set C=true
18 @ endif
19 @ jump back
|
|
Output of
"/opt/somusar/bin/tefigel logical"
|
1 ---- Begin logical expression evaluation
2 true, false, unknown are all different
3 ---- End logical expression evaluation
4 ---- Begin logical expression evaluation
5 true, false, true are not all different
6 ---- End logical expression evaluation
|
|
Another main function of Tefigel is constituted by
its set of input and output control instructions.
Input flow is managed by means of instructions
PROCESS and CALL, which respectively allow
to process an input file in the same or in a new
name space, or by means of instruction
ATTACH which barely attaches the contents of a given file
to Tefigel's output without actually processing it - that is,
without applying neither variable substitution nor instruction
recognition.
Output flow is managed by means of instructions OUTPUT and
APPEND, which redirect the standard output of Tefigel to a given
file, respectively creating it from scratch, or extending it by appending
new text to the text that it previously contained.
Code Example 13 - Input and output
|
Create two output files "outp1" and "outp2"
on lines 2 and 7, and extend "outp1" on line 12.
Contents are provided by three input files "inp1",
"inp2" and "inp3", each of which gets in turn
PROCESSed, CALLed and ATTACHed.
Note that standard output is left empty, as no output text
appears before the first OUTPUT instruction.
|
|
Source code - File "in_out"
|
1 @ set GREETING=Hello!
2 @ output outp1
3 @ process inp1
4 @ call inp2
5 @ attach inp3
6 @ set GREETING=Good morning!
7 @ output outp2
8 @ call inp1
9 @ attach inp2
10 @ process inp3
11 @ set GREETING=Goodbye!
12 @ append outp1
13 @ attach inp1
14 @ process inp2
15 @ call inp3
|
|
Output of
"/opt/somusar/bin/tefigel in_out"
|
|
|
The resulting contents of the output files of this example are listed
below.
First output file - File "outp1"
|
1 [File "inp1"] Today's greeting is Hello!
2 [File "inp2"] Today's greeting is Hello!
3 [File "inp3"] Today's greeting is GREETING
4 [File "inp1"] Today's greeting is GREETING
5 [File "inp2"] Today's greeting is Goodbye!
6 [File "inp3"] Today's greeting is Goodbye!
|
|
Second output file - File "outp2"
|
1 [File "inp1"] Today's greeting is Good morning!
2 [File "inp2"] Today's greeting is GREETING
3 [File "inp3"] Today's greeting is Good morning!
|
|
The actual contents of the input files of this example are listed
below.
First input file - File "inp1"
|
1 [File "inp1"] Today's greeting is GREETING
|
|
Second input file - File "inp2"
|
1 [File "inp2"] Today's greeting is GREETING
|
|
Third input file - File "inp3"
|
1 [File "inp3"] Today's greeting is GREETING
|
|
[Previous chapter]
[Next chapter]
[Back to top]
|