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

1. Introduction
2. Language Summary
3. Text File Components
4. Text File Processing
4.1 Arithmetic Computation
4.2 Control Flow and Boolean Computation
4.3 Input and Output
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 4 - Text File Processing

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.

4.1 - Arithmetic Computation        top

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.

Code Example 10 - Arithmetic computation
Simple arithmetic computations: two divisions on lines 5 and 9, and a subtraction on line 7.
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

4.2 - Control Flow and Boolean Computation        top

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.

Code Example 11 - Simple loop
Loop three times, printing out a message on each loop.
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

4.3 - Input and Output        top

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]

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