Parcourir la source

initial import of uncompressed RIGAL files from Mikhail Auguston <maugusto@nps.edu>

Kyle P Davis il y a 9 ans
commit
e84a669a56
100 fichiers modifiés avec 8563 ajouts et 0 suppressions
  1. 92 0
      README
  2. 32 0
      examp1/a.bal
  3. 14 0
      examp1/a.toy
  4. 45 0
      examp1/analyse.rig
  5. 88 0
      examp1/bcomp.rig
  6. 21 0
      examp1/bigload.rig
  7. 1 0
      examp1/ex.txt
  8. 39 0
      examp1/ex1.pas
  9. 19 0
      examp1/ex1.rig
  10. 10 0
      examp1/ex1.txt
  11. 48 0
      examp1/ex2.rig
  12. 26 0
      examp1/gram1.rig
  13. 19 0
      examp1/gram2.rig
  14. 88 0
      examp1/hanoi.rig
  15. 71 0
      examp1/inter.rig
  16. 35 0
      examp1/label.txt
  17. 4 0
      examp1/linta.rig
  18. 8 0
      examp1/mmm.rig
  19. 208 0
      examp1/proglist.txt
  20. 93 0
      examp1/rapid.txt
  21. 504 0
      examp1/short.txt
  22. 145 0
      examp1/sourguid.txt
  23. 48 0
      examp1/tex1.rig
  24. 83 0
      examp1/tlist.rig
  25. 201 0
      examp1/toylan.rig
  26. 90 0
      examp1/ttree.rig
  27. 38 0
      examp1/work.rig
  28. 61 0
      examples/baltree.rig
  29. 107 0
      examples/opt.rig
  30. 12 0
      examples/readexam.txt
  31. 63 0
      examples/stack.rig
  32. 31 0
      examples/stack2.rig
  33. 9 0
      examples/strusca1.inp
  34. 5 0
      examples/strusca2.inp
  35. 5 0
      examples/strusca3.out
  36. 62 0
      examples/struscan.rig
  37. 54 0
      examples/travtree.rig
  38. 264 0
      rigal.man
  39. 45 0
      rigdm218/ANALYSE.RIG
  40. 88 0
      rigdm218/BCOMP.RIG
  41. 324 0
      rigdm218/DEMO.BAT
  42. 1 0
      rigdm218/EMPTY.RIG
  43. 0 0
      rigdm218/EX.LER
  44. 1 0
      rigdm218/EX.TXT
  45. 39 0
      rigdm218/EX1.PAS
  46. 19 0
      rigdm218/EX1.RIG
  47. 10 0
      rigdm218/EX1.TXT
  48. 48 0
      rigdm218/EX2.RIG
  49. BIN
      rigdm218/EX2.RSC
  50. 29 0
      rigdm218/EXA.LST
  51. 14 0
      rigdm218/EXA.RIG
  52. 26 0
      rigdm218/GRAM1.RIG
  53. 19 0
      rigdm218/GRAM2.RIG
  54. 87 0
      rigdm218/HANOI.RIG
  55. 75 0
      rigdm218/HELP.TXT
  56. 71 0
      rigdm218/INTER.RIG
  57. 59 0
      rigdm218/README.1ST
  58. BIN
      rigdm218/RIG.EXE
  59. 505 0
      rigdm218/RIGAL.DOC
  60. 15 0
      rigdm218/RIGAL.PCK
  61. 30 0
      rigdm218/WORK.RIG
  62. BIN
      rigdm218/XTRA.COM
  63. 18 0
      rigdm218/~~CONTIN.BAT
  64. 284 0
      rigdm218/~~DEMO.BAT
  65. 526 0
      rigdm218/~~DEMO_D.DAT
  66. 177 0
      rigdm218/~~DEMO_F.DAT
  67. 222 0
      rigdm218/~~DEMO_G.DAT
  68. 4 0
      rigdm218/~~STOP.BAT
  69. 4 0
      rigdm218/~~WAIT.BAT
  70. BIN
      rigdm218/~~WAIT0.EXE
  71. 6 0
      rigdm218/~~WAIT0.PAS
  72. BIN
      rigdm218/~~WAITPA.EXE
  73. 49 0
      rigdm218/~~WAITPA.PAS
  74. 175 0
      rigdos/80.TXT
  75. 171 0
      rigdos/80TST.RIG
  76. 32 0
      rigdos/A.BAL
  77. 14 0
      rigdos/A.TOY
  78. 50 0
      rigdos/ANALYSE.RIG
  79. BIN
      rigdos/ANRIG.EXE
  80. 87 0
      rigdos/BCOMP.RIG
  81. 19 0
      rigdos/BIGLOAD.RIG
  82. 173 0
      rigdos/CALL_PAS.TXT
  83. 4 0
      rigdos/CMPLBEG.BAT
  84. 12 0
      rigdos/CMPLEND.BAT
  85. 1 0
      rigdos/EX.TXT
  86. 19 0
      rigdos/EX1.RIG
  87. 10 0
      rigdos/EX1.TXT
  88. 48 0
      rigdos/EX2.RIG
  89. BIN
      rigdos/GENRIG.EXE
  90. 26 0
      rigdos/GRAM1.RIG
  91. 19 0
      rigdos/GRAM2.RIG
  92. 89 0
      rigdos/HANOI.RIG
  93. BIN
      rigdos/HANOI.RSC
  94. 54 0
      rigdos/INC.RIG
  95. BIN
      rigdos/INT.EXE
  96. 71 0
      rigdos/INTER.RIG
  97. 1384 0
      rigdos/LANGDESC.TXT
  98. 209 0
      rigdos/PROGLIST.TXT
  99. 93 0
      rigdos/RAPID.TXT
  100. 265 0
      rigdos/README

+ 92 - 0
README

@@ -0,0 +1,92 @@
+This directory contains programs and documents
+related to the programming language RIGAL,
+a tool for compiler writing.
+
+This directory is available by anonymous FTP 
+ ftp.ida.liu.se //info/ftp/pub/labs/pelab/rigal
+
+Rigal home page
+   http://www.ida.liu.se/~vaden/rigal.html
+is under construction.
+
+
+-rw-r--r--  1 vaden       32106 May 27 15:25 nwper94rigal.ps.gz
+ Paper about RIGAL implementation and how it has been used
+ in industry, as well as
+ introduction of an advanced type system into RIGAL.
+ Presented at Nordic Workshop on Programming Environments,
+ Lund, June  1-3, 1994.  
+    
+
+-rw-r--r--  1 vaden      123793 May 27 10:43 rigdm218.zip
+ Demo for MS-DOS. Includes animated demonstration
+ of the environment and the language. Running environment
+ (without the compiler), examples, language description.   
+
+-rw-r--r--  1 vaden      805824 Jum 16 14:42 rigdos.zip
+ Complete environment for MS-DOS. Running environment,
+ with compiler Rigal->Pascal, examples, language distribution.
+ Note: for compilation Turbo Pascal 6.0 file TPC.EXE is
+ necessary !
+
+-rw-r--r--  1 vaden      572139  Feb 22 19:34 rigsc.445.tar.Z
+-rw-r--r--  1 vaden      ......  ............ rigsc.445.*.tar.Z
+ RIGAL for UNIX. Source code in C. Includes RIGAL to C compiler, examples,
+ detailed language description and user guide.
+
+ The BUGs fixed (in 445, after 444)
+  -  capitalisation  of characters in the scaner.
+  -  more options added to #CALL_PAS(80). See 80.txt for description.
+
+ 445.1  - Fixed bug in scaner, the problem was with the last line
+          if it has no end-of-line character
+  
+ 445.2  - Fixed bug in PRINT statement. When compiled it worked
+          differently with and without -p flag
+        - $rig/rc <program> -c  -P -DXX
+          gives the trace for compiled task, similar to
+          interpreter produces.
+
+ 446   - Fixed bug in the A[i]!!:=X and A[i]++:=X statements.
+         (Earlier they had no effect if A[i]==NULL and X is
+          a variable).
+       - option  "P" added to   #CALL_PAS(80). See 80.txt.
+
+ 446a  - Fixed a very rare bug with ley_.c , Rigal scaner.
+         It had strange code fragment for reading strings,
+         I removed it.
+         Fixed the case when "!." did not work after "COPY".
+         Applies to c2.c, erm.c,  functions "copyop()".
+
+-rw-r--r--  1 vaden        9875 Mar  8 11:25 rigal.man
+ RIGAL for UNIX: Manual page
+
+-rw-r--r--  1 vaden       .................. README
+ This file
+
+-rw-r--r--  1 vaden       34134 Jul  1 18:05  examp1.tar.Z
+ Main set of examples. Toy compilers and interpreters.
+ (for UNIX variant) 
+
+-r--r--r--  1 vaden        5844 Jun  7 14:27 examples.zip
+ More examples (for DOS variant) 
+
+-rw-r--r--  1 vaden        6942 Jun  7 14:26 examples.tar.Z
+ More examples (for UNIX variant)
+
+IF YOU WANT TO BE INFORMED EACH TIME 
+WHEN NEW FILES AND NEW VERSIONS
+ARE UPLOADED, PLEASE SEND E-MAIL TO Vadim Engelson,
+vaden@ida.liu.se
+
+IF YOU HAVE NEW EXAMPLES, you are also very welcome.
+
+More products and information available from Vadim Engelson,
+Dept. of Computer and Information Science,
+Linkoping University, S-58183, Linkoping, Sweden,
+tel. 46 13 28 1979
+E-mail vaden@ida.liu.se
+
+
+
+

+ 32 - 0
examp1/a.bal

@@ -0,0 +1,32 @@
+
+MOV =1,VAR3
+WRITE =3
+WRITE =1
+READ VAR1 
+LOAD R0,VAR1
+LOAD R1,VAR1
+MULT R0,R1
+WRITE R0
+LOAD R0,VAR1
+LOAD R1,VAR1
+MULT R0,R1
+LOAD R2,=4
+LOAD R3,=12
+ADD R2,R3
+COMPARE R0,R2
+BRANCH R0,L1
+WRITE =77
+JUMP L2
+L1: NOP
+WRITE =88
+L2: NOP
+LOAD R0,VAR1
+LOAD R1,=4
+COMPARE R0,R1
+BRANCH R0,L3
+WRITE =99
+L3: NOP
+EOJ 
+VAR1 : DEFWORD 0 
+VAR2 : DEFWORD 0 
+VAR3 : DEFWORD 0 

+ 14 - 0
examp1/a.toy

@@ -0,0 +1,14 @@
+ PROGRAM AAAA
+ INTEGER A,B;
+ BOOLEAN C;
+ C:=TRUE;
+
+ PUT (3,1);
+ GET (A);
+ PUT (A*A);
+ IF A*A=4+12 THEN
+    PUT(77)
+ ELSE
+    PUT (88)       
+ FI;
+ IF A=4 THEN PUT(99) FI; 

+ 45 - 0
examp1/analyse.rig

@@ -0,0 +1,45 @@
+-- parsing of Prof. Blikle small language
+--
+-- file ANALYSE.RIG
+--
+#analyse_program
+     (. (* $rez !.:= #analyse_stmt  * ';' )  [ ';' ]  .)
+     / RETURN $rez /  ##
+
+#analyse_stmt
+    $rez := ( #assignment  !  #while_op  ) / RETURN $rez/ ;;
+
+    (* $R !.:= S'( $$ <> ';' ) *)
+    / report << unrecognised statement $R ; FAIL /
+##
+
+#assignment
+    $var := #variable  ':=' $E := #expression  V'( $$ = ';' OR $$ = 'OD')
+    / RETURN 'assignment_op' :: <. left_part: $var,
+                                   right_part: $E   .> /  ##
+
+#while_op
+    'WHILE'  $E := #expression  'DO'
+             (* $body !.:= #analyse_stmt * ';' )
+                                'OD'
+     / RETURN 'while_op' :: <. condition: $E,
+                               body:   $body  .> /   ##
+
+#expression
+     $a1 := #arithm_expr
+     [  '<'  $a2 := #arithm_expr
+          / RETURN '<' :: <. arg1: $a1,  arg2: $a2 .>/ ]
+     / RETURN $a1 /   ##
+
+#arithm_expr
+    $a1 := #term   / RETURN $a1 / ;;
+
+    '('  $a1 := #arithm_expr  '+' $a2 := #arithm_expr  ')'
+       / RETURN '+' :: <. arg1: $a1, arg2: $a2 .> /  ##
+
+#term
+    $NUM  / RETURN  $NUM /  ;;
+    $rez :=   #variable    /RETURN $rez /  ##
+
+#variable
+    $R := ( W ! V ! X ! Y ! Z ) / RETURN $R /  ##

+ 88 - 0
examp1/bcomp.rig

@@ -0,0 +1,88 @@
+-- Program BCOMP.RIG in directory \RIGAL
+-- Compiles program written in Prof.Blikle small language
+-- to PASCAL code.
+#MAIN
+$LIST:=#CALL_PAS(35 'ex1.txt');
+--PRINT $LIST;
+$TREE_CODE:=#analyse_program($LIST);
+#GEN_PROGRAM($TREE_CODE);
+##
+%INCLUDE analyse.rig
+#GEN_PROGRAM
+ /#GEN_PROLOG() /
+(. (* #GEN_STMT *) .)
+ / #GEN_EPILOG() / ##
+
+#GEN_PROLOG
+/OPEN G 'ex1.pas';
+ G<<' Program Main;';
+ G<<' const tt=101;ff=102;err=103;';
+ G<<' var state:record w,v,x,y,z:integer end;';
+ G<<' function PLUS (a,b:integer) :integer;';
+ G<<' begin if (a>100) or (b>100) then Plus:=err ';
+ G<<'       else if a+b >100 then Plus:=err ';
+ G<<'            else Plus:=a+b; end; ';
+ G<<' function LESS (a,b:integer) :integer;';
+ G<<' begin if (a>100) or (b>100) then Less:=err ';
+ G<<'       else if a<b then Less:=tt ';
+ G<<'            else Less:=ff; end; ';
+ G<<' Procedure Val(a:integer);';
+ G<<'  begin case a of ';
+ G<<'   101 : writeln (''tt''); ';
+ G<<'   102 : writeln (''ff''); ';
+ G<<'   103 : writeln (''err''); ';
+ G<<'   otherwise   writeln (a);end;end; ';
+ G<<' BEGIN WITH STATE DO BEGIN ';
+ G<<'  w:=1;v:=1;x:=1;y:=1;z:=1; '/
+ ##
+ #GEN_EPILOG
+  / G<<'Writeln ('' Post-DUMP : '');';
+    G<<'Write (''w='');Val(w);';
+    G<<'Write (''v='');Val(v);';
+    G<<'Write (''x='');Val(x);';
+    G<<'Write (''y='');Val(y);';
+    G<<'Write (''z='');Val(z);';
+    G<<'readln;end; ';
+    G<<'END.'/
+##
+#GEN_STMT
+ 'assignment_op' ::
+   <. left_part : $Id
+        / G<< $Id ':=' /,
+      right_part : #GEN_EXPR
+        / G<] ';' / .>
+;;
+ 'while_op'::
+   <. condition :
+         / G<<' WHILE ' /
+         #GEN_EXPR
+         / G<] '=tt DO BEGIN '/,
+      body : (. (* #GEN_STMT *) .)
+         / G<<'END;' / ,
+      condition :
+         / G<< ' IF ' /
+         #GEN_EXPR
+         / G<] ' =err THEN x:=err; ' /
+  .>
+##
+#GEN_EXPR
+ $N / G<] $N / ;;
+
+ $Id / G<] $Id / ;;
+
+ '+' :: <. arg1:
+               / G<] ' PLUS( '/
+               #GEN_EXPR,
+           arg2:
+               / G<] ',' /
+               #GEN_EXPR
+               / G<] ')' / .>
+ ;;
+ '<' :: <. arg1:
+               / G<] ' LESS( '/
+               #GEN_EXPR,
+           arg2:
+               / G<] ',' /
+               #GEN_EXPR
+               / G<] ')' / .>
+ ##

+ 21 - 0
examp1/bigload.rig

@@ -0,0 +1,21 @@
+--
+#MAIN
+OPEN S ' ';
+ LOOP
+  LOOP
+    $I+:=1;
+    $E!.:=(.A B C F D J K L N M B G H .);
+    IF $I=300 -> PRINT $J;$I:=0; $J+:=1;BREAK;FI;
+  END;
+  IF $J=300 -> BREAK FI; 
+ END;
+  S<<#LEN($E);
+  SAVE $E 'E.SS';
+  S<< $E[-1];
+  LOAD $Q 'E.SS';
+  S<< $Q[-1];
+   
+    
+  #CALL_PAS(1 'End?');
+ ##
+   

+ 1 - 0
examp1/ex.txt

@@ -0,0 +1 @@
+ (  ABC + 77  )  *  XYZ  -  55

+ 39 - 0
examp1/ex1.pas

@@ -0,0 +1,39 @@
+
+ Program Main; 
+ const tt=101;ff=102;err=103; 
+ var state:record w,v,x,y,z:integer end; 
+ function PLUS (a,b:integer) :integer; 
+ begin if (a>100) or (b>100) then Plus:=err  
+       else if a+b >100 then Plus:=err  
+            else Plus:=a+b; end;  
+ function LESS (a,b:integer) :integer; 
+ begin if (a>100) or (b>100) then Less:=err  
+       else if a<b then Less:=tt  
+            else Less:=ff; end;  
+ Procedure Val(a:integer); 
+  begin case a of  
+   101 : writeln ('tt');  
+   102 : writeln ('ff');  
+   103 : writeln ('err');  
+   otherwise   writeln (a);end;end;  
+ BEGIN WITH STATE DO BEGIN  
+  w:=1;v:=1;x:=1;y:=1;z:=1;  
+Z := 1 ; 
+X :=  PLUS(  Z , 1 ) ; 
+Y := 1 ; 
+ WHILE   LESS(  Y ,  PLUS(  X , 1 ) ) =tt DO BEGIN  
+Z :=  PLUS(  Z , Z ) ; 
+Y :=  PLUS(  Y , 1 ) ; 
+END; 
+ IF   LESS(  Y ,  PLUS(  X , 1 ) )  =err THEN x:=err;  
+V :=  PLUS(  1 , 1 ) ; 
+V :=  PLUS(   PLUS(  V , V ) , V ) ; 
+W := 1 ; 
+Writeln (' Post-DUMP : '); 
+Write ('w=');Val(w); 
+Write ('v=');Val(v); 
+Write ('x=');Val(x); 
+Write ('y=');Val(y); 
+Write ('z=');Val(z); 
+readln;end;  
+END. 

+ 19 - 0
examp1/ex1.rig

@@ -0,0 +1,19 @@
+-- This example illustrates how to program TAIL and HEAD 
+-- functions in RIGAL.
+ #MAIN
+  $E:=(. ALFA BETA GAMMA DELTA .);
+ OPEN S ' ';   -- Opens file S for output to the screen
+ S<<$E;
+ S<<'HEAD=' #HEAD($E);
+ S<<'TAIL=' #TAIL($E);
+ $W:=<. SEL1 : $E,
+        SEL2 : #HEAD($E),
+        SEL3 : #TAIL($E) .>;
+ PRINT $W;
+##
+#HEAD 
+  (. $E   (* $A *) .) / RETURN $E / ##
+#TAIL
+  (. $A   (* $L!.:=$E *) .) /RETURN $L /##
+
+

+ 10 - 0
examp1/ex1.txt

@@ -0,0 +1,10 @@
+
+    z:=1 ; x:= ( z + 1 ); 
+    y:=1;  
+    while y < (x+1) do
+         z:=(z+z);
+         y:=(y+1) od;
+
+    v:=(1+1);
+    v:=((v+v)+v); 
+    w:=1;

+ 48 - 0
examp1/ex2.rig

@@ -0,0 +1,48 @@
+ -- Example of RIGAL program.
+ -- Takes input from file EX.TXT
+ -- Performs simple arithmetical expression parsing.
+ -- Expression tree is returned.
+ -- Polish Postfix Form is printed out.
+#MAIN
+ OPEN S ' ';        -- Opens file S for output to the screen
+ $E:=#CALL_PAS(3 'EX.TXT'); -- Scanner takes input from file EX.TXT
+ S<<$E;             -- Prints the input text
+ $T:=#ANALYSE($E);  -- Calls expression analysis
+ PRINT $T;          -- Prints expression tree
+ #CALL_PAS(13 $T);  -- Prints expression tree in graphical form
+ S<<;
+ #PRINT_POLISH($T); -- Calls Polish  Postfix Form printing
+##
+
+#ANALYSE -- Traverses token list
+ (. $E:=#EXPRESSION .)   / RETURN $E /
+##
+                                                  --      BNF form :
+#EXPRESSION                                      -- expression ::=
+ $A1:=#ADDITIVE_EL                               --  add_el
+ (* $OP := ( '+' ! '-' )  $A2:=#ADDITIVE_EL      --  ( ('+'!'-') add_el )*
+  / $A1 := <. OP:$OP, ARG1:$A1 , ARG2:$A2 .> / *)
+  / RETURN $A1 /
+##
+
+#ADDITIVE_EL                                     --  add_el ::=
+ $A1:=#TERM                                      --    term
+ (* $OP := ( '*' ! '/' ) $A2 :=#TERM             --   ( ('*'!'/') term )*
+  / $A1 := <. OP:$OP, ARG1:$A1 , ARG2:$A2 .> / *)
+  / RETURN $A1 /
+##
+
+#TERM                                            -- term ::=
+ $A := ( $ID ! $NUM )    / RETURN $A / ;;        --  (identifier ! number !
+
+ '(' $A:=#EXPRESSION ')' / RETURN $A /           --    '(' expression ')' )
+##
+
+#PRINT_POLISH
+ <. ARG1 : #PRINT_POLISH,       -- Trees are traversed recursively
+    ARG2 : #PRINT_POLISH,
+    OP : $OP .>
+   / S<] $OP / ;;
+
+  $EL / S<] $EL /               -- Leaves are printed immediately
+##

+ 26 - 0
examp1/gram1.rig

@@ -0,0 +1,26 @@
+-- abstract syntax grammar of tree for language SL
+#program
+        (. (* #stmt  *) .)   ##
+
+#stmt
+     ( #assignment  !  #while  )  ##
+
+#assignment
+           'assignment_op' :: <. left_part: $Id,
+                                 right_part: #expression .>
+##
+
+#while
+      'while_op' :: <. condition: #expression,
+                       body:      (. (* #stmt *) .)  .>
+##
+
+#expression
+           1 ;;
+           $Id ;;
+           '+' :: <. arg1: #expression,
+                     arg2: #expression .> ;;
+
+           '<' :: <. arg1: #expression,
+                     arg2: #expression .>
+##

+ 19 - 0
examp1/gram2.rig

@@ -0,0 +1,19 @@
+-- source grammar for SL
+#program
+        (. (* #stmt * ';' ) .)  ##
+#stmt
+     ( #assignment ! #while_op )   ##
+#assignment
+           $Id  ':='  #expression   ##
+#while_op
+         'while'  #expression 'do'
+                  (* #stmt  * ';' )  'od'  ##
+#expression
+           #arithm_expr  [ '<'  #arithm_expr ]  ##
+#arithm_expr
+           #term   ;;
+        '(' #arithm_expr   '+'  #arithm_expr ')'  ##
+#term
+     ( 1 ! #variable )  ##
+#variable
+         ( w ! v ! x ! y ! z )   ##

+ 88 - 0
examp1/hanoi.rig

@@ -0,0 +1,88 @@
+
+  -- Hanoi tower problem
+#MAIN
+ OPEN S ' ';
+ $Count:=4; -- Count of rings in first tower
+ S<<' Rings count =' $Count ;
+ $STATE:=#INIT($Count); -- Global variable 
+
+ #VIDEOSHOW(T); 
+#H( $Count 1 3 );
+ 
+##
+#H
+ $Num $From $To
+ / 
+S<< ' $Num $From $To ='  $Num $From $To ;
+
+ IF $Num=1 -> 
+       S << 'FROM' $From 'TO ' $To;
+       #VIDEOMOVE ($From $To);
+       #VIDEOSHOW (T)
+   ELSIF T->
+       $Middle := 6-$From-$To ;
+      #H( $Num-1 $From $Middle );
+      #H( 1      $From $To );
+      #H( $Num-1 $Middle $To )
+FI / ##
+
+#INIT  $Count
+/  $V:=(.
+      <. LEN : COPY($Count), BODY : (.COPY($Count).) .>
+      <. LEN : 0     , BODY : (.0.)      .>
+      <. LEN : 0     , BODY : (.0.)      .> .);
+   LOOP
+    IF $Count=1 -> BREAK FI;
+    $Count:=COPY($Count-1);
+    $V[1].BODY!.:=$Count;
+    $V[2].BODY!.:=0;
+    $V[3].BODY!.:=0;
+  END;
+  RETURN $V;
+ / ##
+
+#VIDEOMOVE
+  $From $To
+  / 
+   $S_from := LAST #MAIN $STATE [$From];
+   $S_to   := LAST #MAIN $STATE [$To];
+   $Ring:=COPY( $S_from.BODY[$S_from.LEN]);
+   $S_from.BODY[$S_from.LEN]:=0;
+   $S_from.LEN+:=-1;
+   $S_to.LEN+:=1;
+   $S_to.BODY[$S_to.LEN]:=$Ring;
+  /
+##
+
+#VIDEOSHOW
+
+/ $X:=LAST #MAIN $STATE;
+  $I:=1;
+  LOOP
+   S<<$I '   ';
+   #STR($X[1].BODY[-$I]);
+   S<]'   ';
+   #STR($X[2].BODY[-$I]) ;
+   S<]'   ';
+   #STR($X[3].BODY[-$I]);
+   IF $I>=LAST #MAIN $Count -> BREAK;FI;
+   $I+:=1;
+  END;
+  S<<;
+#CALL_PAS(1 '<<<<<>>>>>>')/##
+
+#STR
+  $N
+/ $E:=LAST #MAIN $Count-$N;
+  #FILL(' ' $E); 
+  #FILL('O' 2*$N);
+  #FILL(' ' $E)/ ##  
+
+#FILL 
+ $SYM $CNT
+ /LOOP
+   $CNT:=$CNT-1;
+   IF $CNT<0 -> BREAK FI;
+   S<]@$SYM; 
+  END; 
+ /## 

+ 71 - 0
examp1/inter.rig

@@ -0,0 +1,71 @@
+-- interpreter for Prof. Blikle small language (SL)
+-- written in Riga 13.10.1989
+--     takes input from file EX1.TXT
+--
+#main
+     $token_list := #CALL_PAS(35  'ex1.txt' );
+-- reads token list
+   OPEN report ' ';
+   $abstract_syntax := #analyse_program( $token_list );
+   IF $abstract_syntax -> report <<' no errors in program ... ';
+                          #interpret_program ( $abstract_syntax )
+   ELSIF   T           -> report << 'an error is found ...' FI  
+##
+
+%INCLUDE analyse.rig
+#interpret_program
+-- has global variable $state
+     / $state := <. W: 1, V: 1, X: 1, Y: 1, Z: 1 .>/
+-- assigns initial values to variables
+      #interpret_stmt_list
+      / report << 'end of interpretation, the state is:';
+        PRINT $state /
+##
+
+#interpret_stmt_list
+         (. (* #interpret_stmt 
+--/ PRINT LAST #interpret_program $state /
+            *) .)  ##
+
+#interpret_stmt
+         ( #interpret_assignment  !  #interpret_while )  ##
+
+#interpret_assignment
+        'assignment_op' ::
+               <.  left_part: $var,
+                   right_part: $rez := #eval_expr .>
+        / LAST #interpret_program $state ++:=
+                         <. $var :  $rez .> /  ##
+
+#interpret_while
+        'while_op' ::
+               <.  condition: $rez := #eval_expr .>
+         / IF $rez = tt  ->  #interpret_stmt_list( $. body);
+                             #interpret_while( $)
+           ELSIF  $rez = ff  ->  RETURN finished
+           ELSIF  $rez = err  OR  #NUMBER( $rez) ->
+                  LAST #interpret_program $state . X := err
+           FI /   ##
+
+#eval_expr
+     $NUM  / RETURN $NUM / ;;
+
+     $Id / RETURN LAST #interpret_program $state . $Id /;;
+
+     '+' :: <. arg1: $val1 := #eval_expr,
+               arg2: $val2 := #eval_expr .>
+        / IF $val1 = err OR $val2 = err ->  RETURN err
+          ELSIF  NOT ( #NUMBER( $val1) AND #NUMBER( $val2) ) ->
+                     RETURN err
+          ELSIF $val1 + $val2 > 100 -> RETURN err
+          ELSIF  T  ->  RETURN $val1 + $val2
+          FI  / ;;
+
+     '<' :: <. arg1: $val1 := #eval_expr,
+               arg2: $val2 := #eval_expr .>
+        / IF $val1 = err OR $val2 = err ->  RETURN err
+          ELSIF  NOT ( #NUMBER( $val1) AND #NUMBER( $val2) ) ->
+                     RETURN err
+          ELSIF $val1 < $val2  -> RETURN tt
+          ELSIF  T  ->  RETURN ff        FI  /
+##

+ 35 - 0
examp1/label.txt

@@ -0,0 +1,35 @@
+            Latvia University
+Institute of Mathematics and Computer Science
+            RIGAL system group       
+Contact:   Mikhail Auguston (or Vadim Engelson)
+   room 418 (420),Institute of Math. and Comp. Sci.,
+   Latvian University, Rainis blvd. 29,SU-226250 Riga , Latvia
+   Telex 161172 TEMA SU, Phone (0132)224363 (or (0132)226997)
+   E-MAIL:  auguston@lumii.lat.su   vadim@lumii.lat.su
+
+  Given version of the RIGAL system consists of [yes/no]
+   Integrated environment (version A)
+                          (version B)
+   Language description 
+   User's guide
+   Demo film with Rigal examples
+   Source Pascal codes
+   Source Rigal codes
+--------------------------------------------------------
+ RIG.EXE version (MM-DD-YY) HH:MM=
+                  length in bytes=
+                          version=  
+---------------------------------------------------------
+ This system copy (version B) is given for non commercial
+ use ONLY and WITHOUT rigths for further distribution.
+ Demonstration version is free available in SoftPanorama
+ (February, 1991), Kiew.
+--------------------------------------------------------
+ Date
+ Name of user
+
+ Address for contact
+
+
+
+---------------------------------------------------------

+ 4 - 0
examp1/linta.rig

@@ -0,0 +1,4 @@
+#SS
+ $D:=(. TT TT .);
+ $E:= $D.Y;
+## 

+ 8 - 0
examp1/mmm.rig

@@ -0,0 +1,8 @@
+--:**  See error message in line 3
+#MYRULE
+zz
+##
+--:^
+--:** 224 WRONG BEGINNING OF THE STATEMENT
+--:** **************************************************
+--:** **************************************************

+ 208 - 0
examp1/proglist.txt

@@ -0,0 +1,208 @@
+ TABLE OF UNITS AND PROCEDURES
+ RIGAL INTEGRATED ENVIRONMENT V.2.04
+------------------------------------------
+FORMAT OF TABLE :
+UNIT NAME
+   %INCLUDED FILE NAME
+   (PROCEDURE NAME IF IT<>FILE_NAME)
+   PROCEDURE NAME
+   = EXPLAINATION
+   == IMPLEMENTED RIGAL KEYWORDS
+-------------------------------------------
+
+PROGRAM RIG_CHE; = CHECKER OF RIGAL SYNTAX
+DEFINE   = COMMON TYPES
+DEFPAGE  = VIRTUAL MEMORY MANAGER
+  GETS1,GETS2,GETS5   = TAKES VIRTUAL MEMORY
+  POINTS, POINTR = REFERS TO VIRTUAL MEMORY
+  PUTATM = TAKES VIRTUAL ATOM SPACE
+  POINTA = REFERS TO VIRTUAL ATOM SPACE
+  REOPEN = Re-opens S-space
+GNVAR    = COMMON VARIABLES
+NEF      = PTR ( POINTER TO LIST ) OPERATIONS
+  NEXT   = MOVING PTR TO NEXT ELEMENT
+  FIRST  = STARTING PTR FROM LIST START
+  EQUATOMS = COMARING TWO ATOMS
+  LCONC   == !.
+  CRLST   ==  (. .)
+  CRLISTFR == (.  .. .)
+  CRTREE   ==  <. .>
+  CRTREEFR ==  <.  .. .>
+  CHANGEEL ==  $E[$a]:=...
+  PLNUM    ==  PTR -> integer
+  MKNUMB   ==  integer -> atom
+  ADDEL3   ==  ++:=<.A:B.>
+  ADDTRE   ==  ++:=<.A:B,C:D.>
+
+EXTERNS  = COMMON CHECKER SUBPROCEDURES
+  %MIST (ERR) = SYNTAX ERROR HANDLER
+  %TABR (TABRULE) = RULES AND VARIABLES TABLE CREATOR
+  DUL,PUSHL,DES,NEXTL,VAL,EL = TEST AND CHANGE
+     CONDITION OF LIST MARKED BY VARIABLE L
+  BLTN   = TEST BUILT-IN RULE NAME
+EXPRU
+  EXPR   = EXPRESSION ANALYSIS
+OPERU
+  OPERATOR = STATEMENT ANALYSIS
+  INSTRUC  = /../ ANALYSIS
+PICTU
+  PICT     = PATTERN ANALYSIS
+  %SPECADR = SPECIAL CONSTANTS
+RULEU
+  RULE     = RULE ANALYSIS
+  SIMPLERULE = BRANCH-OF-RULE ANALYSIS
+CHEPROU
+  CHEPRO   = PROLOG OF CHECK
+CHENU
+  CHEPIL   = EPILOG AND TABLES TEST
+LEYER
+  LEY      = RIGAL LEXIC SCANNER
+STLEV      = SCANNER VARIABLES
+CH
+  CHE11    = MAIN CHECKER PROCEDURE
+CFGU       = TAKES AND RETURNS CONFIGURATION
+
+---------------------------------------------
+
+
+PROGRAM RIG_INT; = RIGAL built-in interpreter
+PROGRAM INT;     = RIGAL independent interpreter
+DEFINE   ^
+DEFPAGE  ^
+GLOVAR   = COMMON VARIABLES
+  ERR    = RUNTIME ERRORS HANDLER
+NEF      ^
+DOUTU
+  DOUT   = #CALL_PAS(12,13 ..) - NICE PRINT
+POUTLEXU
+  %POUTX (POUT) == PRINT
+USEPASU    == #CALL_PAS  PASCAL interface
+  -> LEDER, LEYER, TABUSE
+> SCAN -  new user-oriented lexical analyser
+RUSCODE = russian identifiers coding
+LEDER
+  LED  = PASCAL LEXIC SCANNER
+  %LEDPRO = PROLOG OF PASCAL LEXIC SCANNER
+LEYER
+  LEY      = RIGAL LEXIC SCANNER
+STLEV      = SCANNERS VARIABLES
+TABUSE    = TABLES MANAGER
+>TABDESK   = DESCRIPTORS AND MEMORY
+>TN        = NUMERIC TABLE UTILITY
+>TA        = ATOMIC TABLE  UTILITY
+>TSELECT   = TREE PRIMITIVES
+   SELOP3
+   SETSEL3
+
+BEI
+  %BLTIN  = BUILT_IN RULES
+  %PARMINT == #PARM = COMMAND LINE PARAMETERS
+  %EXPLODE == #EXPLODE
+  %IMPLODE == #IMPLODE
+  %NAMEOP  == ::
+  %CONCOP  == !!
+ARU
+  %ARITHM  = ARITHMETICS
+  %COPYOP  == COPY
+  %INDXOP  == [7]
+  %AUMINS  == -7
+  %SELCTR  == A.B
+  %EQOP    == =
+  %EQOP1   == =
+  %ADD     == +
+PSU
+  PUSH    = ADDING VALUE TO STACK
+  PRATOM  = PRINT ATOM
+  PRBLT   = PRINT BUILT-IN RULE
+  %COMPNAMES = COMPARE NAMES
+  SRCHRULE = SEARCH RULE IN CODE
+  SRCHRULE1 = SEARCH RULE IN CODE
+  LASTOP == LAST
+CI
+  %ALTER  == ( ! )
+  %STARLIST == (* *)
+  %FACULT   == [ $A ]
+  %TREE     == <. $A : $B .>
+  %LIST     == (.  .)
+  %SPATT    == S'( )  V'( )
+  %PATTERN  =  PATTERN DISPATCHER
+  %SIMPLE   ==  ;;
+  %RULE     == #h ... ##
+  %CONLST   =  MAKE LIST
+  %CONTRE   =  MAKE TREE
+  %EXPRESS  =  EXPRESSION DISPATCHER
+  %OBJEXPR  =  LEFTSIDE   DISPATCHER
+  %ASSGN    == :=
+  %COND     == IF
+  %LOOP     == FORALL LOOP
+  %INOUT    == OPEN << <] @ SAVE LOAD PRINT
+  %STATEMENT =  STATEMENT DISPATCHER
+PROLOGU
+  PROLOG    = PROLOG AND CODE READING
+  EPILOG    = EPILOG
+INT1
+  INT11     = MAIN PROCEDURE
+CFGU       = TAKES AND RETURNS CONFIGURATION
+
+----------------------------------------
+
+
+PROGRAM XCRG; = RIGAL COMPILED PROGRAM
+= ==== GENERATED PART =================
+XCRG     = FIRST RULE OF PROGRAM
+XCRG_0   = OTHER RULES OF PROGRAM
+XCRG_1,XCRG_2 = RULES IN INCLUDED PART OF PROGRAM
+XCRG_C   = COMMON (LAST) VARIABLES
+  RMI    = RULE DISPATCHER
+XCRG_N   = CONSTANT (ATOMS) LOADING TO MEMORY
+
+= ==== SUPPORT BY RUNTIME LIBRARY ====
+
+DEFINE ^
+DEF180   = COMMON TYPES
+DEFPAGE ^
+NEF     ^
+USEPASU ^  ( Same structure as in interpreter )
+C1
+  %BLTINC (BLTIN) = BUILT_IN RULES
+  %PARMTAKE == #PARM = COMMAND LINE PARAMETERS
+  %POUTX (POUT) == PRINT
+  ER,ERRSTR = RUNTIME ERRORS HANDLER
+  D,D1      = STATISTIC HANDLER
+  NUMVAL    = CONVERTION ATOM TO NUMBER
+C2
+  CONCOP    == !!
+  INDXOP    == [7]
+  SELOP     == A.B
+  SETIND    == [7]:=
+  SETSEL    == A.B:=
+  ADDNUM    == +:=7
+  COPYOP    == COPY
+C3
+  EPILOG    == EPILOG
+  PROLOG    == PROLOG
+  OUTXT     == <<,<] FOR EXPRESSIONS
+  OUTATM    == <<,<] FOR ATOMS
+  OPN       == OPEN
+  LOASAV    == LOAD SAVE
+  EXPLOD    == #EXPLODE
+  IMPLOD    == #IMPLODE
+  BLTIN1    =  BUILT_IN RULE DISPATCHER
+  CLSFIL    == CLOSE
+C4
+  EQOP      = COMPARING DISPATCHER
+  VARPAT    = PATTERN IS VARIABLE
+  ATMPAT    = PATTERN IS ATOM
+  EQNUM     = COMPARES NUMBERS
+  EQATOM    = COMPARES ATOMS
+--------------------------------------
+RIG_EDIT PROGRAM
+WED = COMMON DISPATCHER
+WEDVAR = VARIABLES AND KEYBOARD DRIVER
+WIN    = WINDOWS MAKER
+WAR    = MOVING AND CHANGING SCREEN
+WIO    = INPUT/OUTPUT,PICK,DIRECTORY
+FRAMES = SCREEN FRAMES & BOXES
+CFGU   = TAKES AND RETURNS CONFIGURATION
+======================================
+

+ 93 - 0
examp1/rapid.txt

@@ -0,0 +1,93 @@
+  RIGAL RAPID PROGRAMMING GUIDE       (W.E. 26.10.90)
+  =============================
+ Some considerations on fast Rigal execution and about
+some optimizations for recursive programs.
+ Global algorithmic ideas :
+If your algorithm is tree-building - try use such ideas :
+1.Every tree node accords to one call of Rigal rule
+2.Next node is recursive call result (from previous rule),
+  may be through some other rules.
+3. Node is element of big array (list) and node refers to others
+by their "numbers of elements" in this array.
+4. Tree (may be) not exist as data structure at execution
+time. Tree represented by tree-like history of execution
+of recursive rules."Good" nodes are accumulated in special list,
+or (more fast to search) in special another tree with well-chosen
+selectors. This way is good if tree building and tree traversing
+may be done in one pass.
+5. Prepare all possible trees and tables in form of array or tree
+of arrays - before starting recursion. It helps to write
+cycles on lists , not on trees.
+6. Use #CALL_PAS(60-66) - fast trees and lists.
+
+Local optimizations of programs.
+-------------------------------
+Don't use constructors in recursive called rule. It eats
+both time and memory.
+Operations in order of descending efficiency (from very slow to fast)
+as it is in compiled Rigal program.
+
+INEFFICIENT:
+================
+ SAVE; If SAVE is last statement in program -> it is implemented
+       1 1/2 times faster.
+ LOAD
+ #EXPLODE - very inefficient
+ #IMPLODE
+ FORALL $A IN $B - if $B is tree
+ <* $A : $B *>
+ $A !! $B  - if $B is big list - elements copied one after one.
+ $A ++ $B  - if $B is big
+ $A ++ $B  - if $A is big
+ $A:=<.D:E.>   - every tree or list takes minimum 40 bytes
+ $A:=(. D E .)
+ #A ( $B $C ) - if call any rule with 2 or more parameters
+            ( this will be optimized in nearest future )
+
+MIDDLE EFFICIENCY AND GOOD
+==========================
+ $A!.:=$K  - if $A is small
+ $A.$D:=$K
+ $A++:=<. A:B, C:D, F:E.>
+ $A!!(. A B C .)
+ Arithmetical expressions
+ $A.$B, $A[$B]
+ $A.ABC  $A[5]
+ Patterns with constants.
+
+IMPLEMENTED VERY GOOD (in Pascal level):
+=======================================
+ Clusters ( will be implemented in future )
+ #CALL_PAS,#CHR, #ORD, predicates
+ #LEN of tree or list
+ #AA( $P1 $P2 $P3 $P4  ) - with one to four parameters
+ FORALL $A IN $B - if $B is list
+ $A+:=number
+ $A !. $B
+ IF/ELSE/FI, LOOP, BREAK , RETURN
+ LAST #A $A
+ $ $$
+ $A:=$B;
+ Single variable everywhere is of equal (or a
+  little more) efficient as constant with the same value.
+
+ON PAGING CONTROL
+=================
+We recommend to use new #CALL_PAS(42) to know count
+of filled virtual memory pages in every N-th step
+of algorithm.
+Use #CALL_PAS(1) to require user to stop execution
+in every N-th step.
+If algorithm is iterative - use #CALL_PAS(45) to clean
+memory
+
+Every page is 8 KBytes.
+Totally is 256 pages ( 2 MBytes )
+In heap memory - no more than 50 pages,
+in 1300 Kb virtual disk - 170 pages
+in  300 Kb vitrual disk -  45 pages
+in hard disk - all remainder.
+
+One atom (or number) takes 8 bytes,
+One list of length N takes N*5 bytes, minimum 40
+One tree of length N takes N*10 bytes, minimum 40

+ 504 - 0
examp1/short.txt

@@ -0,0 +1,504 @@
+   Programming  language  RIGAL  as  a  compiler  writing  tool
+
+                          M. I. AUGUSTON
+          Computing Center of the Latvia State University
+                226250,  Riga, Rainis boulevard 29,
+                           Latvia, USSR
+
+     Abstract. A new programming language for compiler writing  is
+     described briefly in this paper. The main data structures are
+     atoms, lists and trees. The control structures are based on a
+     advanced  pattern  matching.  All  phases  of   compilation,
+     including parsing, optimization and code generation,  can  be
+     programmed in this language in short and readable form.
+
+
+                          1. Introduction
+
+     Programming language RIGAL is  intended  to  be  a  tool  for
+syntactic analysis, program optimization, code generation and  for
+preprocessor and convertor writing. The main principles  of  RIGAL
+are the following:
+     a) formal grammars are used in the pattern matching mode;
+     b) operations, such as  tables  formation,  code  generation,
+message output are executed simultaneously with parsing,  like  in
+YACC [1], CDL-2 [2]. Therefore, the  principle  of  dependence  of
+control structures in the program upon data  structures  used  for
+program's work is well supported;
+     c) attribute grammars can be modeled easily  in  RIGAL.  The
+language has reference facility,  which  is  a  good  solution  of
+global attribute problem;
+     d) the  language  has  rich  spectrum  of  tree  manipulation
+facilities, like in Vienna Definition Language [3], including tree
+grammars. Trees can be conveniently used  as  data  structure  for
+different table implementation;
+     e) the language supports multi pass compiler design, as  well.
+Trees can be used as intermediate data;
+     f) the language provides the  split  of  program  into  small
+modules (rules) and presents various means to arrange  interaction
+of these modules;
+     g) RIGAL  is  a  closed  language,  i.e.  all  the  necessary
+computations and input-output could be executed by internal  means
+and there is no need to use external  semantic  subroutines  which
+are written in Pascal or C. Therefore, the  portability  of  RIGAL
+programs to other computers is increased.
+     Detailed presentation of language, as well as  more  examples
+are given in [4].
+
+                  2. Data Structures. Operations
+
+     The only data structures in RIGAL are atoms, lists and trees.
+     The atom is a string of characters or a  number.  Identifiers
+and numbers can be written just in the RIGAL program  text,  other
+atoms must be quoted. Special atom NULL represents an empty  list,
+an empty tree and Boolean value "false".
+     Variable name begins with symbol $. Values can be assigned to
+variables. For example, $E := ABC assigns atom ABC to variable $E.
+     The  list  is  an  ordered  sequence  of  objects  -  atoms,
+another lists and trees.
+     The list constructor yields a list of objects.  For  example,
+$E := (. A B C .) assigns a list of  atoms  A,  B  and  C  to  the
+variable  $E . It is possible to  get  elements  from  a  list  by
+indexing, e.g. $E[ 2] is atom B, but $E[ -1] is atom C.  Operation
+L !. e appends element e to the end of list L. Two lists L1 and L2
+can be concatenated by operation L1 !! L2 .
+     For tree creation the tree constructor is used, e.g.
+                        <. A : B, C : D .>
+     Objects placed  just  before  ':'  are  called  selectors.  A
+selector may be any atom, except NULL. Selectors of the same level
+must be different. The pair 'selector : object' in the tree is   a
+branch. Branches in the tree are unordered.
+     Statement $E := <. A : X, B :(.3 7.), C  :<.  A  :  2  .>  .>
+assigns  a tree  with  three  branches  to  variable  $E.   It  is
+possible to extract components from the tree by means of selection
+operation . For example, $E.A is atom X, $E.C.A  is  atom  2,  and
+$E.B[2] is atom 7. But $E.D  yields  NULL,  because  there  is  no
+branch with selector D in this tree.
+     Operation T1 ++ T2 appends branches of tree T2 to tree T1. If
+T1 has a branch with the same selector, this branch is replaced by
+the  branch from the T2.
+     The equality of objects can be checked  using  operations  =
+and <>. The result is atom T ('true') or NULL  ('false').
+     Common arithmetic and relational operations  +,  -,  *,  div,
+mod, <, >, <= and >= are defined for numerical atoms .
+     The arguments of logical operations and, or and  not  can  be
+arbitrary objects. If the object differs from NULL, it  represents
+the 'true' value.
+     It is possible to write $X !.:= e instead of   statement
+$X := $X !. e .The same short form is allowed for  operations  !!,
+++ and + .
+
+                     3. Rules. Simple Patterns
+
+     Rules are used basically to check if an object or sequence of
+objects complies with some grammar.
+     The grammar is described by the patterns. A rule call  should
+be accomplished by some object or  object  sequence  called   rule
+arguments . They are matched with the patterns in the rule.   Some
+statements  (  assignments,  input-output  operations  )  can   be
+executed simultaneously with pattern matching .
+     Rule can compute and return some value to the calling  point.
+Thus, the concept of rule is analogous to concept of procedure and
+function in conventional languages.
+     The rule execution ends with success or failure depending  on
+the result of argument and pattern matching. That is  why  a  rule
+can be used as a pattern in another rule.
+     Example of a rule definition:     #L1 A B ##
+     Here the pattern contains atoms A and  B.  Rule  #L1  can  be
+called, for example, in such a way:  #L1(A B). Atoms A and  B  are
+given as arguments. In this case argument matching with pattern is
+successful.
+     Call #L1(A C) fails, because the  second  argument  fails  to
+match the second pattern, but #L1(A B C) ends with success, as the
+third argument is not requested by any pattern element.
+    Variable can be a pattern  element.  It  matches  successfully
+just one object from the argument sequence and, as a side  effect,
+this object is assigned to the variable.
+     Statements can be placed before the pattern element and after
+it. The statement group is closed in symbols  '/'.  Statements  in
+the group are separated by semicolons.
+     The return statement in the rule ends the rule execution  and
+yields the returned value.
+     Example. #L2  $A  $B  / return (. $B $A.)/   ##
+     Variable $X gets value (.2 1.) after statement $X:= #L2(1  2)
+is executed .
+     If return statement is not described in the  rule,  then  the
+NULL value is returned.
+     The  rule  pattern  element  can  refer  to   some   rule
+(recursively, as well).
+          Example.
+          #L3   B  C  ##
+          #L4   A  #L3   D  ##
+     Call #L4( A B C D ) is successful, but #L4( A  E  F  D  )  is
+unsuccessful.
+     Every  pattern  element,  when  successfully   matched   with
+corresponding rule argument, returns some  value.  Value  of  atom
+pattern coincides  with  this  atom,  value  of  variable  pattern
+coincides with the value obtained by this variable as a result  of
+matching with the argument.  The value of rule is  formed  by  the
+return statement. Value, returned by the pattern  element  can  be
+assigned to a variable.
+        Example.
+        #L5   $R !.:= $A     $RN!!:= #L6   / RETURN  $R/  ##
+        #L6   $M !.:= $B     $M !.:= $C    / RETURN  $M/  ##
+    When statement  $X := #L5( 1 2 3 ) is  executed,  variable  $X
+gets value  (. 1 2 3 .). All variables in the rule are initialized
+by NULL. Then the first application of pattern element  $R !.:= $A
+in #L5 assigns to variable $R the value of expression  NULL !.  $A
+that equals to (. $A .) .
+     There are some built-in rules, such  as  #NUMBER  or  #IDENT.
+Patterns of the type $Id := #IDENT and  $N := #NUMBER are used  so
+often, that a default is introduced. If the name  of  the  pattern
+variable  begins  with  letter  "I",  then  it  matches  atoms   -
+identifiers, and, if it begins with letter "N",  then  it  matches
+numerical atoms.
+     One rule can contain several groups  of  patterns.  They  are
+called branches of the rule. Arguments of  the  rule  are  matched
+with branches in succession,  until one branch succeeds.
+     Branches in the rule are delimited by symbol ';;'. In case of
+branch failure, some statements can  be  executed. Such statements
+can be written at the end of the branch after keyword  ONFAIL.  In
+case of  branch  failure,  control  is  transferred  to  them  and
+statements,given in ONFAIL-unit , are executed.  So,  in  case  of
+branch failure, causes of failure could be  analyzed  and  message
+could be output.
+
+                            4. Patterns
+
+     List pattern (. P1 P2 ... Pn .) matches only  those  objects,
+which are lists and elements of which match patterns  P1, P2,  ...
+and   Pn  respectively.
+     There are patterns for alternative
+                      ( P1 ! P2 ! ... ! Pn )
+and for option
+                         [ P1 P2  ... Pn ]
+with usual semantics.
+     Iterative sequence pattern  (* P1 P2 ... Pn  *)  denotes  the
+repetition of pattern sequence zero or more times. It is  possible
+to define rules with a variable number of arguments.
+     Example.
+        #Sum (*  $S +:= $Num  *) / RETURN $S/   ##
+     Call #Sum(2 5 11) returns 18.
+     Example. Rule that determines length of the  list  can  be
+defined as follows:
+     #Len   (. (* $E / $L +:= 1 / *) .)   / RETURN $L/   ##
+     Call #Len( (. A B C .) ) returns 3.
+     Iterative sequence pattern (+ ... +) is similar to (* ... *),
+but the former denotes the repetition one or more times.
+     It is possible to describe iterative sequence  patterns  with
+delimiters in such form: (* P1 P2 ... Pn * delimiter ) .  An  atom
+or a rule name can be used as delimiter .
+     Example. Analysis of a simple Algol-like  declaration.  A
+fragment of variable table coded in a tree form is returned  as  a
+result.
+     #Declaration
+        $Type := ( integer ! real )
+        (+ $Id  / $Rez ++:= <. $Id : $Type .> /  + ',')
+        / RETURN $Rez /   ##
+     Call #Declaration ( real X ',' Y ) returns value
+                     <. X : real, Y  : real .>
+
+     Example.   Simple   arithmetic   expression   parsing.   When
+successful, an expression tree is returned, which can be  regarded
+as an intermediate form for the next compilation phases.
+     #Expression
+        $A1 := #Additive_el
+        (* $Op := ( '+' ! '-' )  $A2 := #Additive_el
+           / $A1 := <. op : $Op , arg1 : $A1 , arg2 : $A2 .> / *)
+        / RETURN $A1 /   ##
+     #Additive_el
+        $A1 := #Term
+        (* $Op := ( '*' ! 'div' )  $A2 := #Term
+           / $A1 := <. op : $Op, arg1 : $A1, arg2 : $A2 .> / *)
+        / RETURN $A1 /    ##
+     #Term
+        $A := ( $Id  ! $Num ) / RETURN $A /  ;;
+        '('  $A := #Expression ')'  / RETURN $A /   ##
+     Call #Expression( X '*' Y '+' 7 ) returns value
+              <. op: '+', arg1: <. op: '*', arg1: X,
+                                            arg2: Y .>,
+                          arg2: 7 .>
+
+                         5. Tree Patterns
+
+     Tree pattern can be written in the form
+              <. a1 : p1, a2 : p2, ...  , an : pn .>
+where ai are atoms and pi are patterns.
+     Tree pattern branches are applied to  corresponding  branches
+of the argument tree in the same order as they are written in  the
+pattern.
+     Therefore,the order of tree traversing may be controlled.  We
+can  traverse  some  branches  of  the  tree  repeatedly,  if  the
+corresponding selector in the tree pattern is repeated, or we  can
+omit some branches of the tree, if the corresponding selectors are
+omitted in the pattern.
+     Optional branches in tree pattern are  enclosed  in  brackets
+'[' and ']'.
+     Example. Let us suppose expression tree to be formed like  in
+the above mentioned example. The task is to traverse the tree  and
+return a list that represents the  Polish  postfix  form  of  this
+expression.
+#Postfix_form
+     <.  arg1: $Rez := #Postfix_form,
+         arg2: $Rez !!:= #Postfix_form,
+         op:   $Rez !.:= $Op  .>       / RETURN $Rez /  ;;
+     $Rez := ( $Id ! $Num )      / RETURN (. $Rez .) /
+##
+     Call #Postfix_form( <. op: '-', arg1: X, arg2:  <.  op:  '*',
+arg1: Y, arg2: 5 .> .>) returns value (. X Y 5 '*' '-' .)
+     Iterative tree pattern has the form <* $V : P *> ,  where  $V
+is a variable and P - pattern. This pattern defines  a  loop  over
+the tree. All selectors of  the  argument  tree  are  assigned  to
+variable $V one by one. Pattern P is applied to each object, which
+corresponds in the  argument  tree  to  the  current  selector  in
+variable $V.
+     Example. Traversing the variable table.
+#Var_table
+     <*  $Id : $E  :=  ( integer ! real )
+               / $R !.:= (. $Id  $E .) /  *> / RETURN $R /  ##
+     Call #Var_table( <. X : integer, Y : real, Z :  real  .>)
+returns value (. (. X integer .) (. Y real .) (. Z real .) .)
+
+              6. Pattern of Logical Condition Testing
+
+     Pattern S'( expression) is performed as follows. First of all
+the expression is evaluated, and iff its value is  different  from
+NULL then matching  with  the  argument  is  successful.  Special
+variable $$ in the expression denotes current argument,  to  which
+this  pattern  is  applied.  Using  this  kind  of  pattern   many
+context-sensitive situations can be  described.  For  example,  by
+such pattern  we  can  recognize  a  special  case  of  assignment
+statement "X := X + E"
+            $Id  ':='  S'( $$ = $Id )  '+'  #Expression
+     We can skip tokens, until semicolon using pattern
+                      (*  S'( $$ <> ';' )  *)
+
+
+                           7. Statements
+
+     There is an analog of McCarthy's  conditional statement  in
+RIGAL. It has the following form :
+                       IF    cond  ->  stmts
+                       ELSIF cond  ->  stmts
+                           ...  ...  ...
+                       FI
+     If the value of conditional expression is not equal to NULL ,
+then corresponding statements are executed.
+     The FAIL statement ends the execution of the rule branch with
+failure.
+     Loop statement
+                  FORALL $V IN Expr DO stmts  OD
+iterates its body over a list or a tree  described  by  expression
+Expr. All elements of the list or all selectors of  the  tree  are
+assigned to variable $V in succession .
+     Loop statement of the type
+                         LOOP  stmts  END
+repeats statements of the loop body, until one of the statements -
+BREAK, RETURN or FAIL is not executed.
+     Objects designed by RIGAL program can be saved  on  disc  and
+loaded  back by statements SAVE and LOAD .
+     Text files can be opened by OPEN statement for text output of
+messages, generated code, etc.
+     Sequence of atoms can be output  in  text  file  FFF  by  the
+statement of the form
+             FFF << expr1   expr2  ...  ... ... exprN
+     A blank is output after  each  atom.  Symbol  @  cancels  the
+additional blank symbol output.
+     Statement '<<' always begins output on a new line, but   '<]'
+statement continues output on current line.
+
+                       8. Program Structure
+
+     RIGAL program consists of main program and rules.
+     Operations like initial object loading from  external  files,
+rule calls  and  created  object  saving  on  external  files  are
+concentrated in the main program .
+     When RIGAL is used for parsing, first the input text  has  to
+be processed by scanner - a program, which converts the text  into
+a list of tokens. This list is an object  of  RIGAL,  and  can  be
+loaded and processed by RIGAL program.
+     Intermediate results, e.g., abstract syntactic trees  can  be
+saved, and another RIGAL program can load and update them.
+
+        9. Attribute Grammars and RIGAL. Global References
+
+     There is a close analogy between attribute grammar and  RIGAL
+program. Rules in RIGAL correspond to grammar  nonterminals,  and
+variables - to attributes.
+     In attribute grammars the greatest  part  of  attributes  are
+used as transit attributes. To avoid this, global  attributes  are
+introduced in the attribute grammar implementations.
+     There is  a  good  conformity  between  data  structures  and
+control structures in RIGAL program. Hence, it is possible to  use
+the control structures of RIGAL program, in order to refer to  the
+data elements.
+     Rule variables can be accessed from  some  other  rule  using
+reference of the type :
+                           LAST  #L  $X
+     This reference denotes the value of variable $X in  the  last
+(in time) and still active instance of rule  #L.  Such  references
+can be used  in left and  right  sides  of  assignment  statement.
+Therefore,  implementation  of  both  synthesized  and   inherited
+attributes is possible as it  is  demonstrated  in  the  following
+scheme.
+#LA  ... ... ...
+     assigns value to attribute $A
+     calls #LB
+     ... ... ...
+##
+#LB  ... ... ...
+     $B1 := LAST #LA $A
+          -- uses inherited attribute $A from #LA
+     calls #LC
+          -- after this call the value of attribute $C from #LC is
+          -- assigned to the synthesized attribute $B2
+     ... ... ...
+##
+#LC  ... ... ...
+     assigns value to attribute $C
+     LAST #LB $B2 := $C
+          -- the value is assigned to  the  synthesized  attribute
+          -- $B2 of #LB
+     ... ... ...
+##
+
+                   10. Simple Telegram Problem.
+
+     We shall consider simple telegram  problem  [5]  as  compiler
+model. A program is required to process a stream of telegrams. The
+stream is available as a sequence of words and spaces. The  stream
+is terminated by an empty telegram.
+     Each telegram is delimited by symbol "***". Telegrams are  to
+be processed to determine  the number  of  words  with  more  than
+twelve characters  for  each  telegram.  Telegrams  together  with
+statistics have to be stored on an output file eliminating all but
+one space between the words.
+     For demonstration purpose the program  is  divided  into  two
+parts - parsing phase and output code generation phase.
+     The input stream is represented as a list of tokens, where  a
+token  is  an  one-character  atom.  The  first  phase  builds  an
+intermediate result - abstract syntactic tree.
+     The structure of input, intermediate and output data  can  be
+described by RIGAL rules.
+
+     The input stream.
+     #telegram_stream
+          (+  #telegram   #end +)  [ #blanks ] #end   ##
+     #telegram
+          (+  #word   #blanks +)   ##
+     #word
+          (+  #letter  +)    ##
+     #blanks
+          (+  ' '  +)       ##
+     #end
+          '*'  '*'  '*'        ##
+     #letter
+          ( A ! B ! C ! ... ! X ! Y ! Z )    ##
+
+     The intermediate data.
+     #S_telegram_stream
+          (.  (+  #S_telegram  +)  .)    ##
+     #S_telegram
+          <. text :       (.  (+  #S_word  +)  .),
+             long_word_n: $N   .>      ##
+     #S_word
+          (. (+  #letter  +) .)        ##
+
+     The output stream.
+     #output_telegram_stream
+          (+   #telegram1   #end   +)   #end    ##
+     #telegram1
+          (+  #word  ' '  +)  $long_word_num     ##
+
+     The main program has form:
+     #telegram_problem
+          LOAD  $T   'Letters.lex';
+          $S := #telegram_stream_analysis($T);
+          OPEN  Out  'LP:';
+          #generate_output_stream($S)
+     ##
+
+     The rules are:
+     #telegram_stream_analysis
+          (. (+  $R !.:= #A_telegram  #end  +)
+              [  #blanks  ]   #end   .)  / RETURN $R /   ##
+     #A_telegram
+          / $long_word_num := 0/
+          (+ $R !.:= #A_word    #blanks  +)
+          / RETURN <. text: $R,
+                      long_word_n: $long_word-num .> /   ##
+     #A_word
+          (+  $R !.:=  #A_letter   +)
+          / IF #Len($R) > 12  ->
+               LAST #A_telegram $long_word_num + :=1
+               -- rule #Len was defined in Unit 4.
+            FI;
+            RETURN $R /    ##
+     #A_letter
+          $R := ( A ! B ! C ! ... ! X ! Y ! Z ) / RETURN $R / ##
+     #generate_output_stream
+          (. (+  #G_telegram  +) .)
+          / Out <<  '***'/    ##
+     #G_telegram
+          <. text: (.  (+  #G_word  / Out <] ' ' /  +)  .),
+             long_word_n: $N  .>
+          / Out <] $N '***' /  ##
+     #G_word
+          (. (+  $L / Out <]  @ $L /  +)  .)    ##
+
+     These rules are obtained  from  rules,  which  describe  data
+structures, by adding operations to  the  corresponding  patterns.
+The whole program  is written by the recursive descent method.
+
+                        11. Implementation
+
+     RIGAL is implemented on PDP-11 in RSX-11,and then  ported  to
+VAX-11 in VMS and to IBM PC AT in MS DOS.
+     First the interpreter of RIGAL was  written  in  Pascal,  and
+afterwards the optimizing compiler RIGAL --> Pascal was written in
+RIGAL itself.
+
+                  12. Conclusions and Future Work
+
+     As it was demonstrated above, RIGAL supports  syntax-oriented
+style  of  compiler  design.  Programs  written   in   RIGAL   are
+well-structured and it is easy to read and debug them.
+     As it was proved by our experience [6], the optimizing  RIGAL
+compiler in VAX/VMS environment makes  it  possible  to  implement
+production quality compilers for high level languages.
+     RIGAL can be considered as yet another  language  prototyping
+tool in the sense of  [7],  because  it  allows  the  designer  to
+develop an experimental translator in a short period of time.
+     RIGAL  support  system  besides  interpreter  for   debugging
+purposes and  optimizing  compiler  includes  a  cross-referencer,
+which helps to avoid misuse of global variables.
+     In  order  to  improve  static  and  dynamic  type  checking,
+variable type descriptions in the form of formal comments would be
+added to the language.
+     Taking in  account  that  the  control  structures  of  RIGAL
+program  are  very  close  to  input  data  structures,  it  seems
+promising to develop automatic and semiautomatic methods for  test
+example generation for the given RIGAL program.
+
+
+                            References
+
+     [1] Johnson S.C. YACC - yet another compiler compiler.  -Bell
+          laboratories, Murray Hill,N.J., 1978, a technical manual.
+     [2] Koster C.H.A. Using the CDL compiler  compiler.-  Lecture
+          Notes in Computer Science, 1977, vol. 21.
+     [3] Lucas P. Formal definition of programming  languages  and
+          systems. - IFIP congress, 1971.
+     [4] Auguston M.I. Programming language RIGAL.  -  Riga,  LSU,
+          1987, (in Russian ).
+     [5] Jackson M. Principles  of  Program  design.  -   Academic
+          Press , 1975.
+     [6] Barzdin J.M., Kalnins A.A., Auguston M.I. SDL  tools  for
+          rapid  prototyping  and  testing.  -  in  SDL'89  :  The
+          Language at  Work,  ed.  O.Faergemand  and  M.M.Marques,
+          North-Holland, 1989, pp.127-133.
+     [7] Herndon R., Berzins  V.  The  Realizable  Benefits  of  a
+          Language Prototyping Language. -  IEEE  Transactions  on
+          Software Engineering,  vol.14,  No  6,  June  1988,  pp.
+          803-809.
+

+ 145 - 0
examp1/sourguid.txt

@@ -0,0 +1,145 @@
+--- SOURGUID.TXT ---
+By Wadim Engelson , IMCS LU Riga, Latvia     16-oct-1990
+Revised  1-dec-1990 (for version 1.4)
+         8-apr-1991: (for version 1.50-no changes)
+         15-sep-1991: (for version 2.04, TP 5.5 changed to 
+6.0)
+
+                Rigal source guide
+                ==================
+
+     Rigal is implemented as some  tasks  (.EXE-files),  in
+two versions : RIG.EXE which is without the compiler option
+(more simple ) , and RIG1.EXE which calls  several  another
+tasks including interpreter, compiler and so on.
+     Some of parts  were  compiled  Pascal  programs,  some
+(ANRIG,GENRIG, RIG_LINT, RIG_CRF, RIG_PNT  )  are  compiled
+RIGAL programs.
+     Pascal source files include all necessary  subprograms
+( UNITS in Turbo Pascal terms ) and main programs  (  their
+names are equal to task names).  Units  are  used  both  to
+compile tasks and to form additional part, which  is  added
+to standard Turbo PascaL library TURBO.TPL, which  is  used
+as Rigal runtime library.
+     Turbo Pascal 6.0 (TPC.EXE) is  used  both  to  compile
+pascal code and in Rigal Compiler (as last  phase  of  it).
+Pascal code compilation may run as batch  (  batch  command
+file RECOMP.BAT ) where  correct  directory  name  must  be
+given as command line parameter). This directory  must  yet
+contain  TPC.EXE   ,   any   version   of   TURBO.TPL   and
+TPUMOVER.EXE. At the beginning all old  Units  are  removed
+from TURBO.TPL, then normal compilation of  some  tasks  is
+executed, then new Unit codes are added to TURBO.TPL.
+     Rigal-written programs may be compiled by  F8  key  of
+the integrated environment (or simply by running RIGCOMP.BAT)
+and their  names  are  equal  to
+tasks (ANRIG, GENRIG are analysis and  generation  part  of
+the compiler itself, CRF (=RIG_CRF) is Cross-referencer.
+
+             ----- Porting considerations -----
+
+      Before porting to another  Pascal  version  -  simple
+translation in MS-DOS Turbo Pascal 6.0 is recommended  (5.0
+also may be used ).
+     Two main problems are (1) using built-in Turbo  Pascal
+procedures and  functions  and  (2)  using  Unit-dependency
+schema.
+     Here are recommended sequence of works which are  need
+for porting of Rigal Environment from  MS-DOS/Turbo  Pascal
+version to Unix/Pascal or any another.
+     At first we recommend to compile DEFINE.PAS  unit.  It
+describes types A and AA (the same) which must be  4  bytes
+length positive number, it is used everywhere as address of
+structured  objects  (atoms,  list  and  tree  descriptors)
+(S-space),and text pieces (symbolic constants) ( A-space).
+     Below described fields of records must be of the  same
+sub-division to bytes ( in  Turbo  Pascal  no  division  to
+bits). Length of records in memory must be the same.
+     DEFPAGE.PAS describes paging manager and  loading  and
+saving rigal objects. In preliminary  porting  loading  and
+saving  rigal  objects  in  files  is  not   implementable,
+butanother  procedures  will  allocate  rigal  objects   in
+ordinary heap memory, using A as POINTER type.
+     In more advanced level of porting we need  take  under
+control such considerations about current version of paging
+manager : Low-level  operations  semantics  must  be  under
+control; Virtual disk name comes as parameter from  command
+line , and we are sure that if heap memory is big enough  (
+8 MBytes ?) - then no paging and no special disk  name  are
+needed. File names ( they are now defined  as  constants  )
+may be of ANY nature , because they normally  will  not  be
+opened, and all paging will execute only  in  heap  memory.
+BlockRead & BlockWrite & Seek procedure  semantic  must  be
+carefully tested; no special disk-error or memory-error  or
+disk-overflow messages are produced now. It is not so  easy
+to separate paging from SAVE/LOAD of Rigal objects and only
+Andris Zarins (third author) knows the  details.  Parameter
+passing by reference is essential now.
+     Unit LEYER.PAS describes lexical  analyzer  of  Rigal.
+STRING type is used to form every one  token.  STRING  zero
+byte is not mentioned in programs. GotoXY and Write are not
+essential here. Pascal lexical analyzer (if it is  need  at
+all) may be changed later - as you want.
+     Program RIGCHECK (version 1.4) is the simplest one:
+it  takes  a command line  parameter - file  which  contains
+ a .RIG program and
+executes syntax checking of  Rigal  program.  Program  name
+(a.rig) is given , lexical analyzer  and
+(then) recursive descending analyze executes; either  error
+message is showed in the screen (might be redirected by
+'>' DOS symbol),   either   program   special   code
+(need    for interpretation ) is saved in A.RSC file.
+     W*.PAS are parts  of  our  domestic  text  editor.  No
+toolboxes were used, only GotoXY, ClrScr , ClrEol and Write
+procedures were used for output to the screen.  Colors  are
+yet fixed as declared constants. Double direction chain  of
+records in heap represents  global  buffer  and  additional
+one.  We  save  names  of  8  last  used  files.  Procedure
+FindFirst and similar one are used to show directory. Error
+messages returned  from  checker,  and  editor  shows  this
+message and goes to according line and column  where  error
+occurred. You can of course to use your own text editor  if
+you can form output and input parameters of  procedure  WED
+or similar one, menus , and to put error message  into  the
+appropriate place.( In any case it is much better to  use
+ ready text editor like
+MS-DOS  MULTIEDIT (with Muliedit's "Big compile" option)).
+
+     INT.EXE is interpreter  of  RSC  files.  There  is  no
+porting  problems;  circular  calling  of   procedures   is
+essential. No problems in text output or PRINT.
+     First version (really working) RIG.EXE  prototype  now
+may be compiled. In preliminary version paging  we  do  not
+use - it simplifies work  (without  real  SAVE  and  LOAD).
+After  this  moment  really  working  SAVE  and  LOAD   are
+absolutely necessary.
+     Now,   COMPILER.   Current   Rigal->Pascal    compiler
+generates some pascal files from one rigal program.  Pascal
+code patterns and unit dependency is common for all  cases,
+only count of files is  changeable.  You  must  design  new
+dependency schema (what  and  how  to  generate  in  pascal
+files). After fixing all  changes  must  be  inserted  into
+programs ATN.RIG and ATI3.RIG of compiler generation  part.
+Compiler analysis part will  not  be  changed.  New  pascal
+codes must allow  circular calling of many procedures  each
+other and all they call  the  Runtime  Library.  Of  course
+dependency schema will  be  simple  if  it  is  allowed  to
+compile more than 2 MBytes of pascal  source  code  as  one
+unit.
+     Runtime library must be formed from  the  same  pascal
+sources, which were used in interpreter or checker.
+     Now run both parts of  compiler  may  be  run  through
+themselves (using interpreter first time, and then - bootstrapping).
+ Such a  way  you
+get  ready  ANRIG.EXE  and  GENRIG.EXE.  Understanding   of
+command line parameters passing is essential. Task  calling
+we recommend to implement through  additional  batch  file,
+which  is  generated  by  checker.  It   requires   correct
+references  to  files  and  directories  of  user  and   of
+implementation and of PASCAL compiler.
+     Now all tasks are linked to one or to  set  of  tasks.
+RIG1 must be the main task.
+     My experience shows that porting  from  RSX11M  Oregon
+Pascal to VAX/VMS Pascal and then to  MS-DOS  Turbo  Pascal
+takes one man * month each. It not includes paging manager,
+studying pascal differenced and operating systems.

+ 48 - 0
examp1/tex1.rig

@@ -0,0 +1,48 @@
+ --  Now TEX scaner is available.
+ --    T+ defines LaTeX lexical rules
+ --    and value of new "tex_lexics" boolean variable
+ --    @+ defines (additionaly to T+) .sty - file mode of LaTeX,
+ --     when @ characters are allowed in command names
+
+ --   .TEX file have to be with 'P-U-p-A-T+'
+ --   .STY file have to be with 'P-U-p-A-T+@+'
+#E
+ OPEN S 'S2.LST';
+ $L:=#CALL_PAS(35 'sample.TEX'     'P-U-p-A-T+');
+ PRINT $L;
+
+ $L:= #CONV($L);
+ PRINT $L;
+ #STAT($L);
+ #CALL_PAS(1);
+ FORALL $E IN $L DO S<]@$E; IF NOT $E->S<<;S<<;FI;OD;
+##
+
+#CONV
+ (. (*   (  ( '%'  (* S'($$) *) NULL  )  -- removes all comments
+         !  ( $X!.:=' ' (* ' ' *) ) -- removes all spaces but one
+         !  ( NULL (+ NULL +) / $X!.:=NULL / ) -- leave one NULL if many
+         !  ( NULL / $X!. :=' '/)    -- removes single NULLs,
+                                     -- changing them to spaces
+         !  $X!.:=$E
+         )
+     *)
+ .)
+/RETURN $X/
+##
+
+#STAT
+ (. (* ( $IDENT!.:=#IDENT
+       ! $KEYS!.:=#_KEYWORD
+       ! $NULLS!.:=NULL
+       ! $ATOMS!.:=$ANY
+       )
+    *)
+ .)
+/
+PRINT (. IDENTIFIERS $IDENT .);
+PRINT (. KEYWORDs   $KEYS .);
+PRINT (. NULLs $NULLS .);
+PRINT (. OTHER GOOD THINGS $ATOMS .);
+/
+##

+ 83 - 0
examp1/tlist.rig

@@ -0,0 +1,83 @@
+#BUBBLE_SORT
+-- This test shows use of traditional list and
+--  of numeric table .
+-- Executes bubble sorting of list of numbers
+-- Used interactively and through parameters
+$B:=#PARM(T);
+OPEN S ' ';
+$MEMORY:=$B[1];
+IF NOT $MEMORY ->
+  LOOP
+    $MEMORY:=#CALL_PAS(1 'Enter size of the table {elements, <=total');
+               --     1=WRITE/READ
+    IF $MEMORY>0 -> BREAK FI;
+  END;
+FI;
+
+$SIZE:=$B[2];
+IF NOT $SIZE ->
+  LOOP
+    $SIZE:=#CALL_PAS(1 'Enter count of sorted numbers');
+                  --    1=WRITE/READ
+    IF $SIZE>0 -> BREAK FI;
+  END;
+FI;
+
+$TAB:=#CALL_PAS(60 $MEMORY); -- create
+IF $TAB<=0 -> #CALL_PAS(1 'STOP, TABLE NOT CREATED');FI;
+$I:=1;
+LOOP
+  $RAND:=#CALL_PAS(20 100); -- random
+  $LIST!.:=$RAND;
+  #CALL_PAS(62 $TAB $I $RAND); -- put
+  IF $I=$SIZE->BREAK FI;
+  $I+:=1;
+END;
+#CALL_PAS(30 '  Starts work with list ');
+PRINT $LIST;
+$FLAG:=T;
+LOOP
+IF NOT $FLAG->BREAK FI;
+  $FLAG:=NULL;
+  $I:=1;
+  LOOP
+   IF $LIST[$I]>$LIST[$I+1] ->
+        $M:=$LIST[$I];
+        $LIST[$I]:=$LIST[$I+1];
+        $LIST[$I+1]:=$M;
+        $FLAG:=T;
+    FI;
+    IF $I=$SIZE-1->BREAK FI;
+    $I+:=1;
+  END;
+END;
+
+
+PRINT $LIST;
+#CALL_PAS(30 ' Starts work with table  ');
+PRINT #CALL_PAS(65 $TAB);
+$FLAG:=T;
+LOOP
+IF NOT $FLAG->BREAK FI;
+  $FLAG:=NULL;
+  $I:=1;
+  LOOP
+   IF #CALL_PAS(63 $TAB $I)>#CALL_PAS(63 $TAB $I+1) ->
+        $M:=#CALL_PAS(63 $TAB $I);
+        #CALL_PAS(62 $TAB $I #CALL_PAS(63 $TAB $I+1));
+        #CALL_PAS(62 $TAB $I+1 $M);
+        $FLAG:=T;
+    FI;
+    IF $I=$SIZE-1->BREAK FI;
+    $I+:=1;
+  END;
+END;
+IF #CALL_PAS(65 $TAB)=$LIST ->
+   S<<RESULTS ARE EQUAL
+ELSIF T->
+   S<<RESULTS ARE DIFFERENT
+FI;
+PRINT #CALL_PAS(65 $TAB);
+#CALL_PAS(30 ' --- end --- ');
+##
+

+ 201 - 0
examp1/toylan.rig

@@ -0,0 +1,201 @@
+#TOYLAN_COMPILER
+   
+    OPEN REP ' ';  --message file is connected with the screen
+    $LEXEMS:=#CALL_PAS(35 'a.toy');
+     -- a list of tokens is loaded from the file A.TOY by scanner
+    $S_TREE := #A_PROGRAM($LEXEMS);
+    -- 1st  phase; result of parsing - abstract syntax tree - is
+    -- imbedded in the variable $S_TREE; during parsing messages
+    -- about discovered errors in file REP can be output.
+    IF $S_TREE  ->  OPEN GEN 'a.bal'; -- if the tree is created,
+         -- then file is opened to output the generated BAL text
+           #G_PROGRAM($S_TREE); -- 2nd phase-code generation
+           #INTERPRETER($S_TREE) -- 2nd phase-code interpretation
+    ELSIF  T  ->  REP << errors are discovered   FI;
+    REP << end ##
+
+
+
+
+#A_PROGRAM    -- the rule is applied to the list of tokens
+    (. PROGRAM  $Id
+         (*  $DECL++:= #A_DECLARATION  ';'  *)
+                  --formation of variables table
+          (+  $STATEMENTS !.:= #A_STATEMENT   + ';' )
+                  --formation of statements list
+    .)  / RETURN 'PROGRAM' :: <. NAME : $Id,
+                                  DECLARATIONS : $DECL ,
+                                  STATEMENTS : $STATEMENTS .>/ ##
+#A_DECLARATION     $TYPE := ( INTEGER ! BOOLEAN )
+  (+ $Id /IF LAST #A_PROGRAM $DECL.$Id OR $REZ.$Id ->
+              REP << VARIABLE $Id DOUBLE DEFINED  FI;
+           $REZ++:= <.$Id : $TYPE .>/  + ',' ) / RETURN $REZ / ##
+#A_STATEMENT   $REZ := ( #A_ASSIGNMENT ! #A_INPUT !
+               #A_OUTPUT ! #A_CONDITIONAL )  / RETURN $REZ / ;;
+
+     (* $A!.:=S'($$ <> ';' ) *)   -- skip until nearest ';'
+               / REP << UNRECOGNIZED STATEMENT $A /
+##
+
+#A_ASSIGNMENT $Id  ':='/ $LPType := LAST #A_PROGRAM $DECL .$Id;
+        IF NOT $LPType  -> REP << VARIABLE $Id 'IS NOT DEFINED' FI /
+    $E:= #A_EXPRESSION
+         /IF $LPType <> $E . TYPE ->
+              REP<< 'LEFT AND RIGHT SIDE TYPES ARE DIFFERENT '
+                     'IN ASSIGNMENT STATEMENT ' FI;
+         RETURN ASSIGNMENT::<. LEFT: $Id, RIGHT: $E .> /
+ ONFAIL IF $LPType  -> REP<< 'WRONG EXPRESSION IN ASSIGNMENT'  FI  ##
+#A_INPUT      GET  '('
+    (+ $E !.:= $Id  /IF  LAST #A_PROGRAM $DECL.$Id <> INTEGER ->
+            REP << $Id 'IN STATEMENT GET IS NOT OF THE TYPE INTEGER'
+                      FI / + ',' ) ')' / RETURN INPUT :: $E /   ##
+#A_OUTPUT   PUT  '(' (+  $C := #A_EXPRESSION  / $E !.:= $C;
+              IF  $C . TYPE  <> INTEGER ->
+        REP << 'OPERAND OF PUT STATEMENT IS NOT OF THE TYPE INTEGER'
+                FI /   + ',' ) ')'/ RETURN OUTPUT :: $E /       ##
+#A_CONDITIONAL     'IF' $BE := #A_EXPRESSION
+    /IF $BE . TYPE <> BOOLEAN ->
+              REP<< 'CONDITION IS NOT OF BOOLEAN TYPE' FI /
+                   'THEN' (+ $P1 !.:= #A_STATEMENT + ';' )
+         [ 'ELSE' (+ $P2 !.:= #A_STATEMENT + ';' ) ]      'FI'
+    / RETURN CONDITIONAL :: <. COND : $BE , THEN : $P1 ,
+                               ELSE : $P2  .> /            ##
+#A_EXPRESSION      $A := #A_SUM   [  '=' $B := #A_SUM
+    / $A := COMPARE::<. ARG1 : $A, ARG2 : $B, TYPE : BOOLEAN.>/ ]
+    / RETURN $A /           ##
+#A_SUM   $A := #A_FACTOR    (* '+' $B := #A_FACTOR
+         / $A := ADD::<. ARG1: $A, ARG2: $B, TYPE: INTEGER .>/ *)
+    / RETURN $A  /          ##
+#A_FACTOR  $A := #A_TERM     (* '*' $B := #A_TERM
+         /$A := MULT::<. ARG1: $A, ARG2: $B, TYPE: INTEGER .>/ *)
+    / RETURN $A /           ##
+#A_TERM
+    $N  / RETURN <. CONSTANT : $N , TYPE : INTEGER .>/;;
+  ( ( TRUE / $K :=1/ ) ! ( FALSE / $K :=0 / ) )
+                 /RETURN <. CONSTANT: $K, TYPE: BOOLEAN .>/  ;;
+    $Id  / $X:= LAST #A_PROGRAM $DECL.$Id;
+         IF NOT $X  ->  REP << VARIABLE $Id IS NOT DECLARED
+         ELSIF T -> RETURN <. VARIABLE: $Id, TYPE: $X .> FI / ;;
+    '(' $E := #A_EXPRESSION ')' / RETURN $E /        ##
+
+
+#INTERPRETER
+  $P
+ / $++:= <. VARIABLES : #CREATE_TABLE ($P.DECLARATIONS) .>;
+--PRINT $;
+   #I_PROGRAM ($);
+PRINT $.VARIABLES;
+ /
+##
+#CREATE_TABLE
+ <* $Id : $Type / $Y ++ := <. $Id : 0 .> / *>
+ / RETURN $Y /
+##
+
+#I_PROGRAM
+ <. STATEMENTS : #I_STATEMENTS .>
+##
+
+#I_STATEMENTS (. (* #I_STATEMENT
+/ PRINT LAST #INTERPRETER $.VARIABLES;
+  #CALL_PAS(1) /
+ *) .) ##
+#I_STATEMENT
+ ( #I_INPUT ! #I_OUTPUT ! #I_ASSIGNMENT ! #I_CONDITIONAL ) ##
+#I_INPUT
+  INPUT :: (. (* $Id
+    /
+     LAST #INTERPRETER $.VARIABLES.$Id:= 
+         #CALL_PAS(1 'toylan>') /
+  *) .)
+##
+#I_OUTPUT
+  OUTPUT :: (. (* $E:= #I_EXPRESSION
+   / REP << $E /
+   *) .)
+##
+
+#I_ASSIGNMENT
+  ASSIGNMENT :: <. LEFT : $Id,
+                   RIGHT : $R:=#I_EXPRESSION
+                .>
+   / LAST #INTERPRETER $.VARIABLES.$Id:=$R/
+##
+#I_CONDITIONAL
+  CONDITIONAL :: <. COND : $E:=#I_EXPRESSION .>
+  / IF $E<>0 -> #I_STATEMENTS ($.THEN)
+    ELSIF $.ELSE -> #I_STATEMENTS ($.ELSE)
+    FI  /
+##
+#I_EXPRESSION
+ <. CONSTANT : $N .> / RETURN $N /;;
+ <. VARIABLE : $Id .> 
+   / RETURN LAST #INTERPRETER $.VARIABLES.$Id/;;
+ ADD:: <. ARG1 : $E1:=#I_EXPRESSION,
+         ARG2 : $E2:=#I_EXPRESSION
+       .>
+      / RETURN $E1+$E2 /;;
+ MULT:: <. ARG1 : $E1:=#I_EXPRESSION,
+         ARG2 : $E2:=#I_EXPRESSION
+       .>
+      / RETURN $E1*$E2 /;;
+ COMPARE:: <. ARG1 : $E1:=#I_EXPRESSION,
+         ARG2 : $E2:=#I_EXPRESSION
+       .> / IF $E1=$E2 -> RETURN 1 
+            ELSIF T ->    RETURN 0
+            FI/ ##
+
+
+#G_PROGRAM    / $LABEL := 0 /   --global variable $LABEL serves
+                                 --to generate unique labels.
+  PROGRAM::<.DECLARATIONS: $TAB := #TABLE_OF_NUMBERS,
+              --creation of the table of unique variable numbers
+             STATEMENTS: (.(* #G_STATEMENT *).) / GEN << 'EOJ' /,
+             DECLARATIONS : #G_DECLARATIONS      .>       ##
+#TABLE_OF_NUMBERS <* $Id: $TYPE /$N :=$N+1; $T++:=<. $Id: $N.>/ *>
+                   /RETURN $T/    ##
+#G_STATEMENT ( #G_ASSIGNMENT ! #G_INPUT !
+              #G_OUTPUT     ! #G_CONDITIONAL )      ##
+#G_ASSIGNMENT    ASSIGNMENT::<. LEFT: $Id := #NAME,
+  RIGHT :( ( <. VARIABLE: $Id1:=#NAME .>
+              /GEN << MOV @ $Id1 ',' $Id / ) !
+           ( <. CONSTANT : $N .> /GEN << MOV @ '=' $N ',' $Id /) !
+           ( $NREG := #G_EXPRESSION
+              /GEN << 'SAVE' @ 'R' $NREG ',' $Id / ) )  .>    ##
+#G_INPUT INPUT::(. (* $Id := #NAME /GEN << READ $Id / *) .)   ##
+#G_OUTPUT     OUTPUT :: (. (*
+    ( ( <. VARIABLE : $Id := #NAME .> /GEN << WRITE $Id / ) !
+       ( <. CONSTANT : $N .> /GEN << WRITE @ '=' $N / )  !
+       ( $NREG := #G_EXPRESSION /GEN << WRITE @ 'R' $NREG /) )
+                         *) .)                                ##
+#G_CONDITIONAL     CONDITIONAL ::
+     <. COND : $NREG := #G_EXPRESSION
+            / $LABEL1 :=#NEW_LABEL(); $LABEL2 :=#NEW_LABEL() /,
+         THEN   : / GEN << BRANCH @ 'R' $NREG ',L' $LABEL1  /
+                  (. (* #G_STATEMENT *) .)
+               / IF $.ELSE -> GEN << JUMP @ 'L' $LABEL2 FI;
+                             GEN << @ 'L' $LABEL1 ': NOP' / ,
+       [ ELSE : (. (* #G_STATEMENT *) .)
+               / GEN << @ 'L' $LABEL2 ': NOP' / ]     .>  ##
+#G_EXPRESSION --returns the number of the register containing
+               --result of the evaluation of expression
+  $EXPR
+/ $NREG := 0 / -- number of the first accessible register
+/RETURN #G_EXPR($EXPR)/
+ ##
+
+
+#G_EXPR     ( <. VARIABLE: $ID :=#NAME .>  !
+              <. CONSTANT: $N / $ID := #IMPLODE('=' $N)/ .>)
+            / $REG := COPY( LAST #G_EXPRESSION $NREG ) ;
+              GEN << 'LOAD' @ 'R' $REG ',' $ID  ;
+              LAST #G_EXPRESSION $NREG + := 1; RETURN $REG /  ;;
+         $OP::<. ARG1 : $R1 := #G_EXPR, ARG2 : $R2 := #G_EXPR .>
+          / GEN << $OP @ 'R' $R1 ',R' $R2 ; RETURN $R1 /   ##
+#G_DECLARATIONS
+<* $ID: $TYPE /$ID1 := #NAME($ID); GEN<< $ID1 ':' DEFWORD 0 /*> ##
+#NEW_LABEL    --auxiliary rule
+    /LAST #G_PROGRAM  $LABEL+:=1;
+     RETURN COPY (LAST #G_PROGRAM $LABEL )/              ##
+#NAME    $ID --returns standard name of the variable $ID in $TAB
+     / RETURN #IMPLODE( VAR  LAST #G_PROGRAM $TAB.$ID)/    ##

+ 90 - 0
examp1/ttree.rig

@@ -0,0 +1,90 @@
+#DICTIONARY
+-- This test shows use of traditional tree and of atomic table utility
+-- It creates dictionary of all words in given file
+-- and removes all words which appear more than once.
+-- Information comes through parameters of task or interactively;
+$B:=#PARM(T);
+OPEN S ' ';
+$MEMORY:=$B[1];
+IF NOT $MEMORY ->
+  LOOP
+    $MEMORY:=
+               #CALL_PAS(1 'Enter size of the table {elements, <=total / 5} ');
+                  -- 21=VAL       1=WRITE/READ
+    IF $MEMORY>0 -> BREAK FI;
+  END;
+FI;
+
+$TAB:=#CALL_PAS(61 $MEMORY); -- create
+$TAB2:=#CALL_PAS(61 $MEMORY); -- create
+IF ($TAB<=0)OR($TAB2<=0)
+    -> #CALL_PAS( 1 'STOP ! ERROR IN CREATION ');FI;
+
+
+$FILE:=$B[2];
+IF NOT $FILE ->
+  $FILE:=#CALL_PAS(1 'Enter file name ');
+FI;
+
+$LIST:=#CALL_PAS(3 $FILE);    -- Pascal scanner
+
+S<<' Tree creation ';
+FORALL $E IN $LIST  DO
+  IF #IDENT($E) ->
+     IF $DICT.$E -> $DICT.$E+:=1
+     ELSIF     T -> $DICT++:=<.$E:1.>
+     FI;
+  FI;
+OD;
+
+S<<' Tree copy    ';
+$DICT1:=COPY($DICT);
+
+S<<' Tree  update ';
+FORALL $E IN $DICT DO
+   IF $DICT.$E>1 -> $DICT1.$E:=NULL FI;OD;
+
+S<<' Table creation ';
+FORALL $E IN $LIST DO
+  IF #IDENT($E) ->
+    $V:=#CALL_PAS(63 $TAB $E);          -- get n
+    IF $V->#CALL_PAS(62 $TAB $E $V+1)   -- put n+1
+    ELSIF T-> #CALL_PAS(62 $TAB $E 1)   -- put 1
+    FI;
+  FI;
+OD;
+
+S<<' Table copy ';
+$TABCOPY:=#CALL_PAS(65 $TAB);           -- unpack
+          #CALL_PAS(66 $TAB2 $TABCOPY); -- pack
+
+S<<' Table update ';
+$I:=1;
+$ENDLOOP:=#CALL_PAS(64 $TAB);  -- card
+LOOP
+  $SEL:=#CALL_PAS(67 $TAB $I);  -- num to sel
+  $VAL:=#CALL_PAS(63 $TAB $SEL); -- get
+  IF $VAL>1 -> #CALL_PAS(62 $TAB2 $SEL NULL); -- put null
+  FI;
+  IF $I=$ENDLOOP -> BREAK; FI;
+  $I+:=1;
+END;
+
+S<<' End of work ; test for correctness:';
+
+IF $DICT=#CALL_PAS(65 $TAB) ->      -- card
+   S<< SOURCES ARE EQUAL
+ELSIF T->
+   S<< SOURCES ARE DIFFERENT;
+FI;
+
+IF $DICT1=#CALL_PAS(65 $TAB2) ->     -- card
+   S<< RESULTS ARE EQUAL
+ELSIF T->
+   S<< RESULTS ARE DIFFERENT;
+FI;
+
+S<< 'TOTAL WORDS=' #CALL_PAS(64 $TAB)
+    ' ONCE OCCURED=' #CALL_PAS(64 $TAB2) ;
+##
+

+ 38 - 0
examp1/work.rig

@@ -0,0 +1,38 @@
+-- This is file WORK.RIG
+-- You can try  examples 
+--  EX1.RIG - how to take Tail and Head of list
+--  EX2.RIG - how to analyse and print polish form of arithmetic expression
+--  GRAM2.RIG - small language (SL) source syntax grammar
+--  GRAM1.RIG - tree abstract grammar for SL
+--  INTER.RIG - interpreter of SL
+--  BCOMP.RIG - compiler of SL to Pascal
+--  EX1.txt   - input text in SL
+
+-- THIS IS SIMPLE PROGRAM ; TRY press F6 and then F7; Exit ALT+X
+#START 
+  OPEN S ' ';
+  S<<FFFFF;
+  
+   $E:=2000000001;
+   PRINT (. #NUMBER($E)   $E DIV 5   $E DIV 100 .);
+   $N:=3;
+   $A:=<. AA : $E , BB : $N .>;
+   #CALL_PAS(13 $A);
+   #CALL_PAS(12 $A);
+-- $S:=$E[4];
+##  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 61 - 0
examples/baltree.rig

@@ -0,0 +1,61 @@
+-- Balanced tree
+-- This program takes list of numbers, produced by random
+-- number generator and puts them to balanced tree. 
+-- Then it traverses the balanced tree and outputs the
+-- numbers in increasing order.
+#MAIN
+ $limit:=50;
+ $numlist:=#gen_random_list($limit);
+ $baltree:=#list_2_bal_tree($numlist);
+ $ordered_list:=#bal_tree_2_list($baltree);
+ PRINT $numlist;
+ PRINT $ordered_list;
+##
+
+#gen_random_list $limit
+-- $limit - how many numbers to generate
+/#CALL_PAS(19); -- Randomize. Sets internal random generator
+                -- to seed depending on currernt time.
+ LOOP
+   IF $limit<=0 -> RETURN $res FI;
+   $res!.:=#CALL_PAS(20 100); -- returns random integer in 0..99
+   $limit+:=-1; -- normal way how to do FOR-loops in Rigal
+ END / 
+##
+
+#list_2_bal_tree 
+ (. $first
+    / $tree:=<. 'val': $first .> /
+    (* $other / #insert ( $tree $other ) /
+     *)
+  .)
+/ RETURN $tree /
+##
+
+#insert $tree $newval
+-- $tree - a balanced tree node. It cannot be NULL.
+-- $newval - value added to the tree.
+
+ / IF $newval=$tree.val -> RETURN t FI;
+   -- if duplicates come, they are ignored
+   IF $newval<$tree.val ->
+      IF $tree.left -> #insert($tree.left $newval)
+      ELSIF T -> $tree ++:=<. left: <. val: $newval .> .>
+      FI
+   ELSIF T ->
+      IF $tree.right -> #insert($tree.right $newval)
+      ELSIF T -> $tree ++:=<. right: <. val: $newval .> .>
+      FI
+   FI / 
+##
+
+#bal_tree_2_list        
+ <.  [ left : $list!!:=#bal_tree_2_list ],     
+       val   : $list !.:=$the_val,
+     [ right : $list!!:=#bal_tree_2_list ]     
+ .>
+ /RETURN $list/
+##         
+    
+
+  

+ 107 - 0
examples/opt.rig

@@ -0,0 +1,107 @@
+-- Time estimation
+-- This program can be used in order to estimate the
+-- time of access to Rigal data structures, as well as
+-- understand expensive and not expensive operations.
+-- Results in speed.res.
+-- Measurements are in cs - 1/100 of seconds.
+-- The computer clock gives results with resolution 
+-- not more than 6 cs. So, normally you shouldn't pay attention
+-- to fluctuations less than 10 cs.
+-- MEASUREMENTS
+-- For 5000 times on LEO (IBM AT 486) computer , in 1/100 of seconds
+
+--           counter list-cr tree-cr list[19] tree.(19)
+-- Int/11     1600    600     4500    1000       1000
+-- Int/72      350    140     1300     220        220
+-- Comp/11      65     48      620      80        250    
+-- Comp/72      11     10      125      13         35
+-- Comp/72/Win  11     15      150      16         35  
+-- LEGEND:
+-- Int - interpreter. Comp - compiled program
+-- 11 - non-turbo mode. 11 times faster than IBM XT 88 /4.7 MHz
+-- 72 -     turbo mode. 72 times faster than ------- " -------- 
+-- Win - MS-Windows version.
+
+
+
+#M
+ -- OPEN S 'speed.res';
+ OPEN S ' ';
+ $EOLD:=(.0 0 0 0 0 0 0 0.);
+ $CORR:=0;
+-- All tested operations are performed in loops. These loops
+-- are controlled by counter. Since we are not interested in
+-- time consumed by counter, we have to substract the time
+-- consumed by the counter ($CORR) from all experiments. 
+
+ $MAX:=20000;
+-- Useful values: Maximal 20000. 
+-- Minimal 26
+
+ #time();
+ $I:=1;
+ LOOP $I+:=1; IF $I=$MAX->BREAK FI; END;
+ $CORR:=#time();
+ S<< ' Correction = ' $CORR  ' cs used by the counter ' ;
+ 
+ $I:=1;
+ LOOP $I+:=1; IF $I=$MAX->BREAK FI; $Z!.:=T; END;
+ S<< ' Creation of list with ' $MAX ' elements  ' #time()  cs ; 
+
+ $I:=0;
+ LOOP $I+:=1; IF $I=$MAX->BREAK FI; $TR++:=<.
+   #CHR(#ORD(A)+ $I MOD 25)
+   :T.>; END;
+  S<< ' Creation of tree with ' $MAX '(different=' #LEN($TR)
+   ') elements  ' #time()  cs ; 
+ -- PRINT $TR;
+
+
+ 
+ $J:=1;
+ LOOP
+  $I:=1;
+  LOOP $I+:=1; IF $I=$MAX->BREAK FI; $R:=$Z[$J]; END;
+  S << ' Access to ' $J '-th element of list ' $MAX 
+       ' times  ' #time() cs;
+  $J:=$J+3;
+  IF $J>=20->BREAK FI;
+ END;
+
+
+ 
+ $J:=0;
+ LOOP
+  $LET:=#CHR(#ORD(A)+ $J MOD 26);
+  $I:=1;
+  LOOP 
+    $I+:=1; 
+    IF $I=$MAX->BREAK FI; 
+    $R:=$TR.$LET; 
+  END;
+
+  S << ' Access to ' $J '-th element (' $LET ') of tree ' $MAX 
+       ' times  ' #time() cs;
+  $J:=$J+3;
+  IF $J>=26->BREAK FI;
+ END;
+ 
+
+
+#CALL_PAS(1 'Press ENTER');
+
+## 
+#time
+ /
+  $E:=#CALL_PAS(89); -- Current time , 8 integers
+  -- Last 2 are seconds and centi-seconds
+--  S<<$E;
+  $EOLD:=LAST #M $EOLD;
+  $sec:=$E[7]-$EOLD[7]; -- seconds elapsed after last #time
+  IF $sec<0 -> $sec+:=60;FI;
+  $td:=($E[8]-$EOLD[8])
+       +100*$sec
+       -LAST #M $CORR;
+   
+  LAST #M $EOLD:=$E;
+RETURN $td/ ##

+ 12 - 0
examples/readexam.txt

@@ -0,0 +1,12 @@
+List of examples:
+(in order)
+
+STRUSCA*.* Describes how to use structure scaner.
+           Useful when you input is not a hand written but generated
+           by another tool.
+OPT.RIG    Time measurement in RIGAL
+TRAVTREE.RIG Typical traverse of tree. Leaf value change "at
+           place"
+BALTREE.RIG Building a balanced tree. Sorting.
+STACK.RIG   Implementation of stack (size+list)
+STACK2.RIG  Another implementation of stack (list only)

+ 63 - 0
examples/stack.rig

@@ -0,0 +1,63 @@
+-- Implementation of stack when the length of the stack
+-- and the list are stored both in a tree #stack_abstract.
+
+#STACKS
+ $S:=#NEWSTACK(T);
+ #PUSH(A $S);
+
+  #PUSH(B $S);
+   PRINT #TOP($S);
+  #POP($S);
+
+  #PUSH(C $S);
+  #POP($S);
+
+ #POP($S);
+ PRINT $S;
+##
+
+
+#stack_abstract
+<. size: #NUMBER,
+   [ list : (. (+ $ELEMENT +) .) ]
+.>
+##
+
+
+#NEWSTACK
+/ RETURN 'stack'::<.size:0.> /
+-- This 'stack' is added for better understanding of printouts
+-- only.
+##
+
+#PUSH  $EL
+$STACK:=
+ <. size : $size / $size+:=1 /,
+  [ list : $list
+    /IF #LEN($list)>=$size -> $list[$size]:=$EL   
+     ELSIF T -> $list!.:=$EL
+     FI;
+     RETURN T/
+   ]
+ .>
+/ $STACK++:=<.list:(.$EL.).> /
+##
+
+#PUSH2  $EL $S -- The same as push, without patterns
+/$S.size+:=1;
+ IF $S.list ->
+    IF #LEN($S.list)>=$S.size -> $S.list[$S.size]:=$EL   
+    ELSIF T -> $S.list!.:=$EL
+    FI;
+  ELSIF T->$S++:=<.list:(.$EL.).>
+  FI;
+/##
+
+
+#POP $S
+/ IF $S.size>0 -> $S.size+:=-1; FI; /
+##
+
+#TOP $S
+/ RETURN $S.list[$S.size] /
+##     

+ 31 - 0
examples/stack2.rig

@@ -0,0 +1,31 @@
+-- Stack in RIGAL
+#STACK2
+ -- stacks are modelled by lists.
+ -- The only problem is removing elements from the end.
+ -- "Base" RIGAL does not support this operation and you
+ -- have either to store "current length" of the stack in a separate
+ -- numeric variable, ( see "stack.rig") or
+ -- make copy of the list (it is very expensive).
+ 
+ -- However ther is a wayaround in the internals of Rigal
+ -- descriptors:
+ $ST:=(. 2 3 .);
+ $ST1:=#POP($ST);  -- changes $ST to (.2.) and returns it
+ PRINT (.$ST $ST1.);
+
+  -- There is, however, problem with "empty" stack, represented by NULL.
+  -- The #POP operation cannot assign NULL to argument, so then NULL
+  -- is only returned. 
+
+ $ST2:=#POP($ST1); -- leaves $ST1 as (.2.) and returns NULL
+ PRINT (.$ST1 $ST2.);
+##  
+#POP $ST
+ / IF #LIST($ST) AND (#LEN($ST)>1)->
+      #CALL_PAS(91 $ST); RETURN $ST;
+   ELSIF T->
+      RETURN NULL
+   FI;
+ /
+##
+      

+ 9 - 0
examples/strusca1.inp

@@ -0,0 +1,9 @@
+ MAIN_LIST  EL1 § 
+   medium § 
+     DEEP 1 
+          2
+         
+   other_medium
+ 
+ outer1
+ outer2

+ 5 - 0
examples/strusca2.inp

@@ -0,0 +1,5 @@
+ MAIN_LIST
+   label1
+       sel1 val1
+        sel2  §DEEP 1 §   2.5 'Text' 
+      

+ 5 - 0
examples/strusca3.out

@@ -0,0 +1,5 @@
+§   MAIN_LIST      LABEL1      SEL1     VAL1     SEL2   §   DEEP     1   §   
+  2.5000000000E+00    'Text'    
+ 
+ 
+

+ 62 - 0
examples/struscan.rig

@@ -0,0 +1,62 @@
+#STRUSCAN
+ -- Structured scaner is very useful if your input is not from
+ -- a textual representation but from some code generated by
+ -- another program, that can output both text and special characters.
+
+ -- You can create any RIGAL data simply by reading such code.
+ -- You can also create such code from RIGAL.
+
+ -- The special characters have code chr(21) .. chr(25).
+ -- Reads "strusca1.inp" and prints it.
+ -- Note chr(21) and chr(22) there 
+ 
+ -- Reads "strusca2.inp" and prints it.
+ -- Note chr(21) ... chr(25) there
+ 
+ $T:=#CALL_PAS(35 'strusca1.inp'); 
+ PRINT $T;
+ 
+ $T:=#CALL_PAS(35 'strusca2.inp');
+ PRINT $T;
+ OPEN S 'strusca3.out';
+ #emit_spec($T);
+ CLOSE S;
+ $K:=#CALL_PAS(35 'strusca3.out');
+ PRINT $K;
+
+ -- Not all text editors support editing of files with
+ -- special characters. Usually it is posible to enter
+ -- them (in PC) by holding the ALT-key and entering,e.g., 0 2 1
+ -- in right, numeric keyboard.
+
+##  
+#emit_spec
+ -- This rule creates code that can be read again by
+ -- the structured scaner. 
+
+ NULL / S <] #CHR(21) #CHR(22) / ;; -- 
+ $LABEL::(.
+ / IF $LABEL -> S<] #CHR(25); #emit_spec($LABEL); FI;
+   S<] #CHR(21)/
+  (* #emit_spec *)
+   .)     / S <] #CHR(22);S<<; /
+ ;;
+ $LABEL :: <* $SEL :
+ / IF $LABEL -> S<] #CHR(25); #emit_spec($LABEL);$LABEL:=NULL; FI;
+   IF NOT $START-> S<] #CHR(23);$START:=T; FI;
+   #emit_spec($SEL)
+ / #emit_spec
+  *>
+  / S<] #CHR(24);S<< /
+;;
+ $ATOM / S <] ' ' $ATOM ' ' / 
+##  
+
+
+   
+ 
+   
+
+
+
+

+ 54 - 0
examples/travtree.rig

@@ -0,0 +1,54 @@
+-- Tree traverse examples
+-- They work with trees with arbitrary selectors.
+-- Values under selectors must bee numbers or trees.
+-- Rule #num calculates number of leaves ($n) in the tree.
+-- Rule #sum1 adds $n to each leaf. It actually constructs
+-- a new tree.
+-- Rule #sum2 does the same "at place". 
+
+#main
+$tree:=<.A:1,B:5,C:<.a:2,b:7.>.>;
+PRINT $tree;
+$n:=#num($tree);
+PRINT $n;
+$tree1:=#sum1($n $tree);
+PRINT $tree;
+PRINT $tree1;
+#sum2($n $tree1);
+PRINT $tree1;
+#sum3($tree1);
+PRINT $tree1;
+##
+#num
+   <* $m:($N/$eq+:=1/ ! $eq+:=#num)*>/RETURN $eq/
+##
+#sum1   $EQ
+   <*$m:
+      ($N /$tr++:=<.$m:$N+$EQ.>/ 
+       -- $N in pattern accepts only numerical atom.
+       -- $N+$EQ creates new numeric atom. $N does not
+       -- change.
+       !
+       $a /$tr++:=<.$m:#sum1($EQ $a).>/) 
+   *>
+ /RETURN $tr/ 
+##
+#sum2   $EQ
+   <*$m:($N/$N+:=$EQ
+           -- This incremention is made "at place"
+           / !
+         $a /#sum2($EQ $a)/
+        ) *>
+##
+#sum3 <* $m : ($N / $N+:=LAST #main $n 
+    -- Similar to #sum2, but we dont pass $EQ each time,
+    -- and simply take it from #main. 
+                  / !
+               #sum3
+               ) *>
+##
+ 
+             
+
+ 
+

+ 264 - 0
rigal.man

@@ -0,0 +1,264 @@
+
+
+
+RIGAL(1)                 USER COMMANDS                   RIGAL(1)
+
+
+
+NAME
+      rc - checks and compiles RIGAL file
+      ic - interprets intermediate RIGAL code
+      v - viewer for RIGAL data saved in file
+      rig_crf  -  RIGAL cross-referencer
+      rig_lint - RIGAL Lint (data type checker)
+
+SYNOPSIS
+      rc  _f_i_l_e_n_a_m_e  [-c] [-D] [-P  parameter]...
+      ic _c_o_d_e_f_i_l_e_n_a_m_e  [-p _p_r_i_n_t_f_i_l_e_n_a_m_e] [-d][ parameter...]
+      v  _f_i_l_e_n_a_m_e
+      rig_crf  _f_i_l_e_n_a_m_e
+      rig_lint  _f_i_l_e_n_a_m_e
+      _e_x_e_c_u_t_a_b_l_e  [-p _p_r_i_n_t_f_i_l_e_n_a_m_e] [ parameter...]
+       (!)  the options and parameters must be separated  by  one
+     or more spaces.
+
+COMPILATION TARGET (Pascal and C)
+          There  are  two  variants  of   RIGAL   implementation:
+     RIGAL/Pascal  in  UNIX  Pascal  and  RIGAL/C in UNIX C.  The
+     differences between them are mentioned below.
+
+DESCRIPTION OF rc
+       rc  _f_i_l_e_n_a_m_e  [-c] [-D] [-P  parameter]...
+       rc - checks source file written  in  RIGAL  language.  The
+     source  code file  must have suffix .rig, but in the command
+     _f_i_l_e_n_a_m_e is specified without the suffix.
+       rc reports error messages if any appear; file  name,  row,
+     column and message text are  reported to standard output.
+       rc creates intermediate code  _f_i_l_e_n_a_m_e.rsc  which  can  be
+     used for interpretation.
+
+OPTIONS
+     -c   creates an executable file _f_i_l_e_n_a_m_e  (without  suffix).
+          In  RIGAL/Pascal variant an intermediate Pascal code is
+          generated and then Pascal compiler (pc) and linker  are
+          invoked.   In RIGAL/C variant an intermediate C code is
+          generated and then  C  compiler  (cc)  and  linker  are
+          invoked.   Some  intermediate  files, among them script
+          file xd, also appear.
+
+     -D   does not remove intermediate files after  the  compila-
+          tion.
+
+     -P _p_a_r_a_m_e_t_e_r
+          passes option to Pascal or C compiler. You can  use  -P
+          several times or use  -P  '_p_a_r_a_m_1 _p_a_r_a_m_2'  syntax. Typ-
+          ically you may  be  need  to  compile  with  statically
+          linked  standard  libraries, e.g.  $rig/rc rigcrf -c -P
+          -Bstatic
+
+
+
+
+
+Sun Release 4.1Last change: 7.7.1993, Linkoping Univ             1
+
+
+
+
+
+
+RIGAL(1)                 USER COMMANDS                   RIGAL(1)
+
+
+
+DESCRIPTION OF _e_x_e_c_u_t_a_b_l_e file (compilation result)
+          _e_x_e_c_u_t_a_b_l_e [-p _p_r_i_n_t_f_i_l_e_n_a_m_e] [parameter...]
+         The parameters are passed to RIGAL program  and  can  be
+     received  through  #PARM built-in rule which returns list of
+     parameters. The execution is identical  to  the  interpreted
+     program.
+
+OPTION
+        -p _p_r_i_n_t_f_i_l_e_n_a_m_e   - name of  file  for  statement  PRINT
+     output.  By default output is written to standard output.
+
+DESCRIPTION OF ic
+      ic _c_o_d_e_f_i_l_e_n_a_m_e [-p _p_r_i_n_t_f_i_l_e_n_a_m_e] [-d] [parameter...]
+      ic   - interprets the intermediate code,  created  by   rc.
+     The intermediate code must have suffix .rsc, but in the com-
+     mand it is specified without the  suffix.  Other  parameters
+     are  passed  to  RIGAL  program  and can be received through
+     #PARM built-in rule which  returns  list  of  parameters.The
+     execution is identical to the compiled program.
+
+OPTIONS
+     -p _p_r_i_n_t_f_i_l_e_n_a_m_e
+          name of file for statement  PRINT  output.  By  default
+          output is written to standard output.
+
+     -d   tracing mode is turned on. Trace of rules and branches,
+          rule  arguments and success/unsuccess messages is writ-
+          ten to file specified by -p option and  is  mixed  with
+          output  from  PRINT  statements. If -p option is absent
+          trace is written to standard output.
+
+DESCRIPTION of v
+      v _f_i_l_e_n_a_m_e
+      v    writes the contents of RIGAL code  saved  in  file  to
+     standard  output.  The  structure  of  code  is written with
+     indentation, in well-readable form. If  the  depth  of  some
+     element of the structure is more than 15 levels, then  char-
+     acters '..' appear instead of the element.
+        The _f_i_l_e_n_a_m_e must contain data saved by RIGAL statement
+               SAVE $_v_a_r  '_f_i_l_e_n_a_m_e'
+
+DESCRIPTION of rig_crf
+      rig_crf _f_i_l_e_n_a_m_e
+      rig_crf creates cross reference table for given RIGAL  pro-
+     gram  _f_i_l_e_n_a_m_e. The program file  must have suffix .rig, but
+     in the command _f_i_l_e_n_a_m_e is specified without the suffix. The
+     result  is  written to file _f_i_l_e_n_a_m_e.crf. For every rule the
+     following is reported: rules calling this one, rules  called
+     by this one, variables, use of global variables.
+
+DESCRIPTION of rig_lint
+      rig_lint _f_i_l_e_n_a_m_e
+
+
+
+Sun Release 4.1Last change: 7.7.1993, Linkoping Univ             2
+
+
+
+
+
+
+RIGAL(1)                 USER COMMANDS                   RIGAL(1)
+
+
+
+       rig_lint   creates warning table for given  RIGAL  program
+     _f_i_l_e_n_a_m_e.  The  program  file  must have suffix .rig, but in
+     the command _f_i_l_e_n_a_m_e is specified without  the  suffix.  The
+     result is written to file _f_i_l_e_n_a_m_e.lnt.
+        rig_lint checks type compatibility and cases when  values
+     of different types can be assigned to the same variable.
+
+ERROR MESSAGES
+       Error in file _f_i_l_e_n_a_m_e Line=_n_n  Message=_t_e_x_t Column=_m_m
+      - checker found syntax error in your RIGAL file. Intermedi-
+     ate code is not created, compilation failed.
+
+       *** ERROR  _n_n _x_x_x
+      - runtime warnings about dangerous manipulations with RIGAL
+     data structures or runtime input/output errors.
+
+       rig:undefined variable
+       pc:command not found
+       - see ENVIRONMENT  section of this manual
+
+        ERROR:COMPILATION ERROR IN RIGAL, rule #_n_a_m_e
+         -  internal  compilation  message,  normally  does   not
+     appear; try to simplify this rule.
+
+         ld() errors  or warnings
+         - try command
+            ranlib $rig/lib/riglib.a
+           to remove errors.
+
+ENVIRONMENT
+        For running RIGAL/Pascal you must have Sun Pascal release
+     2.1 (or higher). Command pc (Pascal compiler) must be avail-
+     able.
+        For running RIGAL/C  you must have a C compiler  (command
+     cc) available.
+        You must have environment variable rig set to the name of
+     directory where RIGAL system binary files are located.
+        You can set it by command
+             setenv rig _f_u_l_l__p_a_t_h/bin
+        in your .login file
+        It is recommended to include this directory at the  start
+     of path list by command
+           set path=( $rig ... )
+        in your .login file. Then you can use RIGAL commands  rc,
+     ic etc. from any directory.
+
+INSTALLATION of RIGAL from sources
+        All files are packed and compressed in file
+       rigs_v_a_r_i_a_n_t._s_y_s_t_e_m__v_e_r_s_i_o_n.tar.Z  (e.g.  rigsp.444.tar.Z).
+     Here rigsp denotes Pascal sources, rigsc - C sources.
+      uncompress  file   (without suffix .Z)
+      tar -xvf   file
+
+
+
+Sun Release 4.1Last change: 7.7.1993, Linkoping Univ             3
+
+
+
+
+
+
+RIGAL(1)                 USER COMMANDS                   RIGAL(1)
+
+
+
+      execute instructions in ENVIRONMENT section.
+
+      Go to RIGAL source directory (/src)  and execute  make ; it
+     takes  3-5  minutes  to  compile all sources  by Sun  Pascal
+     (or C) compiler and perform  self-test.  The  result  is  in
+     /bin
+
+FILES
+       bin/rc, bin/ic, bin/rig_crf, bin/rig_lint,  bin/v    basic
+     RIGAL system executable files
+       lib/riglib.a         RIGAL compiler  runtime  library.  If
+     you  move  it from one directory to another, execute command
+     ranlib _n_e_w__d_i_r_e_c_t_o_r_y/riglib.a
+       include/_f_i_l_e.inc,  include/_f_i_l_e.h m include files for com-
+     pilation
+       bin/anrig, bin/genrig     parts of RIGAL compiler
+       doc/rigal.1              this manual
+       doc/langdesc.txt         RIGAL language description
+       doc/impl.txt             User's guide
+      _f_i_l_e.rig  source programs in RIGAL
+      _f_i_l_e.rsc intermediate code for interpreter
+      xcrg*.pas, _f_i_l_e.RC2, _f_i_l_e.RC4, _f_i_l_e.TMP intermediate files,
+     appear and by default are removed during compilation.
+
+PRINTED DOCUMENTATION
+         The documentation is in doc subdirectory.
+         Use
+         troff -man -t rigal.1 | lpr -h -t        to print manual
+     page
+         nroff -man -t  rigal.1  >  rigal.man         to  prepare
+     readable manual page file
+         troff -ms -t  langdesc.txt  |  lpr  -h  -t     to  print
+     language description
+         troff -ms -t impl.txt | lpr -h -t         to  print  the
+     programmer's guide
+
+
+AUTHORS
+      Mikhail Auguston and Vadim Engelson,  Inst.  of  Math.  and
+     Comp.Sci,  University  of Latvia, Rainis blvd. 29, Riga, LV-
+     1459, Latvia (Lettland). Currently (1994-1995) Vadim  Engel-
+     son  is  at  IDA,  S-58183, Linkoping University, Linkoping,
+     Sweden.  e-mail:  vadim@mii.lu.lv , vaden@ida.liu.se.
+
+     Some info  and   pointers  to  papers  are   available  from
+     http://www.ida.liu.se/labs/pelab/members/vaden/rigal.html
+
+     Rigal and papers about it available by  ftp   ftp.ida.liu.se
+     /pub/labs/pelab/rigal
+
+
+
+
+
+
+Sun Release 4.1Last change: 7.7.1993, Linkoping Univ             4
+
+
+

+ 45 - 0
rigdm218/ANALYSE.RIG

@@ -0,0 +1,45 @@
+-- parsing of Prof. Blikle small language
+--
+-- file ANALYSE.RIG
+--
+#analyse_program
+     (. (* $rez !.:= #analyse_stmt  * ';' )  [ ';' ]  .)
+     / RETURN $rez /  ##
+
+#analyse_stmt
+    $rez := ( #assignment  !  #while_op  ) / RETURN $rez/ ;;
+
+    (* $R !.:= S'( $$ <> ';' ) *)
+    / report << unrecognised statement $R ; FAIL /
+##
+
+#assignment
+    $var := #variable  ':=' $E := #expression  V'( $$ = ';' OR $$ = 'od')
+    / RETURN 'assignment_op' :: <. left_part: $var,
+                                   right_part: $E   .> /  ##
+
+#while_op
+    'while'  $E := #expression  'do'
+             (* $body !.:= #analyse_stmt * ';' )
+                                'od'
+     / RETURN 'while_op' :: <. condition: $E,
+                               body:   $body  .> /   ##
+
+#expression
+     $a1 := #arithm_expr
+     [  '<'  $a2 := #arithm_expr
+          / RETURN '<' :: <. arg1: $a1,  arg2: $a2 .>/ ]
+     / RETURN $a1 /   ##
+
+#arithm_expr
+    $a1 := #term   / RETURN $a1 / ;;
+
+    '('  $a1 := #arithm_expr  '+' $a2 := #arithm_expr  ')'
+       / RETURN '+' :: <. arg1: $a1, arg2: $a2 .> /  ##
+
+#term
+    $NUM  / RETURN  $NUM /  ;;
+    $rez :=   #variable    /RETURN $rez /  ##
+
+#variable
+    $R := ( w ! v ! x ! y ! z ) / RETURN $R /  ##

+ 88 - 0
rigdm218/BCOMP.RIG

@@ -0,0 +1,88 @@
+-- Program BCOMP.RIG in directory \RIGAL
+-- Compiles program written in Prof.Blikle small language
+-- to PASCAL code.
+#MAIN
+$LIST:=#CALL_PAS(14 'EX1.TXT');
+OPEN report ' ';
+$TREE_CODE:=#analyse_program($LIST);
+#GEN_PROGRAM($TREE_CODE);
+##
+%INCLUDE ANALYSE.RIG
+#GEN_PROGRAM
+ /#GEN_PROLOG() /
+(. (* #GEN_STMT *) .)
+ / #GEN_EPILOG() / ##
+
+#GEN_PROLOG
+/OPEN G 'ex1.pas';
+ G<<' Program Main;';
+ G<<' const tt=101;ff=102;err=103;';
+ G<<' var state:record w,v,x,y,z:integer end;';
+ G<<' function PLUS (a,b:integer) :integer;';
+ G<<' begin if (a>100) or (b>100) then Plus:=err ';
+ G<<'       else if a+b >100 then Plus:=err ';
+ G<<'            else Plus:=a+b; end; ';
+ G<<' function LESS (a,b:integer) :integer;';
+ G<<' begin if (a>100) or (b>100) then Less:=err ';
+ G<<'       else if a<b then Less:=tt ';
+ G<<'            else Less:=ff; end; ';
+ G<<' Procedure Val(a:integer);';
+ G<<'  begin case a of ';
+ G<<'   101 : writeln (''tt''); ';
+ G<<'   102 : writeln (''ff''); ';
+ G<<'   103 : writeln (''err''); ';
+ G<<'   else  writeln (a);end;end; ';
+ G<<' BEGIN WITH STATE DO BEGIN ';
+ G<<'  w:=1;v:=1;x:=1;y:=1;z:=1; '/
+ ##
+ #GEN_EPILOG
+  / G<<'Writeln ('' Post-DUMP : '');';
+    G<<'Write (''w='');Val(w);';
+    G<<'Write (''v='');Val(v);';
+    G<<'Write (''x='');Val(x);';
+    G<<'Write (''y='');Val(y);';
+    G<<'Write (''z='');Val(z);';
+    G<<'readln;end; ';
+    G<<'END.'/
+##
+#GEN_STMT
+ 'assignment_op' ::
+   <. left_part : $Id
+        / G<< $Id ':=' /,
+      right_part : #GEN_EXPR
+        / G<] ';' / .>
+;;
+ 'while_op'::
+   <. condition :
+         / G<<' WHILE ' /
+         #GEN_EXPR
+         / G<] '=tt DO BEGIN '/,
+      body : (. (* #GEN_STMT *) .)
+         / G<<'END;' / ,
+      condition :
+         / G<< ' IF ' /
+         #GEN_EXPR
+         / G<] ' =err THEN x:=err; ' /
+  .>
+##
+#GEN_EXPR
+ $N / G<] $N / ;;
+
+ $Id / G<] $Id / ;;
+
+ '+' :: <. arg1:
+               / G<] ' PLUS( '/
+               #GEN_EXPR,
+           arg2:
+               / G<] ',' /
+               #GEN_EXPR
+               / G<] ')' / .>
+ ;;
+ '<' :: <. arg1:
+               / G<] ' LESS( '/
+               #GEN_EXPR,
+           arg2:
+               / G<] ',' /
+               #GEN_EXPR
+               / G<] ')' / .>
+ ##

+ 324 - 0
rigdm218/DEMO.BAT

@@ -0,0 +1,324 @@
+echo off
+xtra
+clear +cyan,black,blue
+big 3,,7,University
+big 12,,7,of
+big 19,,7,Latvia
+call ~~wait  60 %1
+clear
+big 9,,8,  PRESENTS
+call ~~wait  35 %1
+clear
+big 1,,7,new programming
+big 6,,7,language
+call ~~wait  5 %1
+color 12
+big 16,,8,R{{{I{{{G{{{A{{{L
+call ~~wait  60 %1
+rem ---------------------------------------------- 1
+clear
+color 14
+
+box 2,,50,16,2
+put 3,,This is DEMO film about RIGAL.
+put 4,,Contains 20 pages.
+put 5,,You can SUSPEND it by pressing any key
+put 6,,and CONTINUE by pressing "ENTER" key
+put 8,,To change speed - run
+put 9,,       DEMO 10 (fast)     or
+put 10,,      DEMO 300 (low speed)
+put 12,,DEMO is arranged for IBM/PC/XT/AT or compatible,
+put 13,,with any graphic card;
+put 14,,DEMO requires 400 KBytes free RAM.
+put 16,,DEMO is not copy protected.
+put 18,,Written by Vadim Engelson Univ. of Latvia RIGA
+call ~~wait  170 %1
+
+rem ---------------------------------------------- 2
+clear 14,0,1
+
+color 14
+big 1,,7,Rigal assigned for
+color 14,1
+box 9,,40,13,2
+call ~~wait  10 %1
+color 15,1
+put 10,,PARSING
+put 12,,PROGRAM OPTIMIZATION
+put 14,,CODE GENERATION
+put 16,,STATIC ANALYSIS OF PROGRAMS
+put 18,,PREPROCESSOR AND CONVERTOR WRITING
+put 20,,PROGRAM TRANSFORMATION
+call ~~wait  150 %1
+
+rem --------------------------------------------- 3
+clear 14,0,1
+color 14
+
+big 1,,7,Rigal data types are
+color 14,0
+
+box 7,5,20,2,2
+
+color 15,1
+put 8,9,ATOMS :
+color 14,0
+put 9,8,ABC  37  ':='
+
+box 7,45,20,2,2
+color 15,1
+put 8,55,LISTS :
+color 14,0
+put 9,50, (. AA BB CC .)
+
+box 12,27,25,8,2
+color 15,1
+put 13,,TREES :
+color 14,0
+put 14,29,. S1 : AB , S2 : CD .
+put 14,28,12
+put 14,50,14
+color 15,0
+put 16,, represents tree
+put 17,,       / \
+put 18,,   S1/     \S2
+put 19,34,/
+put 19,45,\
+color 0,7
+put 20,32,AB
+put 20,46,CD
+call ~~wait  200 %1
+
+rem ------------------------------------------ 4
+clear 14,0,1
+color 14
+
+big 1,,7,can manipulate with
+color 14,1
+box 7,,40,14,2
+call ~~wait  10 %1
+color 15,1
+put 8,,VARIABLES
+put 10,,are
+color 14,0
+put 12,,$AA     $SUMMA
+color 15,1
+put 14,,We assign them ANY value
+color 14,0
+put 16,, $SUMMA := 77+2 ;
+put 18,, $NAME_OF_BOY := JOHN;
+put 20,, $FR := (. AA BB CC .);
+call ~~wait  130 %1
+
+rem ------------------------------------------- 5
+clear 14,0,1
+color 14
+
+big 1,,7,can operate with
+color 14,1
+box 7,,40,15,2
+call ~~wait  10 %1
+color 15,1
+put 8,,L I S T S
+put 10,,Adds element to list
+color 14,0
+put 11,,$FR := (. AA BB CC .)  !. DD;
+color 15,1
+put 12,,After the execution value of $FR is
+color 14,0
+put 13,, (. AA BB CC DD .);
+color 15,1
+put 15,,Takes element of list :
+put 16,,  $FR [2]  is
+color 14,0
+put 17,, BB
+color 15,1
+put 19,, Concatenates :
+put 20,, $FR !! (. KKK AA .)  is
+color 14,0
+put 21,, (. AA BB CC DD KKK AA .);
+call ~~wait  200 %1
+
+rem ------------------------------------------ 6
+clear 14,0,1
+
+color 14
+big 1,,7,can operate with
+color 14,1
+box 7,,40,15,2
+call ~~wait  10 %1
+color 15,1
+put 8,,T R E E S
+color 14,0
+put 10,,$M:=   . S1 :  AAA , S2 : BBB . ;
+put 10,29,12
+put 10,54,14
+color 15,1
+put 11,,Takes component of tree :
+put 12,,Value of   $M.S1 is
+color 14,0
+put 13,, AAA
+color 15,1
+put 15,,Adds new branch to tree:
+color 14,0
+put 16,,$NEW := $M ++  . R2 : 33 .
+put 16,41,12
+put 16,53,14
+color 15,1
+put 17,, in result value of $NEW is
+color 14,0
+put 18,,  . S1 : AAA , S2 : BBB , R2 : 33 . ;
+put 18,21,12
+put 18,55,14
+call ~~wait  220 %1
+
+rem ---------------------------------------------- 7
+clear 14,0,1
+
+color 14
+big 1,,7,P{{A{{R{{S{{I{{N{{G
+color 14,1
+box 7,,55,15,2
+call ~~wait  10 %1
+color 15,1
+put 8,,For    P A R S I N G    we use
+put 9,,PATTERNS.
+put 11,,They  may  be  written  like
+put 12,,BACKUS - NAUR    FORMULAE (BNF).
+
+put 14,,If  SS  is  any  pattern  then
+color 14,0
+put 16,14,(* SS *)
+put 18,14,(+ SS +)
+put 20,14,[  SS  ]
+put 22,14,(SS1 ! SS2)
+color 15,1
+put 16,33,0
+put 16,35,or some times SS
+put 18,33,1
+put 18,35,or  some  times SS
+put 20,33,SS   or    nothing
+put 22,33,SS1  or   SS2
+color 15,0
+put 15,63,*
+put 16,57,( SS )
+put 17,65,+
+put 18,59,( SS )
+call ~~wait  180 %1
+
+CALL ~~contin.BAT %1
+
+rem ----------------------------------------- 8
+clear 14,0,1
+color 14
+
+big 1,,7,R{{U{{L{{E
+color 14,1
+box 7,,53,15,2
+call ~~wait  10 %1
+color 15,1
+put 8,,R U L E  is the main control tool in Rigal.
+put 10,22, IN RIGAL :
+put 10,43, IN PASCAL :
+color 14,0
+
+put 11,19,#SUMMA
+put 12,23,   $A $B
+put 13,23,   / $C := $A+$B ;
+put 14,23,   RETURN $C   /
+put 15,19,##
+put 17,19, -- call of #SUMMA:
+put 18,19, $E:=#SUMMA(5 6)
+color 15,0
+put 11,40, Function Summa
+put 12,43,  (a:int;b:int):int;begin
+put 13,43,  c:=a+b;
+put 14,43,  Summa:=c;
+put 15,40, end;
+put 17,43,  { call of Summa }
+put 18,40,  e:=Summa(5,6);
+color 15,1
+put 20,,Rule in RIGAL - like Function in PASCAL
+call ~~wait  190 %1
+
+rem ------------------------------------------- 9
+clear 14,0,1
+
+color 14
+big 1,,2,list and tree
+big 5,,2,patterns
+color 14,1
+box 10,,55,12,2
+call ~~wait  10 %1
+color 15,1
+put 11,,WE CAN TRAVERSE LISTS :
+color 14,0
+put 13,20,#STATEMENT_LIST
+put 14,25,(. (* #STATEMENT *) .)
+put 15,20,##
+color 15,1
+put 16,,... AND TREES:
+color 14,0
+put 17,20,#EXPRESSION
+put 18,25,[. OPERATION : ( '+' ! '-' ),
+put 18,25,12
+put 19,28,   ARGUMENT_1 : #FACTOR ,
+put 20,28,   ARGUMENT_2 : #FACTOR  .]
+put 20,51,14
+put 21,20,##
+call ~~wait  220 %1
+
+rem --------------------------------------------- 10
+clear 14,0,1
+color 14
+
+big 1,,7,T{{W{{O{{{{{R{{U{{L{{E{{S
+color 14,1
+box 7,,50,15,2
+call ~~wait  10 %1
+color 15,1
+put 8,,R U L E   IS  like  BACKUS-NAUR FORMULA:
+put 10,22,IN RIGAL
+put 10,43,IN   B N F
+color 14,0
+put 11,17,#PROGRAM
+put 12,20, 'BEGIN'
+put 13,20, (* #STATEMENT *)
+put 14,20, 'END'
+put 15,17,##
+put 16,17,#STATEMENT
+put 17,20,  #VARIABLE
+put 18,20,  ':='
+put 19,20,  #EXPRESSION
+put 20,17,##
+color 15,0
+put 11,40,program ::=
+put 12,44,   'BEGIN'
+put 12,56,*
+put 13,47,      statement
+put 14,44,   'END'
+put 16,40,statement ::=
+put 17,44,   variable
+put 18,44,   ':='
+put 19,44,   expression
+color 15,1
+put 21,,This is the way to
+put 22,,describe and parse program structure
+call ~~wait  150 %1
+
+
+clear 14,0,1
+big 1,,7,new programming
+big 6,,7,language
+call ~~wait  5 %1
+color 12
+big 16,,8,R{{{I{{{G{{{A{{{L
+call ~~wait  60 %1
+clear
+color 14
+big 1,,7,powerful
+big 6,,7,and simple
+big 12,,7,tool for writing
+big 18,,7,compilers
+call ~~wait  100 %1
+call ~~demo %1

+ 1 - 0
rigdm218/EMPTY.RIG

@@ -0,0 +1 @@
+  

+ 0 - 0
rigdm218/EX.LER


+ 1 - 0
rigdm218/EX.TXT

@@ -0,0 +1 @@
+ (  ABC - 7  )  *  XYZ  +  55

+ 39 - 0
rigdm218/EX1.PAS

@@ -0,0 +1,39 @@
+
+ Program Main; 
+ const tt=101;ff=102;err=103; 
+ var state:record w,v,x,y,z:integer end; 
+ function PLUS (a,b:integer) :integer; 
+ begin if (a>100) or (b>100) then Plus:=err  
+       else if a+b >100 then Plus:=err  
+            else Plus:=a+b; end;  
+ function LESS (a,b:integer) :integer; 
+ begin if (a>100) or (b>100) then Less:=err  
+       else if a<b then Less:=tt  
+            else Less:=ff; end;  
+ Procedure Val(a:integer); 
+  begin case a of  
+   101 : writeln ('tt');  
+   102 : writeln ('ff');  
+   103 : writeln ('err');  
+   else  writeln (a);end;end;  
+ BEGIN WITH STATE DO BEGIN  
+  w:=1;v:=1;x:=1;y:=1;z:=1;  
+z := 1 ; 
+x :=  PLUS(  z , 1 ) ; 
+y := 1 ; 
+ WHILE   LESS(  y ,  PLUS(  x , 1 ) ) =tt DO BEGIN  
+z :=  PLUS(  z , z ) ; 
+y :=  PLUS(  y , 1 ) ; 
+END; 
+ IF   LESS(  y ,  PLUS(  x , 1 ) )  =err THEN x:=err;  
+v :=  PLUS(  1 , 1 ) ; 
+v :=  PLUS(   PLUS(  v , v ) , v ) ; 
+w := 1 ; 
+Writeln (' Post-DUMP : '); 
+Write ('w=');Val(w); 
+Write ('v=');Val(v); 
+Write ('x=');Val(x); 
+Write ('y=');Val(y); 
+Write ('z=');Val(z); 
+readln;end;  
+END. 

+ 19 - 0
rigdm218/EX1.RIG

@@ -0,0 +1,19 @@
+-- This example illustrates how to program TAIL and HEAD 
+-- functions in RIGAL.
+ #MAIN
+  $E:=(. ALFA BETA GAMMA DELTA .);
+ OPEN S ' ';   -- Opens file S for output to the screen
+ S<<$E;
+ S<<'HEAD=' #HEAD($E);
+ S<<'TAIL=' #TAIL($E);
+ $W:=<. SEL1 : $E,
+        SEL2 : #HEAD($E),
+        SEL3 : #TAIL($E) .>;
+ PRINT $W;
+##
+#HEAD 
+  (. $E   (* $A *) .) / RETURN $E / ##
+#TAIL
+  (. $A   (* $L!.:=$E *) .) /RETURN $L /##
+
+

+ 10 - 0
rigdm218/EX1.TXT

@@ -0,0 +1,10 @@
+
+    z:=1 ; x:= ( z + 1 ); 
+    y:=1;  
+    while y < (x+1) do
+         z:=(z+z);
+         y:=(y+1) od;
+
+    v:=(1+1);
+    v:=((v+v)+v); 
+    w:=1;

+ 48 - 0
rigdm218/EX2.RIG

@@ -0,0 +1,48 @@
+ -- Example of RIGAL program.
+ -- Takes input from file EX.TXT
+ -- Performs simple arithmetical expression parsing.
+ -- Expression tree is returned.
+ -- Polish Postfix Form is printed out.
+#MAIN
+ OPEN S ' ';        -- Opens file S for output to the screen
+ $E:=#CALL_PAS(3 'EX.TXT'); -- Scanner takes input from file EX.TXT
+ S<<$E;             -- Prints the input text
+ $T:=#ANALYSE($E);  -- Calls expression analysis
+ PRINT $T;          -- Prints expression tree
+ #CALL_PAS(13 $T);  -- Prints expression tree in graphical form
+ S<<;
+ #PRINT_POLISH($T); -- Calls Polish  Postfix Form printing
+##
+
+#ANALYSE -- Traverses token list
+ (. $E:=#EXPRESSION .)   / RETURN $E /
+##
+                                                  --      BNF form :
+#EXPRESSION                                      -- expression ::=
+ $A1:=#ADDITIVE_EL                               --  add_el
+ (* $OP := ( '+' ! '-' )  $A2:=#ADDITIVE_EL      --  ( ('+'!'-') add_el )*
+  / $A1 := <. OP:$OP, ARG1:$A1 , ARG2:$A2 .> / *)
+  / RETURN $A1 /
+##
+
+#ADDITIVE_EL                                     --  add_el ::=
+ $A1:=#TERM                                      --    term
+ (* $OP := ( '*' ! '/' ) $A2 :=#TERM             --   ( ('*'!'/') term )*
+  / $A1 := <. OP:$OP, ARG1:$A1 , ARG2:$A2 .> / *)
+  / RETURN $A1 /
+##
+
+#TERM                                            -- term ::=
+ $A := ( $ID ! $NUM )    / RETURN $A / ;;        --  (identifier ! number !
+
+ '(' $A:=#EXPRESSION ')' / RETURN $A /           --    '(' expression ')' )
+##
+
+#PRINT_POLISH
+ <. ARG1 : #PRINT_POLISH,       -- Trees are traversed recursively
+    ARG2 : #PRINT_POLISH,
+    OP : $OP .>
+   / S<] $OP / ;;
+
+  $EL / S<] $EL /               -- Leaves are printed immediately
+##

BIN
rigdm218/EX2.RSC


+ 29 - 0
rigdm218/EXA.LST

@@ -0,0 +1,29 @@
+ 
+     (.  'ALFA' 'BETA' 'GAMMA' 'DELTA'
+         'LAMBDA'
+     .) 
+    
+
+=>>>CALLS RULE #HEAD IN STATEMENT
+  1-ST ARGUMENT($):  
+     (.  'ALFA' 'BETA' 'GAMMA' 'DELTA'
+         'LAMBDA'
+     .) 
+    
+<<<=EXITS FROM RULE #HEAD: SUCCESS
+RESULT= 'ALFA' 'ALFA'
+
+=>>>CALLS RULE #TAIL IN STATEMENT
+  1-ST ARGUMENT($):  
+     (.  'ALFA' 'BETA' 'GAMMA' 'DELTA'
+         'LAMBDA'
+     .) 
+    
+<<<=EXITS FROM RULE #TAIL: SUCCESS
+RESULT= 
+     (.  'BETA' 'GAMMA' 'DELTA' 'LAMBDA'
+     .) 
+     
+     (.  'BETA' 'GAMMA' 'DELTA' 'LAMBDA'
+     .) 
+    

+ 14 - 0
rigdm218/EXA.RIG

@@ -0,0 +1,14 @@
+--  FILE   EXA.RIG
+--  This example illustrates how to program
+-- TAIL and HEAD functions in RIGAL.
+#MAIN
+ $E:= (. ALFA BETA GAMMA DELTA LAMBDA .) ; 
+ PRINT $E;
+ PRINT #HEAD($E);
+ PRINT #TAIL($E);
+##
+
+#HEAD
+ (. $E   (*  $A *) .)   / RETURN $E / ##
+#TAIL
+ (. $A   (* $L !.:= $E *) .) / RETURN $L / ## 

+ 26 - 0
rigdm218/GRAM1.RIG

@@ -0,0 +1,26 @@
+-- abstract syntax grammar of tree for language SL
+#program
+        (. (* #stmt  *) .)   ##
+
+#stmt
+     ( #assignment  !  #while  )  ##
+
+#assignment
+           'assignment_op' :: <. left_part: $Id,
+                                 right_part: #expression .>
+##
+
+#while
+      'while_op' :: <. condition: #expression,
+                       body:      (. (* #stmt *) .)  .>
+##
+
+#expression
+           1 ;;
+           $Id ;;
+           '+' :: <. arg1: #expression,
+                     arg2: #expression .> ;;
+
+           '<' :: <. arg1: #expression,
+                     arg2: #expression .>
+##

+ 19 - 0
rigdm218/GRAM2.RIG

@@ -0,0 +1,19 @@
+-- source grammar for SL
+#program
+        (. (* #stmt * ';' ) .)  ##
+#stmt
+     ( #assignment ! #while_op )   ##
+#assignment
+           $Id  ':='  #expression   ##
+#while_op
+         'while'  #expression 'do'
+                  (* #stmt  * ';' )  'od'  ##
+#expression
+           #arithm_expr  [ '<'  #arithm_expr ]  ##
+#arithm_expr
+           #term   ;;
+        '(' #arithm_expr   '+'  #arithm_expr ')'  ##
+#term
+     ( 1 ! #variable )  ##
+#variable
+         ( w ! v ! x ! y ! z )   ##

+ 87 - 0
rigdm218/HANOI.RIG

@@ -0,0 +1,87 @@
+  -- Hanoi tower problem
+#MAIN
+ OPEN S ' ';
+
+ LOOP
+ $Count:=#CALL_PAS(1 ' Rings count = ') ;
+ IF #NUMBER($Count) -> BREAK FI;
+ END;
+ $STATE:=#INIT($Count); -- Global variable 
+
+ #VIDEOSHOW(T); 
+ #H( $Count 1 3 );
+ 
+##
+#H
+ $Num $From $To
+ /  IF $Num=1 -> 
+       S << 'FROM' $From 'TO ' $To;
+       #VIDEOMOVE ($From $To);
+       #VIDEOSHOW (T)
+   ELSIF T->
+       $Middle := 6-$From-$To ;
+      #H( $Num-1 $From $Middle );
+      #H( 1      $From $To );
+      #H( $Num-1 $Middle $To )
+FI / ##
+
+#INIT  $Count
+/  $V:=(.
+      <. LEN : COPY($Count), BODY : (.COPY($Count).) .>
+      <. LEN : 0     , BODY : (.0.)      .>
+      <. LEN : 0     , BODY : (.0.)      .> .);
+   LOOP
+    IF $Count=1 -> BREAK FI;
+    $Count:=COPY($Count-1);
+    $V[1].BODY!.:=$Count;
+    $V[2].BODY!.:=0;
+    $V[3].BODY!.:=0;
+  END;
+  RETURN $V;
+ / ##
+
+#VIDEOMOVE
+  $From $To
+  / 
+   $S_from := LAST #MAIN $STATE [$From];
+   $S_to   := LAST #MAIN $STATE [$To];
+   $Ring:=COPY( $S_from.BODY[$S_from.LEN]);
+   $S_from.BODY[$S_from.LEN]:=0;
+   $S_from.LEN+:=-1;
+   $S_to.LEN+:=1;
+   $S_to.BODY[$S_to.LEN]:=$Ring;
+  /
+##
+
+#VIDEOSHOW
+
+/ $X:=LAST #MAIN $STATE;
+  $I:=1;
+  LOOP
+   S<<$I '   ';
+   #STR($X[1].BODY[-$I]);
+   S<]'   ';
+   #STR($X[2].BODY[-$I]) ;
+   S<]'   ';
+   #STR($X[3].BODY[-$I]);
+   IF $I>=LAST #MAIN $Count -> BREAK;FI;
+   $I+:=1;
+  END;
+  S<<;
+#CALL_PAS(1 '  Press Enter')/##
+
+#STR
+  $N
+/ $E:=LAST #MAIN $Count-$N;
+  #FILL(' ' $E); 
+  #FILL('O' 2*$N);
+  #FILL(' ' $E)/ ##  
+
+#FILL 
+ $SYM $CNT
+ /LOOP
+   $CNT:=$CNT-1;
+   IF $CNT<0 -> BREAK FI;
+   S<]@$SYM; 
+  END; 
+ /## 

+ 75 - 0
rigdm218/HELP.TXT

@@ -0,0 +1,75 @@
+
+=== PROGRAMMING IN RIGAL ===
+        Short guide
+      by Vadim Engelson
+    Last revision 29-May-92
+
+1.  RIGAL LEXIC
+===============
+LETTER is [A..Z,a..z,_,{,},`,|,~,Chr(128)..Chr(255)]
+SYMBOL is LETTER or [0..9]
+Variables are $ SYMBOLS, Rules are # SYMBOLS
+Identifiers are  LETTER SYMBOLS
+Numbers are from 0 to 2**31-1
+Comments - after -- in string
+Character strings are  ' ANY_CHARACTERS '
+    To use single quote - write twice : ''
+Including files - (no inside #rule text)
+    %INCLUDE  filename with extension
+    (no anything more till the end of this line)
+(!) ALL RIGAL KEYWORDS MUST BE WRITTEN IN UPPERCASE (CAPITAL
+      LETTERS)
+      (load - wrong , LOAD - right)
+(!) Rules, identifiers, variables in UPPERCASE & LOWERCASE
+     are different
+      ( $SOMETHING <> $something )
+    and using here Chr(128)-Chr(255) not recommeded
+
+2.  LEXIC OF BUILT-IN SCANNER
+=============================
+ We have built-in scanner to read text file and transform
+it to the list of atoms.
+ Using:
+    $E:=#CALL_PAS(35 'filename');
+    (35 is built-in function number)
+
+"SYMBOL" "LETTER" - same as in Rigal lexic.
+Identifiers are  LETTER SYMBOLS
+   but { and } are not allowed !
+Numbers are from 0 to   2147483647  ( 2**31-1 )
+                 $0 to $7FFFffff
+                 #0 to #2147483647
+Comments are (*  *) or {  }
+One-character elements include  # & ! ? ^ @
+Character strings are  ' ANY_CHARACTERS '
+    To use single quote - write twice : ''
+(!) ALL KEYWORDS may be WRITTEN IN any case ,but
+     they are capitalized automatically.
+
+3.OTHER SUBROUTINES
+===================
+   The scanners and special subroutines are called in the form
+  #CALL_PAS ( <number>   <parameters  ...>  )
+    1.  If the first parameter  is given, the option writes it  on
+the  screen.  The  option  waits  for  the  user's  answer (Pascal
+READLN(STRING) executes).  When the  user presses  ENTER key,  the
+option returns the atom containing the string.
+     $E:=#CALL_PAS(1 'Enter Y or N ');
+     IF $E ->
+        IF ($E=Y)OR($E=y)-> $REZ:=T;BREAK;FI;
+        IF ($E=N)OR($E=n)-> $REZ:=NULL;BREAK;FI;
+     FI;
+   12.  Parameter  is  any  object. Object is printed out to the
+PRINT  file  using  pseudo  graphic  characters of extended ASCII
+code.
+   Tree                  List
+  ÄÄÄÂÄname::         ÄÄÄÄÒÄname::
+     ÃÄarc1-el1           ÇÄel1
+     ÀÄarc2-el2           ÓÄel2
+   13.  Parameter  is  any  object. Object is printed out to the
+screen using pseudo graphic characters of extended ASCII code.
+   16.  Parameter  must  be existing file name. All the lines of
+the  file  are  read  and appended to the list of atoms (one atom
+corresponds to one line).
+   35. The first parameter must be file name. The atoms are read
+from  file.

+ 71 - 0
rigdm218/INTER.RIG

@@ -0,0 +1,71 @@
+-- interpreter for Prof. Blikle small language (SL)
+-- written in Riga 13.10.1989
+--     takes input from file EX1.TXT
+--
+#main
+     $token_list := #CALL_PAS(14  'ex1.txt' );
+-- reads token list
+   OPEN report ' ';
+   $abstract_syntax := #analyse_program( $token_list );
+   IF $abstract_syntax -> report <<' no errors in program ... ';
+                          #interpret_program ( $abstract_syntax )
+   ELSIF   T           -> report << 'an error is found ...' FI  
+##
+
+%INCLUDE ANALYSE.RIG
+#interpret_program
+-- has global variable $state
+     / $state := <. w: 1, v: 1, x: 1, y: 1, z: 1 .>/
+-- assigns initial values to variables
+      #interpret_stmt_list
+      / report << 'end of interpretation, the state is:';
+        PRINT $state /
+##
+
+#interpret_stmt_list
+         (. (* #interpret_stmt 
+--/ PRINT LAST #interpret_program $state /
+            *) .)  ##
+
+#interpret_stmt
+         ( #interpret_assignment  !  #interpret_while )  ##
+
+#interpret_assignment
+        'assignment_op' ::
+               <.  left_part: $var,
+                   right_part: $rez := #eval_expr .>
+        / LAST #interpret_program $state ++:=
+                         <. $var :  $rez .> /  ##
+
+#interpret_while
+        'while_op' ::
+               <.  condition: $rez := #eval_expr .>
+         / IF $rez = tt  ->  #interpret_stmt_list( $. body);
+                             #interpret_while( $)
+           ELSIF  $rez = ff  ->  RETURN finished
+           ELSIF  $rez = err  OR  #NUMBER( $rez) ->
+                  LAST #interpret_program $state . x := err
+           FI /   ##
+
+#eval_expr
+     $NUM  / RETURN $NUM / ;;
+
+     $Id / RETURN LAST #interpret_program $state . $Id /;;
+
+     '+' :: <. arg1: $val1 := #eval_expr,
+               arg2: $val2 := #eval_expr .>
+        / IF $val1 = err OR $val2 = err ->  RETURN err
+          ELSIF  NOT ( #NUMBER( $val1) AND #NUMBER( $val2) ) ->
+                     RETURN err
+          ELSIF $val1 + $val2 > 100 -> RETURN err
+          ELSIF  T  ->  RETURN $val1 + $val2
+          FI  / ;;
+
+     '<' :: <. arg1: $val1 := #eval_expr,
+               arg2: $val2 := #eval_expr .>
+        / IF $val1 = err OR $val2 = err ->  RETURN err
+          ELSIF  NOT ( #NUMBER( $val1) AND #NUMBER( $val2) ) ->
+                     RETURN err
+          ELSIF $val1 < $val2  -> RETURN tt
+          ELSIF  T  ->  RETURN ff        FI  /
+##

+ 59 - 0
rigdm218/README.1ST

@@ -0,0 +1,59 @@
+RIGAL/DEMO  V.2.18 
+==================
+   May 29, 1992
+
+This version of Rigal is non commercial 
+and useful only for demonstration and simple examples.
+
+For IBM/PC/XT, IBM/PC/AT, IBM/PS-2 and compatible,
+ under MS-DOS with any colour graphic card.
+Hard disc is not used for DEMO execution.
+
+DEMO package may be moved to another hard or floppy disc. 
+Not copy-protected. Free available.
+
+WHAT TO DO
+==========
+1. Insert this floppy disk to drive and close disk drive door.
+ ( for example, drive  A: )
+2. Press    A:  and "ENTER" key.
+3. Press    DEMO and "ENTER" key
+4. Watch demo package - about 20 minutes (in default mode )
+5. Open disk drive door and take out this floppy disc.
+
+
+DEMONSTRATION
+=============
+  Press DEMO 
+
+  Press DEMO 10 for fast show,
+        DEMO 300 for low speed.
+    (default is DEMO 100)   
+  
+RUNNING RIGAL
+=============
+ Press RIG [ file_name ] in this directory  
+       
+ RIG.EXE includes
+           Built-in Text Editor, Checker and Interpreter.
+           Default work file is WORK.RIG.
+           You can call RIG.EXE from ANY directory too.
+           You can give it one parameter - file name without .RIG
+
+      Documents in English
+
+README   1ST  - this file
+HELP     TXT  - small help about scanners
+RIGAL    DOC  - short description of RIGAL language
+
+      Examples
+
+WORK     RIG   - printnig small tree
+EXA      RIG   - used for DEMO.
+EX1      RIG   - takes Head and Tail of list ( like EXA.RIG)
+EX2      RIG   - Analyses arithm. expression
+EX       TXT   - example of expression
+*        RIG  - small language example
+
+      All other files are necessary for running DEMO
+      ( or are generated during running DEMO or RIG )

BIN
rigdm218/RIG.EXE


+ 505 - 0
rigdm218/RIGAL.DOC

@@ -0,0 +1,505 @@
+   Programming  language  RIGAL  as  a  compiler  writing  tool
+
+                          M. I. AUGUSTON
+          Computing Center of the Latvia State University
+                226250,  Riga, Rainis boulevard 29,
+                           Latvia, USSR
+
+     Abstract. A new programming language for compiler writing  is
+     described briefly in this paper. The main data structures are
+     atoms, lists and trees. The control structures are based on a
+     advanced  pattern  matching.  All  phases  of   compilation,
+     including parsing, optimization and code generation,  can  be
+     programmed in this language in short and readable form.
+
+
+                          1. Introduction
+
+     Programming language RIGAL is  intended  to  be  a  tool  for
+syntactic analysis, program optimization, code generation and  for
+preprocessor and convertor writing. The main principles  of  RIGAL
+are the following:
+     a) formal grammars are used in the pattern matching mode;
+     b) operations, such as  tables  formation,  code  generation,
+message output are executed simultaneously with parsing,  like  in
+YACC [1], CDL-2 [2]. Therefore, the  principle  of  dependence  of
+control structures in the program upon data  structures  used  for
+program's work is well supported;
+     c) attribute grammars can be modeled easily  in  RIGAL.  The
+language has reference facility,  which  is  a  good  solution  of
+global attribute problem;
+     d) the  language  has  rich  spectrum  of  tree  manipulation
+facilities, like in Vienna Definition Language [3], including tree
+grammars. Trees can be conveniently used  as  data  structure  for
+different table implementation;
+     e) the language supports multi pass compiler design, as  well.
+Trees can be used as intermediate data;
+     f) the language provides the  split  of  program  into  small
+modules (rules) and presents various means to arrange  interaction
+of these modules;
+     g) RIGAL  is  a  closed  language,  i.e.  all  the  necessary
+computations and input-output could be executed by internal  means
+and there is no need to use external  semantic  subroutines  which
+are written in Pascal or C. Therefore, the  portability  of  RIGAL
+programs to other computers is increased.
+     Detailed presentation of language, as well as  more  examples
+are given in [4].
+
+                  2. Data Structures. Operations
+
+     The only data structures in RIGAL are atoms, lists and trees.
+     The atom is a string of characters or a  number.  Identifiers
+and numbers can be written just in the RIGAL program  text,  other
+atoms must be quoted. Special atom NULL represents an empty  list,
+an empty tree and Boolean value "false".
+     Variable name begins with symbol $. Values can be assigned to
+variables. For example, $E := ABC assigns atom ABC to variable $E.
+     The  list  is  an  ordered  sequence  of  objects  -  atoms,
+another lists and trees.
+     The list constructor yields a list of objects.  For  example,
+$E := (. A B C .) assigns a list of  atoms  A,  B  and  C  to  the
+variable  $E . It is possible to  get  elements  from  a  list  by
+indexing, e.g. $E[ 2] is atom B, but $E[ -1] is atom C.  Operation
+L !. e appends element e to the end of list L. Two lists L1 and L2
+can be concatenated by operation L1 !! L2 .
+     For tree creation the tree constructor is used, e.g.
+                        <. A : B, C : D .>
+     Objects placed  just  before  ':'  are  called  selectors.  A
+selector may be any atom, except NULL. Selectors of the same level
+must be different. The pair 'selector : object' in the tree is   a
+branch. Branches in the tree are unordered.
+     Statement $E := <. A : X, B :(.3 7.), C  :<.  A  :  2  .>  .>
+assigns  a tree  with  three  branches  to  variable  $E.   It  is
+possible to extract components from the tree by means of selection
+operation . For example, $E.A is atom X, $E.C.A  is  atom  2,  and
+$E.B[2] is atom 7. But $E.D  yields  NULL,  because  there  is  no
+branch with selector D in this tree.
+     Operation T1 ++ T2 appends branches of tree T2 to tree T1. If
+T1 has a branch with the same selector, this branch is replaced by
+the  branch from the T2.
+     The equality of objects can be checked  using  operations  =
+and <>. The result is atom T ('true') or NULL  ('false').
+     Common arithmetic and relational operations  +,  -,  *,  div,
+mod, <, >, <= and >= are defined for numerical atoms .
+     The arguments of logical operations and, or and  not  can  be
+arbitrary objects. If the object differs from NULL, it  represents
+the 'true' value.
+     It is possible to write $X !.:= e instead of   statement
+$X := $X !. e .The same short form is allowed for  operations  !!,
+++ and + .
+
+                     3. Rules. Simple Patterns
+
+     Rules are used basically to check if an object or sequence of
+objects complies with some grammar.
+     The grammar is described by the patterns. A rule call  should
+be accomplished by some object or  object  sequence  called   rule
+arguments . They are matched with the patterns in the rule.   Some
+statements  (  assignments,  input-output  operations  )  can   be
+executed simultaneously with pattern matching .
+     Rule can compute and return some value to the calling  point.
+Thus, the concept of rule is analogous to concept of procedure and
+function in conventional languages.
+     The rule execution ends with success or failure depending  on
+the result of argument and pattern matching. That is  why  a  rule
+can be used as a pattern in another rule.
+     Example of a rule definition:     #L1 A B ##
+     Here the pattern contains atoms A and  B.  Rule  #L1  can  be
+called, for example, in such a way:  #L1(A B). Atoms A and  B  are
+given as arguments. In this case argument matching with pattern is
+successful.
+     Call #L1(A C) fails, because the  second  argument  fails  to
+match the second pattern, but #L1(A B C) ends with success, as the
+third argument is not requested by any pattern element.
+    Variable can be a pattern  element.  It  matches  successfully
+just one object from the argument sequence and, as a side  effect,
+this object is assigned to the variable.
+     Statements can be placed before the pattern element and after
+it. The statement group is closed in symbols  '/'.  Statements  in
+the group are separated by semicolons.
+     The return statement in the rule ends the rule execution  and
+yields the returned value.
+     Example. #L2  $A  $B  / return (. $B $A.)/   ##
+     Variable $X gets value (.2 1.) after statement $X:= #L2(1  2)
+is executed .
+     If return statement is not described in the  rule,  then  the
+NULL value is returned.
+     The  rule  pattern  element  can  refer  to   some   rule
+(recursively, as well).
+          Example.
+          #L3   B  C  ##
+          #L4   A  #L3   D  ##
+     Call #L4( A B C D ) is successful, but #L4( A  E  F  D  )  is
+unsuccessful.
+     Every  pattern  element,  when  successfully   matched   with
+corresponding rule argument, returns some  value.  Value  of  atom
+pattern coincides  with  this  atom,  value  of  variable  pattern
+coincides with the value obtained by this variable as a result  of
+matching with the argument.  The value of rule is  formed  by  the
+return statement. Value, returned by the pattern  element  can  be
+assigned to a variable.
+        Example.
+        #L5   $R !.:= $A     $RN!!:= #L6   / RETURN  $R/  ##
+        #L6   $M !.:= $B     $M !.:= $C    / RETURN  $M/  ##
+    When statement  $X := #L5( 1 2 3 ) is  executed,  variable  $X
+gets value  (. 1 2 3 .). All variables in the rule are initialized
+by NULL. Then the first application of pattern element  $R !.:= $A
+in #L5 assigns to variable $R the value of expression  NULL !.  $A
+that equals to (. $A .) .
+     There are some built-in rules, such  as  #NUMBER  or  #IDENT.
+Patterns of the type $Id := #IDENT and  $N := #NUMBER are used  so
+often, that a default is introduced. If the name  of  the  pattern
+variable  begins  with  letter  "I",  then  it  matches  atoms   -
+identifiers, and, if it begins with letter "N",  then  it  matches
+numerical atoms.
+     One rule can contain several groups  of  patterns.  They  are
+called branches of the rule. Arguments of  the  rule  are  matched
+with branches in succession,  until one branch succeeds.
+     Branches in the rule are delimited by symbol ';;'. In case of
+branch failure, some statements can  be  executed. Such statements
+can be written at the end of the branch after keyword  ONFAIL.  In
+case of  branch  failure,  control  is  transferred  to  them  and
+statements,given in ONFAIL-unit , are executed.  So,  in  case  of
+branch failure, causes of failure could be  analyzed  and  message
+could be output.
+
+                            4. Patterns
+
+     List pattern (. P1 P2 ... Pn .) matches only  those  objects,
+which are lists and elements of which match patterns  P1, P2,  ...
+and   Pn  respectively.
+     There are patterns for alternative
+                      ( P1 ! P2 ! ... ! Pn )
+and for option
+                         [ P1 P2  ... Pn ]
+with usual semantics.
+     Iterative sequence pattern  (* P1 P2 ... Pn  *)  denotes  the
+repetition of pattern sequence zero or more times. It is  possible
+to define rules with a variable number of arguments.
+     Example.
+        #Sum (*  $S +:= $Num  *) / RETURN $S/   ##
+     Call #Sum(2 5 11) returns 18.
+     Example. Rule that determines length of the  list  can  be
+defined as follows:
+     #Len   (. (* $E / $L +:= 1 / *) .)   / RETURN $L/   ##
+     Call #Len( (. A B C .) ) returns 3.
+     Iterative sequence pattern (+ ... +) is similar to (* ... *),
+but the former denotes the repetition one or more times.
+     It is possible to describe iterative sequence  patterns  with
+delimiters in such form: (* P1 P2 ... Pn * delimiter ) .  An  atom
+or a rule name can be used as delimiter .
+     Example. Analysis of a simple Algol-like  declaration.  A
+fragment of variable table coded in a tree form is returned  as  a
+result.
+     #Declaration
+        $Type := ( integer ! real )
+        (+ $Id  / $Rez ++:= <. $Id : $Type .> /  + ',')
+        / RETURN $Rez /   ##
+     Call #Declaration ( real X ',' Y ) returns value
+                     <. X : real, Y  : real .>
+
+     Example.   Simple   arithmetic   expression   parsing.   When
+successful, an expression tree is returned, which can be  regarded
+as an intermediate form for the next compilation phases.
+     #Expression
+        $A1 := #Additive_el
+        (* $Op := ( '+' ! '-' )  $A2 := #Additive_el
+           / $A1 := <. op : $Op , arg1 : $A1 , arg2 : $A2 .> / *)
+        / RETURN $A1 /   ##
+     #Additive_el
+        $A1 := #Term
+        (* $Op := ( '*' ! 'div' )  $A2 := #Term
+           / $A1 := <. op : $Op, arg1 : $A1, arg2 : $A2 .> / *)
+        / RETURN $A1 /    ##
+     #Term
+        $A := ( $Id  ! $Num ) / RETURN $A /  ;;
+        '('  $A := #Expression ')'  / RETURN $A /   ##
+     Call #Expression( X '*' Y '+' 7 ) returns value
+              <. op: '+', arg1: <. op: '*', arg1: X,
+                                            arg2: Y .>,
+                          arg2: 7 .>
+
+                         5. Tree Patterns
+
+     Tree pattern can be written in the form
+              <. a1 : p1, a2 : p2, ...  , an : pn .>
+where ai are atoms and pi are patterns.
+     Tree pattern branches are applied to  corresponding  branches
+of the argument tree in the same order as they are written in  the
+pattern.
+     Therefore,the order of tree traversing may be controlled.  We
+can  traverse  some  branches  of  the  tree  repeatedly,  if  the
+corresponding selector in the tree pattern is repeated, or we  can
+omit some branches of the tree, if the corresponding selectors are
+omitted in the pattern.
+     Optional branches in tree pattern are  enclosed  in  brackets
+'[' and ']'.
+     Example. Let us suppose expression tree to be formed like  in
+the above mentioned example. The task is to traverse the tree  and
+return a list that represents the  Polish  postfix  form  of  this
+expression.
+#Postfix_form
+     <.  arg1: $Rez := #Postfix_form,
+         arg2: $Rez !!:= #Postfix_form,
+         op:   $Rez !.:= $Op  .>       / RETURN $Rez /  ;;
+     $Rez := ( $Id ! $Num )      / RETURN (. $Rez .) /
+##
+     Call #Postfix_form( <. op: '-', arg1: X, arg2:  <.  op:  '*',
+arg1: Y, arg2: 5 .> .>) returns value (. X Y 5 '*' '-' .)
+     Iterative tree pattern has the form <* $V : P *> ,  where  $V
+is a variable and P - pattern. This pattern defines  a  loop  over
+the tree. All selectors of  the  argument  tree  are  assigned  to
+variable $V one by one. Pattern P is applied to each object, which
+corresponds in the  argument  tree  to  the  current  selector  in
+variable $V.
+     Example. Traversing the variable table.
+#Var_table
+     <*  $Id : $E  :=  ( integer ! real )
+               / $R !.:= (. $Id  $E .) /  *> / RETURN $R /  ##
+     Call #Var_table( <. X : integer, Y : real, Z :  real  .>)
+returns value (. (. X integer .) (. Y real .) (. Z real .) .)
+
+              6. Pattern of Logical Condition Testing
+
+     Pattern S'( expression) is performed as follows. First of all
+the expression is evaluated, and iff its value is  different  from
+NULL then matching  with  the  argument  is  successful.  Special
+variable $$ in the expression denotes current argument,  to  which
+this  pattern  is  applied.  Using  this  kind  of  pattern   many
+context-sensitive situations can be  described.  For  example,  by
+such pattern  we  can  recognize  a  special  case  of  assignment
+statement "X := X + E"
+            $Id  ':='  S'( $$ = $Id )  '+'  #Expression
+     We can skip tokens, until semicolon using pattern
+                      (*  S'( $$ <> ';' )  *)
+
+
+                           7. Statements
+
+     There is an analog of McCarthy's  conditional statement  in
+RIGAL. It has the following form :
+                       IF    cond  ->  stmts
+                       ELSIF cond  ->  stmts
+                           ...  ...  ...
+                       FI
+     If the value of conditional expression is not equal to NULL ,
+then corresponding statements are executed.
+     The FAIL statement ends the execution of the rule branch with
+failure.
+     Loop statement
+                  FORALL $V IN Expr DO stmts  OD
+iterates its body over a list or a tree  described  by  expression
+Expr. All elements of the list or all selectors of  the  tree  are
+assigned to variable $V in succession .
+     Loop statement of the type
+                         LOOP  stmts  END
+repeats statements of the loop body, until one of the statements -
+BREAK, RETURN or FAIL is not executed.
+     Objects designed by RIGAL program can be saved  on  disc  and
+loaded  back by statements SAVE and LOAD .
+     Text files can be opened by OPEN statement for text output of
+messages, generated code, etc.
+     Sequence of atoms can be output  in  text  file  FFF  by  the
+statement of the form
+             FFF << expr1   expr2  ...  ... ... exprN
+     A blank is output after  each  atom.  Symbol  @  cancels  the
+additional blank symbol output.
+     Statement '<<' always begins output on a new line, but   '<]'
+statement continues output on current line.
+
+                       8. Program Structure
+
+     RIGAL program consists of main program and rules.
+     Operations like initial object loading from  external  files,
+rule calls  and  created  object  saving  on  external  files  are
+concentrated in the main program .
+     When RIGAL is used for parsing, first the input text  has  to
+be processed by scanner - a program, which converts the text  into
+a list of tokens. This list is an object  of  RIGAL,  and  can  be
+loaded and processed by RIGAL program.
+     Intermediate results, e.g., abstract syntactic trees  can  be
+saved, and another RIGAL program can load and update them.
+
+        9. Attribute Grammars and RIGAL. Global References
+
+     There is a close analogy between attribute grammar and  RIGAL
+program. Rules in RIGAL correspond to grammar  nonterminals,  and
+variables - to attributes.
+     In attribute grammars the greatest  part  of  attributes  are
+used as transit attributes. To avoid this, global  attributes  are
+introduced in the attribute grammar implementations.
+     There is  a  good  conformity  between  data  structures  and
+control structures in RIGAL program. Hence, it is possible to  use
+the control structures of RIGAL program, in order to refer to  the
+data elements.
+     Rule variables can be accessed from  some  other  rule  using
+reference of the type :
+                           LAST  #L  $X
+     This reference denotes the value of variable $X in  the  last
+(in time) and still active instance of rule  #L.  Such  references
+can be used  in left and  right  sides  of  assignment  statement.
+Therefore,  implementation  of  both  synthesized  and   inherited
+attributes is possible as it  is  demonstrated  in  the  following
+scheme.
+#LA  ... ... ...
+     assigns value to attribute $A
+     calls #LB
+     ... ... ...
+##
+#LB  ... ... ...
+     $B1 := LAST #LA $A
+          -- uses inherited attribute $A from #LA
+     calls #LC
+          -- after this call the value of attribute $C from #LC is
+          -- assigned to the synthesized attribute $B2
+     ... ... ...
+##
+#LC  ... ... ...
+     assigns value to attribute $C
+     LAST #LB $B2 := $C
+          -- the value is assigned to  the  synthesized  attribute
+          -- $B2 of #LB
+     ... ... ...
+##
+
+                   10. Simple Telegram Problem.
+
+     We shall consider simple telegram  problem  [5]  as  compiler
+model. A program is required to process a stream of telegrams. The
+stream is available as a sequence of words and spaces. The  stream
+is terminated by an empty telegram.
+     Each telegram is delimited by symbol "***". Telegrams are  to
+be processed to determine  the number  of  words  with  more  than
+twelve characters  for  each  telegram.  Telegrams  together  with
+statistics have to be stored on an output file eliminating all but
+one space between the words.
+     For demonstration purpose the program  is  divided  into  two
+parts - parsing phase and output code generation phase.
+     The input stream is represented as a list of tokens, where  a
+token  is  an  one-character  atom.  The  first  phase  builds  an
+intermediate result - abstract syntactic tree.
+     The structure of input, intermediate and output data  can  be
+described by RIGAL rules.
+
+     The input stream.
+     #telegram_stream
+          (+  #telegram   #end +)  [ #blanks ] #end   ##
+     #telegram
+          (+  #word   #blanks +)   ##
+     #word
+          (+  #letter  +)    ##
+     #blanks
+          (+  ' '  +)       ##
+     #end
+          '*'  '*'  '*'        ##
+     #letter
+          ( A ! B ! C ! ... ! X ! Y ! Z )    ##
+
+     The intermediate data.
+     #S_telegram_stream
+          (.  (+  #S_telegram  +)  .)    ##
+     #S_telegram
+          <. text :       (.  (+  #S_word  +)  .),
+             long_word_n: $N   .>      ##
+     #S_word
+          (. (+  #letter  +) .)        ##
+
+     The output stream.
+     #output_telegram_stream
+          (+   #telegram1   #end   +)   #end    ##
+     #telegram1
+          (+  #word  ' '  +)  $long_word_num     ##
+
+     The main program has form:
+     #telegram_problem
+          LOAD  $T   'Letters.lex';
+          $S := #telegram_stream_analysis($T);
+          OPEN  Out  'LP:';
+          #generate_output_stream($S)
+     ##
+
+     The rules are:
+     #telegram_stream_analysis
+          (. (+  $R !.:= #A_telegram  #end  +)
+              [  #blanks  ]   #end   .)  / RETURN $R /   ##
+     #A_telegram
+          / $long_word_num := 0/
+          (+ $R !.:= #A_word    #blanks  +)
+          / RETURN <. text: $R,
+                      long_word_n: $long_word-num .> /   ##
+     #A_word
+          (+  $R !.:=  #A_letter   +)
+          / IF #Len($R) > 12  ->
+               LAST #A_telegram $long_word_num + :=1
+               -- rule #Len was defined in Unit 4.
+            FI;
+            RETURN $R /    ##
+     #A_letter
+          $R := ( A ! B ! C ! ... ! X ! Y ! Z ) / RETURN $R / ##
+     #generate_output_stream
+          (. (+  #G_telegram  +) .)
+          / Out <<  '***'/    ##
+     #G_telegram
+          <. text: (.  (+  #G_word  / Out <] ' ' /  +)  .),
+             long_word_n: $N  .>
+          / Out <] $N '***' /  ##
+     #G_word
+          (. (+  $L / Out <]  @ $L /  +)  .)    ##
+
+     These rules are obtained  from  rules,  which  describe  data
+structures, by adding operations to  the  corresponding  patterns.
+The whole program  is written by the recursive descent method.
+
+                        11. Implementation
+
+     RIGAL is implemented on PDP-11 in RSX-11,and then  ported  to
+VAX-11 in VMS and to IBM PC AT in MS DOS.
+     First the interpreter of RIGAL was  written  in  Pascal,  and
+afterwards the optimizing compiler RIGAL --> Pascal was written in
+RIGAL itself.
+
+                  12. Conclusions and Future Work
+
+     As it was demonstrated above, RIGAL supports  syntax-oriented
+style  of  compiler  design.  Programs  written   in   RIGAL   are
+well-structured and it is easy to read and debug them.
+     As it was proved by our experience [6], the optimizing  RIGAL
+compiler in VAX/VMS environment makes  it  possible  to  implement
+production quality compilers for high level languages.
+     RIGAL can be considered as yet another  language  prototyping
+tool in the sense of  [7],  because  it  allows  the  designer  to
+develop an experimental translator in a short period of time.
+     RIGAL  support  system  besides  interpreter  for   debugging
+purposes and  optimizing  compiler  includes  a  cross-referencer,
+which helps to avoid misuse of global variables.
+     In  order  to  improve  static  and  dynamic  type  checking,
+variable type descriptions in the form of formal comments would be
+added to the language.
+     Taking in  account  that  the  control  structures  of  RIGAL
+program  are  very  close  to  input  data  structures,  it  seems
+promising to develop automatic and semiautomatic methods for  test
+example generation for the given RIGAL program.
+
+
+                            References
+
+     [1] Johnson S.C. YACC - yet another compiler compiler.  -Bell
+          laboratories, Murray Hill,N.J., 1978, a technical manual.
+     [2] Koster C.H.A. Using the CDL compiler  compiler.-  Lecture
+          Notes in Computer Science, 1977, vol. 21.
+     [3] Lucas P. Formal definition of programming  languages  and
+          systems. - IFIP congress, 1971.
+     [4] Auguston M.I. Programming language RIGAL.  -  Riga,  LSU,
+          1987, (in Russian ).
+     [5] Jackson M. Principles  of  Program  design.  -   Academic
+          Press , 1975.
+     [6] Barzdin J.M., Kalnins A.A., Auguston M.I. SDL  tools  for
+          rapid  prototyping  and  testing.  -  in  SDL'89  :  The
+          Language at  Work,  ed.  O.Faergemand  and  M.M.Marques,
+          North-Holland, 1989, pp.127-133.
+     [7] Herndon R., Berzins  V.  The  Realizable  Benefits  of  a
+          Language Prototyping Language. -  IEEE  Transactions  on
+          Software Engineering,  vol.14,  No  6,  June  1988,  pp.
+          803-809.
+
+

+ 15 - 0
rigdm218/RIGAL.PCK

@@ -0,0 +1,15 @@
+A:\DEMO\EX1.TXT
+A:\DEMO\WORK.RIG
+A:\DEMO\EX1.PAS
+D:\WE\DEMO\WORK.RIG
+D:\WE\DEMO\EMPTY.RIG
+D:\WE\DEMO\EXA.RIG
+D:\WE\DEMO\EXA.LST
+D:\WE\DEMO\EX2.RIG
+D:\WE\DEMO\EX.TXT
+D:\USER\WE\DEMO\EMPTY.RIG
+D:\USER\WE\DEMO\EX2.RIG
+D:\USER\WE\DEMO\EX.TXT
+D:\USER\WE\DEMO218\EMPTY.RIG
+D:\USER\WE\DEMO218\EX2.RIG
+D:\USER\WE\DEMO218\EX.TXT

+ 30 - 0
rigdm218/WORK.RIG

@@ -0,0 +1,30 @@
+-- This is file WORK.RIG
+-- You can try  examples 
+--  EX1.RIG - how to take Tail and Head of list
+--  EX2.RIG - how to analyse and print polish form of arithmetic expression
+--  GRAM2.RIG - small language (SL) source syntax grammar
+--  GRAM1.RIG - tree abstract grammar for SL
+--  INTER.RIG - interpreter of SL
+--  BCOMP.RIG - compiler of SL to Pascal
+--  EX1.txt   - input text in SL
+
+-- THIS IS SIMPLE PROGRAM ; TRY press F6 and then F7; Exit ALT+X
+#START 
+   $E:=28; $N:=3;
+   PRINT <. AA : $E , BB : $N .>
+##  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

BIN
rigdm218/XTRA.COM


+ 18 - 0
rigdm218/~~CONTIN.BAT

@@ -0,0 +1,18 @@
+clear +cyan,black,blue
+big 3,,7,University
+big 12,,7,of
+big 19,,7,Latvia
+CALL ~~wait 30 %1
+clear
+big 1,,8,CONTINUES
+big 10,,2,presentation
+big 19,,2,of
+CALL ~~wait 20 %1
+clear
+big 1,,7,new programming
+big 6,,7,language
+CALL ~~wait 5 %1
+color 12
+big 16,,8,R{{{I{{{G{{{A{{{L
+CALL ~~wait 60 %1
+

+ 284 - 0
rigdm218/~~DEMO.BAT

@@ -0,0 +1,284 @@
+echo off
+
+rem ------------------------------------------- 11
+clear 14,0,1
+
+color 14
+big 1,,7,c{{o{{m{{p{{i{{l{{e{{r
+color 14,1
+box 6,,75,15,2
+call ~~wait  10 %1
+color 15,1
+put 7,,HOW CAN YOU WRITE COMPILER IN RIGAL ?
+color 1,7
+box 9,7,15,4,2
+box 9,55,15,4,2
+put 11,13,SOURCE
+put 12,12,PROGRAM
+put 11,59,RESULTING
+put 12,61,CODE
+color 14,4
+call ~~wait  8 %1
+put 11,25,\\\\\
+put 12,25,/////
+call ~~wait  8 %1
+put 11,37,\\\\\
+put 12,37,/////
+call ~~wait  8 %1
+put 11,49,\\\\\
+put 12,49,/////
+call ~~wait  10 %1
+color 0,7
+box 9,,15,4,2
+put 11,,PROGRAM'S
+put 12,,ABSTRACT
+put 13,,TREE
+color 14,4
+call ~~wait  50 %1
+put 13,27,V
+put 13,51,V
+box 14,14,20,3,1
+box 14,42,20,3,1
+call ~~wait  7 %1
+color 14,4
+put 15,21,   PARSING
+put 16,23,     and
+put 17,18,TREE BUILDING
+put 15,43,TRAVERSING THE TREE
+put 16,45,  AND GENERATION
+put 17,47,    OF THE CODE
+color 15,1
+put 21,,YOU WRITE BOTH PHASES IN RIGAL
+call ~~wait  150 %1
+
+rem --------------------------------------- 12
+clear 14,0,1
+
+color 14
+big 1,,7,o{{p{{t{{i{{m{{i{{z{{e{{r
+color 14,1
+box 6,,75,15,2
+call ~~wait  10 %1
+color 15,1
+put 7,,HOW  CAN  YOU  WRITE  OPTIMIZER ?
+color 1,7
+box 9,7,15,4,2
+box 9,55,15,4,2
+put 11,13,SOURCE
+put 12,12,PROGRAM
+put 11,60,OPTIMIZED
+put 12,61,PROGRAM
+put 13,62,TREE
+color 14,4
+put 11,25,\\\\\
+put 12,25,/////
+put 11,49,\\\\\
+put 12,49,/////
+color 0,7
+box 9,,15,4,2
+put 11,,PROGRAM'S
+put 12,,ABSTRACT
+put 13,,TREE
+color 14,4
+call ~~wait  50 %1
+put 13,27,V
+put 13,51,V
+color 0,7
+box 14,14,20,3,1
+put 15,16,... SAME PARSING
+put 16,23,     and
+put 17,18,TREE BUILDING
+call ~~wait  10 %1
+color 14,4
+box 14,42,20,3,1
+put 15,44,TRAVERSING THE TREE
+put 16,51,     AND
+put 17,44,TRANSFORMING IT
+color 15,1
+call ~~wait  150 %1
+
+rem ------------------------------------ 13
+clear 14,0,1
+
+color 14
+big 1,,7,implementation
+color 14,1
+box 6,,75,15,2
+call ~~wait  10 %1
+color 15,1
+put 7,,IMPLEMENTATION OF RIGAL INCLUDES
+color 1,7
+box 9,,15,3,2
+put 10,,TEXT
+put 12,,EDITOR
+box 9,8,17,3,2
+put 10,13,RIGAL
+put 12,12,CHECKER
+box 9,52,17,3,2
+put 10,59,SERVICE
+put 12,58,PROGRAMS
+box 15,19,17,3,2
+put 17,23,INTERPRETER
+box 15,42,17,3,2
+put 17,46,COMPILER
+call ~~wait  10 %1
+color 14,4
+put 21,,ALL COMPONENTS ARE CALLED FROM TEXT EDITOR
+box 9,,15,3,2
+put 10,,TEXT
+put 12,,EDITOR
+put 10,27,----
+put 11,27,----
+put 10,48,----
+put 11,48,----
+put 14,34,!!
+put 14,44,!!
+call ~~wait  200 %1
+color 1,7
+box 9,,15,3,2
+put 10,,TEXT
+put 12,,EDITOR
+color 14,4
+box 9,8,17,3,2
+put 10,13,RIGAL
+put 12,12,CHECKER
+put 21,,CHECKS  RIGAL  PROGRAM  FOR  SYNTAX ERRORS
+call ~~wait  50 %1
+color 1,7
+box 9,8,17,3,2
+put 10,13,RIGAL
+put 12,12,CHECKER
+color 14,4
+box 15,19,17,3,2
+put 17,23,INTERPRETER
+put 21,,EXECUTES   RIGAL  PROGRAM  AFTER  CHECKING
+call ~~wait  50 %1
+color 1,7
+box 15,19,17,3,2
+put 17,23,INTERPRETER
+color 14,4
+box 15,42,17,3,2
+put 17,46,COMPILER
+put 21,,Compiles RIGAL program to PASCAL and then to ".EXE" file
+call ~~wait  50 %1
+color 1,7
+box 15,42,17,3,2
+put 17,46,COMPILER
+color 14,4
+box 9,52,17,3,2
+put 10,59,SERVICE
+put 12,58,PROGRAMS
+put 21,,Different   services  like   CROSS-REFERENCER  or   LINT
+call ~~wait  60 %1
+
+call ~~contin.BAT %1
+
+rem ------------------------------------ 14
+clear 14,0,1
+
+color 14
+big 1,,7,implementation
+color 15,1
+box 5,,60,17,2
+put 6,,RIGAL IMPLEMENTED IN
+put 7,,PDP-11    for    RSX-11M
+put 8,,VAX       for    VAX/VMS
+color 15,0
+put 9,,IBM/PC/XT/AT for MS-DOS/PC-DOS and MS-WINDOWS
+color 15,1
+put 10,,SUN-4 workstations for SUN/UNIX
+put 12,,Tool requires minimum 2 MBytes of hard disc space
+put 13,,and 640 KBytes of RAM memory.
+put 14,,Size of one RIGAL program - not more than 40 000 tokens.
+put 16,,All implementations are written
+put 17,,in PASCAL and RIGAL itself.
+put 18,,THREE LARGE SYSTEMS WERE WRITTEN IN RIGAL:
+put 19,,compiler from RIGAL to PASCAL,
+put 20,,compiler from SDL/PLUS to PASCAL and
+put 21,,compiler from GRAPES/4GL to INFORMIX/4GL plus C
+call ~~wait  200 %1
+
+rem ------------------------------------ 15
+clear 14,0,1
+
+color 14
+big 1,,8,H{{O{{W{{{{I{{T
+big 9,,8,W{{O{{R{{K{{S
+box 17,,60,3,2
+put 18,,LOOK HOW TO CREATE A SIMPLE PROGRAM
+put 19,,in file EXA.RIG and EXECUTE IT
+put 20,,USING THE RIGAL INTEGRATED ENVIRONMENT
+call ~~wait  200 %1
+if exist exa.rig del exa.rig
+RIG.EXE EMPTY ~~demo_D.dat
+if errorlevel 5 ~~stop
+
+rem ------------------------------------ 16
+clear 14,0,1
+
+color 14
+big 1,,7,How to debug
+big 7,,7,RIGAL program ?
+box 13,,60,5,2
+put 15,,LOOK HOW TO DEBUG
+put 17,,EXISTING PROGRAM in file EXA.RIG
+call ~~wait  200 %1
+RIG.EXE EXA ~~demo_F.DAT
+if errorlevel 5 ~~stop
+
+CALL ~~contin.BAT %1
+
+rem ------------------------------------ 17
+clear 14,0,1
+
+color 14
+big 1,,7,How to write
+big 7,,7,parser ?
+box 15,,60,4,2
+put 16,,LOOK HOW TO HAVE
+put 17,,AN ARITHMETICAL EXPRESSION FROM FILE,
+put 18,,HOW TO PARSE IT,
+put 19,,HOW TO GENERATE  THE POLISH POSTFIX FORM.
+call ~~wait  200 %1
+RIG.EXE EMPTY ~~DEMO_G.DAT
+if errorlevel 5 ~~stop
+
+rem ------------------------------------ 18
+clear 14,0,1
+
+color 14
+big 1,,7,Try to write
+big 7,,7,by yourself
+box 15,,60,4,2
+put 16,,YOU CAN MAKE COPY OF THIS DEMO PACKAGE.
+put 17,,TRY TO RUN RIG.EXE WITH DIFFERENT EXAMPLES.
+put 18,,    RIG.EXE  [ filename ]
+put 19,,   default file is Work.rig
+call ~~wait  200 %1
+
+
+
+
+rem ------------------------------------ 19
+clear 14,0,1
+
+color 14
+big 1,,7,CONTACT
+color 15,1
+box 6,,60,15,2
+color 15,1
+put 8,,RIGAL was designed in 1987-1992
+put 9,,IN THE UNIVERSITY OF LATVIA
+put 10,,by MIKHAIL AUGUSTON, VADIM ENGELSON and ANDRIS ZARINSH
+color 15,0
+put 12,,WE WOULD LIKE TO HAVE CONTACTS
+put 13,,DEVOTED TO THE THEORY AND PRACTICE OF RIGAL.
+put 14,,THE TOOL IS COMMERCIALLY AVAILABLE SINCE MIDDLE OF 1990.
+color 15,1
+put 16,,Contact:  Mikhail Auguston, Vadim Engelson
+put 17,,e-mail:   vadim@lumii.lat.su
+PUt 18,,University of Latvia, Institute of Mathematics,
+put 19,,Rainis Boul. 29,       226250 RIGA LATVIA
+put 20,,TELEX: 161172 TEMA SU          Phone:(0132)211014
+call ~~wait  200 %1
+remove > NUL

+ 526 - 0
rigdm218/~~DEMO_D.DAT

@@ -0,0 +1,526 @@
+0 77
+7 15
+78          To create new file
+0 77
+7 16
+78   we press  ALT+F choosing  "Files"  submenu.
+0 77
+1 6000
+0 77
+1 700
+0 33
+7 16
+78    Press   DOWN  key  to choose  "Create"
+0 80
+0 80
+0 80
+0 80
+0 80
+1 600
+13 32
+69 32
+7 16
+78     Enter      new      file      name
+88 32
+65 32
+46 32
+82 32
+73 32
+71 32
+1 1500
+13 32
+1 200
+0 71
+7 18
+78  Write     program     text
+45 32
+45 32
+1 100
+32 32
+32 32
+70 32
+73 32
+76 32
+69 32
+32 32
+32 32
+32 32
+69 32
+88 32
+65 32
+46 32
+82 32
+73 32
+71 32
+13 32
+7 18
+78  Write     program     text
+45 32
+7 19
+78  Now   we   write   COMMENTS
+45 32
+32 32
+32 32
+84 32
+104 32
+105 32
+115 32
+32 32
+101 32
+120 32
+97 32
+109 32
+112 32
+108 32
+101 32
+32 32
+105 32
+108 32
+108 32
+117 32
+115 32
+116 32
+114 32
+97 32
+116 32
+101 32
+115 32
+32 32
+104 32
+111 32
+119 32
+32 32
+116 32
+111 32
+32 32
+112 32
+114 32
+111 32
+103 32
+114 32
+97 32
+109 32
+13 32
+45 32
+45 32
+32 32
+84 32
+65 32
+73 32
+76 32
+32 32
+97 32
+110 32
+100 32
+32 32
+72 32
+69 32
+65 32
+68 32
+32 32
+102 32
+117 32
+110 32
+99 32
+116 32
+105 32
+111 32
+110 32
+115 32
+32 32
+105 32
+110 32
+32 32
+82 32
+73 32
+71 32
+65 32
+76 32
+46 32
+13 32
+1 500
+0 71
+0 71
+35 32
+1 300
+77 32
+65 32
+73 32
+78 32
+13 32
+7 18
+78 Write     program     text
+0 71
+7 19
+78 Now  we  write  MAIN RULE  of the program
+0 71
+32 32
+1 500
+36 32
+69 32
+58 32
+61 32
+32 32
+40 32
+46 32
+32 32
+65 32
+76 32
+70 32
+65 32
+1 100
+32 32
+66 32
+69 32
+84 32
+65 32
+32 32
+71 32
+65 32
+77 32
+77 32
+65 32
+32 32
+68 32
+69 32
+76 32
+84 32
+65 32
+32 32
+46 32
+41 32
+32 32
+59 32
+32 32
+13 32
+32 32
+80 32
+82 32
+73 32
+78 32
+84 32
+32 32
+36 32
+69 32
+59 32
+13 32
+32 32
+80 32
+82 32
+73 32
+78 32
+84 32
+32 32
+35 32
+72 32
+69 32
+65 32
+68 32
+40 32
+36 32
+69 32
+41 32
+59 32
+13 32
+32 32
+80 32
+82 32
+73 32
+78 32
+84 32
+32 32
+35 32
+84 32
+65 32
+73 32
+76 32
+40 32
+36 32
+69 32
+41 32
+59 32
+13 32
+35 32
+35 32
+13 32
+13 32
+35 32
+72 32
+69 32
+65 32
+68 32
+1 300
+13 32
+7 18
+78  Write     program     text
+0 71
+7 19
+78  Now   we   write   another  RULE  of program
+32 32
+40 32
+46 32
+32 32
+36 32
+69 32
+32 32
+32 32
+32 32
+40 32
+42 32
+32 32
+32 32
+36 32
+65 32
+32 32
+42 32
+41 32
+32 32
+46 32
+41 32
+32 32
+32 32
+32 32
+47 32
+32 32
+82 32
+69 32
+84 32
+85 32
+82 32
+78 32
+32 32
+36 32
+69 32
+32 32
+47 32
+32 32
+35 32
+35 32
+1 100
+13 32
+35 32
+84 32
+65 32
+73 32
+76 32
+13 32
+32 32
+40 32
+46 32
+32 32
+36 32
+65 32
+32 32
+32 32
+32 32
+40 32
+42 32
+32 32
+36 32
+76 32
+32 32
+33 32
+46 32
+58 32
+61 32
+32 32
+36 32
+69 32
+32 32
+42 32
+41 32
+32 32
+46 32
+41 32
+32 32
+47 32
+32 32
+82 32
+69 32
+84 32
+85 32
+82 32
+78 32
+32 32
+36 32
+76 32
+32 32
+47 32
+32 32
+35 32
+35 32
+1 7500
+7 18
+78 Program   is   written ...
+0 71
+7 19
+78  To  CHECK  it  we  press  key  F6
+0 64
+7 19
+78  Program checked and  now we return to the text editor
+13 32
+7 18
+78  Program checked and now we will Execute it.
+0 77
+7 19
+78   To  RUN   it  we  press  key  F7
+0 71
+0 65
+7 18
+78  Program is executed; you see the results.
+13 32
+7 19
+78  We are in the text editor again
+0 80
+1 2000
+0 80
+7 19
+78  Now we  EXPLAIN  you  the program; look at the cursor
+0 80
+1 100
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 77
+7 16
+78   We  traverse  list  of  the  atoms
+0 82
+1 4000
+0 82
+1 100
+0 77
+0 77
+0 77
+0 77
+7 16
+78 We load the first element to the variable $E
+0 82
+1 4000
+0 82
+1 100
+0 77
+0 77
+0 77
+0 77
+0 77
+7 16
+78   (*     *)      traverses     other     elements
+0 82
+1 4000
+0 82
+1 100
+0 77
+0 77
+0 77
+0 77
+7 16
+78      other     elements   are   loaded   to  $A
+0 82
+1 4000
+0 82
+1 100
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+7 16
+78    returns  value  back  to the  calling  rule
+0 82
+1 4000
+0 82
+1 100
+0 77
+0 77
+0 71
+0 80
+0 80
+0 77
+0 77
+0 77
+0 77
+0 77
+7 16
+78       loads the first element of list to $A
+0 82
+1 4000
+0 82
+1 100
+0 77
+0 77
+0 77
+0 77
+0 77
+7 16
+78  (*      *)    traverses    other    elements
+0 82
+1 4000
+0 82
+1 100
+0 77
+0 77
+0 77
+7 16
+78  other  elements  are accumulated  in  the  list
+0 82
+1 4000
+0 82
+1 100
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+7 16
+78  this list  is  returned to  the   calling  rule
+0 77
+1 6000
+0 77
+1 100
+0 77
+7 16
+78 NOW   WE   QUIT  RIGAL  INTEGRATED  ENVIRONMENT
+0 77
+7 19
+78       ALT + F   and  then  DOWN  until  "QUIT"
+0 77
+1 4000
+0 77
+0 77
+0 33
+1 250
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+1 800
+0 80
+1 4000
+13 32

+ 177 - 0
rigdm218/~~DEMO_F.DAT

@@ -0,0 +1,177 @@
+1 2000
+7 16
+78 We have entered the text editor and now
+7 17
+78 we can modify our program
+0 80
+0 80
+1 100
+0 80
+0 80
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+1 300
+0 77
+0 77
+76 32
+65 32
+77 32
+66 32
+68 32
+65 32
+32 32
+0 4
+1 7000
+7 16
+78      We SAVE and CHECK it
+7 17
+78      by pressing key  F6
+0 64
+7 16
+78 O.K., no errors
+13 32
+7 16
+78 We want to RUN it , but in DEBUGging (tracing) mode ...
+1 8000
+7 17
+78 We press   ALT + R
+1 7000
+0 19
+1 2000
+0 80
+0 80
+1 7000
+7 16
+78  We  want  to  DEBUG  our  RIGAL  program.
+7 17
+78  Here  we  turn  DEBUGging  on  .
+13 32
+13 32
+7 16
+78  We want to redirect  output of   PRINT-statement
+7 17
+78    to  the  file    EXA.LST
+0 80
+13 32
+69 32
+1 300
+88 32
+65 32
+46 32
+76 32
+83 32
+84 32
+1 2000
+13 32
+1 500
+0 72
+0 72
+0 72
+1 5000
+7 16
+78          Start    the    execution
+7 17
+78       by    pressing     ENTER
+13 32
+1 7000
+7 5
+78   O.K. All output now in file.
+13 32
+7 17
+78 We  load  another  file  by  pressing  key  F3
+0 61
+1 500
+69 32
+88 32
+65 32
+46 32
+76 32
+83 32
+84 32
+1 3000
+13 32
+8 4
+78 In this file we see
+8 5
+78 the trace of the executed rules
+8 6
+78 and results of PRINT statement.
+0 80
+1 8500
+0 80
+1 500
+0 80
+0 80
+1 100
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+1 500
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+1 3000
+7 22
+78 We QUIT the integrated system
+7 23
+78 by  pressing    ALT+F   and  QUIT
+0 33
+0 80
+1 500
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+1 3000
+13 32

+ 222 - 0
rigdm218/~~DEMO_G.DAT

@@ -0,0 +1,222 @@
+1 3000
+7 15
+78 We press  F3  to  load  example
+0 61
+1 100
+69 32
+88 32
+50 32
+46 32
+82 32
+73 32
+71 32
+1 2000
+13 32
+0 80
+1 500
+7 25
+78  Read  the  comments, please
+0 80
+1 15000
+0 80
+1 5000
+0 81
+1 15000
+0 80
+1 5000
+0 81
+1 15000
+0 80
+1 5000
+0 80
+1 1000
+0 73
+0 73
+0 73
+0 73
+1 7500
+0 77
+7 10
+78 We want to modify input data in file EX.TXT
+7 12
+78  We press F3 ...
+1 3000
+0 61
+1 500
+69 32
+88 32
+46 32
+84 32
+88 32
+84 32
+1 2000
+13 32
+1 130
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+1 30
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+0 83
+1 150
+0 83
+7 3
+78 We enter new expression for analysis
+32 32
+32 32
+32 32
+65 32
+66 32
+67 32
+32 32
+45 32
+32 32
+55 32
+0 75
+0 75
+0 75
+0 75
+0 75
+0 75
+0 75
+0 75
+0 75
+40 32
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+0 77
+41 32
+32 32
+32 32
+42 32
+32 32
+32 32
+88 32
+90 32
+0 75
+89 32
+0 77
+0 77
+0 77
+43 32
+32 32
+32 32
+53 32
+53 32
+1 4000
+7 3
+78  we  return   to  the  Rigal program ( F3 again )
+0 61
+1 200
+69 32
+88 32
+50 32
+46 32
+82 32
+73 32
+71 32
+13 32
+1 12000
+7 10
+78 Environment remembers but
+7 11
+78 we forgot to SAVE the current file
+7 12
+78 Now  we  simply  press  "Y"
+121 32
+1 4000
+7 10
+78 Check  ( F6 )
+0 64
+13 32
+7 10
+207 Run   ( F7 )
+0 65
+8 2
+78 Source expression
+8 3
+78 The tree
+8 4
+78 of the expression
+8 11
+78 The tree in
+8 12
+78 graphical form
+8 16
+78 Polish postfix form
+1 25000
+13 32
+1 200
+7 10
+207 EXIT  ( ALT + F )
+0 33
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+0 80
+1 2800
+13 32

+ 4 - 0
rigdm218/~~STOP.BAT

@@ -0,0 +1,4 @@
+remove > NUL
+echo
+echo You pressed ESC , DEMO is stopped .
+

+ 4 - 0
rigdm218/~~WAIT.BAT

@@ -0,0 +1,4 @@
+rem echo on
+rem ~~wait0.exe
+~~waitpa.exe %1 %2
+if errorlevel 3 ~~stop

BIN
rigdm218/~~WAIT0.EXE


+ 6 - 0
rigdm218/~~WAIT0.PAS

@@ -0,0 +1,6 @@
+Program E;
+Uses Crt;
+var c:char;
+begin
+c:=Readkey;
+end.

BIN
rigdm218/~~WAITPA.EXE


+ 49 - 0
rigdm218/~~WAITPA.PAS

@@ -0,0 +1,49 @@
+Program Wait;
+uses Crt;
+label 99;
+var i,j,k,X,Y,TA:integer; s:string[5];c,c1:char;
+begin
+Randomize;
+X:=WhereX; Y:=WhereY; TA:=TextAttr;
+s:=ParamStr(1);
+Val(s,i,j);
+s:=ParamStr(2);
+if s='' then j:=100 else Val(s,j,k);
+i:=i*j;
+i:=i-300;
+Window(1,1,80,25);
+GotoXY(20,25);
+TextAttr:=74;
+    Write('Press any key to suspend execution or ESC to exit');
+
+for k:=1 to (i div 100) do begin
+  Delay(100);
+  if keypressed then
+    begin
+    GotoXY(20,25);
+    write('   Press  ENTER  to  continue  or  ESC  to  exit ');
+    repeat
+       c:=Readkey;
+       if c=#0 then c1:=Readkey; 
+    until ((c=#27) or (c=#13));
+    if c=#27 then halt(3);
+    goto 99;
+    end;
+ end;
+if i>10000 then
+  begin  Sound(500);Delay(100);Nosound;Delay(2000);end;
+
+99:
+
+GotoXY(X,Y);
+TextAttr:=TA;
+Sound(400+Random(600));
+Delay(100);
+Sound(400+Random(600));
+Delay(100);
+Sound(400+Random(600));
+Delay(100);
+Nosound;
+
+end.
+

+ 175 - 0
rigdos/80.TXT

@@ -0,0 +1,175 @@
+Starting from Rigal V.2.34
+
+   Operations with  real values in Rigal
+  =======================================
+
+   Limitations of Turbo Pascal
+   ===========================
+
+
+Rigal is implemented via Pascal real run time library. The
+following sequence of characters is accepted by Pascal VAL
+procedure as a real number:
+
+  (* space *) [ (+!-) ] (* digits1 *) [ '.' (* digit2 *) ]
+              [ (e!E)   [ (+!-) ] (* digit3 *) ]
+  The context constraints are that:
+   digit1+digit2<37  ( limited number of digits )
+   The absolute value of digits1.digits2E[-]digits3 must be
+   in 2.9e-39 ... 1.7e38
+
+  Input real number from lexical analyzer
+  =======================================
+
+We call real numbers stored in Rigal memory as #FATOMs. Use
+built-in Rigal predicate #FATOM to recognize them. They
+can be read by the lexical analyzer from its input as
+sequences of characters that must match following grammar
+rule
+
+   (+ digits1 +)
+   ( '.' (* digit2 *)  [ (e!E)   [ (+!-) ] (* digit3 *) ]
+   !                     (e!E)   [ (+!-) ] (* digit3 *) )
+
+and it must be acceptable by procedure VAL (see above). If
+#FATOM is read then it is stored in 8-byte-length atom, 6
+bytes are occupied by standard representation of REAL type
+in Pascal. In other two bytes number of digits before dot
+and number of digits after the dot are stored. If the input
+number was in exponential form then these bytes contain
+zeros.
+
+Since standard 6-byte representation is stored, only 10 or
+11 digits are valid.
+
+If the input value matches grammar and does not match "VAL
+rules"  then atom with type #KEYWORD is produced (it is
+used for diagnostic purposes).  Normally #FATOM is produced.
+
+ Output of real numbers
+ ======================
+ Statements PRINT, <<, ,<], built-in rules #IMPLODE and
+#EXPLODE output real numbers in form
+    Sd.ddddddddddEZdd
+  S is space or '-'
+  d are digits (exactly 10 digits after dot)
+  E is character 'E'
+  Z is '+' or '-'
+
+ Real numbers in traditional operators
+ =====================================
+  If you use real numbers in traditional arithmetical
+operators and comparisons, all #FATOMs  are accepted the
+same way as NULL. It corresponds to 0 value. If you  compare
+#FATOMs with '=', their internal representation (with 6
+or 8 bytes long code) will be compared.
+
+  Ways to create #FATOM
+  =====================
+ #CALL_PAS(80 S any_string)
+  returns #FATOM if string value matches "VAL rule".
+Otherwise NULL is returned.
+
+  #CALL_PAS(80 I integer)
+  returns #FATOM. Integer value can be arbitrary.
+
+  Ways to get information from #FATOM
+  ===================================
+  #CALL_PAS(80 D #FATOM) returns pair
+   (. digits_before  digits_after .)
+  for FATOM values that were entered through the
+lexical analyzer. If the number was entered in exponential
+style (with character, 'E'), value (. 0 0 .) is returned.
+If the value was obtained by #CALL_PAS(80..),  NULL is
+returned. There is no other ways to create #FATOM.
+
+  NOTE:
+ If you have entered #FATOM to variable $X via lexical
+analyzer, you can output it with the same number of digits
+before and after the point (if it was not exponential
+style) as it was read by lexical analyser:
+
+  $D:=#CALL_PAS(80 D $X);
+  IF $D AND ($D[1]+$D[2]>0) ->
+   $REZ:=#CALL_PAS(80 Z $X ($D[1]+$D[2]+1)*100+$D[2])
+  ELSIF T->
+   $REZ:=#CALL_PAS(80 V $X)
+  FI;
+
+  Conversions
+  ===========
+  #CALL_PAS(80 T #FATOM)
+  returns #NUMBER - whole part of real value. If the
+number is not in -2147483648..2147483647 then NULL is
+returned.
+
+  #CALL_PAS(80 Z #FATOM D*100+A)
+  returns formatted string with the value of the real
+number. "A" can be positive or negative.
+
+  If "A" is arbitrary NEGATIVE number then exponential form
+is produced in following form:
+   Sd.dEZdd (e.g. -7.7E01)
+   S is  space or '-' Z is '-' or '+'
+
+  If D>=9 then additional digits are added after the point,
+but not more than 10 digits.
+
+  If "A" is 0 then integer value is produced, possible with
+'-'.
+  If "A" is positive, it specifies number of digits after
+the point. Non-exponential form is produced.
+Zeros are appended after point if necessary. The
+number of digits after the point cannot be larger than 11.
+
+  After all cases discussed above, if "D" is larger than the
+new string, RIGAL adds spaces from the left side of the
+string. The result string length is not less than "D".
+
+  #CALL_PAS(80 R #FATOM p)
+  - returns rounded value of real number. The number is
+rounded such way that digits after p-th position after the
+dot  must be set to zeros. E.g. 23.1415 rounded at 2 nd
+position must be 23.140000.
+   If p is not positive, it is  accepted as 0.  If absolute
+value of real*(10 in p-th degree) is larger than 1e37 then
+NULL is returned.
+
+  #CALL_PAS(80 V #FATOM)
+  - creates string from real number in form
+    [-]d.ddddddddddESdd
+    S is '+' or '-'
+
+  #CALL_PAS(80 Q #FATOM) returns square root if argument is
+not negative, NULL otherwise.
+  #CALL_PAS(80 X #FATOM) returns exponential ( e in r-th
+degree) of the argument.
+  #CALL_PAS(80 L #FATOM) returns natural logarithm if the
+argument is positive, otherwise NULL.
+  #CALL_PAS(80 op #FATOM #FATOM)
+  Operations "op" can be '+','-', '*','/',  '<','>',
+'<=','>=', '<>','='
+  If '+' or '-' applied, absolute value of the arguments
+must be less than 6.2e37 otherwise NULL is returned.
+  If '*' or '-' applied, absolute value of the result must
+be between 1.6e-38..6.2e37 and the second argument of '/' is
+not 0, otherwise NULL is returned.
+  If '<','>','<=','>=','<>','=' are applied, one of the
+arguments is returned to indicate 'true', NULL is returned
+to indicate 'false' Note that it is IMPOSSIBLE to check the
+results of real arithmetic using '=' or '<>' operations,
+because the computer never calculates precise results. You
+can compare two real numbers only after some conversion,
+e.g. using #CALL_PAS(80 V ...).
+
+   Common note about #CALL_PAS(80..).
+   =================================
+  It has no run time diagnostic.
+  If wrong types of arguments  of wrong number of arguments
+or wrong operation name is given, NULL is returned.
+  If #CALL_PAS(80...) produces a #FATOM, it is 6 bytes long
+and it has no information about the digits before and after
+the dot.
+  You can learn more details about #CALL_PAS(80) from
+source files USE80.PAS and SERVICES.PAS.
+

+ 171 - 0
rigdos/80TST.RIG

@@ -0,0 +1,171 @@
+-- tests all details of USE80.PAS implemantation
+#W
+$A:=#F('4.0');
+$B:=#F('0.1');
+PRINT (. $A $B .);
+PRINT #CALL_PAS(80 '*' $A $B);
+#CALL_PAS(1);
+$F:=#TEST1(); -- returns 123.456
+
+ #TEST2($F[1]);
+ #TEST3( $F);
+ #TEST4( $F);
+ #TEST5();
+##
+
+
+#TEST2  $F
+ /
+  PRINT (. 'printout in exponential forms:' .);
+  PRINT (. print $F .);
+  PRINT (. explode #EXPLODE($F) .);
+  PRINT (. implode #IMPLODE($F) .);
+  OPEN D ' ';
+  D<< '<<-output ' $F;
+  CLOSE D/
+##
+
+
+#TEST3 $F
+ / $XX:=#CALL_PAS(80 S '123.456');
+  PRINT (. '80-S:good' $XX .);
+  PRINT (. '80-s:NULL' #CALL_PAS(80 S '-1E77') .);
+  PRINT (. '80-i:integer' #CALL_PAS(80 I 123)  .);
+  PRINT (. 'digits for 123.456 ' #CALL_PAS(80 D $F[1]) .);
+  PRINT (. 'digits for 123E+12 ' #CALL_PAS(80 D $F[3]) .);
+  PRINT (. 'digits for my-num=null ' #CALL_PAS(80 D $XX) .) ;
+
+  $X:=$F[1];
+  $D:=#CALL_PAS(80 D $X);
+  IF $D AND ($D[1]+$D[2]>0) ->
+   $REZ:=#CALL_PAS(80 Z $X ($D[1]+$D[2]+1)*100+$D[2])
+  ELSIF T->
+   $REZ:=#CALL_PAS(80 V $X)
+  FI;
+  PRINT(. 'doctest=123.456=' $REZ .);
+  #CALL_PAS(1 'test3 ended');
+/
+##
+
+#F $S / RETURN #CALL_PAS(80 S $S) / ##
+
+#TEST4
+ / 
+PRINT (. 'T-good' #CALL_PAS(80 T #F('2.14E+9')) .);
+PRINT (. 'T-bad ' #CALL_PAS(80 T #F('2.15E+9')) .);
+PRINT (. 'T-good' #CALL_PAS(80 T #F('-2.14E+9')) .);
+PRINT (. 'T-bad ' #CALL_PAS(80 T #F('-2.15E+9')) .);
+PRINT (. 'Z-expo 7.7e+00 ' #CALL_PAS(80 Z #F('7.7') (-1) ) .);
+PRINT (. 'Z-expo 7.7e+00 ' #CALL_PAS(80 Z #F('7.7') (799) ) .);
+PRINT (. 'Z-expo 7.70e+00 ' #CALL_PAS(80 Z #F('7.7') (899) ) .);
+PRINT (. 'Z-expo  8 ' #CALL_PAS(80 Z #F('7.7') (0) ) .);
+PRINT (. 'Z-expo *8 ' #CALL_PAS(80 Z #F('7.7') (1000) ) .);
+#CALL_PAS(1);
+PRINT (. 'Z-expo  7.7 ' #CALL_PAS(80 Z #F('7.7') (1) ) .);
+PRINT (. 'Z-expo *7.7 ' #CALL_PAS(80 Z #F('7.7') (801) ) .);
+PRINT (. 'Z-expo *7,70' #CALL_PAS(80 Z #F('7.7') (802) ) .);
+PRINT (. 'R 23.14000'    #CALL_PAS(80 R #F('23.138') 2 ) .);
+PRINT (. 'R 23.14000'    #CALL_PAS(80 R #F('23.144') 2 ) .);
+PRINT (. 'R 23.00000'    #CALL_PAS(80 R #F('23.138') 0 ) .);
+PRINT (. 'R 23.00000'    #CALL_PAS(80 R #F('23.138') (-2)) .);
+PRINT (. 'R -23.14000'    #CALL_PAS(80 R #F('-23.138') 2 ) .);
+PRINT (. 'R -23.14000'    #CALL_PAS(80 R #F('-23.144') 2 ) .);
+PRINT (. 'R -23.00000'    #CALL_PAS(80 R #F('-23.138') 0 ) .);
+PRINT (. 'R -23.00000'    #CALL_PAS(80 R #F('-23.138') (-2)) .);
+PRINT (. 'R null    '    #CALL_PAS(80 R #F('23.138') 42) .);
+#CALL_PAS(1 'test4 ended' );
+/##
+
+#TEST1
+-- Part 1 reading float number from the lexical analyser
+
+
+/
+OPEN D '80TST.LST';
+D<<' 123.456    7.33333333333333333333333333333333333333333333333333';
+D<<' 123E+12 123E-12 123.456E+12 123.456E12 123. ';
+D<<' .56';
+$V:=(.F K F F F F F A N K F F F .);
+D<<' 7777777777777777777777777777777777777.88'; --39
+D<<' 777777777777777777777777777777777777.88'; --38
+D<<' 77777777777777777777777777777777777.88'; --37
+D<<' 7777777777777777777777777777777777.88';  --36
+CLOSE D;
+$A:=#CALL_PAS(35 '80TST.LST');
+FORALL $E IN $A DO
+ IF #FATOM($E) -> $M:='F'
+ ELSIF #_KEYWORD ($E) -> $M:='K'
+ ELSIF #NUMBER($E) ->  $M:='N'
+ ELSIF #ATOM($E)    -> $M:='A';
+ ELSIF T-> $M:='X';
+ FI;
+ $MA!.:=$M;
+OD;
+PRINT (. really   $MA .);
+PRINT (. expected $V .);
+#CALL_PAS(1);
+RETURN $A;
+/##
+
+#TEST5/
+ $A:=#F('-1E20');
+ $B:=#F('1.2E20');
+ $C:=#F('-1.2E-20');
+ $N:=#F('0');
+ PRINT (. a b $A $B .);
+ PRINT(.  '+ good'  #CALL_PAS(80 '+' $A $B) .);
+ PRINT(.  '- good'  #CALL_PAS(80 '-' $A $B) .);
+ PRINT(.  '* good'  #CALL_PAS(80 '*' $A #F('1e10')) .);
+ PRINT(.  '* good'  #CALL_PAS(80 '*' #F('1e10') $B) .);
+ PRINT(.  '/ good'  #CALL_PAS(80 '/' $A #F('1e10')) .);
+ PRINT(.  '/ good'  #CALL_PAS(80 '/' #F('1e10') $B) .);
+ PRINT(.  '* bad '  #CALL_PAS(80 '*' $A $B) .);
+ PRINT(.  '* bad '  #CALL_PAS(80 '*' $C $C) .);
+ PRINT(.  '/ bad '  #CALL_PAS(80 '/' $A $C) .);
+ PRINT(.  '/ bad '  #CALL_PAS(80 '/' $C $A) .);
+ PRINT(.  '/ bad '  #CALL_PAS(80 '/' $B $N) .);
+ #CALL_PAS(1); 
+ PRINT(.  '+ good'  #CALL_PAS(80 '+' $A $N) .);
+ PRINT(.  '+ good'  #CALL_PAS(80 '+' $N $A) .);
+ PRINT(.  '+ good0' #CALL_PAS(80 '+' $N $N) .);
+ PRINT(.  '- good'  #CALL_PAS(80 '-' $A $N) .);
+ PRINT(.  '- good'  #CALL_PAS(80 '-' $N $A) .);
+ PRINT(.  '- good0' #CALL_PAS(80 '-' $N $N) .);
+ PRINT(.  '* good0' #CALL_PAS(80 '*' $A $N) .);
+ PRINT(.  '* good0' #CALL_PAS(80 '*' $N $A) .);
+ PRINT(.  '* good0' #CALL_PAS(80 '*' $N $N) .);
+ PRINT(.  '/ good0' #CALL_PAS(80 '/' $N $A) .);
+ PRINT(.  '/ bad '  #CALL_PAS(80 '/' $A $N) .);
+ PRINT(.  '/ bad '  #CALL_PAS(80 '/' $N $N) .);
+ #CALL_PAS(1); 
+/##
+
+#TEST4x
+/ OPEN S ' ';
+ $E:=#CALL_PAS(80 S '5.0');
+  $E:=NULL;
+PRINT (.$E<0 $E>0 $E+0=0 $E=COPY($E).);
+ $E1:=#CALL_PAS(80 S '4.0');
+ S<<' to screen ' $E1 $E;
+ PRINT (. $E1 $E .);
+  $E:=COPY($E1);
+#CALL_PAS(1);
+ PRINT #CALL_PAS(80 '+' $E $E1);
+ PRINT #CALL_PAS(80 '*' $E $E1);
+ PRINT #CALL_PAS(80 '/' $E $E1);
+ PRINT #CALL_PAS(80 '/' $E #CALL_PAS(80 I 0));
+ $E:=$E1;
+ #CALL_PAS(1);
+ PRINT 'COMPARING';
+ PRINT #CALL_PAS(80 '<' $E $E1);
+ PRINT #CALL_PAS(80 '>' $E $E1);
+ PRINT #CALL_PAS(80 '<=' $E $E1);
+ PRINT #CALL_PAS(80 '>=' $E $E1);
+ PRINT #CALL_PAS(80 '=' $E $E1);
+PRINT #CALL_PAS(80 '<>' $E $E1);
+PRINT #CALL_PAS(80 'T' $E1 );
+PRINT #CALL_PAS(80 'Z' $E1 2505);
+ $E:=#CALL_PAS(80 I  994);
+ PRINT $E;
+  #CALL_PAS(1);
+/##

+ 32 - 0
rigdos/A.BAL

@@ -0,0 +1,32 @@
+
+MOV =1,VAR3
+WRITE =3
+WRITE =1
+READ VAR1 
+LOAD R0,VAR1
+LOAD R1,VAR1
+MULT R0,R1
+WRITE R0
+LOAD R0,VAR1
+LOAD R1,VAR1
+MULT R0,R1
+LOAD R2,=4
+LOAD R3,=12
+ADD R2,R3
+COMPARE R0,R2
+BRANCH R0,L1
+WRITE =77
+JUMP L2
+L1: NOP
+WRITE =88
+L2: NOP
+LOAD R0,VAR1
+LOAD R1,=4
+COMPARE R0,R1
+BRANCH R0,L3
+WRITE =99
+L3: NOP
+EOJ 
+VAR1 : DEFWORD 0 
+VAR2 : DEFWORD 0 
+VAR3 : DEFWORD 0 

+ 14 - 0
rigdos/A.TOY

@@ -0,0 +1,14 @@
+ PROGRAM AAAA
+ INTEGER A,B;
+ BOOLEAN C;
+ C:=TRUE;
+
+ PUT (3,1);
+ GET (A);
+ PUT (A*A);
+ IF A*A=4+12 THEN
+    PUT(77)
+ ELSE
+    PUT (88)       
+ FI;
+ IF A=4 THEN PUT(99) FI; 

+ 50 - 0
rigdos/ANALYSE.RIG

@@ -0,0 +1,50 @@
+--:**  See error message in line 6
+-- parsing of Prof. Blikle small language
+--
+-- file ANALYSE.RIG
+--
+#analyse_program
+     (. (* $rez !.:= #analyse_stmt  * ';' )  [ ';' ]  .)
+--:-----^
+--:** 323 UNEXPECTED SYMBOL (END OF '<<'-STATEMENT NOT FOUND)
+--:** **************************************************
+--:** **************************************************
+     / RETURN $rez /  ##
+
+#analyse_stmt
+    $rez := ( #assignment  !  #while_op  ) / RETURN $rez/ ;;
+
+    (* $R !.:= S'( $$ <> ';' ) *)
+    / report << unrecognised statement $R ; FAIL /
+##
+
+#assignment
+    $var := #variable  ':=' $E := #expression  V'( $$ = ';' OR $$ = 'OD')
+    / RETURN 'assignment_op' :: <. left_part: $var,
+                                   right_part: $E   .> /  ##
+
+#while_op
+    'WHILE'  $E := #expression  'DO'
+             (* $body !.:= #analyse_stmt * ';' )
+                                'OD'
+     / RETURN 'while_op' :: <. condition: $E,
+                               body:   $body  .> /   ##
+
+#expression
+     $a1 := #arithm_expr
+     [  '<'  $a2 := #arithm_expr
+          / RETURN '<' :: <. arg1: $a1,  arg2: $a2 .>/ ]
+     / RETURN $a1 /   ##
+
+#arithm_expr
+    $a1 := #term   / RETURN $a1 / ;;
+
+    '('  $a1 := #arithm_expr  '+' $a2 := #arithm_expr  ')'
+       / RETURN '+' :: <. arg1: $a1, arg2: $a2 .> /  ##
+
+#term
+    $NUM  / RETURN  $NUM /  ;;
+    $rez :=   #variable    /RETURN $rez /  ##
+
+#variable
+    $R := ( W ! V ! X ! Y ! Z ) / RETURN $R /  ##

BIN
rigdos/ANRIG.EXE


+ 87 - 0
rigdos/BCOMP.RIG

@@ -0,0 +1,87 @@
+-- Program BCOMP.RIG in directory \RIGAL
+-- Compiles program written in Prof.Blikle small language
+-- to PASCAL code.
+#MAIN
+$LIST:=#CALL_PAS(3 'EX1.TXT');
+$TREE_CODE:=#analyse_program($LIST);
+#GEN_PROGRAM($TREE_CODE);
+##
+%INCLUDE ANALYSE.RIG
+#GEN_PROGRAM
+ /#GEN_PROLOG() /
+(. (* #GEN_STMT *) .)
+ / #GEN_EPILOG() / ##
+
+#GEN_PROLOG
+/OPEN G 'ex1.pas';
+ G<<' Program Main;';
+ G<<' const tt=101;ff=102;err=103;';
+ G<<' var state:record w,v,x,y,z:integer end;';
+ G<<' function PLUS (a,b:integer) :integer;';
+ G<<' begin if (a>100) or (b>100) then Plus:=err ';
+ G<<'       else if a+b >100 then Plus:=err ';
+ G<<'            else Plus:=a+b; end; ';
+ G<<' function LESS (a,b:integer) :integer;';
+ G<<' begin if (a>100) or (b>100) then Less:=err ';
+ G<<'       else if a<b then Less:=tt ';
+ G<<'            else Less:=ff; end; ';
+ G<<' Procedure Val(a:integer);';
+ G<<'  begin case a of ';
+ G<<'   101 : writeln (''tt''); ';
+ G<<'   102 : writeln (''ff''); ';
+ G<<'   103 : writeln (''err''); ';
+ G<<'   else  writeln (a);end;end; ';
+ G<<' BEGIN WITH STATE DO BEGIN ';
+ G<<'  w:=1;v:=1;x:=1;y:=1;z:=1; '/
+ ##
+ #GEN_EPILOG
+  / G<<'Writeln ('' Post-DUMP : '');';
+    G<<'Write (''w='');Val(w);';
+    G<<'Write (''v='');Val(v);';
+    G<<'Write (''x='');Val(x);';
+    G<<'Write (''y='');Val(y);';
+    G<<'Write (''z='');Val(z);';
+    G<<'readln;end; ';
+    G<<'END.'/
+##
+#GEN_STMT
+ 'assignment_op' ::
+   <. left_part : $Id
+        / G<< $Id ':=' /,
+      right_part : #GEN_EXPR
+        / G<] ';' / .>
+;;
+ 'while_op'::
+   <. condition :
+         / G<<' WHILE ' /
+         #GEN_EXPR
+         / G<] '=tt DO BEGIN '/,
+      body : (. (* #GEN_STMT *) .)
+         / G<<'END;' / ,
+      condition :
+         / G<< ' IF ' /
+         #GEN_EXPR
+         / G<] ' =err THEN x:=err; ' /
+  .>
+##
+#GEN_EXPR
+ $N / G<] $N / ;;
+
+ $Id / G<] $Id / ;;
+
+ '+' :: <. arg1:
+               / G<] ' PLUS( '/
+               #GEN_EXPR,
+           arg2:
+               / G<] ',' /
+               #GEN_EXPR
+               / G<] ')' / .>
+ ;;
+ '<' :: <. arg1:
+               / G<] ' LESS( '/
+               #GEN_EXPR,
+           arg2:
+               / G<] ',' /
+               #GEN_EXPR
+               / G<] ')' / .>
+ ##

+ 19 - 0
rigdos/BIGLOAD.RIG

@@ -0,0 +1,19 @@
+--
+#MAIN
+OPEN S ' ';
+ LOOP
+ $J+:=1;
+  $E!.:=(.A B C F D J K L N M B G H .);
+--  IF $I=300 -> PRINT $J;$I:=0; $J+:=1;FI;
+  IF $J=300 -> BREAK FI; 
+ END;
+  S<<#LEN($E);
+  SAVE $E 'E.SS';
+  S<< $E[-1];
+  LOAD $Q 'E.SS';
+  S<< $Q[-1];
+   
+    
+  #CALL_PAS(1 'End?');
+ ##
+   

+ 173 - 0
rigdos/CALL_PAS.TXT

@@ -0,0 +1,173 @@
+
+
+
+
+
+
+Addressing list applied to structure 92
+Assign coordinate to atom 44
+Atom to number 21
+Available memory 119
+Box with input value 83
+Box with message or question 82
+Box with standard output - location 84
+Buffer allocation for DLL 76
+C format - convert string 116
+Clear to end of line in texts screen 28
+Clear to end of screen in texts screen 29
+Coding russian 5,6
+Color in text screen 27
+Comiler - insert statement to code 99
+Compiler or Interpreter ? 46
+Convert atom to number 21
+Convert integer to real 80-I
+Convert real to string 80-Z
+Convert string to C format 116
+Convert string to real 80-S
+Convert to lowercase 86
+Convert to uppercase 85
+Coordinate - assign it to atom 44
+Coordinate 4
+Current directory 47
+Cursor in text screen - where (X) 33
+Cursor in text screen - where (Y) 34
+Cursor mive 25
+Cut lines in text file after ';' 109
+Data and time (current) 89
+DDE (?) - Window initialization 81
+DDE (old) - set message 75
+DDE (old) - wait and get a message 74
+DDE (old) - wait for initial answer 73
+Decimal fixed numbers - get format 80-D
+Delay 22
+Delete file 8
+Depth of PRINT, maximal 78
+Directory - "home" directory of EXE(RSC) 105
+Directory current 47
+DLL - buffer allocation 76
+DLL - call function in library 102
+DLL - load library 101
+DLL - release library 103
+DLL call - PFDLL 118
+DLL call - RFDLL 117
+DLL call - SFDLL 77
+Dump of memory 10
+Environment variable 108 
+Execute Windows application 104 106
+Execute Windows or DOS application 107
+Exists file ? 48
+Expand file name 47
+File - find from path with wildcards 120 
+File - reads by lines 16
+File delete 8
+File exists ? 48
+File name expanding 47
+File rename 7
+Find file from path with wildcards  120
+Find index from element 79
+Find position of string in string 88
+Find selector from branch 79
+Float operations 80
+Function call (DLL library) 102
+Get environment variable 108
+Graphic printout to file 12
+Graphic printout to screen 13
+Halt program 90
+Home directory of EXE (RSC) 105
+Index in list: find it from element 79
+INDEX of services in #CALL_PAS
+Input box 83
+Insert statement to compiled code 99
+Integer to real conversion 80-I
+Interpreter or Compiler ? 46
+Key pressed check 32
+Keyboard - check if key pressed 32
+Keyboard - read key 18
+Lexical analyser (from atom) 36
+Lexical analyser (from DOS memory) 37
+Lexical analyser (from file) 35
+Lexical analyser (from memory stream) 114
+Lexical analyser (old) 2
+Lexical analyser - list of errors 38
+Lexical scanner of Rigal 14,15
+Library DLL - call function 102
+Library DLL - load 101
+Library DLL - release 103
+Line read from file 16
+List - remove last element 91
+Load DLL library 101
+Load s-code from memory stream 113
+Lowercase 86
+Memory - reopen 45
+Memory available and compacted 119
+Memory dump 10
+Memory information - newest S-address value 41
+Memory information - page number 42
+Memory information - page number on disk 43
+Memory information - S-address value 40
+Memory stream - lexical analyser 114
+Memory stream - load S-code  113
+Memory stream - save S-code  112
+Message box 82
+Move cursor 25
+Operations winth real 80
+PFDLL call 118
+Position if string in string 88
+PRINT depth (maximal) 78
+Print in graphic form to file 12
+Print in graphic form to screen 13
+Random value 20
+Randomize 19
+Read file by lines 16
+Read from screen 1
+Read key from keyboard 18
+Real numbers, operations 80
+Real to string conversion 80-Z
+Release DLL library 103
+Remove last element of list 91
+Rename file 7
+Reopen memory 45
+RFDLL call 117
+Rigal scanner 14,15
+Root, square 110 111
+Run Windows application     104  106
+Run Windows or DOS application     107
+Russian code 5,6
+S-Address value 40
+S-Address value, newest 41
+Save s-code to memory stream 112
+Scaner (from atom) 36
+Scaner (from DOS memory) 37
+Scaner (from file) 35
+Scaner (from memory stream) 114
+Scaner - list of errors 38
+Scanner (old) 2
+Selector in tree: find it from branch 79
+SFDLL call 77
+Sound control 23,24
+Square root 110 111
+Stack size 93
+Stop program 90
+String to real conversion 80-S
+Structure - apply addressing list  92
+Substring 87
+Table - create atomic 61
+Table - create from list or tree 66
+Table - create numeric 60
+Table - get data 63
+Table - get data by key 67 
+Table - get size 64
+Table - put data 62
+Table - unpack table 65
+Text screen - clear to end of line 28
+Text screen - clear to end of screen 29
+Text screen - where is cursor (X) 33
+Text screen - where is cursor (Y) 34
+Text screen color 27
+Text screen window 26
+Time and data (current) 89
+Uppercase 85
+Wincrt box location 84
+Window in text screen 26
+Write to screen 1
+Write to screen 30,31

+ 4 - 0
rigdos/CMPLBEG.BAT

@@ -0,0 +1,4 @@
+@echo off
+rem if not exist USERCALL.PAS copy %2USERCALL.PAS
+if exist %2USEPASU.TPU del %2USEPASU.TPU
+if exist %2usepasu.tpw del %2usepasu.tpw

+ 12 - 0
rigdos/CMPLEND.BAT

@@ -0,0 +1,12 @@
+@echo off
+rem RIGAL STANDARD COMPILATION TERMINATION FILE
+del xcrg*.tpu
+del xcrg.exe
+del *.rc4
+echo %1.EXE ready
+pause
+rem del %2usepasu.tpu
+del %2scan.tpu
+rem del rigcomp.tmp
+del xcrg*.pas
+

+ 1 - 0
rigdos/EX.TXT

@@ -0,0 +1 @@
+ (  ABC + 77  )  *  XYZ  -  55

+ 19 - 0
rigdos/EX1.RIG

@@ -0,0 +1,19 @@
+-- This example illustrates how to program TAIL and HEAD 
+-- functions in RIGAL.
+ #MAIN
+  $E:=(. ALFA BETA GAMMA DELTA .);
+ OPEN S ' ';   -- Opens file S for output to the screen
+ S<<$E;
+ S<<'HEAD=' #HEAD($E);
+ S<<'TAIL=' #TAIL($E);
+ $W:=<. SEL1 : $E,
+        SEL2 : #HEAD($E),
+        SEL3 : #TAIL($E) .>;
+ PRINT $W;
+##
+#HEAD 
+  (. $E   (* $A *) .) / RETURN $E / ##
+#TAIL
+  (. $A   (* $L!.:=$E *) .) /RETURN $L /##
+
+

+ 10 - 0
rigdos/EX1.TXT

@@ -0,0 +1,10 @@
+
+    z:=1 ; x:= ( z + 1 ); 
+    y:=1;  
+    while y < (x+1) do
+         z:=(z+z);
+         y:=(y+1) od;
+
+    v:=(1+1);
+    v:=((v+v)+v); 
+    w:=1;

+ 48 - 0
rigdos/EX2.RIG

@@ -0,0 +1,48 @@
+ -- Example of RIGAL program.
+ -- Takes input from file EX.TXT
+ -- Performs simple arithmetical expression parsing.
+ -- Expression tree is returned.
+ -- Polish Postfix Form is printed out.
+#MAIN
+ OPEN S ' ';        -- Opens file S for output to the screen
+ $E:=#CALL_PAS(3 'EX.TXT'); -- Scanner takes input from file EX.TXT
+ S<<$E;             -- Prints the input text
+ $T:=#ANALYSE($E);  -- Calls expression analysis
+ PRINT $T;          -- Prints expression tree
+ #CALL_PAS(13 $T);  -- Prints expression tree in graphical form
+ S<<;
+ #PRINT_POLISH($T); -- Calls Polish  Postfix Form printing
+##
+
+#ANALYSE -- Traverses token list
+ (. $E:=#EXPRESSION .)   / RETURN $E /
+##
+                                                  --      BNF form :
+#EXPRESSION                                      -- expression ::=
+ $A1:=#ADDITIVE_EL                               --  add_el
+ (* $OP := ( '+' ! '-' )  $A2:=#ADDITIVE_EL      --  ( ('+'!'-') add_el )*
+  / $A1 := <. OP:$OP, ARG1:$A1 , ARG2:$A2 .> / *)
+  / RETURN $A1 /
+##
+
+#ADDITIVE_EL                                     --  add_el ::=
+ $A1:=#TERM                                      --    term
+ (* $OP := ( '*' ! '/' ) $A2 :=#TERM             --   ( ('*'!'/') term )*
+  / $A1 := <. OP:$OP, ARG1:$A1 , ARG2:$A2 .> / *)
+  / RETURN $A1 /
+##
+
+#TERM                                            -- term ::=
+ $A := ( $ID ! $NUM )    / RETURN $A / ;;        --  (identifier ! number !
+
+ '(' $A:=#EXPRESSION ')' / RETURN $A /           --    '(' expression ')' )
+##
+
+#PRINT_POLISH
+ <. ARG1 : #PRINT_POLISH,       -- Trees are traversed recursively
+    ARG2 : #PRINT_POLISH,
+    OP : $OP .>
+   / S<] $OP / ;;
+
+  $EL / S<] $EL /               -- Leaves are printed immediately
+##

BIN
rigdos/GENRIG.EXE


+ 26 - 0
rigdos/GRAM1.RIG

@@ -0,0 +1,26 @@
+-- abstract syntax grammar of tree for language SL
+#program
+        (. (* #stmt  *) .)   ##
+
+#stmt
+     ( #assignment  !  #while  )  ##
+
+#assignment
+           'assignment_op' :: <. left_part: $Id,
+                                 right_part: #expression .>
+##
+
+#while
+      'while_op' :: <. condition: #expression,
+                       body:      (. (* #stmt *) .)  .>
+##
+
+#expression
+           1 ;;
+           $Id ;;
+           '+' :: <. arg1: #expression,
+                     arg2: #expression .> ;;
+
+           '<' :: <. arg1: #expression,
+                     arg2: #expression .>
+##

+ 19 - 0
rigdos/GRAM2.RIG

@@ -0,0 +1,19 @@
+-- source grammar for SL
+#program
+        (. (* #stmt * ';' ) .)  ##
+#stmt
+     ( #assignment ! #while_op )   ##
+#assignment
+           $Id  ':='  #expression   ##
+#while_op
+         'while'  #expression 'do'
+                  (* #stmt  * ';' )  'od'  ##
+#expression
+           #arithm_expr  [ '<'  #arithm_expr ]  ##
+#arithm_expr
+           #term   ;;
+        '(' #arithm_expr   '+'  #arithm_expr ')'  ##
+#term
+     ( 1 ! #variable )  ##
+#variable
+         ( w ! v ! x ! y ! z )   ##

+ 89 - 0
rigdos/HANOI.RIG

@@ -0,0 +1,89 @@
+
+
+  -- Hanoi tower problem
+#MAIN
+ OPEN S ' ';
+ $Count:=4; -- Count of rings in first tower
+ S<<' Rings count =' $Count ;
+ $STATE:=#INIT($Count); -- Global variable 
+
+ #VIDEOSHOW(T); 
+#H( $Count 1 3 );
+ 
+##
+#H
+ $Num $From $To
+ / 
+S<< ' $Num $From $To ='  $Num $From $To ;
+
+ IF $Num=1 -> 
+       S << 'FROM' $From 'TO ' $To;
+       #VIDEOMOVE ($From $To);
+       #VIDEOSHOW (T)
+   ELSIF T->
+       $Middle := 6-$From-$To ;
+      #H( $Num-1 $From $Middle );
+      #H( 1      $From $To );
+      #H( $Num-1 $Middle $To )
+FI / ##
+
+#INIT  $Count
+/  $V:=(.
+      <. LEN : COPY($Count), BODY : (.COPY($Count).) .>
+      <. LEN : 0     , BODY : (.0.)      .>
+      <. LEN : 0     , BODY : (.0.)      .> .);
+   LOOP
+    IF $Count=1 -> BREAK FI;
+    $Count:=COPY($Count-1);
+    $V[1].BODY!.:=$Count;
+    $V[2].BODY!.:=0;
+    $V[3].BODY!.:=0;
+  END;
+  RETURN $V;
+ / ##
+
+#VIDEOMOVE
+  $From $To
+  / 
+   $S_from := LAST #MAIN $STATE [$From];
+   $S_to   := LAST #MAIN $STATE [$To];
+   $Ring:=COPY( $S_from.BODY[$S_from.LEN]);
+   $S_from.BODY[$S_from.LEN]:=0;
+   $S_from.LEN+:=-1;
+   $S_to.LEN+:=1;
+   $S_to.BODY[$S_to.LEN]:=$Ring;
+  /
+##
+
+#VIDEOSHOW
+
+/ $X:=LAST #MAIN $STATE;
+  $I:=1;
+  LOOP
+   S<<$I '   ';
+   #STR($X[1].BODY[-$I]);
+   S<]'   ';
+   #STR($X[2].BODY[-$I]) ;
+   S<]'   ';
+   #STR($X[3].BODY[-$I]);
+   IF $I>=LAST #MAIN $Count -> BREAK;FI;
+   $I+:=1;
+  END;
+  S<<;
+#CALL_PAS(1 '<<<<<>>>>>>')/##
+
+#STR
+  $N
+/ $E:=LAST #MAIN $Count-$N;
+  #FILL(' ' $E); 
+  #FILL('O' 2*$N);
+  #FILL(' ' $E)/ ##  
+
+#FILL 
+ $SYM $CNT
+ /LOOP
+   $CNT:=$CNT-1;
+   IF $CNT<0 -> BREAK FI;
+   S<]@$SYM; 
+  END; 
+ /## 

BIN
rigdos/HANOI.RSC


+ 54 - 0
rigdos/INC.RIG

@@ -0,0 +1,54 @@
+#IN $A (. (* ( S'($$=$A) / RETURN T / ! $X ) *) .)
+    / RETURN NULL /
+##
+
+#PRESS_ENTER
+/ #REQUEST('Press ENTER to continue')/
+##
+
+#WRLIST 
+ (.(* #WRITELN *) .)
+##
+
+#WRITELN $
+ /#WRITE ($);#WRITE(#CHR(13));#WRITE(#CHR(10))/
+##
+
+
+#REQUEST /RETURN #CALL_PAS(1 $)/ ##
+#SCANER /RETURN #CALL_PAS(2 $)/ ##
+#COORD   /RETURN #CALL_PAS(4 $)/ ##
+#COORD_MESS / RETURN 
+  #IMPLODE (' AT LINE ' #COORD($) DIV 80 ' SYMBOL ' #COORD($) MOD 80 );/##
+#RUSS_IDENT /RETURN #CALL_PAS(5 $)/ ##
+#IS_RUSS_ID /RETURN #CALL_PAS(6 $)/ ##
+#RENAME_FILE $A $B /RETURN #CALL_PAS(7 $A $B)/##
+#DELETE_FILE /RETURN #CALL_PAS(8 $)/ ##
+#HEX_DUMP /#CALL_PAS (10 $)/ ##
+#NICE_PRINT / #CALL_PAS (12 $) / ##
+#NICE       / #CALL_PAS (13 $) / ##
+#RIGAL_SCANER / RETURN #CALL_PAS (14 $) /##
+#RIGAL_SCANER_NOINCL / RETURN #CALL_PAS (15 $) / ##
+#STRING_SCANER / RETURN #CALL_PAS (16 $) / ##
+#READKEY /RETURN #CALL_PAS(18) /##
+#RANDOMIZE /#CALL_PAS(19) / ##
+#RANDOM /RETURN #CALL_PAS(20 $) / ##
+#INT_STRING /RETURN #CALL_PAS(21 $) / ##
+#DELAY / #CALL_PAS(22 $) / ##
+#SOUND / #CALL_PAS(23 $) / ##
+#NOSOUND / #CALL_PAS(24) / ##
+#GOTOXY $X $Y/ #CALL_PAS(25 $X $Y) / ##
+#WINDOW $X1 $Y1 $X2 $Y2 /RETURN #CALL_PAS(26 $X1+$Y1*80 $X2+$Y2*80) / ##
+#TEXTATTR $B $F  / #CALL_PAS(27 $B*16+$F) / ##
+#CLREOL /#CALL_PAS(28 $) / ##
+#CLRSCR /#CALL_PAS(29 $) / ##
+--#WRITELN / #CALL_PAS(30 $) / ##
+#WRITE $A [$B] /RETURN #CALL_PAS(31 $A $B)/##
+#KEYPRESSED /RETURN #CALL_PAS(32) / ##
+#WHEREX  /RETURN #CALL_PAS(33) / ##
+#WHEREY  /RETURN #CALL_PAS(34) / ##
+#S_ADDR  /RETURN #CALL_PAS(40 $) / ##
+#S_SELF_ADDR /RETURN #CALL_PAS(41) / ##
+#PAGENUM /RETURN #CALL_PAS(42) / ##
+#PAGENUM_DISK /RETURN #CALL_PAS(43) / ##
+#SET_COORD $A $B/RETURN #CALL_PAS(44 $A $B) / ##

BIN
rigdos/INT.EXE


+ 71 - 0
rigdos/INTER.RIG

@@ -0,0 +1,71 @@
+-- interpreter for Prof. Blikle small language (SL)
+-- written in Riga 13.10.1989
+--     takes input from file EX1.TXT
+--
+#main
+     $token_list := #CALL_PAS(3  'ex1.txt' );
+-- reads token list
+   OPEN report ' ';
+   $abstract_syntax := #analyse_program( $token_list );
+   IF $abstract_syntax -> report <<' no errors in program ... ';
+                          #interpret_program ( $abstract_syntax )
+   ELSIF   T           -> report << 'an error is found ...' FI  
+##
+
+%INCLUDE ANALYSE.RIG
+#interpret_program
+-- has global variable $state
+     / $state := <. W: 1, V: 1, X: 1, Y: 1, Z: 1 .>/
+-- assigns initial values to variables
+      #interpret_stmt_list
+      / report << 'end of interpretation, the state is:';
+        PRINT $state /
+##
+
+#interpret_stmt_list
+         (. (* #interpret_stmt 
+--/ PRINT LAST #interpret_program $state /
+            *) .)  ##
+
+#interpret_stmt
+         ( #interpret_assignment  !  #interpret_while )  ##
+
+#interpret_assignment
+        'assignment_op' ::
+               <.  left_part: $var,
+                   right_part: $rez := #eval_expr .>
+        / LAST #interpret_program $state ++:=
+                         <. $var :  $rez .> /  ##
+
+#interpret_while
+        'while_op' ::
+               <.  condition: $rez := #eval_expr .>
+         / IF $rez = tt  ->  #interpret_stmt_list( $. body);
+                             #interpret_while( $)
+           ELSIF  $rez = ff  ->  RETURN finished
+           ELSIF  $rez = err  OR  #NUMBER( $rez) ->
+                  LAST #interpret_program $state . X := err
+           FI /   ##
+
+#eval_expr
+     $NUM  / RETURN $NUM / ;;
+
+     $Id / RETURN LAST #interpret_program $state . $Id /;;
+
+     '+' :: <. arg1: $val1 := #eval_expr,
+               arg2: $val2 := #eval_expr .>
+        / IF $val1 = err OR $val2 = err ->  RETURN err
+          ELSIF  NOT ( #NUMBER( $val1) AND #NUMBER( $val2) ) ->
+                     RETURN err
+          ELSIF $val1 + $val2 > 100 -> RETURN err
+          ELSIF  T  ->  RETURN $val1 + $val2
+          FI  / ;;
+
+     '<' :: <. arg1: $val1 := #eval_expr,
+               arg2: $val2 := #eval_expr .>
+        / IF $val1 = err OR $val2 = err ->  RETURN err
+          ELSIF  NOT ( #NUMBER( $val1) AND #NUMBER( $val2) ) ->
+                     RETURN err
+          ELSIF $val1 < $val2  -> RETURN tt
+          ELSIF  T  ->  RETURN ff        FI  /
+##

+ 1384 - 0
rigdos/LANGDESC.TXT

@@ -0,0 +1,1384 @@
+                       University of Latvia
+           Institute of Mathematcs and Computer Science
+
+
+
+
+                     RIGAL PROGRAMMING SYSTEM
+
+                     ========================
+
+
+                    FOR IBM/PC/XT/AT IN MS-DOS
+
+
+                       LANGUAGE DESCRIPTION
+
+
+
+                        by  M. I. AUGUSTON
+
+
+
+
+                         TABLE OF CONTENTS
+
+ ABSTRACT
+ 1. Introduction
+ 2. Implementation
+ 3. Lexical Rules
+ 4.   Data
+ 4.1 Atoms
+ 4.2 Variables
+ 4.3 Lists
+ 4.4 Trees
+ 5. Expressions
+ 5.1 Accumulative Assignment Statements
+ 5.2  Semantics of Variables
+ 6. Rules
+ 6.1. Simple Patterns
+ 6.2. Assignment in Patterns
+ 6.3 Rule Branches. Onfail Operations
+ 6.4 Special Variables
+ 7. Compound Patterns
+ 7.1 List Pattern
+ 7.2 Iterative Pattern of Sequence
+ 7.3 Patterns for Alternative and Option
+ 7.4 Tree Pattern
+ 7.5 Iterative Tree Pattern
+ 7.6 Names of Lists and Trees in Patterns
+ 7.7 Patterns of Logical Condition Testing
+ 8. Statements
+ 8.1 Assignment Statement
+ 8.2 Conditional Statement
+ 8.3 FAIL Statement
+ 8.4 Loop Statements
+ 8.5 Rule Call
+ 9. Input and Output
+ 9.1 SAVE and LOAD Statements
+ 9.2 Text Output
+ 10. Program Structure
+ 10.1 Local Variables
+ 10.2 References to Variables of Other Rules
+ 10.3 Attribute Grammars and RIGAL. Global Attributes
+ 11. Built-in Rules
+ 12. Sample Compiler
+ 12.1 TOYLAN Language
+ 12.2 Intermediate Form of Program.
+ Abstract syntax tree
+ 12.3 Target Language BAL
+ 12.4 Main Module of Compiler
+ 12.5 Parsing Phase
+ 12.6 Code Generation Phase
+ 13. Conclusions and Future Work
+ References
+
+
+                               ABSTRACT
+
+    A new programming language for compiler writing is described.
+The  main data structures are atoms, lists and trees. The control
+structures  are based on advanced pattern matching. All phases of
+compilation, including parsing, optimization and code generation,
+can  be  programmed  in this language in short and readable form.
+Sample compiler written in RIGAL is presented. 
+
+
+                         1. Introduction
+
+
+    Programming  language  RIGAL  is  intended  to  be a tool for
+parsing(  context  checking,  diagnosing  and  neutralization  of
+errors included ), for code optimization, code generation, static
+analysis   of  programs,  as  well  as  for  the  programming  of
+preprocessors and convertors. 
+    Almost   all   the   systems   envisaged  to  solve  compiler
+construction  problems  contain  means  to  describe context-free
+grammar of the source language. Earlier systems, like the Floyd -
+Evans  language,  [1]  present tools to work with stack, which is
+used for parsing. Parsing methods for limited grammar classes are
+implemented  in  the  languages  and systems of later generations
+(usually LL(1) or LR(1) ). 
+    Such systems as YACC (Johnson [2]), CDL-2 ( Koster [3]), SHAG
+(Agamirzyan   [4])  and  many  others  make  use  of  synchronous
+implementation  of  parsing  and  different  computations,  e.g.,
+formation of tables, context checking, etc. Usually these actions
+are  performed  by  call of semantic subroutines, written in some
+universal programming language ( e.g., in Pascal or C). 
+    Attribute   grammars  advanced  by  Knuth  [5]  have  greatly
+influenced  development  of  systems  for  compiler construction.
+Systems,  like,  SUPER  (Serebryakov  [6]), ELMA (Vooglaid, Lepp,
+Lijb  [7]),  MUG2 (Wilhelm [9]) are based on the use of attribute
+grammars not only for parsing, but for code generation as well. 
+    Pattern  matching  is  a  convenient  tool for programming of
+parsing,  optimization and code generation. The REFAL programming
+language  [10], acknowledged for translator writing, may serve as
+a good example. 
+    Vienna method for defining semantics of programming languages
+[11] suggests the usage of labelled trees in order to present the
+abstract   syntax  of  programs.  Representation  of  compilation
+intermediate  results  in  the  tree  form  has become usual (see
+[12]). 
+    Dependence  of  control  structures  in the program from data
+structures used for program's work is one of the basic principles
+in  programming. The recursive descent method could be considered
+to be the application of dependence principle. 
+    The above mentioned ideas and methods were taken into account
+when creating RIGAL language. 
+    The  language  possesses  few  basic notions. Data structures
+contain  atoms,  lists  and  trees. Advanced mechanism of pattern
+matching lies at the basis of control structures. 
+    The  fact  that  RIGAL  is  a  closed  language  makes  RIGAL
+distinctive.   That   means   that   almost   all  the  necessary
+computations and input-output could be executed by internal means
+and  there  is  no  need  to  use  external semantic subroutines.
+Therefore the portability of RIGAL programs to other computers is
+increased. 
+    Means  for  work  with  trees,  different patterns including,
+enable  both  programming  of parsing algorithms and optimization
+phases  and code generation as well. The language supports design
+of multipass translators. Trees are used as intermediate data. 
+    The  language  allows to split the program into small modules
+(rules)  and  presents  various  means  to arrange interaction of
+these modules. Pattern matching is used for parameter passing. 
+    RIGAL   supports   attribute   translation  scheme  and  easy
+implementation   of   synthesized  and  inherited  attributes  is
+possible.  The problem of global attributes is solved by usage of
+special references. 
+    Lexical  analysis  is  a  separate  task and requires special
+language  facilities  for  description  as it is, for example, in
+LEX/YACC  [2]  system. In the current implementation of RIGAL two
+scanners are included that accept lexics of Pascal and RIGAL. 
+
+
+                        2. Implementation
+
+    RIGAL was designed and implemented in the Computing Center of
+Latvia  University  in  years 1987-1988. The first implementation
+was for PDP-11 in RSX-11. 
+    At the present stage RIGAL interpreter has been developed and
+optimizing compiler RIGAL -> Pascal has been implemented by means
+of  RIGAL  itself.  The  interpreter  and  the compiler have been
+ported to VAX/VMS and IBM PC XT/AT (MS-DOS) environments. 
+
+
+                        3. Lexical Rules
+
+    The  text  of  RIGAL  program is a sequence of tokens - atoms
+(e.g.,  identifiers and integers ), keywords (e.g., if, return ),
+special  symbols  (e.g.,  +,  ##  ), names of variables and rules
+(e.g.,  $A,  #L  ).  Tokens  may  be  surrounded by any number of
+blanks.  A  comment is any string of symbols that begins with two
+consecutive  symbols  '-' (minus ). The end of the comment is the
+end of the line. For example, 
+ #Sum    -- rule for addition of two numbers
+      $N1   -- the first number
+      $N2   -- the second number
+    /  return  $N1 + $N2 /   -- return of the result
+ ##
+
+                            4.   Data
+
+                            4.1 Atoms
+
+    An  atom is a string of symbols. If the atom is an identifier
+(  the  first symbol is a letter followed by letters or digits or
+underscore  symbols),  in  the  text of RIGAL program it could be
+written directly: AABC total_number x25 
+    Numerical atoms are integers, for instance, 2, 187, 0, -25
+    In other cases the atom is quoted: '+'    ':='     '1st'
+    Some  identifiers  are reserved as keywords in RIGAL. If they
+are  used  as  RIGAL  atoms,  they should be quoted. For example,
+'if',  'return'.  Besides, any atom, which is an identifier, also
+can be quoted - ABC and 'ABC' represent one and the same atom. 
+    It  should be noted that 25 and '25' are different atoms, the
+latter is just a string of symbols '2' and '5'. 
+    Two special atoms are distinguished in the language.
+    NULL  -  this  atom  is  frequently  yielded  as  a result of
+different  operations,  if something was incorrect in the process
+of  computations.  This  atom  also  represents an empty list, an
+empty tree and Boolean value "false". 
+     T  -  usually this atom is yielded by logical operations and
+represents value "true". 
+
+                          4.2 Variables
+
+    The name of a variable must begin with the symbol $, followed
+by  an  identifier.  Value  can  be  assigned  to a variable, for
+example, by the help of assignment statement: $E := A 
+    In this case the atom A becomes value of the variable $E.
+    In  RIGAL variables have no types, the same variable may have
+an atom, a list or a tree as a value in different time moments. 
+
+                            4.3 Lists
+
+    Ordered sequences, i.e., lists can be composed from atoms and
+from  other  lists  and trees, as well. A special function - list
+constructor  serves for list formation. For instance, (. A B C .)
+forms a list of three atoms A, B and C. 
+    Arguments  of  the  list  constructor may be expressions. The
+sample  $E  := (. (. 8 14 7 .) (. A B .) .) could be rewritten as
+follows: 
+  $A := (. 8  14  7 .); $B := (. A  B  .); $E := (. $A  $B .);
+    Separate  elements  of  the list can be selected by indexing.
+Hence, $B [1] is atom A, $A [2] is atom 14, $E [2] is list 
+ (. A B .), but $E [10] is atom NULL
+    If  the value of the index is a negative number, for instance
+-N, then the N-th element, beginning from the end of the list, is
+selected. For example, $A [-1] is atom 7. 
+    The  necessity  to  add one more element to the list is quite
+common. Operation !. is envisaged for this purpose. 
+    Example. (. A  B .) !. C  yields the list (. A  B  C .)
+    To link two lists in a new list the operation !! is applied (
+list  concatenation). For instance, (. A B .) !! (. C D .) yields
+(. A B C D .). 
+
+                            4.4 Trees
+
+    Tree constructor is used to create a tree. For example,
+                      <.  A : B,  C : D  .>
+    One  can  imagine  tree  as  a graph, the nodes and arches of
+which are marked by some objects. 
+    Objects   before  ':'  in  the  tree  constructor  are  named
+selectors.  In  the  given implementation solely atoms, which are
+identifiers  (  except  NULL  ),  may  serve as selectors. In the
+graphical  representation  selectors  correspond to arches of the
+graph.  All  selectors of one and the same level in the tree must
+be different. 
+    Any  object  -  atom,  list  or  tree,  except atom NULL, may
+correspond  to  terminal  nodes  of  the  graph ( "leaves" of the
+tree). Hence, multilayer trees can be built. For instance, 
+              <. A : B,  C : <. D : E, F : G .> .>
+    Pair  "selector  : object" in the tree is named branch of the
+tree. Branches are unordered in the tree. 
+    Likewise  for  the list constructor, the tree constructor may
+be  described  by  expressions  (  in  both  selector  and object
+places),  for instance, $X := D; $B := (. 2 8 .); $C := <. A : <.
+M : K .>, $X : '+' , E : $B .>; 
+    Select  operation serves to extract the tree component. It is
+in the following form: tree . sel , where tree is the expression,
+whose  value  must be some tree, but sel is the expression, whose
+value must be an atom-identifier. 
+    Consequently,  $C . A is the tree <. M : K .> , $C . D is the
+atom '+' , $C . E is the list (. 2 8 .) , $C . E[2] is the atom 8
+, $C . A . M is the atom K 
+    If there is no branch with a given selector in the tree, then
+the result is NULL: $C . W is atom NULL. 
+    Operation  of the tree "addition" is performed as well: T1 ++
+T2 , where T1 and T2 are trees. Tree T2 branches are added to the
+tree  T1  one  by  one.  If in the tree T1 there already exists a
+branch with the same selector, the branch is substituted by a new
+one. Therefore, the operation "++" is not commutative. 
+    It  should  be  pointed  out  that  the  tree  constructor is
+computed  from  left to right, i.e., <. s1 : a1, s2 : a2, s3 : a3
+.> gives the same result as the expression 
+  (( NULL ++ <. s1 : a1 .> ) ++ <. s2 : a2 .>) ++ <. s3 : a3 .>
+
+                         5. Expressions
+
+    Operations  = and <> serve for the comparison of objects. The
+result of the comparison is either T ("true") or NULL ("false"). 
+    Atoms  are  matched directly, for instance, a = b gives NULL,
+25 = 25 gives T, 17 <> 25 gives T. 
+    Lists  are  considered equal iff they contain equal number of
+components and if these components are equal respectively. 
+    Trees  are  considered equal iff they contain equal number of
+branches  and  if  one of the trees contains the branch "S : OB",
+then  the  other tree also contains the branch "S : OB1" and OB =
+OB1. 
+    Arithmetical  operations  +,  -, *, DIV, MOD are assigned for
+numerical  atoms.  The  essence of these operations is similar to
+those  in  Pascal.  The  result of an arithmetical operation is a
+numerical  atom.  Atom  NULL  is also admitted as the argument of
+arithmetical  operation, in this case integer 0 is supposed to be
+its  value.  Under matching these atoms are considered different,
+i.e., NULL = 0 gives NULL. 
+    Besides  the  operations  =  and <> numerical values could be
+compared by the help of >, <, >= and <=. 
+    Logical  operations AND, OR and NOT usually are applied under
+conditions  in  conditional  statements.  Their  arguments may be
+arbitrary  objects.  If  the  object  differs  from  NULL,  it is
+supposed  to  have  the value "true" in a logical operation. Atom
+NULL  represents  the  "false"  value.  The  result  of a logical
+operation always is either T or NULL. 
+    In order to make complex hierarchic objects ( trees and lists
+of  complex  structure  )  more visual and to improve the work of
+pattern  matching,  trees and lists may be labelled. A name is an
+atom  opposed  to  the  root  node of the tree or the whole list.
+Labelling operation is written the following way: 
+                             A  ::  OB where A is an atom , OB is
+an object (a tree or a list). For example, Add_op :: <. arg1 : 5,
+arg2 : 4 .> 
+    The  execution  order  of  operations  in  the  expression is
+controlled  by  parentheses  "(" and ")". Priority is assigned to
+every  operation,  and,  if the execution order is not defined by
+parentheses,   operations   are   executed   according  to  their
+priorities  -  beginning  with  the  higher and proceeding to the
+lower. 
+    Operations are listed in decreasing order of priorities (some
+operations will be discussed later). 
+  1) Rule call, list constructor, tree constructor, last
+  2) Selector ".", index "[]",  ::
+  3) NOT, unary -
+  4) *, DIV, MOD
+  5) !. , !! , ++ , +, binary -
+  6) = , <> , > , < , >= , <=
+  7) AND
+  8) OR
+    Binary operations of the same priority are executed from left
+to right, while unary operations from right to left. 
+
+
+             5.1 Accumulative Assignment Statements
+
+    It is quite often that working with a list or a tree elements
+are  added  step  by step, thus the growing object is retained in
+the  same  variable. Therefore short form of assignment statement
+has  been  introduced.  For  the  operations  !.  , !! , ++ and +
+statements of the form $X := $X op Expr can be written as 
+ $X op := Expr .
+
+
+                   5.2  Semantics of Variables
+
+    In  the  implementation of RIGAL every object - atom, list or
+tree  has  a  descriptor.  It  is  a  special data structure that
+contains  some  information about this object: the value of atom,
+the  number  of  elements  and pointers to elements for lists and
+trees. Variables have pointers to object descriptors as values. 
+    Statement  $X  :=  OB assigns to the variable $X a pointer to
+the descriptor of object OB. After the execution of the statement
+$Y  :=  $X  both variables $X and $Y contain pointers to the same
+object OB. 
+    Operations  !.:=  , !!:= , +:= and ++:= change the descriptor
+of  their  first argument, i.e., have a side effect. Sometimes it
+can be undesirable. For example, 
+            $A := (. 3 17 .); $B := $A;  $B  !.:= 25;
+    The  value  of  $B  becomes list (. 3 17 25 .), but operation
+!.:= has added element 25 immediately to the list (. 3 17 .), and
+the  descriptor  of  this  list  is  changed. As the value of the
+variable  $A  was  a  pointer  to this descriptor, then after the
+execution  of  the statement $B !.:= 25 the value of the variable
+$A is changed, too. 
+    To  prevent this, we must have a copy of the object, to which
+$A refers to before assigning it to $B. Built-in rule #COPY( OB )
+is  used  for  this purpose. It makes a copy of the descriptor of
+the object OB. 
+    Now  we can write a "safe" call of the operation !.:= in such
+a way: $A := (. 3 17 .); $B := #COPY( $A); $B !.:= 25; 
+    As  a result $B takes the value (. 3 17 25 .), but $A remains
+equal  to  (.  3  17  .).  The  same effect can be obtained after
+execution of statements $A := (. 3 17 .); $B := $A !. 25; 
+
+
+                            6. Rules
+
+    The concept of rule is analogous to concepts of procedure and
+function in conventional languages, such as Pascal or C. 
+    First  of all, by the help of a rule we can check, whether an
+object  or  a sequence of objects complies with some grammar. For
+this  purpose  rule  has  a pattern. Objects, assigned under rule
+call  (arguments  of  the rule), are matched with the pattern. If
+there  is  a  necessity,  some  operations could be executed, for
+instance,     computations     and    input-output    operations,
+simultaneously with rule arguments and pattern matching. 
+    Rule  that  is  called can compute and return back some value
+(object),i.e., it can be used as function. 
+    Depending  on  the  result  of  rule  arguments  and  pattern
+matching,  the  rule  call ends with success or failure. Thus the
+rule call could be used in another rule patterns. 
+
+
+                      6.1. Simple Patterns
+
+    Definition of the rule begins with the indication of the name
+of   the   rule   in   the  form  of  #LLL  ,  where  LLL  is  an
+atom-identifier. In the most common case the pattern is indicated
+after  the  name  of  the  rule. Rule definition ends with symbol
+'##'. For instance, 
+ #L1    A  B   ##
+    In  this  case the pattern consists of atoms A and B. Call of
+the rule #L1 takes place, for instance, the following way : 
+                          #L1 ( A  B )
+    The  sequence of objects - atoms A and B, is assigned as rule
+arguments. 
+    After rule call the argument and pattern matching begins. The
+first  argument - atom A is matched with the first pattern, which
+is  also  an  atom.  These  atoms are equal, so their matching is
+successful.  After  that  the  next  object  from the sequence of
+arguments  -  atom  B  and  the  next  pattern,  also atom B, are
+matched.  Their  matching is also successful, therefore, the call
+of the rule #L1 is successful, too. 
+    #L1(  A  C ) call fails, because the second argument - atom C
+was not successfully matched with the pattern - atom B. 
+    #L1(  A  )  call  fails, as there is no object for the second
+pattern with which it could be matched successfully. 
+    But  #L1(  A  B  C)  call  is  successful,  as the third rule
+argument - atom C was not demanded by any pattern and matching of
+the first two rule arguments was successful. 
+    Arbitrary  atoms,  both  non-numerical  and numerical, may be
+described as patterns. 
+    Such  operations as assignment statements, input - output and
+others  may be indicated before the pattern, after it and between
+patterns.  These statements are quoted in the pair of symbols '/'
+.  If there is a necessity to write several statements within the
+pair '/' , these statements are separated by the symbol ';' . 
+    A  group  of  statements  is executed in the rule pattern, if
+matching  of  the  previous  pattern  with the corresponding rule
+arguments was successful. 
+    The  value  returned  by  the rule is worked out by statement
+return   .   It   has  the  following  form:  return  expression.
+Simultaneously  this  statement  completes  the  execution of the
+rule. 
+    Example.
+ #L2  'begin'  'end'  / return  'The pair begin-end' /  ##
+    Rule call is illustrated in the following example.
+ $A   :=   #L2   (   'begin'  'end'  );  As  a  result  the  atom
+'Thetpairtbegin-end' is assigned to the variable $A. 
+    If  return  statement  is not described in the rule, then the
+NULL value is returned. 
+    If  the rule call ends in failure, then usually value NULL is
+returned, although in case of failure, it is possible to work out
+the returned value, which is not NULL; for this purpose statement
+return must be used in onfail-operations (see sect.6.3.). 
+    Variable  could  be  used  as pattern. It is matched with one
+object  (atom, list or tree) from the sequence of rule arguments.
+Matching  always  ends  in  success,  and  as  a  side effect the
+variable  obtains  this object as value. For example, #L3 $A $B /
+return (. $B $A .)/ ## 
+    After  the  call  $X := #L3 ( 1 2) the variable $X obtains as
+value (. 2 1 .) 
+    The  rule  pattern,  in  its  turn,  may  refer  to some rule
+(recursively,  as well). Then the subsequence of the calling rule
+arguments  become arguments of rule - pattern. If the call of the
+rule  -  pattern is successful, then matching of further patterns
+of the calling rule with the remaining arguments proceeds. If the
+call  of  the  rule - pattern fails, then the pattern matching of
+the calling rule fails, too. For example, 
+ #L4   A  #L5  D  ##
+ #L5   B  C       ##
+    Then the call #L4( A B C D) is successful, but the call
+ #L4( A E F D) is unsuccessful.
+    There  is  a  number  of  built-in rules in the language (see
+section  11.). For instance, #NUMBER is successfully matched with
+a  numerical atom and returns it as a value, other arguments fail
+and  return  NULL.  #IDENT  is  successfully  matched with atom -
+identifier and returns it as value. 
+
+
+                   6.2. Assignment in Patterns
+
+    Every   pattern,   when   successfully   matched   with   the
+corresponding  rule  argument,  returns  some value. The value of
+atom  pattern  coincides  with  this  atom, the value of variable
+pattern  coincides  with the value obtained by this variable as a
+result  of matching with the arguments. The value of rule pattern
+is defined by statement return in this rule. 
+    If  the matching ends in failure, the pattern usually returns
+value NULL. 
+    These  values,  returned by patterns, can be assigned at once
+to  some variable. It is enough to write the name of the variable
+and the assignment symbol ':=' before the pattern element. 
+ Example.
+ #L6   $A  $R := #L7  / return  (. $A .) !! $R /  ##
+ #L7   $B  $C   / return  (.  $B  $C .) /   ##
+    After execution of the statement $X := #L6 ( 1 2 3) the value
+of $X will be (. 1 2 3 .) 
+    Symbols  of  accumulative assignment '!.:=' , '!!:=' , '++:='
+and '+:=' can be used instead of ':=' in patterns . 
+    Therefore,  we can rewrite the previous example the following
+way: 
+ #L6_1  $R !.:= $A    $R !!:= #L7_1  / return  $R /  ##
+ #L7_1  $M !.:=  $B   $M !.:=  $C    / return  $M /  ##
+    It  should  be  noted  that  all  variables  in  the rule are
+initialized by value NULL, so the value of the expression NULL !.
+$A  that equals to (. $A .) is assigned to the variable $R by the
+first application of the pattern $R !.:= $A in #L6_1. 
+    Patterns  of the type $N := #NUMBER or $ID := #IDENT are used
+very  often,  therefore, following defaults are introduced in the
+language.  If  the  first  letter of the variable name is N, then
+this  variable,  having been used as pattern element, will have a
+successful  matching  only  with a numerical atom, in other cases
+matching ends in failure, and variable obtains value NULL. If the
+first  letter  of the name of the variable is I, this variable is
+matched successfully only with an atom-identifier. 
+
+
+              6.3 Rule Branches. Onfail Operations
+
+    Several groups of patterns may be united in one rule.
+    The  first group of patterns is applied to the rule arguments
+first.  If  matching of this group of patterns with the arguments
+is  successful,  the rule call is successful. But if matching has
+failed, transition to the next group of patterns takes place, and
+it  is  matched  with  the  same arguments. It goes on until some
+group   of   rule   patterns   is   matched  with  the  arguments
+successfully.  If not a single pattern group matches successfully
+with rule arguments, the rule call ends in a failure. 
+    Such  alternative  pattern  groups  are called rule branches,
+and,  when  writing  the  rule,  they are separated by the symbol
+';;'. 
+    If  the  branch  fails,  the  execution  of  its patterns and
+statements  is  abandoned  at  the  place,  where  branch pattern
+failed,  and  control is transferred to the next branch (if there
+is  one)  or  the  whole rule fails (if the current branch is the
+last  one  in  the rule). Still there is a possibility to execute
+some operations before exit from the branch. 
+    ONFAIL  operation is a sequence of statements, written at the
+end  of  the  branch  and  delimited  from  patterns  and  branch
+statements by keyword ONFAIL. 
+    If  ONFAIL-statements  are  described  in the branch, then in
+case  of  branch  failure,  control  is  transferred  to them and
+statements,  given  in ONFAIL-unit , are executed. So, in case of
+branch failure, causes of failure can be analyzed and message can
+be output. Statement return can be executed in ONFAIL operations,
+as  well. Then exit from the rule takes place (with failure), and
+some other value than NULL can be returned. 
+
+
+                      6.4 Special Variables
+
+    Special  variable  without  name  $  denotes  the  first rule
+argument matched by a rule pattern. 
+    The  value  of  special  variable  $$  equals to the value of
+current rule argument, to which current rule pattern is applied. 
+
+
+                      7. Compound Patterns
+
+    Lists,  sequences  of  elements  in  lists  and  trees can be
+analyzed   by   patterns.  Nesting  of  patterns  practically  is
+unlimited.  It  is allowed to insert statements before, after and
+within any pattern. 
+
+                        7.1 List Pattern
+
+    List pattern is written in the rule the following way:
+                    (.  S1 S2 ... SN .) where S1, S2, ..., SN are
+patterns . For instance, 
+ #L8  (. $E1  $E2 .)  ##
+    Pattern  of  the  rule  #L8  is matched successfully with any
+list, containing precisely two elements. Such call is successful: 
+ #L8( (. (. 1  2 .)  <. A : B .> .) )
+    But  the following calls end in failure. #L8( A B ) - because
+pattern will be applied to the first argument, i.e., to atom A. 
+ #L8(  (. 13 .) )  -  because the argument is one element list.
+    In  case of success the list pattern yields value that can be
+assigned  to  some  variable. This value coincides with the whole
+list, to which the pattern was applied. 
+
+
+                7.2 Iterative Pattern of Sequence
+
+    In  RIGAL  the  following  pattern  is  defined  for sequence
+recognition:  (*  S1 S2 ... SN*) , where S1 , S2, ... SN are some
+patterns.  This  pattern  describes  the  repetition  of enclosed
+sequence of patterns zero or several times. 
+    Rules  with  a variable number of arguments can be defined by
+iterative pattern of sequence. For example, 
+ #Sum  (*   $S +:= $N   *)  / RETURN $S /  ##
+    This rule is used for summing up any amount of numbers.
+ #Sum( 2  5  11) = 18  and  #Sum( 3 ) = 3
+    Iterative pattern is very often used within list pattern. For
+instance, the following rule counts the number of list elements. 
+ #Length (. / $L := 0 / (*  $E / $L +:= 1 / *) .) / RETURN $L / ##
+    Samples of rule call.
+ #Length( (. A  B  C .) ) = 3  and  #Length( NULL ) = 0
+    Iterative  pattern  (+  S1  S2  ... SN +) is analogous to the
+pattern (* ... *), but assigns the repetition of enclosed pattern
+sequence one or several times. 
+    In the iterative pattern of sequence the element delimiter is
+indicated  in  the form of (* S1 S2 ... SN * Delimiter ) or (+ S1
+S2 ... SN + Delimiter +) 
+    Atom or name of the rule may serve as Delimiter .
+    Example.  Analysis  of  a  simple  Algol-like  declaration. A
+fragment  of variable table coded in a tree form is returned as a
+result. #Declaration $Type := ( integer ! real ) 
+               (+ $Id  / $Rez ++:= <. $Id : $Type .> /  + ',')
+        / RETURN $Rez /   ##
+    Call #Declaration ( real X ',' Y ) returns value
+                    <. X : real, Y  : real .>
+    It  should  be  noted  that the pattern (* $E * ',' ) differs
+from  the  pattern (* $E ',' *) in the point that the presence of
+atom  ','  is  obligatory  in  the  second  pattern at the end of
+sequence. 
+
+
+
+             7.3 Patterns for Alternative and Option
+
+    The  choice  of  several  possible  patterns  is  written the
+following way: ( S1 ! S2 ! ... ! SN ) 
+    Patterns  S1 , S2 , ... , SN are applied one by one from left
+to right, until one of them succeeds. 
+    In  case  of  success  alternative  pattern  yields value. It
+coincides  with  the  value  of the successful pattern within the
+alternative and may be assigned by some variable. 
+    Example.   Simple   arithmetic   expression   parsing.   When
+successful, an expression tree is returned, which can be regarded
+as an intermediate form for the next compilation phases. 
+ #Expression     $A1 := #Term
+        (* $Op := ( '+' ! '-' )  $A2 := #Term
+           / $A1 := <. op : $Op , arg1 : $A1 , arg2 : $A2 .> / *)
+        / RETURN $A1 /   ##
+ #Term   $A := ( $Id  ! $Num ) / RETURN $A /  ;;
+        '('  $A := #Expression ')'  / RETURN $A /   ##
+    The call #Expression( X '-' Y '+' 7 ) returns the value
+  <. op: '+', arg1: <. op: '-', arg1: X, arg2: Y .>, arg2: 7 .>
+    In  RIGAL  we may write a rule that matches successfully with
+an empty sequence of arguments: #empty ## 
+    Now the pattern for option can be written down: ( S ! #empty )
+    In  short  form  this  issue may be written down in RIGAL the
+following way: [ S ] where S is some pattern or pattern sequence.
+Pattern [ S ] always ends in success. 
+
+
+                        7.4 Tree Pattern
+
+    Tree  pattern checks, whether the object is a tree with fixed
+structure.  By  means of this pattern access to the components of
+the tree is obtained. The tree pattern is described the following
+way: 
+       <.  Sel1  :  Pat1, Sel2 : Pat2, ... , SelN : PatN .> where
+Sel1,  Sel2,  ... SelN are atoms-identifiers, but Pat1, Pat2, ...
+PatN are patterns. 
+    If the object, to which the tree pattern is applied, is not a
+tree, then the application of the pattern fails at once. If there
+is  the  selector  Sel1  in  the  tree,  then the pattern Pat1 is
+applied to the corresponding object. If there is no selector Sel1
+in  the  tree  or  the  application of Pat1 has failed, the whole
+pattern also fails. 
+    If  matching the first branch was successful, branch matching
+of the pattern 'Sel2 : Pat2' , etc. begins. 
+    Hence,  pattern  branches are applied to the tree in the same
+order as they are written in the pattern. Therefore, the order of
+tree  traversing  may  be  controlled.  It  is  possible  to have
+reiterative  visit  of  branches  (  if  selectors are repeatedly
+described  in  the  tree  pattern)  or  omission  of branches (if
+corresponding selectors are not given in the pattern). 
+    In  case of success the tree pattern returns the value, which
+coincides  with  the  whole object - a tree, to which the pattern
+was  applied,  irrespective  of presence of all tree selectors in
+the pattern or absence of some. 
+    Example.  Let us suppose expression tree to be formed like in
+the  above example. The task is to traverse the tree and return a
+list that represents the Polish postfix form of this expression. 
+ #Postfix_form  <. arg1: $Rez := #Postfix_form,
+                  arg2: $Rez !!:= #Postfix_form,
+                  op:   $Rez !.:= $Op  .>   / RETURN $Rez /  ;;
+               $Rez := ( $Id ! $Num )  / RETURN (. $Rez .) /  ##
+    The  call  #Postfix_form(  <.  op: '-', arg1: X, arg2: <. op:
+'+',  arg1:  Y, arg2: 5 .> .>) returns the value (. X Y 5 '+' '-'
+.) 
+    Some  branches  in  the  tree  pattern  may  be  described as
+optional,  in this case they are enclosed in brackets '[' and ']'
+.  If  there  is  no  selector of optional branch in the argument
+tree,  its  pattern  is  omitted  and  transition to next pattern
+branch  takes  place.  If  there is a selector of the type in the
+argument tree, the pattern branch is developed as usual. 
+
+
+                   7.5 Iterative Tree Pattern
+
+    The simplest form of iterative tree pattern is the following:
+                        <*  $Var  :  P  *>  where  $Var  is  some
+variable, and P is a pattern. 
+    A  loop  over  the  tree  is  performed  by  the help of this
+pattern.  All  selectors of the argument tree are assigned to the
+variable  $Var  one  by  one.  The  pattern  P is applied to each
+object,  which  corresponds  in  the argument tree to the current
+selector  in  the  variable  $Var. If even one application of the
+pattern  P  fails,  the  whole  iterative tree pattern fails. For
+example, 
+ #Variable_table  <* $Id : $E := ( integer ! real )
+                   / $R !.:= (. $Id  $E .)/  *>  / RETURN $R /  ##
+ Call example.
+ #Variable_table( <. X : integer, Y : real, Z : real .> ) =
+    (. (. X  integer .) (. Y  real .) (. Z  real .)  .)
+    Sometimes,  performing  a  loop  over the tree, some branches
+should  be  updated  in a special way. For this purpose iterative
+tree pattern with distinguished branches is used. 
+   <*  Sel1  :  Pat1,  Sel2 : Pat2, ..., SelN : PatN, $Var : P *>
+where Sel1, Sel2, ... SelN are atoms-identifiers; Pat1, Pat2, ...
+PatN  are  patterns,  i.e., like elements in simple tree pattern;
+$Var  is  a  variable,  but  P is a pattern, as in simple case of
+iterative tree pattern. 
+    The  pattern  is  applied  to the argument tree the following
+way.  First of all distinguished pattern branches 'Sel : Pat' are
+developed.  Their  matching  with  branches  of the argument tree
+happens  exactly  the  same way as with simple tree pattern. Then
+the  element  '$Var  :  P'  is  applied  to other branches of the
+argument tree the same way as in simple iterative tree pattern. 
+    Some distinguished branches can be optional, for this purpose
+they  are enclosed in brackets '[' and ']'. Semantics is the same
+as in the case of simple tree pattern. 
+    Example.  Let  it be a tree of arbitrary size. In some of its
+subtrees  there is the selector LABEL, to which numerical atom is
+attached. All these numbers over the whole tree must be collected
+in a list, and the list must be returned as result. #Label_list 
+ <*  [ LABEL : $Result !.:= $N ],
+        $S   : $Result !!:= #Label_list  *> / RETURN  $Result / ;;
+    $E            ##
+    The  rule  has  two  branches. Traversing of the tree and its
+subtrees  is described in the first branch. The resulting list is
+formed  in  the  variable  $Result. The traversing of subtrees is
+carried   out   by  the  help  of  recursive  call  of  the  rule
+#Label_list. The second branch of the rule consisting of just one
+pattern  $E  is  applied  at  the leaves of the tree. The pattern
+matches successfully with any object and the whole branch returns
+value NULL, which is accepted as empty list at the previous level
+of recursion. 
+    Call  sample.  #Label_list  (  <.  A: <. LABEL: 5, B: abc .>,
+LABEL: 17, D: 25 .> ) = (. 17 5 .) 
+
+
+            7.6 Names of Lists and Trees in Patterns
+
+    The assignment of names was discussed in Section 5.
+    In  list  and  tree patterns we can have matching of list and
+tree names with the described values or simply get these names in
+the  described  variable.  For  this  purpose  the  name  may  be
+indicated before list or tree pattern: atom :: pattern 
+    If  the atom described in the pattern coincides with the name
+of  the  list  (or  tree),  to  which the pattern is applied, the
+application  of  the  pattern  to the argument begins. If it does
+not,  other  pattern  elements  are  not  applied and the pattern
+fails. 
+    To obtain access to the name of the argument, instead of atom
+we  must  indicate the variable, in which the name is assigned as
+value. 
+
+
+            7.7 Patterns of Logical Condition Testing
+
+    Pattern  of  the  type: S' ( expression ) works the following
+way.  First  of  all  the  expression  is evaluated. If its value
+differs  from  NULL,  the pattern is successful. The value of the
+matched  argument  is  returned  as  the value of the pattern, if
+matching was successful. If the value of the expression equals to
+NULL, the pattern fails and returns NULL. 
+    The  value  of  special  variable  $$  in  the  expression of
+S-pattern equals to the value of the argument, to which S-pattern
+is applied. 
+    The  skip  of  token sequence until the nearest symbol ';' is
+described by the pattern: (* S' ( $$ <> ';' ) *) 
+    Let  under  parsing a case is accentuated when the assignment
+statement  is  in the form of X := X + E , where X is a variable,
+and  E  is an expression. This case could be described by pattern
+of the type: $Id ':=' S' ( $$ = $Id ) '+' #Expression 
+    Pattern  of  the  type:  V'  (  expression ) works similar to
+S-pattern, yet in case of success no advancing along the sequence
+of  rule  arguments  takes  place, so the next pattern element is
+applied to the same argument. 
+    This  pattern is useful for context condition check. Example.
+The pattern S' ( #NUMBER($$) and ( $$ > 7)) may be substituted by
+a sequence of patterns $Num V'($Num > 7) 
+
+
+                         8. Statements
+
+                    8.1 Assignment Statement
+
+    In  the  left  side of assignment statement a variable may be
+indicated,  which  is  followed  by  an  arbitrary number of list
+indexes and/or tree selectors. For example, $X := (. A B C .); $Y
+:= <. D : E, F : G .>; 
+    After assignment $X[2] := T  the value of $X is (. A T C .) .
+    After assignment $Y.D :=17 the value of $Y is <.D :17, F:G .>
+    The  execution of the statement $Y.A := T yields the run time
+error  message.  The  necessary  result is obtained the following
+way: 
+ $Y ++:= <. A : T .>;
+    Tree  branch  is  deleted by assigning an empty object to the
+corresponding selector: $Y.D := NULL; 
+
+                  8.2 Conditional Statement
+
+   Conditional statement has the following form:
+                 IF  expression  ->  statements Then branches may
+follow (it is not compulsory) 
+                ELSIF   expression   ->   statements  Conditional
+statement ends with keyword FI. 
+    In  conditional  statement  branches expressions are computed
+one  by  one, until a value different from NULL is obtained. Then
+the statements described in this branch are executed. 
+
+
+                       8.3 FAIL Statement
+
+    FAIL statement finishes the execution of the rule branch with
+failure.  Example.  In order to repair errors in parsing process,
+the  sequence  of  tokens should be skipped quite frequently, for
+instance, until semicolon symbol. It is done the following way. 
+ #statement    ...            ;; -- branches for statement analysis
+    (*  #Not_semicolon   *)   ';'   -- no statement is recognised
+ ##
+ #Not_semicolon   $E / IF  $E = ';' -> FAIL  FI/   ##
+
+
+                      8.4 Loop Statements
+
+    Statement of the types
+         FORALL $VAR  IN expression
+            DO  statements  OD
+         FORALL SELECTORS $VAR BRANCHES $VAR1 IN expression
+            DO  statements  OD
+         FORALL BRANCHES $VAR1 IN expression
+            DO statements OD loops over a list or a tree. 
+    The  value of the expression must be either a list or a tree.
+Value  of the current list element (if the loop is over the list)
+or  value  of the current selector (if the loop is over the tree)
+is   assigned   to  the  loop  variable  $VAR  one  by  one.  The
+corresponding  branch value is assigned to the variable $VAR1 (if
+the  loop  is  over the tree). Statements, describing body of the
+loop, may use the current value of the variables $VAR and $VAR1. 
+
+    LOOP statement of the type
+                     LOOP  statements  END; repeats statements of
+the  loop  body,  until  one of the statements - break, RETURN or
+FAIL is not executed. 
+
+
+                          8.5 Rule Call
+
+    If  a  rule is called just to execute statements described in
+it,  and  value  returned  by the rule is not necessary, the rule
+call  is  written down as statement. It is analogous to procedure
+call in traditional programming languages. Success/failure of the
+rule and value returned by it is disregarded in such a call. 
+
+
+                       9. Input and Output
+
+                 9.1 SAVE and LOAD Statements
+
+    Objects created by RIGAL program (atoms, lists, trees) can be
+saved in the file and loaded back to the memory. 
+    Statement  SAVE  $Var  file-specification unloads the object,
+which  is  the  value  of  the variable $Var to the file with the
+given  specification.  File,  formed  by SAVE statement, contains
+precisely one object (atom, list or tree). 
+    We  can  load  the  object from the file in the memory having
+executed statement: LOAD $Var file-specification 
+
+
+                         9.2 Text Output
+
+    To  output  texts  (messages,  generated object codes, etc. )
+several  text  files can be opened in the RIGAL program. The text
+file  FFF  is  opened  by  statement: OPEN FFF file-specification
+File-specification  may be an expression. It presents the name of
+the file on the device. 
+    Statement of the type
+                FFF  <<  Expr1 Expr2 ... ExprN outputs a sequence
+of atoms to the file FFF. Values of expressions Expr1, Expr2, ...
+are  either  atoms or lists consisting of objects, different from
+trees. 
+    This  statement  outputs atoms as sequences of symbols to the
+text  file, inserting a blank after every atom. Atoms in the list
+are output in the same order as they are in the list. 
+    Example.   FFF <<  A B 12 ;
+    A  string  of  characters  is output in the text file FFF the
+following way: "A B 12 " 
+    Symbol  @  in the sequence of expressions of output statement
+switches over to other output mode of blanks separating atoms. By
+default  at  the  beginning of execution of text output statement
+the output mode with blanks is on. 
+    Example.   FFF << A B  @  C D  25  @  E F 57 ;
+    The following string of characters is output to the text file
+                      "A B CD25E F      57"
+    Statement  of  the  type FFF << ... always begins output with
+the  beginning  of a new record. Output statement of the type FFF
+<] ... continues output in the current record. 
+
+    By the help of the statement of the type
+
+                        PRINT  expression the value of atom, list
+or  tree can be output in a readable form on the display, disk or
+on the printer. It is useful when debugging RIGAL programs. 
+
+
+                      10. Program Structure
+
+    Program  written  in  the RIGAL language consists of the main
+program and rules. The main program text must be at the beginning
+of  the  RIGAL program text, but the text of the rules is written
+afterwards.  Main  program,  as  well as rule, begins by the name
+indication in the form of #main_program_name, then statements are
+described, separated by symbols ';' . The end of the main program
+is marked by the symbol '##'. 
+    Usually operations that deal with the initial object loading,
+rule  call  and  unloading  of  created  objects in the files are
+concentrated  in the main program. Therefore, main program has no
+pattern elements or arguments of its own. 
+    When  RIGAL  is  used  for  parsing, text file with the input
+information first is updated by scanner, which transforms it into
+a  list  of tokens. Thus rules describing required parsing can be
+applied  to this list. Intermediate results of the RIGAL program,
+for  instance,  abstract  syntax trees obtained by parsing can be
+unloaded  in  the  file  by  the help of SAVE statement. They are
+unloaded  so,  that  other  RIGAL  programs (for instance, those,
+which  implement  phase of code generation in compilers) can load
+them  as  input  data. Sample of main program is given in Section
+12.4. 
+    Rules can be written down after main program  in  any  order.
+
+
+                      10.1 Local Variables
+
+    There are no special variable declarations in RIGAL. The fact
+that  a variable is used in some statement, pattern or expression
+implies  that  the  variable  is defined as local variable of the
+rule or the main program. 
+    For recursive rule calls local rule variables are pushed in a
+stack,  so,  that  every  active rule instance has its own set of
+local variables. 
+    All  variables  are  initialized  by the NULL value, when the
+corresponding  rule  or  the  main program is called and when the
+execution of rule branch starts. 
+
+           10.2 References to Variables of Other Rules
+
+    The  construction of RIGAL makes it possible to obtain access
+from  the  rule  to  local  variables of another rule. It has the
+following form: LAST #L $X 
+    This  reference  denotes  the value of the variable $X in the
+last  (in  time  ) and still active instance of the rule #L. Such
+references  can  be  used  in  left and right sides of assignment
+statement. 
+    If  at  the moment of evaluation of the expression LAST #L $X
+there  is  no  active  instance  of the rule #L, the value of the
+expression  LAST  #L $X equals NULL. If such LAST #L $X is in the
+left  side  of assignment statement, the statement is disregarded
+(and run time error message is output). 
+    By  the  help  of  LAST  we  may  refer to both rule and main
+program variables. 
+
+      10.3 Attribute Grammars and RIGAL. Global Attributes
+
+    There  is a close analogy between attribute grammar and RIGAL
+program.  Rules  in RIGAL correspond to grammar nonterminals, and
+variables - to attributes. 
+    In  attribute  grammars  the  greatest part of attributes are
+used  as  transit attributes. To avoid this global attributes are
+introduced in the attribute grammar implementations. The usage of
+LAST references solves this problem in RIGAL. 
+    Implementation  of  both synthesized and inherited attributes
+is possible as it is demonstrated in the following scheme. 
+ #LA  ... ... ...
+    assigns value to the attribute $A
+    calls #LB     ... ... ...     ##
+ #LB ... ... ...
+    $B1 := LAST #LA $A -- uses the inherited attribute $A from #LA
+    calls #LC
+     -- after this call the  value  of  the attribute  $C
+     -- from #LC is  assigned to the synthesized attribute $B2
+    ... ... ...     ##
+ #LC ... ... ...
+    assigns value to the attribute $C
+    LAST #LB $B2 := $C  -- the value is assigned to  the
+                         -- synthesized  attribute  $B2 of #LB
+    ... ... ...         ##
+
+
+                       11. Built-in Rules
+
+    There  is  a  number of built-in rules in the language. These
+rules   implement  functions,  the  implementation  of  which  is
+impossible or ineffective by other language means. 
+    Call  of  built-in rules is written down the same way as call
+of  rules  defined  by  the  user  itself. Along with the value a
+built-in rule yields success or failure hence, built-in rules are
+used as patterns. 
+    There are predicates such as #ATOM(E), #NUMBER(E), #IDENT(E),
+#LIST(E) and #TREE(E). 
+    The built-in rule #LEN(E) returns numerical atom as value. If
+E  is an atom, then for non-numerical atoms it returns the number
+of atom symbols. For numerical atoms this rule returns the number
+of  significant  digits plus 1, if the atom is a negative number.
+#LEN( NULL) equals 0, #LEN('ABC') equals 3, #LEN(-185) equals 4. 
+    If  E  is  a  list,  then  #LEN(E) returns the number of list
+elements, but, if E is a tree, then it returns the number of tree
+branches. 
+    #EXPLODE(E).  If  E  is an atom, then it succeeds and returns
+one  character atom list that represents the value E 'decomposed'
+in   separate   characters.  If  E  is  a  numerical  atom,  only
+significant digits are present. 
+    Examples.#EXPLODE(X25) yields (. 'X' '2' '5' .).
+              #EXPLODE(-34) yields (. '-' '3' '4' .).
+    #IMPLODE(E1 E2 ... EN). This rule yields the concatenation of
+atoms or lists E1, E2, ..., EN in a new, non-numerical atom. 
+    Examples.#IMPLODE( A B 34) equals 'AB34'.
+              #IMPLODE(25 (. A -3 .) ) equals '25A-3'.
+    #CHR(N). The rule returns an atom, which consists of just one
+ASCII character with the code N ( 0 <= N <= 127). 
+    #ORD(A). Returns an integer, which is an internal code of the
+first character of the nonnumerical atom A. 
+    For instance, #ORD( A) = 65, #ORD( ABC) = 65.
+    #PARM(T) . Returns list of parameters which was assigned when
+the whole program called for execution. 
+    #DEBUG(E). If E equals the atom 'RULES', then, as soon as the
+rule  is  called, information concerning calls of the rules (both
+user defined and built-in rules) and their execution results will
+be  output.  The  call #DEBUG(NORULES) stops the debugging of the
+rules. 
+
+
+                       12. Sample Compiler
+
+    Compiler  for  the  TOYLAN  language,  which is a very simple
+programming  language,  is  discussed  in  the  following  units.
+Compiler  works  in  two  passes.  The first phase is parsing and
+construction  of  the  program's  intermediate  form  as abstract
+syntax tree. The second phase is code generation. 
+    Description  of  input  and intermediate language grammars by
+means   of   RIGAL   is   presented.   Thus  formalized  compiler
+documentation (admitting checking on a computer) is obtained. 
+
+
+                     12.1 TOYLAN Language
+
+    The   description   of  TOYLAN  syntax  can  be  regarded  as
+description  of  acceptable  sequences of tokens. Atoms represent
+lexical   elements  of  TOYLAN  program:  keywords,  identifiers,
+constants,  operation signs, delimiters. The context free grammar
+of TOYLAN can be described in the form of RIGAL program. 
+  #PROGRAM      'PROGRAM' $Id
+                 (* #DECLARATION ';' *)  (+ #STATEMENT + ';' )  ##
+  #DECLARATION  ('INTEGER'!'BOOLEAN')   (+ $Id  + ',')        ##
+  #STATEMENT     ( #ASSIGNMENT      !  #INPUT     !
+                   #OUTPUT          !  #CONDITIONAL  )          ##
+  #ASSIGNMENT   $Id ':='  #EXPRESSION                         ##
+  #INPUT        'GET' '(' (+ $Id  + ',') ')'                   ##
+  #OUTPUT       'PUT' '(' (+ #EXPRESSION + ',') ')'            ##
+  #CONDITIONAL  'IF' #EXPRESSION   'THEN' (+ #STATEMENT + ';')
+                ['ELSE' (+ #STATEMENT + ';' )]    'FI'         ##
+  #EXPRESSION   #SUM     [  '='  #SUM  ]                      ##
+  #SUM          #FACTOR   (* '+'  #FACTOR   *)                ##
+  #FACTOR       #TERM    (* '*' #TERM      *)                 ##
+  #TERM         $N ;; -- numeric constant
+                ('TRUE' ! 'FALSE' ) ;; -- Boolean constants
+                $Id;; -- variable
+                '(' #EXPRESSION ')'                           ##
+    Context conditions are the following:
+    1)  all  variables used in statements and expressions must be
+declared, 
+    2)  one  and  the  same  variable name should not be declared
+twice, 
+    3)  left  and  right parts of assignment statement must be of
+the same type, 
+    4)  operands  of  input-output statements must be of the type
+INTEGER. 
+    All  variables  of the type INTEGER have initial value 0, and
+all variables of the type BOOLEAN have initial value FALSE. 
+
+
+               12.2 Intermediate Form of Program.
+                         Abstract syntax tree
+
+    Special   languages  to  represent  intermediate  results  of
+compilation are used in compiler building practice. For instance,
+P-code for PASCAL compilers and language DIANA [8] for ADA. 
+    The  result  of  the  first phase of the TOYLAN compiler is a
+tree.   Let's   call  it  abstract  syntax  tree.  Along  program
+components  it  contains  some semantic attributes, for instance,
+types  of  expressions. One of the most significant attributes is
+table of variables, obtained as a result of parsing of the TOYLAN
+program declarations. 
+    The  structure  of abstract syntax tree of the TOYLAN program
+is described by the following rules. 
+  #S_PROGRAM
+      'PROGRAM'::<. NAME : $Id,
+                     DECLARATIONS : #S_DECLARATIONS ,
+                     STATEMENTS   : (.(* #S_STATEMENT *).) .>    ##
+  #S_DECLARATIONS    -- variables table
+      <* $Id : ( INTEGER ! BOOLEAN )  *>                       ##
+  #S_STATEMENT
+      ASSIGNMENT :: <. LEFT  : $Id,
+                        RIGHT : #S_EXPRESSION   .>   ;;
+      INPUT :: (. (* $Id *) .)    ;;
+      OUTPUT :: (. (* #S_EXPRESSION *) .)      ;;
+      CONDITIONAL :: <. COND : #S_EXPRESSION,
+                         THEN : (.(* #S_STATEMENT *).),
+                         [ ELSE : (.(* #S_STATEMENT *).)] .>   ##
+  #S_EXPRESSION
+      COMPARE :: <. ARG1 : #S_EXPRESSION, ARG2 : #S_EXPRESSION,
+                     TYPE : BOOLEAN    .>  ;;
+      ADD :: <. ARG1 : #S_EXPRESSION,  ARG2 : #S_EXPRESSION,
+                 TYPE : INTEGER       .>  ;;
+      MULT :: <. ARG1 : #S_EXPRESSION,  ARG2 : #S_EXPRESSION,
+                  TYPE : INTEGER       .>  ;;
+      <. VARIABLE : $Id ,  TYPE     : ( INTEGER ! BOOLEAN ) .>   ;;
+      <. CONSTANT : $N ,   TYPE     : INTEGER .>   ;;
+      <. CONSTANT : ( 0 ! 1) , TYPE : BOOLEAN .>            ##
+
+
+                    12.3 Target Language BAL
+
+    The  goal of the TOYLAN compiler is to obtain program text in
+a  low level language BAL. This language is a simplified model of
+assembler  languages.  The  memory of BAL-machine is divided into
+separate words. Every word may contain an integer, besides, there
+are  work registers R0, R1, R2, ... of the word size each. Let us
+suppose  the  number  of  registers  to be unlimited, in order to
+eliminate the problem of optimal register usage during generation
+phase. 
+    Command  of  BAL ABC: DEFWORD N reserves a word in the memory
+and  imbeds  integer  N in it. We can refer to this word in other
+commands by name ABC. 
+    Commands  of BAL have two operands which are described by the
+name of memory word, by the name of register or by the literal of
+the type =NNN, where NNN is an integer. Commands can be marked by
+labels. 
+  1) MOV A1,A2  This command moves memory word A1 to memory word A2.
+  2) LOAD  RI,A  Loading of word A into register RI.
+  3) SAVE RI,A Unloading of the contents of register RI into memory
+                word A.
+  4) ADD RI,A  or  ADD RI,RJ  The sum of operands is imbedded in RI.
+  5) MULT RI,A  or  MULT RI,RJ   Multiplication of operands is
+                imbedded in RI.
+  6) COMPARE RI,A  or  COMPARE RI,RJ  If operand values are equal,
+                it is 1 that is imbedded in RI,  if  they  are  not
+                equal, 0 is imbedded.
+  7) BRANCH RI,M  If the value of RI is equal to 0, then transfer
+                to the command marked  by  label  M  takes  place,
+                otherwise, to the next command.
+  8) JUMP M  Unconditional transfer to the command marked by label M.
+  9) EOJ       Completes the execution of the BAL program.
+  10) READ A    Reads the integer from standard  input  device  and
+                imbeds it in word A.
+  11) WRITE A  or  WRITE RI Outputs the integer from memory word or
+                from register to standard output device.
+  12) NOP      An empty statement.
+
+
+                  12.4 Main Module of Compiler
+
+    The main program of the TOYLAN compiler contains calls of the
+first and second compilation phases and file opening statements. 
+ #TOYLAN_COMPILER
+    OPEN REP ' ';  --message file is connected with the screen
+    $LEXEMS:=#CALL_PAS(35 'A.TOY');
+     -- a list of tokens is loaded from the file A.TOY by scanner
+    $S_TREE := #A_PROGRAM($LEXEMS);
+    -- 1st  phase; result of parsing - abstract syntax tree - is
+    -- imbedded in the variable $S_TREE; during parsing messages
+    -- about discovered errors in file REP can be output.
+    IF $S_TREE  ->  OPEN GEN 'A.BAL'; -- if the tree is created,
+         -- then file is opened to output the generated BAL text
+                 #G_PROGRAM($S_TREE) -- 2nd phase - code generation
+    ELSIF  T  ->  REP << errors are discovered   FI;
+    REP << end of compilation                   ##
+    The  compilation  listing that contains source text and error
+messages  is  not  envisaged in the TOYLAN compiler. Formation of
+the listing can be a separate phase. 
+
+
+                       12.5 Parsing Phase
+
+    The  rule  #A_PROGRAM  carries  out  parsing  of tokens list,
+checks  context  conditions,  generates error messages and builds
+abstract syntax tree of TOYLAN program. 
+    Patterns  of the rule #A_PROGRAM and of the rules subordinate
+to  it, actually, coincide with patterns of the rule #PROGRAM and
+with  the  associated rules that describe context free grammar of
+the TOYLAN language. Just operations to check context conditions,
+to  output  error  messages and to construct abstract syntax tree
+are added. 
+    In   our   parser  diagnostics  is  based  on  the  following
+principles.  First of all, "panic" reaction to an error should be
+avoided  and  several  messages concerning one and the same error
+should  not  be  output  (though,  we  can't  manage  it always),
+secondly,  error  neutralization is transition to the analysis of
+the next statement, i.e., skip of tokens until the nearest symbol
+';'. 
+
+
+
+ #A_PROGRAM    -- the rule is applied to the list of tokens
+    (. PROGRAM  $Id
+         (*  $DECL++:= #A_DECLARATION  ';'  *)
+                  --formation of variables table
+          (+  $STATEMENTS !.:= #A_STATEMENT   + ';' )
+                  --formation of statements list
+    .)  / RETURN 'PROGRAM' :: <. NAME : $Id,
+                                  DECLARATIONS : $DECL ,
+                                  STATEMENTS : $STATEMENTS .>/ ##
+ #A_DECLARATION     $TYPE := ( INTEGER ! BOOLEAN )
+  (+ $Id /IF LAST #A_PROGRAM $DECL.$Id OR $REZ.$Id ->
+              REP << VARIABLE $Id DOUBLE DEFINED  FI;
+           $REZ++:= <.$Id : $TYPE .>/  + ',' ) / RETURN $REZ / ##
+ #A_STATEMENT   $REZ := ( #A_ASSIGNMENT ! #A_INPUT !
+               #A_OUTPUT ! #A_CONDITIONAL )  / RETURN $REZ / ;;
+
+     (* $A!.:=S'($$ <> ';' ) *)   -- skip until nearest ';'
+               / REP << UNRECOGNIZED STATEMENT $A /
+ ##
+
+ #A_ASSIGNMENT $Id  ':='/ $LPType := LAST #A_PROGRAM $DECL .$Id;
+        IF NOT $LPType  -> REP << VARIABLE $Id ' IS NOT DEFINED ' FI /
+    $E:= #A_EXPRESSION
+         /IF $LPType <> $E . TYPE ->
+              REP<< 'LEFT AND RIGHT SIDE TYPES ARE DIFFERENT '
+                     'IN ASSIGNMENT STATEMENT ' FI;
+         RETURN ASSIGNMENT::<. LEFT: $Id, RIGHT: $E .> /
+ ONFAIL IF $LPType  -> REP<< 'WRONG EXPRESSION IN ASSIGNMENT'  FI  ##
+ #A_INPUT      GET  '('
+    (+ $E !.:= $Id  /IF  LAST #A_PROGRAM $DECL.$Id <> INTEGER ->
+            REP << $Id 'IN STATEMENT GET IS NOT OF THE TYPE INTEGER'
+                      FI / + ',' ) ')' / RETURN INPUT :: $E /   ##
+ #A_OUTPUT   PUT  '(' (+  $C := #A_EXPRESSION  / $E !.:= $C;
+              IF  $C . TYPE  <> INTEGER ->
+        REP << OPERAND OF PUT STATEMENT IS NOT OF THE TYPE INTEGER
+                FI /   + ',' ) ')'/ RETURN OUTPUT :: $E /       ##
+ #A_CONDITIONAL     'IF' $BE := #A_EXPRESSION
+    /IF $BE . TYPE <> BOOLEAN ->
+              REP<< CONDITION IS NOT OF BOOLEAN TYPE FI /
+                   'THEN' (+ $P1 !.:= #A_STATEMENT + ';' )
+         [ 'ELSE' (+ $P2 !.:= #A_STATEMENT + ';' ) ]      'FI'
+    / RETURN CONDITIONAL :: <. COND : $BE , THEN : $P1 ,
+                               ELSE : $P2  .> /            ##
+ #A_EXPRESSION      $A := #A_SUM   [  '=' $B := #A_SUM
+    / $A := COMPARE::<. ARG1 : $A, ARG2 : $B, TYPE : BOOLEAN.>/ ]
+    / RETURN $A /           ##
+ #A_SUM   $A := #A_FACTOR    (* '+' $B := #A_FACTOR
+         / $A := ADD::<. ARG1: $A, ARG2: $B, TYPE: INTEGER .>/ *)
+    / RETURN $A  /          ##
+ #A_FACTOR  $A := #A_TERM     (* '*' $B := #A_TERM
+         /$A := MULT::<. ARG1: $A, ARG2: $B, TYPE: INTEGER .>/ *)
+    / RETURN $A /           ##
+ #A_TERM
+    $N  / RETURN <. CONSTANT : $N , TYPE : INTEGER .>/;;
+  ( ( TRUE / $K :=1/ ) ! ( FALSE / $K :=0 / ) )
+                 /RETURN <. CONSTANT: $K, TYPE: BOOLEAN .>/  ;;
+    $Id  / $X:= LAST #A_PROGRAM $DECL.$Id;
+         IF NOT $X  ->  REP << VARIABLE $Id IS NOT DECLARED
+         ELSIF T -> RETURN <. VARIABLE: $Id, TYPE: $X .> FI / ;;
+    '(' $E := #A_EXPRESSION ')' / RETURN $E /        ##
+
+
+                  12.6 Code Generation Phase
+
+    Code  generation is performed when traversing abstract syntax
+tree. 
+    To  avoid  possible  conflicts  between variable names in the
+TOYLAN  program  and register names (of the type RNNN) and labels
+(of  the  type  LNNN)  in  the object program, variable names are
+substituted by standard names of the type VARNNN. 
+
+
+ #G_PROGRAM    / $LABEL := 0 /   --global variable $LABEL serves
+                                 --to generate unique labels.
+  PROGRAM::<.DECLARATIONS: $TAB := #TABLE_OF_NUMBERS,
+              --creation of the table of unique variable numbers
+             STATEMENTS: (.(* #G_STATEMENT *).) / GEN << 'EOJ' /,
+             DECLARATIONS : #G_DECLARATIONS      .>       ##
+ #TABLE_OF_NUMBERS <* $Id: $TYPE /$N :=$N+1; $T++:=<. $Id: $N.>/ *>
+                   /RETURN $T/    ##
+ #G_STATEMENT ( #G_ASSIGNMENT ! #G_INPUT !
+              #G_OUTPUT     ! #G_CONDITIONAL )      ##
+ #G_ASSIGNMENT    ASSIGNMENT::<. LEFT: $Id := #NAME,
+  RIGHT :( ( <. VARIABLE: $Id1:=#NAME .>
+              /GEN << MOV @ $Id1 ',' $Id / ) !
+           ( <. CONSTANT : $N .> /GEN << MOV @ '=' $N ',' $Id /) !
+           ( $NREG := #G_EXPRESSION
+              /GEN << 'SAVE' @ 'R' $NREG ',' $Id / ) )  .>    ##
+ #G_INPUT INPUT::(. (* $Id := #NAME /GEN << READ $Id / *) .)   ##
+ #G_OUTPUT     OUTPUT :: (. (*
+    ( ( <. VARIABLE : $Id := #NAME .> /GEN << WRITE $Id / ) !
+       ( <. CONSTANT : $N .> /GEN << WRITE @ '=' $N / )  !
+       ( $NREG := #G_EXPRESSION /GEN << WRITE @ 'R' $NREG /) )
+                         *) .)                                ##
+ #G_CONDITIONAL     CONDITIONAL ::
+     <. COND : $NREG := #G_EXPRESSION
+            / $LABEL1 :=#NEW_LABEL(); $LABEL2 :=#NEW_LABEL() /,
+         THEN   : / GEN << BRANCH @ 'R' $NREG ',L' $LABEL1  /
+                  (. (* #G_STATEMENT *) .)
+               / IF $.ELSE -> GEN << JUMP @ 'L' $LABEL2 FI;
+                             GEN << @ 'L' $LABEL1 ': NOP' / ,
+       [ ELSE : (. (* #G_STATEMENT *) .)
+               / GEN << @ 'L' $LABEL2 ': NOP' / ]     .>  ##
+ #G_EXPRESSION --returns the number of the register containing
+               --result of the evaluation of expression
+  $EXPR
+ / $NREG := 0 / -- number of the first accessible register
+ /RETURN #G_EXPR($EXPR)/
+ ##
+
+
+ #G_EXPR     ( <. VARIABLE: $ID :=#NAME .>  !
+              <. CONSTANT: $N / $ID := #IMPLODE('=' $N)/ .>)
+            / $REG := COPY( LAST #G_EXPRESSION $NREG ) ;
+              GEN << 'LOAD' @ 'R' $REG ',' $ID  ;
+              LAST #G_EXPRESSION $NREG + := 1; RETURN $REG /  ;;
+         $OP::<. ARG1 : $R1 := #G_EXPR, ARG2 : $R2 := #G_EXPR .>
+          / GEN << $OP @ 'R' $R1 ',R' $R2 ; RETURN $R1 /   ##
+ #G_DECLARATIONS
+ <* $ID: $TYPE /$ID1 := #NAME($ID); GEN<< $ID1 ':' DEFWORD 0 /*> ##
+ #NEW_LABEL    --auxiliary rule
+    /LAST #G_PROGRAM  $LABEL+:=1;
+     RETURN COPY (LAST #G_PROGRAM $LABEL )/              ##
+ #NAME    $ID --returns standard name of the variable $ID in $TAB
+     / RETURN #IMPLODE( VAR  LAST #G_PROGRAM $TAB.$ID)/    ##
+
+
+                 13. Conclusions and Future Work
+
+    As  it was demonstrated above, RIGAL supports syntax-oriented
+style   of   compiler  design.  Programs  written  in  RIGAL  are
+well-structured and it is easy to read and debug them. 
+    Our experience [13] proves that the optimizing RIGAL compiler
+in  VAX/VMS environment makes it possible to implement production
+quality compilers for high level languages. 
+    RIGAL  can  be considered as yet another language prototyping
+tool  in  the  sense  of  [14], because it allows the designer to
+develop an experimental translator in short period of time. 
+    Besides  interpreter  for  debugging  purposes and optimizing
+compiler  RIGAL support system includes a cross-referencer, which
+helps to avoid misuse of global variables. 
+    In  order  to  improve  static  and  dynamic  type  checking,
+variable  type  descriptions in the form of formal comments would
+be added to the language. 
+    Taking  in  account  that control structures of RIGAL program
+are  very  close  to input data structures, it seems promising to
+develop  automatic  and  semiautomatic  methods  for test example
+generation for the given RIGAL program. 
+
+
+                           References
+
+  [1]  A.Aho,  J.Ullman. The  theory  of  parsing,  translation  and
+      compiling// Prentice-Hall, Inc. Englewood Cliffs,N.J. 1972. -
+       vol.1,2.
+  [2] S.C.Johnson. YACC - Yet  Another  Compiler  Compiler  //  Bell
+     Laboratories, Murray Hill,N.J., 1978, € technical manual.
+  [3] C.H.€.Koster. Using the CDL Compiler Compiler// Lecture  Notes
+     in Computer Science , Vol.21, Springer-Verlag, Berlin, 1977.
+  [4] ˆ.�.€£ ¬¨à§ï­. ‘¨á⥬  â¥å­®«®£¨ç¥áª®© ¯®¤¤¥à¦ª¨ ࠧࠡ®âª¨
+     âà ­á«ïâ®à®¢ "˜€ƒ"// €«£®à¨â¬ë ­¥¡¥á­®© ¬¥å ­¨ª¨ (¬ â¥à¨ «ë
+     ¬ â. ®¡¥á¯¥ç¥­¨ï �‚Œ).  -1985.-¢ë¯.79.-á. 1-53.
+  [5] D.E.Knuth. Semantics of context-free languages//  Mathematical
+      Systems Theory, 2, 2, 1968, pp.127-146.
+  [6] ‚.€.‘¥à¥¡à类¢. Œ¥â®¤ë  âਡãâ­®© âà ­á«ï樨 //
+     Ÿ§ëª¨ ¯à®£à ¬¬¨à®¢ ­¨ï. -Œ.� ãª ,1985,á.47-79.
+  [7] €.Ž.‚®®£« ©¤, Œ.‚.‹¥¯¯, „.�.‹¨©¡.  ‚室­ë¥ ï§ëª¨ á¨á⥬ë ELMA
+      //âàã¤ë  ’ ««¨­­áª®£®  �®«¨â¥å­. ˆ­-â .-1982.-¢ë¯.524-á.79-96.
+  [8] The intermediate language DIANA : Design and Implementation
+     //Lecture Notes in Computer Science, Vol.180, Springer-Verlag,
+     Berlin, 1984.
+  [9] R.Vilhelm. Presentation of the compiler generation system MUG2
+     : …xamples, global flow analysis and optimization// Le point
+     sur la compilation, INRIA, 1978, à.307-336.
+  [10] � §¨á­ë© �…”€‹ ¨ ¥£® ॠ«¨§ æ¨ï ­  ¢ëç¨á«¨â¥«ì­ëå ¬ è¨­ å.//
+      –�ˆ�ˆ€‘‘, Œ. 1977.
+  [11] �.Lucas. Formal definition of programming languages and
+      systems // IFIP Congress, 1971.
+  [12] Œ.Ganapatti, C.N.Fisher, J.L.Hennessy. Retargetable  compiler
+      code generation// ACM Computing Survays, 14(4), 1982.
+  [13]  J.Barzdin,  A.Kalnins,  M.Auguston,  SDL  tools  for   rapid
+      prototyping and testing.// in SDL'89 : The language  at  work,
+      ed.  O.Faergemand  and   M.M.Marques,   North-Holland,   1989,
+      pp.127-133.
+  [14] R.Herndon, V.Berzins, The realizable benefits of  a  language
+      prototyping  language.//   IEEE   Transactions   on   Software
+      Engineering , vol.14, No 6, June 1988, pp.803-809

+ 209 - 0
rigdos/PROGLIST.TXT

@@ -0,0 +1,209 @@
+ TABLE OF UNITS AND PROCEDURES
+ RIGAL INTEGRATED ENVIRONMENT V.2.04
+------------------------------------------
+FORMAT OF TABLE :
+UNIT NAME
+   %INCLUDED FILE NAME
+   (PROCEDURE NAME IF IT<>FILE_NAME)
+   PROCEDURE NAME
+   = EXPLAINATION
+   == IMPLEMENTED RIGAL KEYWORDS
+-------------------------------------------
+
+PROGRAM RIG_CHE; = CHECKER OF RIGAL SYNTAX
+DEFINE   = COMMON TYPES
+DEFPAGE  = VIRTUAL MEMORY MANAGER
+  GETS1,GETS2,GETS5   = TAKES VIRTUAL MEMORY
+  POINTS, POINTR = REFERS TO VIRTUAL MEMORY
+  PUTATM = TAKES VIRTUAL ATOM SPACE
+  POINTA = REFERS TO VIRTUAL ATOM SPACE
+  REOPEN = Re-opens S-space
+GNVAR    = COMMON VARIABLES
+NEF      = PTR ( POINTER TO LIST ) OPERATIONS
+  NEXT   = MOVING PTR TO NEXT ELEMENT
+  FIRST  = STARTING PTR FROM LIST START
+  EQUATOMS = COMARING TWO ATOMS
+  LCONC   == !.
+  CRLST   ==  (. .)
+  CRLISTFR == (.  .. .)
+  CRTREE   ==  <. .>
+  CRTREEFR ==  <.  .. .>
+  CHANGEEL ==  $E[$a]:=...
+  PLNUM    ==  PTR -> integer
+  MKNUMB   ==  integer -> atom
+  ADDEL3   ==  ++:=<.A:B.>
+  ADDTRE   ==  ++:=<.A:B,C:D.>
+
+EXTERNS  = COMMON CHECKER SUBPROCEDURES
+  %MIST (ERR) = SYNTAX ERROR HANDLER
+  %TABR (TABRULE) = RULES AND VARIABLES TABLE CREATOR
+  DUL,PUSHL,DES,NEXTL,VAL,EL = TEST AND CHANGE
+     CONDITION OF LIST MARKED BY VARIABLE L
+  BLTN   = TEST BUILT-IN RULE NAME
+EXPRU
+  EXPR   = EXPRESSION ANALYSIS
+OPERU
+  OPERATOR = STATEMENT ANALYSIS
+  INSTRUC  = /../ ANALYSIS
+PICTU
+  PICT     = PATTERN ANALYSIS
+  %SPECADR = SPECIAL CONSTANTS
+RULEU
+  RULE     = RULE ANALYSIS
+  SIMPLERULE = BRANCH-OF-RULE ANALYSIS
+CHEPROU
+  CHEPRO   = PROLOG OF CHECK
+CHENU
+  CHEPIL   = EPILOG AND TABLES TEST
+LEYER
+  LEY      = RIGAL LEXIC SCANNER
+STLEV      = SCANNER VARIABLES
+CH
+  CHE11    = MAIN CHECKER PROCEDURE
+CFGU       = TAKES AND RETURNS CONFIGURATION
+
+---------------------------------------------
+
+
+PROGRAM RIG_INT; = RIGAL built-in interpreter
+PROGRAM INT;     = RIGAL independent interpreter
+DEFINE   ^
+DEFPAGE  ^
+GLOVAR   = COMMON VARIABLES
+  ERR    = RUNTIME ERRORS HANDLER
+NEF      ^
+DOUTU
+  DOUT   = #CALL_PAS(12,13 ..) - NICE PRINT
+POUTLEXU
+  %POUTX (POUT) == PRINT
+USEPASU    == #CALL_PAS  PASCAL interface
+  -> LEDER, LEYER, TABUSE
+> SCAN -  new user-oriented lexical analyser
+RUSCODE = russian identifiers coding
+LEDER
+  LED  = PASCAL LEXIC SCANNER
+  %LEDPRO = PROLOG OF PASCAL LEXIC SCANNER
+LEYER
+  LEY      = RIGAL LEXIC SCANNER
+STLEV      = SCANNERS VARIABLES
+TABUSE    = TABLES MANAGER
+>TABDESK   = DESCRIPTORS AND MEMORY
+>TN        = NUMERIC TABLE UTILITY
+>TA        = ATOMIC TABLE  UTILITY
+>TSELECT   = TREE PRIMITIVES
+   SELOP3
+   SETSEL3
+
+BEI
+  %BLTIN  = BUILT_IN RULES
+  %PARMINT == #PARM = COMMAND LINE PARAMETERS
+  %EXPLODE == #EXPLODE
+  %IMPLODE == #IMPLODE
+  %NAMEOP  == ::
+  %CONCOP  == !!
+ARU
+  %ARITHM  = ARITHMETICS
+  %COPYOP  == COPY
+  %INDXOP  == [7]
+  %AUMINS  == -7
+  %SELCTR  == A.B
+  %EQOP    == =
+  %EQOP1   == =
+  %ADD     == +
+PSU
+  PUSH    = ADDING VALUE TO STACK
+  PRATOM  = PRINT ATOM
+  PRBLT   = PRINT BUILT-IN RULE
+  %COMPNAMES = COMPARE NAMES
+  SRCHRULE = SEARCH RULE IN CODE
+  SRCHRULE1 = SEARCH RULE IN CODE
+  LASTOP == LAST
+CI
+  %ALTER  == ( ! )
+  %STARLIST == (* *)
+  %FACULT   == [ $A ]
+  %TREE     == <. $A : $B .>
+  %LIST     == (.  .)
+  %SPATT    == S'( )  V'( )
+  %PATTERN  =  PATTERN DISPATCHER
+  %SIMPLE   ==  ;;
+  %RULE     == #h ... ##
+  %CONLST   =  MAKE LIST
+  %CONTRE   =  MAKE TREE
+  %EXPRESS  =  EXPRESSION DISPATCHER
+  %OBJEXPR  =  LEFTSIDE   DISPATCHER
+  %ASSGN    == :=
+  %COND     == IF
+  %LOOP     == FORALL LOOP
+  %INOUT    == OPEN << <] @ SAVE LOAD PRINT
+  %STATEMENT =  STATEMENT DISPATCHER
+PROLOGU
+  PROLOG    = PROLOG AND CODE READING
+  EPILOG    = EPILOG
+INT1
+  INT11     = MAIN PROCEDURE
+CFGU       = TAKES AND RETURNS CONFIGURATION
+
+----------------------------------------
+
+
+PROGRAM XCRG; = RIGAL COMPILED PROGRAM
+= ==== GENERATED PART =================
+XCRG     = FIRST RULE OF PROGRAM
+XCRG_0   = OTHER RULES OF PROGRAM
+XCRG_1,XCRG_2 = RULES IN INCLUDED PART OF PROGRAM
+XCRG_C   = COMMON (LAST) VARIABLES
+  RMI    = RULE DISPATCHER
+XCRG_N   = CONSTANT (ATOMS) LOADING TO MEMORY
+
+= ==== SUPPORT BY RUNTIME LIBRARY ====
+
+DEFINE ^
+DEF180   = COMMON TYPES
+DEFPAGE ^
+NEF     ^
+USEPASU ^  ( Same structure as in interpreter )
+C1
+  %BLTINC (BLTIN) = BUILT_IN RULES
+  %PARMTAKE == #PARM = COMMAND LINE PARAMETERS
+  %POUTX (POUT) == PRINT
+  ER,ERRSTR = RUNTIME ERRORS HANDLER
+  D,D1      = STATISTIC HANDLER
+  NUMVAL    = CONVERTION ATOM TO NUMBER
+C2
+  CONCOP    == !!
+  INDXOP    == [7]
+  SELOP     == A.B
+  SETIND    == [7]:=
+  SETSEL    == A.B:=
+  ADDNUM    == +:=7
+  COPYOP    == COPY
+C3
+  EPILOG    == EPILOG
+  PROLOG    == PROLOG
+  OUTXT     == <<,<] FOR EXPRESSIONS
+  OUTATM    == <<,<] FOR ATOMS
+  OPN       == OPEN
+  LOASAV    == LOAD SAVE
+  EXPLOD    == #EXPLODE
+  IMPLOD    == #IMPLODE
+  BLTIN1    =  BUILT_IN RULE DISPATCHER
+  CLSFIL    == CLOSE
+C4
+  EQOP      = COMPARING DISPATCHER
+  VARPAT    = PATTERN IS VARIABLE
+  ATMPAT    = PATTERN IS ATOM
+  EQNUM     = COMPARES NUMBERS
+  EQATOM    = COMPARES ATOMS
+--------------------------------------
+RIG_EDIT PROGRAM
+WED = COMMON DISPATCHER
+WEDVAR = VARIABLES AND KEYBOARD DRIVER
+WIN    = WINDOWS MAKER
+WAR    = MOVING AND CHANGING SCREEN
+WIO    = INPUT/OUTPUT,PICK,DIRECTORY
+FRAMES = SCREEN FRAMES & BOXES
+CFGU   = TAKES AND RETURNS CONFIGURATION
+======================================
+
+

+ 93 - 0
rigdos/RAPID.TXT

@@ -0,0 +1,93 @@
+  RIGAL RAPID PROGRAMMING GUIDE       (W.E. 26.10.90)
+  =============================
+ Some considerations on fast Rigal execution and about
+some optimizations for recursive programs.
+ Global algorithmic ideas :
+If your algorithm is tree-building - try use such ideas :
+1.Every tree node accords to one call of Rigal rule
+2.Next node is recursive call result (from previous rule),
+  may be through some other rules.
+3. Node is element of big array (list) and node refers to others
+by their "numbers of elements" in this array.
+4. Tree (may be) not exist as data structure at execution
+time. Tree represented by tree-like history of execution
+of recursive rules."Good" nodes are accumulated in special list,
+or (more fast to search) in special another tree with well-chosen
+selectors. This way is good if tree building and tree traversing
+may be done in one pass.
+5. Prepare all possible trees and tables in form of array or tree
+of arrays - before starting recursion. It helps to write
+cycles on lists , not on trees.
+6. Use #CALL_PAS(60-66) - fast trees and lists.
+
+Local optimizations of programs.
+-------------------------------
+Don't use constructors in recursive called rule. It eats
+both time and memory.
+Operations in order of descending efficiency (from very slow to fast)
+as it is in compiled Rigal program.
+
+INEFFICIENT:
+================
+ SAVE; If SAVE is last statement in program -> it is implemented
+       1 1/2 times faster.
+ LOAD
+ #EXPLODE - very inefficient
+ #IMPLODE
+ FORALL $A IN $B - if $B is tree
+ <* $A : $B *>
+ $A !! $B  - if $B is big list - elements copied one after one.
+ $A ++ $B  - if $B is big
+ $A ++ $B  - if $A is big
+ $A:=<.D:E.>   - every tree or list takes minimum 40 bytes
+ $A:=(. D E .)
+ #A ( $B $C ) - if call any rule with 2 or more parameters
+            ( this will be optimized in nearest future )
+
+MIDDLE EFFICIENCY AND GOOD
+==========================
+ $A!.:=$K  - if $A is small
+ $A.$D:=$K
+ $A++:=<. A:B, C:D, F:E.>
+ $A!!(. A B C .)
+ Arithmetical expressions
+ $A.$B, $A[$B]
+ $A.ABC  $A[5]
+ Patterns with constants.
+
+IMPLEMENTED VERY GOOD (in Pascal level):
+=======================================
+ Clusters ( will be implemented in future )
+ #CALL_PAS,#CHR, #ORD, predicates
+ #LEN of tree or list
+ #AA( $P1 $P2 $P3 $P4  ) - with one to four parameters
+ FORALL $A IN $B - if $B is list
+ $A+:=number
+ $A !. $B
+ IF/ELSE/FI, LOOP, BREAK , RETURN
+ LAST #A $A
+ $ $$
+ $A:=$B;
+ Single variable everywhere is of equal (or a
+  little more) efficient as constant with the same value.
+
+ON PAGING CONTROL
+=================
+We recommend to use new #CALL_PAS(42) to know count
+of filled virtual memory pages in every N-th step
+of algorithm.
+Use #CALL_PAS(1) to require user to stop execution
+in every N-th step.
+If algorithm is iterative - use #CALL_PAS(45) to clean
+memory
+
+Every page is 8 KBytes.
+Totally is 256 pages ( 2 MBytes )
+In heap memory - no more than 50 pages,
+in 1300 Kb virtual disk - 170 pages
+in  300 Kb vitrual disk -  45 pages
+in hard disk - all remainder.
+
+One atom (or number) takes 8 bytes,
+One list of length N takes N*5 bytes, minimum 40
+One tree of length N takes N*10 bytes, minimum 40

+ 265 - 0
rigdos/README

@@ -0,0 +1,265 @@
+          WELCOME TO RIGAL PROGRAMMING SYSTEM
+          ===================================
+
+                    RIGAL 2.28
+
+This README file contains important, last minute information
+about Rigal 2.28
+
+TABLE OF CONTENTS
+-----------------
+0. You need Turbo Pascal TPC.EXE version 6.0
+1. How to install Rigal
+2. List of files on the disks
+3. Implementation restrictions
+4. Difference between 2.28 and the previous versions
+
+0. YOU HAVE TO OBTAIN Turbo Pascal, version 6.0
+--------------------------------------------------------
+The programming system will allow you to check and
+interprete RIGAL code without Turbo Pascal Compiler.
+In order to compile RIGAL code to efficient executable file
+Turbo Pascal compiler version 6.0 is necessary. File TURBO.TPL
+is in the distribution and it must be used during
+compilation with Turbo Pascal.
+You have to copy TPC.EXE to the directory where
+you installed RIGAL system.
+
+Other versions of Turbo Pascal are NOT supported.
+To be more sure, you can verify that the 
+length of your file TPC.EXE is 69196 bytes.
+
+
+1. HOW TO INSTALL RIGAL
+-----------------------
+ At least 2 MBytes of disk memory are necessary to install Rigal.
+ Copy all the files to any directory of your computer.
+ C:\RIGAL directory is recommended.
+ Look through *.BAT files and modify drive names if necessary.
+ Copy *.BAT to any directory included in DOS PATH.
+
+
+2. LIST OF FILES ON THE DISKS
+-----------------------------
+
+  Rigal integrated environment
+  ----------------------------
+
+RIG      EXE called by RIG.BAT
+RIG      BAT Integrated RIGAL environment Version A
+           Built-in Text Editor, Checker and Interpreter.
+           Default work file is WORK.RIG.
+           You can call RIG.BAT from ANY directory,
+      Parameter:  file name without .RIG
+
+RIG1     EXE called by RIG1.BAT
+RIG1     BAT - same as RIG.BAT, but Version B.
+ Includes all features of version A, the Compiler and some utilities.
+ Command line parameters:
+ ( for advanced users )
+  Additionally to RIG.BAT you can add parameter /E or /D - this means
+using this drive as VIRTUAL .
+ /M3000 makes common memory for fast tables  
+ available through #CALL_PAS(61-66)
+
+
+ Command line programs
+ ---------------------
+
+RPNT     BAT  - for showing Rigal object if it was previously 
+ saved to the disk.
+ Parameters are file name and the components of the object.
+
+INT      EXE called by
+RINT     BAT - Rigal interpreter.
+  Parameters :
+  1th parameter - an intermediate code file name without extension.
+  2nd parameter - PRINT-file name. 
+
+       If you want to have output to the screen - this parameter
+       must be "s".
+       If you don't want output - "NUL"
+       If you want to TURN ON debugging from program start
+       then add "+" at the end of parameter, e.g.
+       Debugging messages go always to same PRINT-file.
+       For advanced users:
+           Additionally to PRINT file: you can
+           add parameter /E or /D - this means
+           using this drive as VIRTUAL.
+          /M3000 makes common memory for fast tables
+           available through #CALL_PAS(61-66)
+
+   3rd and next parameters are user's parameters. You can read
+       them in your program if you use built_in rule #PARM(T)
+       which will return list of parameters.
+       If you call
+       > RINT CODE1 s AA BB CC
+       then #PARM(T) will return (. AA BB CC .) .
+
+RIGCHECK   EXE
+   It CHECKS Rigal program.
+   1st parameter - file name without extension.
+
+RIGCOMP    BAT
+   It COMPILES Rigal program.
+      1st parameter - file name. No extensions. No path.
+      2nd parameter - RIGAL distributive directory path.
+
+
+   DOCUMENTS in ENGLISH
+   --------------------
+
+README        - this file
+SHORT    TXT  - Brief description of Rigal in ENGLISH
+               (published in ACM Sigplan Notices, 12, 1990)
+LANGDESC TXT  - Language description in ENGLISH
+USERGUID TXT  - User's guide in ENGLISH
+
+ For advanced users:
+SOURGUID TXT  - Describes porting to another operating systems
+PROGLIST TXT  - Implementation structure
+LABEL    TXT  - Label for the distributers
+RAPID    TXT  - Notes on rapid programming
+
+
+    DOCUMENTS in RUSSIAN
+    --------------------
+Note: These documents are in separate disk.
+ They usually are NOT included !
+READ     ME   - how to read and print russian in IBM/PC
+OPJAZ1   TXT  - Rigal language description
+OPJAZ2   TXT
+OPJAZ3   TXT
+
+RUKPRG1  TXT  - Rigal Programmer's Guide
+RUKPRG2  TXT
+RUKPRG3  TXT
+RUKPRG4  TXT
+
+         DEMO DISK
+         ---------
+Note: Demo is in separate disk !
+DEMO     BAT  - Run demo film (20 minutes)
+RIGAL    DOC  - Very short description of the language
+README   1ST  - How to run demo
+
+         EXAMPLES
+         --------
+
+WORK     RIG   - Simplest example
+EX1      RIG   - takes Head and Tail of list
+HANOI    RIG   - Hanoi tower example
+
+EX2      RIG   - Analysis of an arithmetical expression
+EX       TXT   - An example of expression
+
+TOYLAN   RIG   - Toylan language compiler and interpreter
+A        TOY   -   input example for Toylan
+
+ANALYSE  RIG   - Small language - Analysis part
+BCOMP    RIG   - Small language - Code generation part
+GRAM1    RIG   - Small language - Abstract tree grammar
+GRAM2    RIG   - Small language - Source grammar
+INTER    RIG   - Small language - Interpreter
+EX1      TXT   - Small language source example
+
+LINTA    RIG   - Rigal Lint demo program
+TLIST    RIG   - Fast numeric tables demo
+TTREE    RIG   - Fast atomic tables demo
+   Files for Integrated Environment
+   --------------------------------
+Note: Don't start these files from DOS command prompt !
+RIG_CHE  EXE
+RIG_EDIT EXE
+RIG_INT  EXE
+CMPLBEG  BAT
+CMPLEND  BAT
+RIG_CRF  EXE
+RIG_LINT EXE
+RIG_PNT  EXE
+
+   Files for RIGAL Compilation
+   ---------------------------
+Note: Don't start these files from DOS command prompt !
+
+ANRIG    EXE    1st part of Compiler
+GENRIG   EXE    2nd part of Compiler
+TPC      EXE    Bordland's Pascal Compiler
+TURBO    TPL    Run-time Library of Compiler
+USEPASU  PAS    User's pascal routines
+SCAN     PAS    User's scanner
+
+ When Rigal Program is compiled to e.g. AAA.EXE  you
+ can press AAA and such parameters:
+   1st - PRINT file name - same as in RINT
+         but "+" not allowed.
+         | For advanced users:
+         |  Additionally to PRINT file: you can
+         |  add parameter /E or /D - this means
+         |  using this disk as VIRTUAL !
+         | /M3000 makes common memory for fast tables
+         |  available through #CALL_PAS(61-66)
+
+   2nd and next parameters are user's
+       parameters as in RINT.
+
+ 3. IMPLEMENTATION RESTRICTIONS
+ ------------------------------
+
+1.  LETTERS are not only A..Z,a..z,_
+    Some symbols {,},~,`,^ and Chr(128)-Chr(255)
+    may be (carifully) used in Rigal & PASCAL lexic.
+    Nevertheless it is not garanteed in future versions.
+
+2.  String of text output may be only of 80 bytes width
+
+3.  Built-in rule #COPY does not exist.
+    Use  key word COPY  with the same effect: $A:=COPY($B).
+
+4. Maximum 255 variables in every rule,
+   maximum 400 rules in programm
+   maximum 1000 variabes active in interpreter's stack
+   maximum 80  bytes atom length
+   maximum 750 lines allows #CALL_PAS(4 ..) for finding coordinate
+   maximum 3   files may be (in depth) included in Rigal program
+   maximum 5   text files may be open by OPEN statement
+   maximum 20000 tokens (approximately) Rigal program size.
+
+
+4. DIFFERENCE BETWEEN 2.05 AND PREVIOUS VERSIONS
+------------------------------------------------
+
+  Difference between 1.XXX and 2.XXX versions
+  -------------------------------------------
+  1. The codes of the objects saved to the disk are NOT compatible.
+  2. #CALL_PAS has been extended, interface description has changed
+
+  Difference between 2.04 and 2.00
+  --------------------------------
+  1. FORALL BRANCHES & SELECTORS added to the language
+  2. New #CALL_PAS(35,36,37,38) - user-oriented lexical analyser,
+  file SCAN.PAS can be modified by the user.
+  3. Some implementation bugs were corrected.
+   
+  Diffrence between 2.28 and 2.04
+  -------------------------------
+  1. Virtual page manager optimized;
+     Speed up 20 %  
+  2. Some source files contain {$IFDEF WIN} directive
+     used for  "Rigal for Windows" version.
+  3. Some errors were corrected
+  4. Added FLOAT arithmetic module #CALL_PAS(80)
+  5. Scanner receives #FATOM atoms when real numbers are processed;
+     These numbers are represented in 6-byte format.
+     They are printed out in 12-digit format.
+  6. Non-numeric atoms now can be compared in lexical order:
+     A<B,  ABC<ABCD.
+  7. The scanner option "modula string" switches off
+     comments like { }. So, '{' is normal symbol, separator,
+     when the scaner is called using 'm+p-'.  
+  8. OPEN A 'aaa.txt+'
+     Appends file if it exists. 
+     Rewrites it if it does not exist.
+
+  NOTE: Files of 2.28 have creation time = 2.28
+   

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff