home *** CD-ROM | disk | FTP | other *** search
/ Complete Bookshop / CompleteWorkshop.iso / compute / cardiac / hrt.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-06-27  |  26.4 KB  |  858 lines

  1. Program Cardiac;
  2.    {[A+,T=3] Instructions to PasMat}
  3.  
  4.    {$C-}
  5.  
  6. {
  7.              Cardiac compiler version 2.5 by Cyrus Patel
  8.  
  9.    This is a complete revision of the Cardiac compiler.  It
  10.    includes  a full 'Pascal' type error documentor, where it
  11.    'points' to the error, as well as displaying the line.
  12.    It checks to see if the files exist, and if it is an output
  13.    file, and it also exists, it will ask the user if they want
  14.    to delete that file.  It also checks to make sure that the
  15.    file is not the same, as the input file.  To make it easier
  16.    on the user (since they are beginners, I've made it such that
  17.    the input filenames default extension (the part after, and
  18.    including the '.') is .HRT, also the default extension on the
  19.    output file is .OUT.  I've also taken out all unnessary variables,
  20.    and changed some of their name, to make it more self documenting.
  21.  
  22. }
  23.  
  24.    Const
  25.       Limit = 500;                      {Max. statements to be executed.}
  26.       MaxLines = 60;                    {Max. number of lines on the printer.}
  27.       Version = '2.5';
  28.  
  29.    Type
  30.       String18 = String [18];
  31.       String79 = String [79];
  32.       StringInt = Array [0..99] of Integer;
  33.  
  34.    Var
  35.       Outf: Text;
  36.       Infile, Outfile: String18;
  37.       Help, Box, Data: StringInt;
  38.       LineNumber, NumberOfStatements, Command, L, Location, MaxData, Step,
  39.         Accumulator: Integer;
  40.  
  41.  
  42.    Procedure Printer;
  43.  
  44.       Begin
  45.          LineNumber := Succ(LineNumber);
  46.          If LineNumber >= MaxLines then
  47.             Begin
  48.             Write(Outf, ^L);
  49.             LineNumber := 1
  50.             End
  51.       End;
  52.  
  53.  
  54.    Procedure PrintBlock;
  55.  
  56.       Begin
  57.          If LineNumber > MaxLines - 6 then
  58.             Begin
  59.             Write(Outf, ^L);
  60.             LineNumber := 1
  61.             End
  62.       End;
  63.  
  64.  
  65.    Procedure Blank(Number: Byte);
  66.  
  67.       Var
  68.          Index: Byte;
  69.  
  70.       Begin
  71.          For Index := 1 to Number do
  72.             Begin
  73.             WriteLn(Outf);
  74.             Printer;
  75.             WriteLn
  76.             End
  77.       End;
  78.  
  79.  
  80.    Procedure Space(Number: Byte);
  81.  
  82.       Var
  83.          Index: Byte;
  84.  
  85.       Begin
  86.          For Index := 1 to Number do
  87.             Begin
  88.             Write(Outf, ' ');
  89.             Write(' ')
  90.             End
  91.       End;
  92.  
  93.  
  94.    Procedure WriteLine(Line: String79);
  95.  
  96.       Begin
  97.          WriteLn(Outf, Line);
  98.          WriteLn(Line);
  99.          Printer
  100.       End;
  101.  
  102.  
  103.    Procedure WriteLine2(Line: String79;
  104.                         Number: Integer);
  105.  
  106.       Begin
  107.          WriteLn(Outf, Line, Number: 1);
  108.          WriteLn(Line, Number: 1);
  109.          Printer
  110.       End;
  111.  
  112.  
  113.    Procedure Exit(Line: String79);
  114.  
  115.       Begin
  116.          WriteLn(Line);
  117.          WriteLn(Outf, Line);
  118.          Close(Outf);
  119.          Halt
  120.       End;
  121.  
  122.  
  123.    Function Exists(FileName: String18): Boolean;
  124.  
  125.       Var
  126.          CheckFile: File;
  127.  
  128.       Begin
  129.          Assign(CheckFile, FileName);
  130.          {$I-}
  131.          Reset(CheckFile);
  132.          {$I+}
  133.          Exists := IOResult = 0
  134.       End;
  135.  
  136.  
  137.    Function Yes: Boolean;
  138.  
  139.       Var
  140.          Ch: Char;
  141.  
  142.       Begin
  143.          Write('? ');
  144.          Repeat
  145.             Read(Kbd, Ch);
  146.             Ch := UpCase(Ch)
  147.          Until Ch In ['Y', 'N'];
  148.          Yes := Ch = 'Y';
  149.          If Ch = 'Y' then
  150.             WriteLn('Yes')
  151.          else
  152.             WriteLn('No')
  153.       End;
  154.  
  155.  
  156.    Function FixLine(Line: String79): String79;
  157.  
  158.       Begin
  159.          While Length(Line) < 9 do
  160.             Line := Line + ' ';
  161.          FixLine := Line
  162.       End;
  163.  
  164.  
  165.    Function FixFileName(FileName: String18;
  166.                         Extension: String18): String18;
  167.  
  168.       Var
  169.          Index: Byte;
  170.  
  171.       Begin
  172.          For Index := 1 to Length(FileName) do
  173.             FileName[Index] := UpCase(FileName[Index]);
  174.          While (FileName[Length(FileName)] = ' ') and
  175.                (Length(FileName) > 1) do
  176.             Begin
  177.             FileName := Copy(FileName, 1, Pred(Length(FileName)));
  178.             End;
  179.          If Length(FileName) = 1 then
  180.             If FileName[1] = ' ' then
  181.                FileName := '';
  182.          If Pos('.', FileName) = 0 then
  183.             FileName := FileName + Extension;
  184.          FixFileName := FileName
  185.       End;
  186.  
  187.  
  188.    Procedure GettingTheFileNames(Var Infile, Outfile: String18);
  189.  
  190.       Begin
  191.          If (ParamCount < 1) or (ParamStr(1) = '?') then
  192.             Begin
  193.             WriteLn(^J, ^J, '': 5,
  194.                     'The Master Silicone  CARDIAC simulator -- Ver ', Version,
  195.                     '  June-87');
  196.             WriteLn(^J);
  197.             WriteLn('HRT is a Cardiac language simulator.');
  198.             WriteLn;
  199.             WriteLn('Usage: HRT Filename1 [Filename2]');
  200.             WriteLn;
  201.             WriteLn(
  202.          'Where Filename1 is the input file name (default extension .HRT) and'
  203.                     );
  204.             WriteLn(
  205.                  'Filename2 is the output file name (default extension .OUT).'
  206.                     );
  207.             WriteLn;
  208.             WriteLn(
  209.         'If Filename2 is not specified then the program will place the output'
  210.                     );
  211.             WriteLn('in a file called filename1.OUT');
  212.             WriteLn;
  213.             Halt
  214.             End;
  215.          Infile := ParamStr(1);
  216.          If ParamCount > 1 then
  217.             Outfile := ParamStr(2)
  218.          else
  219.             Begin
  220.             If Pos('.', Infile) = 0 then
  221.                Outfile := Infile
  222.             else
  223.                Outfile := Copy(Infile, 1, Pred(Pos('.', Infile)))
  224.             End;
  225.          Infile := FixFileName(Infile, '.HRT');
  226.          If Not Exists(Infile) then
  227.             Begin
  228.             WriteLn(Infile, ', does not exist.');
  229.             Halt
  230.             End;
  231.          Outfile := FixFileName(Outfile, '.OUT');
  232.          If Infile = Outfile then
  233.             Begin
  234.             WriteLn('File names can''t be the same.');
  235.             Halt;
  236.             End
  237.          else If Exists(Outfile) then
  238.             Begin
  239.             Write(Outfile, ', already exists, do you want to delete it');
  240.             If Not Yes then
  241.                Halt
  242.             End
  243.       End;
  244.  
  245.  
  246.    Procedure CopyingTheProgram(Infile: String18);
  247.  
  248.       Var
  249.          Inf: Text;
  250.          Line: String79;
  251.  
  252.       Begin
  253.          Assign(Inf, Infile);
  254.          Reset(Inf);
  255.          Blank(2);
  256.          Space(14);
  257.          WriteLine('The Master Silicone  CARDIAC simulator -- Ver ' +
  258.                    Version + '  June-87');
  259.          Blank(3);
  260.          Repeat
  261.             ReadLn(Inf, Line);
  262.             Line := FixLine(Line)
  263.          Until (Line[1] = '6') or (Eof(Inf));
  264.          If Eof(Inf) then
  265.             Exit('  Incomplete program -- Sixes not found.');
  266.          Repeat
  267.             ReadLn(Inf, Line);
  268.             Line := FixLine(Line);
  269.             If Line[1] <> '7' then
  270.                WriteLine(Line)
  271.          Until (Line[1] = '7') or (Eof(Inf));
  272.          If Eof(Inf) then
  273.             Exit('  Incomplete program -- Sevens not found.');
  274.          Repeat
  275.             ReadLn(Inf, Line);
  276.             Line := FixLine(Line)
  277.          Until (Line[1] = '8') or (Eof(Inf));
  278.          If Eof(Inf) then
  279.             Exit('  Incomplete program -- Eights not found.');
  280.          Repeat
  281.             ReadLn(Inf, Line);
  282.             Line := FixLine(Line)
  283.          Until (Line[1] = '9') or (Eof(Inf));
  284.          Close(Inf);
  285.          If Line[1] <> '9' then
  286.             Exit('  Incomplete program -- Nines not found.');
  287.          Blank(1)
  288.       End;
  289.  
  290.  
  291.    Procedure ZeroingTheStorage(Var Help, Box, Data: StringInt);
  292.  
  293.       Var
  294.          Index: Byte;
  295.  
  296.       Begin
  297.          For Index := 0 to 99 do
  298.             Begin
  299.             Help[Index] := 0;
  300.             Box[Index] := 969;
  301.             Data[Index] := 9999
  302.             End
  303.       End;
  304.  
  305.  
  306.    Procedure LoadingTheStorageLocations(Var Box: StringInt;
  307.                                         Infile: String18);
  308.  
  309.       Var
  310.          Inf: Text;
  311.          Line: String79;
  312.          Index, Index2, Index3, Command, Statement: Integer;
  313.  
  314.       Begin
  315.          Assign(Inf, Infile);
  316.          Reset(Inf);
  317.          Index := 0;
  318.          Repeat
  319.             ReadLn(Inf, Line);
  320.             Index := Succ(Index);
  321.             Line := FixLine(Line)
  322.          Until Line[1] = '6';
  323.          Repeat
  324.             ReadLn(Inf, Line);
  325.             Index := Succ(Index);
  326.             Line := FixLine(Line);
  327.             If Line[1] = ' ' then
  328.                Begin
  329.                If (Line[2] In ['0'..'9']) and (Line[3] In ['0'..'9']) and
  330.                   (Line[7] In ['0'..'9']) and (Line[8] In ['0'..'9']) and
  331.                   (Line[9] In ['0'..'9']) then
  332.                   Begin
  333.                   Statement := ((Ord(Line[2]) - 48) * 10) + ((Ord(Line[3]) -
  334.                                48));
  335.                   Command := ((Ord(Line[7]) - 48) * 100) + ((Ord(Line[8]) -
  336.                              48) * 10) + ((Ord(Line[9]) - 48))
  337.                   End
  338.                else
  339.                   Begin
  340.                   PrintBlock;
  341.                   WriteLine(Line);
  342.                   For Index2 := 1 to 9 do
  343.                      If (Index2 In [2, 3, 7..9]) and
  344.                         (Not (Line[Index2] In ['0'..'9'])) then
  345.                         Begin
  346.                         For Index3 := 1 to 9 do
  347.                            If (Line[Index3] = ' ') and
  348.                               (Index3 In [2, 3, 7..9]) then
  349.                               Begin
  350.                               WriteLn(' Line number, ', Index: 1,
  351.                                 ', is blank, and blank lines are not allowed.'
  352.                                       );
  353.                               WriteLn(Outf, ' Line number, ', Index: 1,
  354.                                 ', is blank, and blank lines are not allowed.'
  355.                                       );
  356.                               Close(Outf);
  357.                               Close(Inf);
  358.                               Halt
  359.                               End;
  360.                         Space(Pred(Index2));
  361.                         WriteLine('^');
  362.                         LineNumber := 0;
  363.                         WriteLine2(' Syntax error found on line number: ',
  364.                                    Index);
  365.                         Close(Outf);
  366.                         Close(Inf);
  367.                         Halt
  368.                         End
  369.                   End;
  370.                If Line[6] = '-' then
  371.                   Command := Command * ( - 1);
  372.                Box[Statement] := Command
  373.                End
  374.             else If Line[1] <> '7' then
  375.                Begin
  376.                PrintBlock;
  377.                WriteLine(Line);
  378.                WriteLine('^');
  379.                WriteLine2(' Syntax error found on line number: ', Index);
  380.                Close(Outf);
  381.                Close(Inf);
  382.                Halt
  383.                End
  384.          Until Line[1] = '7';
  385.          Close(Inf)
  386.       End;
  387.  
  388.  
  389.    Procedure LoadingData(Var Data: StringInt;
  390.                          Var MaxData: Integer;
  391.                          Infile: String18);
  392.  
  393.       Var
  394.          Inf: Text;
  395.          Temp: Real;
  396.          Line: String79;
  397.          Index: Integer;
  398.  
  399.       Begin
  400.          Assign(Inf, Infile);
  401.          Reset(Inf);
  402.          Repeat
  403.             ReadLn(Inf, Line);
  404.             Line := FixLine(Line)
  405.          Until Line[1] = '7';
  406.          MaxData := 0;
  407.          Blank(1);
  408.          Repeat
  409.             ReadLn(Inf, Line);
  410.             Line := FixLine(Line);
  411.             If Line[1] <> '8' then
  412.                Begin
  413.                MaxData := Succ(MaxData);
  414.                For Index := 1 to 9 do
  415.                   If ((Index IN [1, 2, 7..9]) and (Line[Index] <> ' ')) or
  416.                      ((Index in [4..6]) and
  417.                      (Not (Line[Index] In ['0'..'9']))) or ((Index = 3) and
  418.                      (Not (Line[Index] In [' ', '-', '+']))) then
  419.                      Begin
  420.                      PrintBlock;
  421.                      WriteLine(Line);
  422.                      Space(Pred(Index));
  423.                      WriteLine('^');
  424.                      Close(Inf);
  425.                      Exit(' Syntax error found in data.')
  426.                      End;
  427.                Temp := 100 * (Ord(Line[4]) - 48);
  428.                Temp := (10 * (Ord(Line[5]) - 48)) + Temp;
  429.                Temp := (Ord(Line[6]) - 48) + Temp;
  430.                If Line[3] = '-' then
  431.                   Temp := Temp * ( - 1);
  432.                Data[MaxData] := Trunc(Temp)
  433.                End
  434.          Until Line[1] = '8';
  435.          Close(Inf)
  436.       End;
  437.  
  438.  
  439.    Procedure GettingTheCommand(Var Command, Location: Integer;
  440.                                NumberOfStatements, Step: Integer;
  441.                                Var Help: StringInt;
  442.                                Box: StringInt);
  443.  
  444.       Begin
  445.          Command := Box[Step] Div 100;
  446.          Location := Box[Step] Mod 100;
  447.          If (Command < 0) or (Location < 0) then
  448.             Begin
  449.             PrintBlock;
  450.             WriteLine2('Illegal statement in statement ', Step);
  451.             WriteLine('Program terminated!');
  452.             WriteLine2('Number of statements executed = ',
  453.                        NumberOfStatements);
  454.             Command := 12
  455.             End
  456.          else
  457.             Help[Step] := Succ(Help[Step])
  458.       End;
  459.  
  460.  
  461.    Procedure WritingOutSummary(NumberOfStatements, Step: Integer);
  462.  
  463.       Begin
  464.          PrintBlock;
  465.          WriteLine2('Halt encountered at statement ', Step);
  466.          WriteLine2('Number of statements executed = ', NumberOfStatements);
  467.          Blank(1)
  468.       End;
  469.  
  470.  
  471.    Procedure ReadData(Var NumberOfStatements, Command, L: Integer;
  472.                       MaxData, Location: Integer;
  473.                       Data: StringInt;
  474.                       Var Box: StringInt);
  475.  
  476.       Begin
  477.          If L > MaxData then
  478.             Begin
  479.             PrintBlock;
  480.             WriteLine2('End of data at statement ', Step);
  481.             WriteLine('Execution terminated!');
  482.             WriteLine2('Number of statements executed = ',
  483.                        NumberOfStatements);
  484.             Command := 12
  485.             End
  486.          else
  487.             Begin
  488.             Box[Location] := Data[L];
  489.             L := Succ(L);
  490.             NumberOfStatements := Succ(NumberOfStatements);
  491.             Command := 10
  492.             End
  493.       End;
  494.  
  495.  
  496.    Procedure Shift(Var Accumulator, Command: Integer;
  497.                    Location: Integer);
  498.  
  499.       Var
  500.          Left, Right: Integer;
  501.  
  502.       Begin
  503.          Left := Location Div 10;
  504.          Right := Location Mod 10;
  505.          If Left in [0..3] then
  506.             Case Left of
  507.                0:
  508.                   Accumulator := Accumulator;
  509.                1:
  510.                   Begin
  511.                   If Accumulator > 1000 then
  512.                      Accumulator := Accumulator - (Accumulator Div 1000 *
  513.                                     1000);
  514.                   Accumulator := Accumulator * 10
  515.                   End;
  516.                2:
  517.                   Begin
  518.                   If Accumulator > 100 then
  519.                      Accumulator := Accumulator - (Accumulator Div 100 * 100);
  520.                   Accumulator := Accumulator * 100
  521.                   End;
  522.                3:
  523.                   Begin
  524.                   If Accumulator > 10 then
  525.                      Accumulator := Accumulator - (Accumulator Div 10 * 10);
  526.                   Accumulator := Accumulator * 1000
  527.                   End
  528.                End
  529.          else
  530.             Accumulator := 0;
  531.          If Accumulator <> 0 then
  532.             If Right In [0..3] then
  533.                Case Right of
  534.                   0:
  535.                      Accumulator := Accumulator;
  536.                   1:
  537.                      Accumulator := Accumulator Div 10;
  538.                   0:
  539.                      Accumulator := Accumulator Div 100;
  540.                   0:
  541.                      Accumulator := Accumulator Div 1000
  542.                   End
  543.             else
  544.                Accumulator := 0;
  545.          Command := 15
  546.       End;
  547.  
  548.  
  549.    Procedure Print(Location: Integer;
  550.                    Box: StringInt);
  551.  
  552.       Begin
  553.          WriteLn(Box[Location]: 6);
  554.          WriteLn(Outf, Box[Location]: 6);
  555.          Printer
  556.       End;
  557.  
  558.  
  559.    Procedure Store(Accumulator, Location: Integer;
  560.                    Var Box: StringInt);
  561.  
  562.       Var
  563.          Number: Integer;
  564.  
  565.       Begin
  566.          Number := Accumulator;
  567.          If Accumulator > 999 then
  568.             Begin
  569.             Number := Accumulator - (1000 * (Accumulator Div 1000));
  570.             PrintBlock;
  571.             WriteLine2('Positive storage overflow at statement ', Step);
  572.             WriteLn(Outf, 'Contents of accumulator (', Accumulator: 1,
  573.                     ') too large for storage!');
  574.             Printer;
  575.             WriteLn('Contents of accumulator (', Accumulator: 1,
  576.                     ') too large for storage!');
  577.             WriteLine('High order digits truncated!');
  578.             WriteLn(Outf, 'Resulting value for location ', Location: 1, ' = ',
  579.                     Number: 1);
  580.             Printer;
  581.             WriteLn('Resulting value for location ', Location: 1, ' = ',
  582.                     Number: 1)
  583.             End
  584.          else If Accumulator < - 999 then
  585.             Begin
  586.             Number := Accumulator - (1000 * (Accumulator Div 1000));
  587.             PrintBlock;
  588.             WriteLine2('Negative storage overflow at statement ', Step);
  589.             WriteLn(Outf, 'Contents of accumulator (', Accumulator: 1,
  590.                     ') too small for storage!');
  591.             Printer;
  592.             WriteLn('Contents of accumulator (', Accumulator: 1,
  593.                     ') too small for storage!');
  594.             WriteLine('High order digits truncated!');
  595.             WriteLn(Outf, 'Resulting value for location ', Location: 1, ' = ',
  596.                     Number: 1);
  597.             Printer;
  598.             WriteLn('Resulting value for location ', Location: 1, ' = ',
  599.                     Number: 1)
  600.             End;
  601.          Box[Location] := Number
  602.       End;
  603.  
  604.  
  605.    Procedure OverflowCheck(Var Accumulator: Integer;
  606.                            Command: Integer);
  607.  
  608.       Var
  609.          Number: Integer;
  610.  
  611.       Begin
  612.          If Accumulator > 9999 then
  613.             Begin
  614.             Number := Accumulator - (10000 * (Accumulator Div 10000));
  615.             If Command <> 15 then
  616.                Begin
  617.                PrintBlock;
  618.                WriteLine2('Positive storage overflow at statement ', Step);
  619.                WriteLn(Outf, 'Contents of accumulator (', Accumulator: 1,
  620.                        ') too large for storage!');
  621.                Printer;
  622.                WriteLn('Contents of accumulator (', Accumulator: 1,
  623.                        ') too large for storage!');
  624.                WriteLine('High order digits truncated!');
  625.                WriteLn(Outf, 'Resulting value for location ', Location: 1,
  626.                        ' = ', Number: 1);
  627.                Printer;
  628.                WriteLn('Resulting value for location ', Location: 1, ' = ',
  629.                        Number: 1)
  630.                End;
  631.             Accumulator := Number
  632.             End
  633.          else If Accumulator < - 9999 then
  634.             Begin
  635.             Number := Accumulator - (10000 * (Accumulator Div 10000));
  636.             If Command <> 15 then
  637.                Begin
  638.                PrintBlock;
  639.                WriteLine2('Negative storage overflow at statement ', Step);
  640.                WriteLn(Outf, 'Contents of accumulator (', Accumulator: 1,
  641.                        ') too small for storage!');
  642.                Printer;
  643.                WriteLn('Contents of accumulator (', Accumulator: 1,
  644.                        ') too small for storage!');
  645.                WriteLine('High order digits truncated!');
  646.                WriteLn(Outf, 'Resulting value for location ', Location: 1,
  647.                        ' = ', Number: 1);
  648.                Printer;
  649.                WriteLn('Resulting value for location ', Location: 1, ' = ',
  650.                        Number: 1)
  651.                End;
  652.             Accumulator := Number
  653.             End
  654.       End;
  655.  
  656.  
  657.    Procedure Subtract(Var Accumulator: Integer;
  658.                       Location: Integer;
  659.                       Box: StringInt);
  660.  
  661.       Begin
  662.          Accumulator := Accumulator - Box[Location];
  663.          Command := 10
  664.       End;
  665.  
  666.  
  667.    Procedure Jump(Var NumberOfStatements, Step: Integer;
  668.                   Location: Integer;
  669.                   Var Box: StringInt);
  670.  
  671.       Begin
  672.          NumberOfStatements := Succ(NumberOfStatements);
  673.          Box[99] := Step + 801;
  674.          Step := Pred(Location)
  675.       End;
  676.  
  677.  
  678.    Procedure CoreDump(Accumulator: Integer;
  679.                       Box, Data, Help: StringInt);
  680.  
  681.       Var
  682.          CR: Boolean;
  683.          K, J, Index, Index2: Integer;
  684.  
  685.       Begin
  686.          Write(Outf, ^L);
  687.          For Index := 1 to 3 do
  688.             WriteLn(Outf);
  689.          LineNumber := 4;
  690.          Blank(2);
  691.          Space(34);
  692.          WriteLine('C O R E   D U M P');
  693.          Space(34);
  694.          WriteLine('-----------------');
  695.          Blank(1);
  696.          Space(20);
  697.          WriteLine('0    1    2    3    4    5    6    7    8    9');
  698.          Blank(1);
  699.          For Index := 0 to 9 do
  700.             Begin
  701.             K := Index * 10;
  702.             Write(Index: 14, '  ');
  703.             Write(Outf, Index: 14, '  ');
  704.             For J := 0 to 9 do
  705.                If Box[K + J] = 969 then
  706.                   Begin
  707.                   Write(Outf, '***': 5);
  708.                   Write('***': 5)
  709.                   End
  710.                else
  711.                   Begin
  712.                   Write(Outf, Box[K + J]: 5);
  713.                   Write(Box[K + J]: 5)
  714.                   End;
  715.             Blank(1)
  716.             End;
  717.          Blank(1);
  718.          Space(14);
  719.          WriteLine2('The value of the accumulator at termination was ',
  720.                     Accumulator);
  721.          Blank(3);
  722.          PrintBlock;
  723.          Space(30);
  724.          WriteLine('Profile of executions');
  725.          Space(30);
  726.          WriteLine('---------------------');
  727.          Blank(1);
  728.          WriteLn(Outf, 'Statment': 20, 'Executions': 15, 'Statement': 19,
  729.                  'Executions': 15);
  730.          Printer;
  731.          WriteLn(Outf, '--------': 20, '----------': 15, '---------': 19,
  732.                  '----------': 15);
  733.          Printer;
  734.          WriteLn('Statment': 20, 'Executions': 15, 'Statement': 19,
  735.                  'Executions': 15);
  736.          WriteLn('--------': 20, '----------': 15, '---------': 19,
  737.                  '----------': 15);
  738.          Blank(1);
  739.          CR := False;
  740.          For Index := 1 to 99 do
  741.             If Box[Index] <> 969 then
  742.                Begin
  743.                If Not CR then
  744.                   Begin
  745.                   Write(Outf, Index: 15, Help[Index]: 15);
  746.                   Write(Index: 15, Help[Index]: 15)
  747.                   End
  748.                else
  749.                   Begin
  750.                   WriteLn(Outf, Index: 20, Help[Index]: 15);
  751.                   WriteLn(Index: 20, Help[Index]: 15);
  752.                   Printer
  753.                   End;
  754.                CR := Not CR
  755.                End;
  756.          Blank(2);
  757.          If Data[1] <> 9999 then
  758.             Begin
  759.             PrintBlock;
  760.             Space(28);
  761.             WriteLine('D A T A   L I S T');
  762.             Space(28);
  763.             WriteLine('-----------------');
  764.             Blank(1);
  765.             Index2 := 0;
  766.             For Index := 1 to 99 do
  767.                If Data[Index] <> 9999 then
  768.                   Begin
  769.                   Write(Outf, '': 20, Data[Index]: 5);
  770.                   Write('': 20, Data[Index]: 5);
  771.                   Index2 := Succ(Index2);
  772.                   If Index2 Div 2 = Index2 / 2 then
  773.                      Blank(1)
  774.                   End;
  775.             Blank(1)
  776.             End
  777.       End;
  778.  
  779.    Begin
  780.       ZeroingTheStorage(Help, Box, Data);
  781.       LineNumber := 1;
  782.       NumberOfStatements := 0;
  783.       Accumulator := 0;
  784.       L := 1;
  785.       GettingTheFileNames(Infile, Outfile);
  786.       Assign(Outf, Outfile);
  787.       Rewrite(Outf);
  788.       CopyingTheProgram(Infile);
  789.       LoadingTheStorageLocations(Box, Infile);
  790.       LoadingData(Data, MaxData, Infile);
  791.       Step := 1;
  792.       WriteLine('     Compilation complete.');
  793.       Blank(1);
  794.       PrintBlock;
  795.       Repeat
  796.          GettingTheCommand(Command, Location, NumberOfStatements, Step, Help,
  797.                            Box);
  798.          Box[0] := 1;
  799.          If NumberOfStatements >= Limit then
  800.             Command := 11;
  801.          If Command IN [1, 2, 4..7, 9] then
  802.             NumberOfStatements := Succ(NumberOfStatements);
  803.          If Command in [0..9, 11, 12] then
  804.             Case Command of
  805.                0:
  806.                   ReadData(NumberOfStatements, Command, L, MaxData, Location,
  807.                            Data, Box);
  808.                1:
  809.                   Accumulator := Box[Location];
  810.                2:
  811.                   Accumulator := Accumulator + Box[Location];
  812.                3:
  813.                   If Accumulator < 0 then
  814.                      Jump(NumberOfStatements, Step, Location, Box);
  815.                4:
  816.                   Shift(Accumulator, Command, Location);
  817.                5:
  818.                   Print(Location, Box);
  819.                6:
  820.                   Store(Accumulator, Location, Box);
  821.                7:
  822.                   Subtract(Accumulator, Location, Box);
  823.                8:
  824.                   Jump(NumberOfStatements, Step, Location, Box);
  825.                9:
  826.                   WritingOutSummary(NumberOfStatements, Step);
  827.                11, 12:
  828.                   Blank(1)
  829.                End
  830.          else
  831.             Begin
  832.             PrintBlock;
  833.             WriteLn(Outf, 'Illegal command in statement ', Step: 1, '!');
  834.             Printer;
  835.             WriteLn('Illegal command in statement ', Step: 1, '!');
  836.             WriteLine('Execution terminated.');
  837.             WriteLine2('Number of statements executed: ', NumberOfStatements);
  838.             Command := 12
  839.             End;
  840.          OverflowCheck(Accumulator, Command);
  841.          Step := Succ(Step)
  842.       Until Command IN [9, 11, 12];
  843.       If Command = 11 then
  844.          Begin
  845.          PrintBlock;
  846.          WriteLine2(
  847.            'Cancelled due to statement execution limit exceeded at statement '
  848.                     , Pred(Step));
  849.          WriteLine2('Number of statements executed: ', NumberOfStatements)
  850.          End;
  851.       Write(^J, 'Do you want a PROFILE');
  852.       If Yes then
  853.          CoreDump(Accumulator, Box, Data, Help);
  854.       Close(Outf);
  855.       WriteLn;
  856.       WriteLn('Program output is stored in ', Outfile)
  857.    End.
  858.