Control verbs

There are verbs which change the flow of command execution - control verbs:

for, break, continue, endfor
Section 15.3.33.
gosub, rts
Section 15.3.35.
goto, label:
Section 15.3.36.
if, else, endif
Section 15.3.38.
loop
Section 15.3.43.
switch, case, break, endswitch
Section 15.3.75.
end
Section 15.3.25 exit file

The control interpreter works in two passes. During the first pass it reads the command file line by line, builds a cross reference table for the labels and an array of pointers to commands structures. The command structures are filled with the results of the command analysis.

The commands are executed during the second pass. It begins with the reset of the index of the pointer array. After a command is executed, the index is incremented by one unless a control command changes it.

The analysis of the command line is bypassed for commands which did not invoke any symbol translations during the analysis phase of the first pass. Otherwise the command line has to be re-analyzed to take the run-time values of the symbols into account.

Since the label cross reference table and the pointer array are local variables to the control interpreter, it can be used recursively.

This is an example of a command file. The output can be viewed in sectionx 15.3.69:

!
! This command file displays the predefined viewports. 
! e.g.:
!
!   SPECTRA> run vp_example.gra 1 4
!
 variables vp_start vp_stop

 if !gra_status()
   end 0
 endif

 del *.*
 set 0.layout/border=1

 crea/notext test 0 1 10 0
 set 1/bg_colour=8/x_maj=-4/y_maj=-4/y_min=0
 deact 1

 if !vp_stop
  create/text/str="Predefined Viewport: V0" 0.2
 else
  creat/text/str="Predefined Viewports: V"vp_start" - V"vp_stop 0.2
 endif

 if vp_start > 10
   set 0.2 /y=0.5/h_ali=2/height=25 
 else
   set 0.2 /y=1.07/h_ali=2/height=25 
 endif

 for( i=vp_start; i < (vp_stop + 1); i = i + 1)
  temp = V""i
  cop 1 temp
  set temp/temp
  create/text/str=temp/height=25/h_al=2 temp
 endfor

 display
 post/eps/col/nocon "vp_"vp_start"_"vp_stop"_example.ps"

 end 1