next up previous contents index
Next: statements vs expressions Up: Control Statements Previous: Control Statements

Scripts

Several script constructions can appear in a TSF program. Each one defines a sequence of statements that can be called from another script. The main script (i.e. that is executed to start the program) is the last one and it does not accept parameters.
     $\vartriangleright$ Syntax:
SCRIPT name (list of parameters)
    list of statements
ENDSCRIPT

When a program contains several script, the execution starts by the last one which can not accept parameters. The statement CALLSCRIPT  (i.e. or the obsolete COMMAND)   is used to call a script.
$\vartriangleright$ Example 6:A 'Hello World' program with two SCRIPT.

  SCRIPT my_print(str)
    PRINT str
  ENDSCRIPT
   
  SCRIPT main ()
    PRINT "Hello " 
    CALLSCRIPT my_print("World")
  ENDSCRIPT

By default, the argument passing protocol is by value (i.e. the script works on a copy). It is possible to use references by adding the prefix "&" before the variable used as an argument. For instance, the example 7 implements a script that increments its argument (if a reference is used of course).

$\vartriangleright$ Example 7: 

  SCRIPT inc(X) 
    X := X+1 
  ENDSCRIPT

  SCRIPT main()
    a:=1 
    CALLSCRIPT inc(&a)
    PRINT a   // print 2
    b:=1 
    CALLSCRIPT inc(b)
    PRINT b   // print 1 (b is unchanged)
  ENDSCRIPT

  $\vartriangleright$ Remark: Arguments passed by reference are not restricted to the scripts. Some predefined functions or attributes may use them.


next up previous contents index
Next: statements vs expressions Up: Control Statements Previous: Control Statements
Yann Mevel
1999-04-30