Section l: User Documentation. l.O: Introduction. Each subsequent section of the user documentation is intended to explain the results and syntax and give examples for clarification of the commands and concepts involved in that section and for no other section. Larger examples covering several points, in the form of small programs and output results are given at the end of this section. l.l: Execution and Termination. The udc is executed by typing ‘udc’. The prompt ’UDC> ', visual notification that the program is in a state ready to accept the next command, then appears. Commands are then entered in the form described in the rest of this section. Each command is either a blank line, an interrogation of an expression or an assignment. If the commands for a udc execution are in a file then prompts, though not error messages or interrogation responses, may be suppressed. A udc execution is terminated by pressing Control-D at the beginning of a new line. 1.2: Expression Types. Expressions can be of the following basic types: a) Non-negative integers in the range 0 to some maximum value determined by the system. e.g. 6, 45 b) Simple variables represented by the 26 letters of the alphabet in small type. e.g. a, b, z c) array variables represented by the 26 letters of the alphabet in capitals followed by a defined array index in brackets in the range 0 to an arbitrary upper index limit which is determined from within the udc program. This upper index limit is here set to 99. e.g. A(7), B(98) d) The undefined value. That is, the value used to represent to the value of variables to which no expression has been assigned or to which an expression with no defined value is assigned. The symbol for this is ‘@’. All variables are set to this value on udc startup. e) Complex expressions, made up by combining these simple expressions using the available operator set. l.3: Command Types. All udc commands are either blanks, assignments or interrogations, though several commands may be placed on one line or one command may be placed over several lines [1.5]. a) A blank command consists of the carriage return char alone. e.g. Udc Sequence 1. UDC> UDC> UDC> b) Assignment is to either a simple or array variable. The expression being assigned to the variable may be of any form, and does not have to be defined numerically at the time of assignment. This is the major feature of the udc. That is it allows the assignment of formulae, so that although the values of variables within an assigned expression may change, this does not make the assignment obsolete since the assignment was to the formula representing the expression, and not to the numerical value that that expression held at the time of assignment. Other than error checks, and possible application of the evaluation operator, nothing is done to an assigned formula other than recording it in a table of variable names. A legal assignment results in the expression assigned being recorded with the variable assigned to by way of a variable table which records all successful assignments. An Assignment has the following syntax = e.g. a = 8 sets the simple variable a to the value 8. A[5] = @ sets the 5th variable of the array A to the undefined value. b = c + d sets b to the formula c+d - not the explicit value of c+d. There are however certain anomalies in what constitutes a valid assignment command [2.4] caused by the context of certain assignations. c) A legal interrogation results in the printing of an expression on standard output. The form of the expression printed depends on the type of the expression interrogated. If the interrogated expression is a simple or vector variable then the expression printed is the formula assigned to that variable in the variable table otherwise the expression printed is the expression interrogated. A legal interrogation has the syntax ? e.g. ? a results in the printing of the formula associated with a in the variable table. ? a + b results, rather unusefully, in the printing of the same expression 'a+b'. ? 8 - 3 results in the printing of '8-3’. So that an interrogation is of some use and expressions can be evaluated, there is the evaluation operator [l.4.6]. 1.4: Operators. 1.4.0: Introduction. The operator set provides a means of combining the simple expressions to make complex and more useful expressions. All operators act on numbers or undefined values only, since at the time of evaluation the subexpressions within an expression that constitute operands are themselves evaluated first to return either a number or the undefined value. With the exception of the ifwthen-else operator, if the expression depends on any operand which, when evaluated is the undefined value then the whole expression is undefined. All explanations of evaluation of operands with a given operator given below are those that would occur when the evaluation is effected, since before then expressions are represented as formulae within the variable table. 1.4.1: Unary Operators. There are two unary operators. a} Gnary minus has the following syntax — The minus sign denotes a unary minus, as opposed to binary minus ( the subtraction operator ), if the previous symbol is not a number, a simple variable, the undefined value, a closing brace or a right parenthesis from an expression or array variable. The effect of the unary minus on an expression is to negate any defined evaluation of it. e.g. - a will negate the value of a if it is explicit at the time of evaluation. — 6 this is not a simple expression but a complex one defined as ‘the negation of 6', that is subtly different from ’minus 6’. b) The logical ’not‘ has the following syntax 1 Its effect on a numeric value is to return 0 if the expression has value not equal to O and to return 1 if the value is O. e.g. E 2 will return 0 on evaluation. 3 0 will return l on evaluation. 2 @ will return the undefined value on evaluation. 1.4.2: Binary Operators. There are fifteen binary operators. a) The additive operator has the following syntax + and the resulting expression is the number defined by sum of the evaluated operands. e.g. l + 2 will return 3 on evaluation. l + @ will return the undefined value on evaluation. b) The subtractive operator has the following syntax ~ The minus sign is assumed to represent a binary minus; the subtractive operator if it does not meet the conditions for being a unary minus; that is it is the subtractive operator if the previous symbol is a number, simple variable, the undefined value, or a closing parenthesis or brace, and the resulting expression is the number defined by the difference of the evaluated operands if expressionl is the greater, otherwise it is the number defined by negation of this difference. e.g. l ~ 2 will return ~l on evaluation. c) The multiplicative operator has the following syntax * and the resulting expression is the number defined by the product of the evaluated operands. e.g. 2 * 3 will return 6 on evaluation. d) The division operator has the following syntax / and results in the number defined by the quotient of the evaluated expressionl divided by the evaluated expression2 unless the evaluated expression2 is zero. e.g. l / 2 will return 0 on evaluation. 2 / 1 will return 2 on evaluation. 6 / @ will return the undefined value on evaluation. e) The modulus operator has the following syntax % fl 9) i) j) K) 1) M) H) O) and returns in the number defined by the remainder of the division of the evaluated expressionl by the evaluated expression2. e.g. 14 % 6 will return 2 on evaluation. The exponent operator has the following syntax and returns the number defined according to the following function of the evaluated operands * ln e e.g. 2 A 4 will return 16 on evaluation. The maximum operator has the following syntax /\ and returns the number defined by the greater of the two evaluated operands. e.g. l /\ 2 will return 2 on evaluation. «l /\ ~2 will return ~l on evaluation. The minimum operator has the following syntax \/ and returns the number defined by the lesser of the two evaluated operands. e.g. l \/ 2 will return l on evaluation. —l \/ ~2 will return -2 on evaluation. The less~than relational operator has the following syntax < and returns the number l if the evaluated expressionl is less than the evaluated expression2, otherwise it returns 0. e.g. 2 < 2 will return 0 on evaluation. 1 < 2 will return l on evaluation. The less~than~or~egual~to relational operator has the following syntax <= and returns the number l if the evaluated expressionl to the evaluated expression2, otherwise it returns 0. e.g. 2 <= 2 will return l on evaluation. 2 <= l will return 0 on evaluation. The equal~to relational operator has the following syntax == and returns the number 1 if the evaluated expressionl is to the evaluated expression2, otherwise it returns 0. e.g. 2 == 2 will return l on evaluation. 2 =2 l will return 0 on evaluation. The greaterwthanwor-egual~to relational operator has the >2 and returns the number l if the evaluated expressionl is to the evaluated expression2, otherwise it returns 0. e.g. 2 >2 3 will return 0 on evaluation. 2 >= l will return l on evaluation. The greater~than relational operator has the following syntax > and returns the number l if the evaluated expressionl is less than to the evaluated expression2, otherwise it returns 0. e.g. 2 > 2 will return 0 on evaluation. 2 > 1 will return l on evaluation. The logical ‘and’ operator has the following syntax & and returns the number l if both evaluated operand expressions are otherwise it returns 0. e.g. 2 & 3 will return l on evaluation. 2 & 0 will return 0 on evaluation. The logical ’or‘ operator has the following syntax I and returns the number 1 if at least one of the evaluated operands is non~zero other wise it returns 0. e.g. 2 i 0 will return l on evaluation. 0 1 0 will return 0 on evaluation. is less than or equal or equal following syntax less than or e ual Q or equal i"10l’1“'“Z€lC'O 1.4.3: If~then~else. If~then—else is a the only ternary operator used to build an expression with the following syntax if then else The expression is defined by the evaluation of expression2 if the evaluated expressionl is nonvzero regardless of whether expression2 is defined or not, and is defined as the evaluation of expression3 if the evaluation of expressionl is zero regardless of whether expression2 is defined or not. If expressionl is is not numerically defined then the value resulting from the evaluation of the whole if~then~else expression is also undefined regardless of whether expression2 or expression3 are defined. e.g. if 75 then 43 else 44 will when evaluated return 43. if 0 then 2 else @ will return @ ~ the undefined value. if l then 2 else @ will return 2. if @ then lOO else 2&0 will return @ since the conditional expression is undefined. l.4.4: Operator Precedence. The unary and binary operators have precedences, which are used to decide the order of evaluation in a unparenthesised expression. For instance the expression 1 + 2 * 3 could have two meanings. Which of the two possible expressions is being represented is decided by the relative positions of the operators concerned in the operator precedence table. The precedences are given below. Table l: Operator Precedences. HIGHEST: unary minus, logical ‘not’ exponentiation multiplication, modular division, quotient division subtraction, addition maximum, minimum relational operators logical ’and' logical 'or' LOWEST: if-then~else This gives us an order for evaluation of multi~operator expressions, e.g. ‘12 + 3 / — 1 /\ 2 & 2 6 I 2 * 4 \/ 0 <2 9° 1) — 1 ~~~~ ~~> -1 E 6 ~~~~ ~~> 0 gives °12 + 3 / ~1 /\ 2 & 0 I 2 t 4 \/ 0 <2 9* 2) 3 / ~l -~~> ~3 2 t 4 ~~~~> 8 gives *12 + -3 /\ 2 & 0 I 8 \/ 0 <2 9* 3) 12 + »3 -~> 9 gives *9 /\ 2 & 0 I 8 \/ 0 <= 9° 4) 9 /\ 2 —~w> 9 8 \/ O ~~~> 0 gives '9 & O I 0 <= 9’ 5) 0 <= 9 ~~~> l gives *9 & O I l‘ 6) 9 & O -~~-> 0 gives *0 I 1* 7) 0 I 1 —~~~> 1 gives *1’ 1.4.5: Parentheses. Operator precedence supplies us with a default set of expression/operator associations within any expression. However we may wish to override this. For the example taken in [l.4.4] we may wish to evaluate the expression l + 2 * 3 by which we mean to represent the expression given in reverse polish notation as l 2 + 3 * rather than the other possibility which is the default. To do this we use parentheses to force evaluation in an order that does not traverse parentheses until there remains a simple expression within them. e.g. l + 2 * 3 gives 7 ( l + 2 ) * 3 gives 9 l + 2 * 3 A 4 gives the same as l + ( 2 * ( 3 " 4 ) ) ) which gives evaluation in the reverse order to ( ( l + 2 ) * 3 ) A 4. l&4§6: Braces. Braces are the evaluation operator, without which calculation can not take place. They have the following syntax { } The result is an expression, either integer or the undefined value. e.g. { 2 + 3 } gives 5 a + { 2 + 3 } gives a + 5 l.5: Spaces, Multiple Commands, Split Lines and Comments, All spaces and tab characters within any entry are ignored. e.g. 'a+b' is the same as ‘a + b‘ Several commands may be entered on one line by separating them with semicolons in the following way ; Prompting if enabled [l.5] will be suppressed until all commands in a command line have been completed. e.g. Udc Sequence 2. UDC> a = b + c ; ? a b + c UDC> b = l ; C = 2 ; ? { a } 3 Conversely, commands may be spread over several lines using a colon to terminate each unfinished line. An in ut on a line be ond a colon is i nored. Y P This allows comments within a udc input program to be inserted. e.g. Udc Sequence 3. UDC> ? { 6 + 9 } l5 UDC> :a is the width a = lOlG UDC> l.5: Silent Mode. Prompting may be suppressed by supplying the udc call with an argument. e.g. ”udc -s“ This gives improved readability of output sent to files. l.6: Error Types and Reports. There are ten basic error types and appropriate diagnostic reports that are provided as an aid to tracing errors. When any error is encountered then the command which contains the error is discarded. Error messages, causes and examples are described below. a) Incomplete expression. This is caused by an operator having insufficient operands to act upon in an expression made up of binary or unary operators. e.g. ? { a + b - ~ } a = b * b) C) 5) 9) f) 9) hi 1) Zero division. This is caused by an attempt to divide by zero either directly in the quotient operator or in the modulo operator. Attempts to divide by zero will only be detected at the time of evaluation, since an operand may become non~zero before evaluation, due to reassignment of variables that the operand depends on. e.g.?{1/<0/\—-1)} a={3%o} Circular definition. This is caused by attempting to define a variable in terms of itself either directly or through the definitions of other variables. e.g. a = a + l b = c ; c = b + l a = b ; b = c ; c = d ; Unknown symbol. This is caused by there being an illegal symbol in the input. e.g. ? { a + # } a = A [ 10 ] Missing symbol. This is caused by an several symbols that given these patterns 1) Right parenthesis e.g. A ( l = 0 d = e ; e = a expected symbol not being encountered. There are are expected after certain symbol patterns. Below are and example errors. follows an array indexing expression. 2) Right brace follows an expression which is preceded by a left brace. e.g.?{2+3) 3) Keyword ‘then’ follows an expression preceded by keyword ‘if’. e.g. if x =2 l else 3 4) Keyword ‘else’ follows an expression preceded by keyword ‘then’. e.g. if x == l then 3 5) Assignment sign follows a simple variable that starts a command. a + b 6) Assignment sign follows an array variable that starts a command. A(l) + 2 Invalid expression. This is caused by an expression having too many operands. e.g. a = b c + d Unexpected symbol. This is caused by an encountered symbol being out of context. e.g. a = ? Invalid statement. This caused by the first symbol in a command not being an interrogation mark, a simple variable or an array variable. e.g. if x > 0 then 4 else ~4 Undefined array index. . This is caused by an array variable’s index being undefined when evaluated. e.g. a = @ ; ? A { a ) Invalid array reference. This is caused by an array variableis index being outside a range of legal indexes determined by a defined constant within the udc source program. e.g. ? A ( lOO0 ) l.7: Example Programs. As an aid to understanding the concepts involved in the udc several example programs are given here. l.7.l: Alternatives to the Logical ‘And’ Operator. This program explores four alternatives to the conventional logical ‘and’ operator. Since the input commands are quite complex they were put in a file and supplied to the udc using the call udc ~silent < inpntfile > outputfile so that program and results, uninterrupted by prompts, could be kept separate. Program 1 ( with line numbering ): Logical ‘And’ Test. 1 . logical ‘and’ by alternative definitions 2 : a and b are the operands 3 2 Ail), A(2), A(3), A(4) are the alternative definitions 4 2 A(O) is normal logical ‘and’ operator 5 6 : function definitions 7 A(0) = a & b 8A(i)=2(zaizb) 9 A(2) = if a then ( if b then 1 else 0 ) else 0 10 A(3) = ( !( la ) + !{ Eb ) ) / 2 11 A(4) = if a*b == 0 then 0 else 1 12 13 : print function definitions 14 ? A(O); ? Ail); ? A{2); ?A(3); ?A(4) 15 16 : tests over all relevant a and h 17 a = O ; b = O 18 :>{A(0>};:>{A<1>};:>{A<2>}::>{A<3>}::>{A<4>} 19 a = 1 20 :>{A<0>}; :>{A<1>}: ? {Am}; ?{A<3>}: :> {A<4>} 21 a = O ; b = l 22 :,>{A<0)}:'2{A<1>}:?{A(2>1;:>{A(3>};:>{A<4>} 23 a = 1 24 ?{A<0>}: :>{A<1)}; :>{A<2>}: :>{A<3>}; :>{A<4>} This program uses variables in an array to store five different functions that represent the logical ‘and‘ operator. The program consists of the definitions of these five functions in terms of two variables a and b ( lines 7~l1 ), the printing of these functions ( line 14 ), and then the evaluation of all five functions with a and h set to all relevant permutations of 1 and O ( lines l7~24 ). The functions are the following A(O) = a & b This makes use of the normal logical ‘and’ operator on the variables a and b, and is included as a control experiment for comparing its results with the results of the other functions. A(l)==i(£aI£b) This function is merely the manipulation of the A(O) function using a hit of boolean algebra. A(2) = if a then ( if b then 1 else 0 ) else 0 This function is a rather wordy way of checking for when both a and b are set to non-zero values. If the first variable, a. is not 0 then the final result depends on the value of the second variable b. A(3) = ( S( la ) + i( lb ) } / 2 This function makes use of two features of the udc. Firstly the logical ‘not’ of the logical ‘not’ of a variable is always 1 or 0. Consider the following table. Table 2: Logical ‘Not’ of Logical ‘Not’. a la 2( la ) ~3 O 1 ~2 O 1 1 O l O 1 O l O 1 2 O 1 3 O 1 2 ( la ) is 0 if a is O and is 1 otherwise. Secondly, this function makes use of integer division. The sum ( !( Ia ) + ( lb ) ) can result in 3 different Values; 0, 1 and 2. Consider the following table. Table 3: Results from Integer Division on the Values 0 to 2. X X/2 X/2 integer 0 0.0 O l 0.5 O 2 1.0 1 This shows that in integer arithmetic, the only combination of a and b that when ’not~notted’, summed and subjected to integer division that gives a nonwzero result is when both variables are non~zero — that is, when a AND b are non—zero. A(4) = if a*h == then 0 else l The final definition depends on the product of any two integers is non~zero only if the two integers are nonwzeroi That is if the product is zero then at least one of the two integers must be zero? so the logical “and” must also return zero“ Udc Sequence 4i a & b 2( Ea I Eh ) if a then ( if b then l e ( i( la ) + 1( Sb 3 ) / 2 if a * b =2 0 then 0 else lse O ) else 0 l f-‘!-‘I--‘R-4}-‘CDCDCDCDCDCZDCDCZDCDCDCDCIJCDCDCD 1.7.2: An Alternative Multi lication Functioni P This function tests on specified values the quick method for multiolying two numbers with a difference of 2 in ones head. That being square the average and subtract l. If the two numbers have not got a difference of 2 then the value returned is undefined. Program 2 ( with line numbering ): Multiplicationl definitions of test values = = U‘ Q) as is difference function (a./\b) “ (a\/b) (3 is average function if c = 2 d = (a\/b) + l f““l"'“‘ F“‘C:7\Q03"\10WU'1+I>aC.2J[‘J}-“ 50 O H e is result function l2 e = if c =2 2 then d “ 2 ~ 1 else @ l3 l4 : interrogate result 15 ?{e} This program is split into 5 sectionsi The first of these defines the values of the variables whose product is to be calculated by this alternative method ( lines l~3 ). The absolute value of the difference is calculated by subtracting the minimum of the two values from the maximum value (lines 5~6 )0 This line could be replaced by a more easily understandable one 6 c = if a >= b then a else b The third section is the defining of the averaging function ( lines 8~9 )@ which if the difference is 2 will be the minimum of the values plus li Fourthly the result function is defined as l2 if the difference is 2 then e is the average of a and b squared minus l otherwise e is undefined Finally, this value is actually calculated ( lines l4~l5 ) This program demonstrates the use of comments and blank lines to make a program more easily understoodi It also shows the way that functions can be defined a long time before calculation. l.7.3: Complete Udc Session ( with inserted comments and line numbering )5 Udc Sequence 59 1 $ udc The udc is called with no arguments so prompting is giveni 2 UDC> ?a 3 @ Any previously undefined variable is initially set to the undefined value, 4 UDC> a = b + c a is assigned the formula b+c 5 UDC> b = l0 ; c = 20 The variables that a depends on are set with two commands on one line. 6 UDc> ?{a} 7 30 An interrogation of the evaluation of a is made, 8 UDC> b = a + c 9 circular definition a depends on b so b=(b+c)+c which is a circular definition and so rejectedi 10 UDC> b = {a} + c However this uses the explicit value of a at the time of this assignment. 11 UDC> ?{b} 12 50 An interrogation of the evaluation of b is made. 13 UDC> b = {b} “ 2 This assigns to b the explicit value of a function of b which is numeric. 14 UDC> ?b 15 50 “ 2 b is here interrogated - note this is not an interrogation of b evaluated 16 UDC> ?{b} 17 2500 and here the interrogation is of the evaluation of b 20 UDC> a = {b / 20 \/ 120} a is set to the lower of the two numbers defined by b/20 and 1209 21 UDC> ?{a} 22 120 The result is printedi 23 o = l5 24 UDC> b = if (a/o) * c== then l else 0 This function will return 1 if c is a factor of a. 25 UDC> ?{b} 25 1 So l5, the value of C, is a factor of l20, stored in a. 27 UDC> A( 28 invalid expression Incomplete expression entered so error» 29 UDC> 30 UDC> Blank entries. 31 Unc> ?A(O) 32 @ A previously undefined variable is interrogated. 33 UDC> ?A(f) 34 undefined array index Error caused by not knowing which variable in the array is being interrogatedl 35 UDC> f = 9 3 ?A(f) 36 @ So defining the variable representing the index allows us to interrogate A(f). 37 UDC> ?b 38 if ( a / o ) * c == a then 1 else 0 b is currently assigned to this formula, 39 UDC> A(O)=A(l)+A{lOO) 40 invalid vector reference Attempt to use a vector variable whose index is above the highest legal index. 41 UDC> A(O)=A(l)+A(99) In this implementation 99 is the default. 42 UDC> if a > S then l else 0 43 invalid start This statement is neither an assignment nor an interrogation. 44 UDC> b = if a > 5 then l else 0 45 UDC> ?b 46 if a > 5 then 1 else 0 47 unc> ?{~(20)} 48 «l This demonstrates the combination of unary operatorsi 49 UDC> ?~~--3 50 incomplete expression Although strictly legal, ~~~~3 is a bit confusing without parenthesese Sl UDC> ?~(~(~(~3))) 52 3 Use of parentheses makes the expression allowable, though pointless, 53 UDC> ?a+b 54 a + b Here the input function is being interrogated - very pointless, 55 UDC> ?{a+b} 55 -880 The same function is interrogated for an explicit value using braces. 57 UDC> “D Exit from udo is made using the CTRL~D symbol at the beginning of a new line, 58 $