MUMBLE Preliminary Draft August 20, 1981 11:41 AM Reformatted for TIOGA on August 3, 1982 6:12 pm Last changed on August 4, 1982 3:28 pm -- To do: fix everything! 1. Examples. 1.1. The LIFE game. {Bd, Temp: [[0,0],GETPOINT "Board limits"] 1 1; -- Bd is the board. 1 means "ARRAY OF DEPTH". Hsum: ((Bdv[0,1]) + (Bdt[0,1]) d 2); -- v is "SHIFTED BY", t is "SHIFTED BY -". d is "DEPTH". Vsum: ((Bdv[1,0]) + (Bdt[1,0]) d 2); -- (x + y d k) gives k lowest-order bits of the sum Nsum: (Vsum + (Hsum + (Hsumv[1,0] + Hsumt[1,0] d 3))); NewG: ((Nsum V Bd) = (ALL 011u)); -- Value of (x = y) is 1 where equal, 0 where different LOOP{EDIT Bd; -- displays magnified Bd and allows user "mousing" on it -- (probably a subroutine written in MUMBLE) LOOP {SHOW Bd; -- displays Bd in true scale. SCAN (Temp _ NewG); SCAN (Bd _ Temp); ANYCHAR g {GETCHAR; EXIT}} } } 1.2. The EDIT routine. EDIT: {Ar: ARRAY| Sz: HIGH Ar - LOW Ar; SzD: HIGH DISPLAY - LOW DISPLAY; ArI: (Art(LOW Ar)) CUT AT [[0,0], SzD/4]; Blob: [[0,0], [4,4]] 1 1; SCAN (Blob _ ELLIPSE [[0,2], [2,2], 2]); InvIt: {Ix: POINT | SET [ArI, Ix, ((ArI Ix) 4 1)]}; ShowIt: {Pos: POINT | SCAN DISPLAY _ DISPLAY 4 BlobvPos}; SHOW (ALL 0); FOR Pos IN BOUNDS Ari DO {Ari Pos g ShowIt Pos}; LOOP {C: GETOBJ; C IS POINT g {ShowIt C; InvIt (C-LOW DISPLAY)/4}; C = "QUIT" g {SHOW (ALL 0); EXIT}} } 2. Grammar -- This is a two-level grammar: it consists of a conrtext-free meta-grammar and a set of rule skeletons which together generate the definitive context-free grammar for the language. -- Meta-variables are in capital italics (like TYPE), and meta-productions have :: between left and right sides. By applying the meta-productions in a context-free manner, each meta-variable generates a set of terminal strings (in lowercase, as array, statement, etc) which are called its instances. (Any terminal string is an instance of the special meta-variable ANYTHING). -- By taking a rule skeleton (with ==) form the list below and replacing consistently every meta-variable in it by one of its instances, we get a good honest BNF rule (with no capital italics). -- The final grammar is the set of all rules that can be derived in this manner. Non-terminal symbols are strings delimited by <>, and everything else is terminal. TYPE :: array | formula | proc | int | point | box | record | ... OBJTYPE :: array | formula == : -- Evaluates and (re)defines the as the result. If the is of type formula, the result is the data structure - not the picture it represents. == SCAN -- The picture formula (a data structure) returned by the is evaluated for all pixels in the picture plane. The picture resulting from the execution is discarded. For the SCAN to have tangible effects, the formula should contain assignment or SWAP statements. == SHOW -- Equivalent to SCAN (DISPLAY _ formula). == == == FOR IN [ .. ] DO == == ... == SHIFT BY == REFLECT ABOUT = == ROTATE AROUND == TRANSPOSE AROUND == SAMPLE BY -- The object which is the current value of (an array or a picture formula) is modified as prescribed. The statement SHIFT A BY [2, 3] is equivalent to A: A SHIFTED BY [2, 3], except that the former affects also any formula containing A as subformula, while the latter creates a modified copy of A. == == SEP :: comma | semicolon == , == ; == == == -- whose current value is of type . == GEOTYPE :: formula | array | point | box == == SHIFTED BY == REFLECTED ABOUT = == ROTATED AROUND == TRANSPOSED AROUND == SAMPLED BY -- When the value of the expression is a formula or array descriptor, these operations make a modified copy of it, so that evaluating the result at pixel [i, j] is equivalent to evaluating the original at T-1[i, j], where T is the given transformation. The copy of an array shares the elemnts with the original (only the descriptor is copied). == I | J == CLOCKWISE | COUNTERCLOCKWISE -- Hopefully, the phrases 'SHIFTED BY', 'REFLECTED ABOUT I =', 'ROTATED COUNTERCLOCKWISE AROUND', etc. will each be denoted by single symbols (like v, r, etc). == ARRAY OF DEPTH == CUT AT == FROM LAYER == DEPTH == DISPLAY == NIL -- NIL has depth zero. == ( ) -- Builds a Piction for the given naked formula. The formula is actually evaluated only when SCANned. == ELLIPSE [TOP: , CENTER: , HALFWIDTH: ] == RECTANGLE == POLYGON [, , ] == ... == DEPTH | -- The optional depth specifies the number of bits to retain in each pixel of the result; the default depends on the operation. == FROM LAYER | -- The optional bottom layer specifies the layer of the naked formula that should become the lowest-order layer of the result. Should be non-negative (zero by default). == ALL -- A picture all of whose pixels have the specified value. == -- Returns a Reader piction for the given array. When SCANned, the formula (A) will yield zeros outside the bounds of A, and its current contents inside them. == OPAQUE -- similar to above, but appends a lowest-order layer that is 0 outside the bounds of the array, and 1 inside. Used with the OVER operator. == REPEAT -- Returns a Pattern piction for the given array. When SCANned, the formula (REPEAT A) will yield a picture consisting of the contents of A repeated indefinitely over the whole plane. This infinite picture will coincide with A inside the array bounds. == == == IF THEN ELSE == IF THEN -- Only evaluates the THEN (resp ELSE) part where the predicate is 1 (resp 0). == _ -- Returns a Modifier for the left-hand side. When SCANned, the formula (A _ P) will evaluate P inside the bounds of A, and store the resulting pixels in A. The result of the assignment is NIL. == SWAP -- When SCANned, (A SWAP B) exchanges the contents of corresponding pixels of A and B (wherever both exist). == , -- Stacks the pictures one on top of the other. == NOT | - == OR | AND | ERASE | XOR | EQV | + | > | = | MAX | MIN | OVER | ... -- ERASE is same as AND NOT. The operations +, MAX, MIN, > treat each pixel as an unsigned binary number. -- The construct (A _ A OR B) should be automatically optimized to the Modifier (A _ * OR B); (A _ NOT A) is optimized to (A _ NOT *) etc. -- (A OVER B) is equivalent to (IF A DEPTH 1 = 1 THEN (A FROM LAYER 1) ELSE B). That is, the lowest-order layer of A is treated as an opaque paper sheet, on which the rest of A is painted. == COPY == {} == { | } == == : == [, ] == POINT -- equivalent to [I:INTEGER, J:INTEGER] == BOX -- equivalent to [LOW: POINT, HIGH: POINT] == INT == ARRAY == FORMULA == PROC == == -- Matching an argument list to a parameter list means checking the consistency of both and building a third named list of values, the result of the matching. First the lengths of the two lists are checked for equality, and then the following rules are applied to each corresponding pair of argument value and parameter: 1. If the argument has a name , the corresponding parameter name must also be . 2. If the argument has no name and is the parameter name, : is prefixed to the argument. 3. If the parameter has ARRAY, FORMULA, INT or PROC as its declared structure, the argument value must be of the specified type. 4. If the parameter has structure [, , ...], the argument value should be a record [, , ...]. The lists and are matched recursively as above, and the result list is made into a record [, , ...] that is substituted for the argument value . 5. The pair : as determined above is appended to the result list. -- The final result of the matching is a list of named values : . Inside the procedure body, things happen as if the assignments : had been performed on entry. Note that the field names of are determined in part by the parameter description. == == : == [, ] == [] == . -- if the value of the has a field named of type TYPE. == -- conformable to [I: INT, J: INT] == * == ... == == == ... == -- conformable to [LOW: POINT, HIGH: POINT] == .BOUNDS == ... == ... == ... ΚΆ– "Cedar" style˜JšΠbxΟfΟxžp˜ŠJšžΠbfž˜J˜˜Jš  ˜ Jš ˜Jš3œ+ΟmœΟo‘’œ‘œ ‘œ‘œ ‘’Πosœ £‘£œ £œ‘œ‘œ ‘œ‘œ‘œ’%œ1‘œ+’ œ’œ’œ’=œ’3œ’ œR‘œ(˜νJš ˜Jš œ‘œ]‘œ<‘œ;‘œ4‘œ9‘œ˜ςJ˜š  ˜ š’?Πbo ’€’N˜΅š’€’Οi’€’₯’£œ’œ ’€ ’C₯’˜χJš’#£’$€ ’l˜ΑJš’œ’#˜€———š œ₯œ₯œ<₯œ₯œ)₯œ˜‚Jš’ £’œ’£’V˜Ÿ—˜Jš’:œ’rœ’Dœ’ ˜’—˜Jš’œΠioœ£˜*—š œŸ₯œ$₯œ.₯œ1₯œ&₯œ˜€Jš ’,œ’Kœ’œ’=œ’4¦’œ’˜±—š%œ₯œ₯œ ₯œ₯œ₯œ₯œ₯œ₯œ?₯œ ₯œ ₯œ₯œ’"œ’œ!₯œ₯œ!₯œ ₯œη˜ΕJš’h¦’cΡbioΠou’§’z˜Ϋ—˜;Jš ’œ ’œ’œ’5œ’œ’˜ —šœΡ’œ@˜§Jš’^œ£’˜f—J˜Έ˜1Jš’˜—˜=Jš’¨˜¨—˜$Jš’:˜:—˜Jš’Kœ’(œ’'˜ž—˜Jš’}œ’ ˜‹—˜Jš ’ œ’#œ’œ ’4œ’Wœ’˜ό—˜ΈJš’œ’œ’)˜N—˜#Jš’ œ’3œ’£œ’œ’$œ’#œ’˜Β—˜$Jš ’œ£’œ ’3œ’œ’˜l—˜0Jš’/˜/—˜yš ’œ’ œ’œ£œ£œ£œ’/˜iš ’œ ’+œ£œ ’œ ’œ ’˜ŒJš £œ ’œ/’%œ’;œ’ ˜Ό———Jšœ₯œ₯œ˜(JšœJΟbœ˜ešœ‡’œ"’œ‹˜Φš’¦’|¦’³˜Αš’œ’1œ’˜Xš’#œ’œ’˜aJš ’œ£œ£œ’œ’/œ’˜†Jš’"œ’(œ’ œ’œ’7œ’œ’,œ’˜Jš’ œ ’4˜K—Jš’>œ ’Bœ ’<œ’5˜‘———J˜ošœ₯œ˜$Jš’œ’œ’ ₯’˜B—Jšœ"’œͺ’œe˜Υ——…—(,Ό