]> thyrsus.com Git - cupl.git/commitdiff
Cleanup of CORC support
authorEric S. Raymond <esr@thyrsus.com>
Thu, 20 Apr 1995 15:57:32 +0000 (15:57 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 20 Apr 1995 15:57:32 +0000 (15:57 +0000)
corc.doc
cupl.xml
cupl.y
execute.c
interpret.c
test/MAKEREGRESS
test/REGRESS

index 432082326aefc2881ba0ace193e54ebe40e2b171..781afb13c776abede1c06f97264a3143d505ccf8 100644 (file)
--- a/corc.doc
+++ b/corc.doc
@@ -10,7 +10,7 @@ The differences:
 
    * The square root radical sign surrounding b is rendered as b^-2
 
-   * metavariable subscripts are simply appended to their metavariables.
+   * |a| is used to render the absolute-value operation.
 
    * `x' between digits is used to render the multiplication sign.
 
@@ -27,8 +27,21 @@ Error corrections:
      compound-AND example was incorrectly lowercased.  In item 1 of the BEGIN
      explanation, the word `statement' was incorrectly uppercased.
 
+Notes:
+
+   * Tags [See *1], [See *2], etc, are not part of the original; they reference
+     footnotes following the transcript.
+
+   * Tags such as [See 5-8] are not part of the original, they reference other
+     quotes from the text given below by page number.
+
 Otherwise, the appendix F transcription is exact, even down to hyphen breaks
-and spacing.
+and spacing (allowing for the fact that the original typewriter spacing was
+somewhat irregular...).
+
+The combination of Appendix F and the notes includes essentially all the
+manual's documentation of the CORC language itself.  Most of the text is
+tutorials and exercises.
 
 This implementation preserves the CORC-62 distinction between LOG and LN, 
 contrary to the transcript below which describes CORC-63 (which identifies
@@ -40,14 +53,17 @@ The following .corc files, included with this distribution, are also
 transcribed from the manual.  We include every complete program
 example.  The following list maps programs to original page numbers:
 
+simplecorc.corc         -- 4-6
+gasbill.corc            -- 4-9
+hearts.corc             -- 4-10
 sumsquares.corc                -- 5-4
-power.corc             -- 5-6
+powercorc.corc         -- 5-6
 factorial.corc         -- 5-6
-quadratic.corc         -- 5-9
-title.corc             -- 7-3
+quadcorc.corc          -- 5-9
+title.corc             -- 7-3  (note: this one uses continuations)
 
-We have supplied leading comments for these programs; they are otherwise
-unaltered.
+We have supplied leading comments and test data for these programs;
+they are otherwise unaltered.
  
 ---------------------------------- CUT HERE ----------------------------------
 
@@ -90,13 +106,13 @@ unaltered.
                     once in label field.
                     Block label used for only one set of BEGIN-END statements.
           e. Variables must be listed in Dictionary. If no initial value
-             is given zero is assumed.
+             is given zero is assumed.  [See *1]
           f. One or two subscripts, enclosed in parentheses.  May be
              any expression (including subscripted variables) whose
              value at execution is a positive integer not greater than
-             the maximum declared for this variable in Dictionary.
+             the maximum declared for this variable in Dictionary. [See D-2]
              In Dictionary and Input Data subscripts given as integers in
-                    subscript field; parentheses are not used.
+                    subscript field; parentheses are not used.  [See *1]
 \f
      Arithmetic Operators
      --------------------
@@ -150,11 +166,11 @@ unaltered.
           Initially right digit should be zero on all cards to leave
                room for later additions.
 
-     Program Arrangement
+     Program Arrangement [See *1]
      -------------------
           Arrange and number programming forms in the following order:
                     1. Preliminary Description
-                    2. Dictionary
+                    2. Dictionary [See 2-10]
                          List all variables to be used
                          Specify initial values if not zero
                          Specify maximum value for each subscript.
@@ -241,7 +257,7 @@ unaltered.
                                with value of expression assigned to
                                variable v.  Three expressions on list
                                enclosed in parentheses mean from h to k
-                               in steps of k.
+                               in steps of k. [See 5-8]
 
      Communication Statements
      ------------------------
@@ -262,3 +278,114 @@ unaltered.
                                notes only.
 
 ---------------------------------- CUT HERE ----------------------------------
+
+[*1] This implementation of CORC does not support or allow a
+Dictionary section.  Instead, variable initializations must be done via
+CUPL-style DATA and ALLOCATE statements.
+
+[*2] Ignore this section.  Program statements are free-format, with
+continuations not supported (though the example program
+test/title.corc shows the syntax, it will break cupl).  Data for read
+statements is accepted in CUPL format following the keyword *DATA.
+
+For completeness, however, the Dictionary feature is documented here.
+
+From 2-10:
+
+Dictionary of Variables
+-----------------------
+     In addition to a set of statements CORC requires a pro-
+gram to contain another part known as the Dictionary.  The Diction-
+ary of a program is merely a list of all the variables used in
+the program. along with, if desired, the initial assigned values of
+the variables.  If no initial value is specified the computer
+assigns the initial value zero.
+
+From 2-11:
+
+     In the above example the Dictionary might look like this:
+
+     A     1
+     B    -1
+     C    -6
+     ROOT
+     X1
+     X2
+
+[The `above example' is the simplecorc.corc program.  The CORC Dictionary
+is equivalent to a CUPL DATA section, but also allowed the programmer to
+dimension array variables.  The example form on 2-12 makes it clear that
+the Dictionary was distinguished from the program proper by being in a
+different lower range of card line numbers.] 
+
+From 5-8:
+
+Three expressions on a list, enclosed in parentheses, are in-
+terpreted in the following way:
+     1. The first expression gives the initial value for the vari-
+        able.
+     2. The second expression gives the difference between con-
+        secutive values.
+     3. The third expression indicates where to stop -- the final
+        value for the variable is less than or equal to the value
+        of the third expression.
+
+[... examples omitted ...]
+
+    More than one such "triple" may be used on a list, and
+"triples" may be intermixed with separate expressions;
+
+From 6-5:
+
+   A particular variable either has no subscripts, one sub-
+script, or two subscripts and this use must be consistent through-
+out a program.  A variable cannot appear as X(I) in one statement
+and X(I, J) or just X in another statement of the same program.
+The nature of a variable (whether it is to be subscripted or not)
+must be indicated when the variable is listed in the CORC Diction-
+ary.  This is done by giving the maximum value of any subscripts
+that will be used in columns 21-25 of the Dictionary form.  If no
+subscripts will be used these columns will be left blank in the
+line for that variable.  If one subscript is to be used, the maxi-
+mum value that that subscript will take on anywhere in the pro-
+gram must be given in columns 21-23; columns 24-25 are left blank.
+(Note that this is the maximum value of the subscript, and not
+the maximum value of the variable.)  If two subscripts are to be
+used the maximum value of the first is given in columns 21-23
+and the maximum value of the second in columns 24-25.  For ex-
+ample, if the Dicitonary [sic] looks like the following:
+
+          SCALAR
+          VECTOR    45
+          MATRIX   100     2
+          ARRAY      3    32
+
+then SCALAR is a simple variable that will not have any sub-
+scripts anywhere in the program.  VECTOR will have one subscript
+everwhere it appears in the program [...] MATRIX [...] will 
+appear each time with two subscripts [...] ARRAY will also
+always have two subscripts; [...]
+
+From D-2:
+
+Automatic Integer Round-off
+---------------------------
+a. The value of a subscript is rounded off to the nearest
+   integer.
+b. If the round-off involves a change of greater than
+   10^-9 (approximately;   the number is subject to some
+   variation) an error message is given.
+
+From D-3:
+
+Automatic Relative Round-off for x r y
+--------------------------------------
+a. If both x and y are zero the condition is applied as it stands.
+b. If either x or y is not zero:
+   (i) Both x and y are multiplied by MAX(|x|, |y|);
+   (ii) The results are rounded off to the nearest 
+        integer if this involves a change of less
+        than 10^-9 (10^-7 for the Burroughs 220), but
+        not otherwise;
+   (iii) The specified condition is interpreted for
+        the resulting numbers.
index 6441b1c57d1e6c79056382b2e5d240df9105f319..19e832c31e24409500d42d86f3958b7803038edb 100644 (file)
--- a/cupl.xml
+++ b/cupl.xml
@@ -46,18 +46,20 @@ CUPL rather resembles early BASICs, minus BASIC's string facility.  It is
 oriented towards scientific calculation and linear algebra, and would be nearly
 impossible (or, at any rate, extremely painful) to use for anything else.
 .P
-The programming-support features of CUPL resembled those of the
+The programming-support features of CUPL and CORC resembled those of the
 better-known WATFOR and WATFIV compilers, incorporating elaborate
 error-correction and trace output features using a runtime monitor.
-CORC does not appear to have supported these features.
 .P
-The only nontrivial difference between the CUPL and CORC languages
-proper was the interpretation of GO TO <label> when <label> is
+The only incompatibility between the CUPL and CORC languages
+documented was the interpretation of GO TO <label> when <label> is
 associated with a block.  In CUPL, this is a go to beginning of block;
 in CORC, it's go to end of block (which in CUPL is GO TO <block> END.
 The interpreter switches on CORC interpretation whenever it detects a
 CORC-specific word (such as NOTE) during lexing.
 .P
+The CORC statement TITLE and the triple iteration construct have no
+counterparts in CUPL.
+.P
 .H 1 "Differences from the original CUPL"
 .P
 The most obvious differences are also the most trivial.  CUPL was
diff --git a/cupl.y b/cupl.y
index 99dd0d18899e4fd530c510c87f2a4118f25cc0bd..9c81c2ca8eb5c43949bac34f7cf65048412a3c31 100644 (file)
--- a/cupl.y
+++ b/cupl.y
@@ -83,9 +83,10 @@ int yydebug;
 %token ISLICE JSLICE
 %token ITERATE
 %token FROM
+%token TRIPLE
 
 %type <node> prog command cond simple guard perform gosub iter expr rel alloc
-%type <node> subscr datal ditem expl readl writel witem allocl varlist
+%type <node> subscr datal ditem triple expl readl writel witem allocl varlist
 %type <node> minl maxl
 
 %%     /* beginning of rules section */
@@ -158,8 +159,13 @@ iter       :    TO expr BY expr            {$$ = cons(TO, $2, $4);}
        |    TO expr                    {$$ = cons(TO, $2, (node *)NULL);}
        ;
 
+triple  :    '(' expr ',' expr ',' expr ')'
+               {$$ = cons(TRIPLE, $2, cons(ITERATE, $4, $6));}
+
 expl   :    expr ',' expl              {$$ = cons(FORLIST, $1, $3);}
+       |    triple ',' expl            {$$ = cons(FORLIST, $1, $3);}
        |    expr                       {$$ = cons(FORLIST, $1, NULLNODE);}
+       |    triple                     {$$ = cons(FORLIST, $1, NULLNODE);}
        ;
 
 /* guard syntax */
index daacb8aeb1f4837367d96e05a1517410d188d868..74401e24b0befc57f9f08e77e68d3096f641184a 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -515,11 +515,27 @@ static value cupl_eval(node *tree)
        if (iterator->type == '=')
        {
            for_cdr(np, iterator->cdr)
-           {
-               result = EVAL_WRAP(cupl_eval(np->car));
-               cupl_assign(iterator->car, result);
-               cupl_eval(tree->cdr);
-           }
+               if (np->car->type == TRIPLE)
+               {
+                   scalar ds, initial, final, increment;
+                   node        *triple = np->car;
+
+                   initial = EVAL_WRAP(cupl_eval(triple->car)).elements[0];
+                   increment = EVAL_WRAP(cupl_eval(triple->cdr->car)).elements[0];
+                   final = EVAL_WRAP(cupl_eval(triple->cdr->cdr)).elements[0];
+
+                   for (ds = initial; ds <= final; ds += increment)
+                   {
+                       tree->car->car->syminf->value.elements[0] = ds;
+                       cupl_eval(tree->cdr);
+                   }
+               }
+               else
+               {
+                   result = EVAL_WRAP(cupl_eval(np->car));
+                   cupl_assign(iterator->car, result);
+                   cupl_eval(tree->cdr);
+               }
        }
        else if (iterator->type == ITERATE)
        {
index 9327dc38cc96632a37b55fccb36a3b0348f3c0a7..ef0880bbbb45893b78eea559114d426330cfbf95 100644 (file)
@@ -34,7 +34,7 @@ differently if we get a compiler back end.
 /* does the node reference a block label? */
 #define BLABELREF(n)   ((n) == PERFORM || (n) == END || (n) == OG)
 /* does the node set a variable? */
-#define VARSET(n)      ((n) == LET || (n) == READ || (n) == ITERATE)
+#define VARSET(n)      ((n) == LET || (n) == READ || (n) == ITERATE || (n) == '=')
 /* does the (non-VARSET) node refer to its left operand as a variable? */ 
 #define LEFTREF(n)     ((n) != FOR && (n) != GO && (n) != OG && (n) != LABEL \
                                && (n) != ALLOCATE && (n) != WATCH \
index 0cb34a7c4fb3c4efa4afcddf1925676d1b7ead48..505531d5c29cce297fc505e91ad6686bddceda94 100755 (executable)
@@ -3,7 +3,7 @@
 # Make regression-test loads for the CUPL compiler front end
 #
 TESTCUPL="cubic fancyquad poly11 power prime quadratic random rise simplequad squares sum"
-TESTCORC="factorial powercorc quadcorc sumsquares"
+TESTCORC="factorial gasbill hearts powercorc quadcorc simplecorc sumsquares"
 
 trap "rm -f testcupl$$; exit 0"
 
index 414f0307347841209a2c51aed4e2466effb36089..f1dbed0dbdee8a5f042d6636d750af044a80ac18 100755 (executable)
@@ -3,7 +3,7 @@
 # Regression-test the CUPL compiler front end
 #
 TESTCUPL="cubic fancyquad poly11 power prime quadratic random rise simplequad squares sum"
-TESTCORC="factorial powercorc quadcorc sumsquares"
+TESTCORC="factorial gasbill hearts powercorc quadcorc simplecorc sumsquares"
 
 trap "rm -f testcupl$$; exit 0"