Section 3: Development, 3,l: Problems and Novelties in Program Development, a) BNF Adaptation. The adaptations made to the original BNF specification served two purposes, Firstly it was necessary to introduce arrays of variables, and secondly the changing of the type of expression returned from comparisons such as a < b which previously would have returned true or false but now returns l or 0 respectively, was to facilitate bottom up parsing as far as possible. This change also brought with it a greater calculating power, since these expressions can now form part of complex arithmetic expressions, b) Input from Files. The silent mode feature was added since when programs that prompt are run into files they normally send prompts without newline characters as well as C) d) the expected results, this can look messy and can make the results hard to read. e.g. Without prompt suppression the following program Program 3: Messy Output Program. a=lO b=2O c=a+b ?c ; ?{c} returned to following Udc Sequence 6a. UDC> UDC> UDC> UDC> a + b 30 UDC> Whereas with prompt suppression achieved by supplying an argument with the udc call. it returned Udc Sequence 6b. a + b 30 The disadvantage of implementing this feature in the program is that the function called in Checkargs [4.3.l], i.e. 'argc', is not common to all versions of Pascal. if~then~else Parse For clarity within seem apt. e.g. The expression 1 ( if b>O then a else -a ) would be represented by the parse tree Tree Cell Adaptation. a parse tree, unary, binary and ternary tree cells would Diagram 7: Parse Tree with Unary, Binary and Ternary Nodes. But this would involve more complicated data structures for containment of the parse tree, so instead the representation of unary and ternary operators was tailored to fit the existing data structure which suited the majority of the operators, which are binary, best. The ifwthen~else structure can be contained in a subtree spanning two levels. As shown in Diagram 4c. The unary operators are inserted into the tree cell structure as shown in Diagram 4a. Binary or Unary Minus ? When a minus sign is encountered in the input, there must be rules to determine whether it is the unary or binary operator. The rule decided upon in this program is that if it is preceded by a right brace or parenthesis. 9) f) or by a number, variable or the undefined value the the minus sign is taken to be a binary minus. This rule works for all cases except multiple consecutive minus signs which could only be interpreted as unary minuses. Thus ~~~~~ «-4 is rejected, but ~(*(“(“(*(“(*4)))))) is not. This fault was not corrected as multiple minus signs are confusing anyway. This rule also applies to the other unary operator ~ logical ‘not’. Tables or Functions ? The various tables referenced during execution of the udc, could more neatly have been included as functions. This was tested but proved to be much slower since the entire set of values set up by the function had to be scanned before the right entry was found, so instead tables were set up at the beginning of execution? this while slowing the program down, for the first few moments, resulted in shorter delays between command executioner Compilation Problemsr In the early stages of development of this program the first prompt of the udo session was preceded by a bell—tone, however this was removed later when the source program was first compiled as it caused compilation EIIDKSE 3.2: Further Development. 3) Additional Operators. With the addition of indexed variables, additional operators would be most useful. In particular, if the existing operators could use entire arrays of these indexed variables then they arrays would become much more useful for manipulating data. e,g. Consider taking the average of the pairs consisting of a fixed number stored in the variable a and the twenty values contained in the array A. Conventionally, this would be performed as follows Program 4a: Long~winded Calculations“ m = ( A(i) + a ) / 2 1 = O ; ? {m} 1 = l ; ? {m} i = 20 , 9 {m} However with operators for whole arrays this task would be reduced to Program 4b: Fast Calculationsr M = ( A + a ) / 2 '9 {M} The expression printing procedure would have to be altered so that it would only print the expressions assigned to an array over a certain index rangei The most suitable way of defining this range would seem to be that variables within the array up to the highest indexed and defined variable are printed. Another useful operator for arrays, not already present, would be a conditional loop variable. Say this be called ’wnz‘ ( While Not Zero this would have the following syntax 'wnz” '[' ’]° ‘end’ ’ The channel number is effectively an evaluable return address for when an ‘end’ command with the same channel number is encountered. e.g. Consider the following alternative method to the above problem, ); Program 4c: Neater Faster Calculationsr b m 0 ( A(b) + a ) / 2 wnz [l] {2l-b} ? {m} b: {b} + 1 end [1] The possibilities with this additional operator are obvious. The channel number would mean easy implementation of nested ‘wnz’ commands. b) Real Arithmetic. Computations in this calculating language would be considerably more applicable if they used real valued variables rather than integer ones. An upgraded version of this program might have real arithmetic over all but a small number of variables, denoted say by a trailing ‘S’ on the variable name. These would typically be used as array indexes. C) Runwtime Input File Change. A more interactive system would be attained if the input file could be switched from inside a program. This would be most useful for reading in values. Say that this command will be denoted by ‘#’ then it would have the following syntax. ’=’ '#’ This would force subsequent input to be read from the standard input file until a carriage return charter appeared. e.g. Consider the following program for taking the average of two numbers. Program 5: Averaging Stdin. b+ ;'C / 2 H0 ) # -otfm r""°‘\H us.-«-4:t:»~\ a This would allow greater ease of use and flexibility of programs. Thus consider the following program which would make use of the previous three additions to the system. Program 6: All The Future Developments. :program to find the average of any number of entered integers. :a$ is entered number, initial value is any non~zero a5 = l :t$ is running total of as t$ = O :i$ is running total number of numbers entered is = ~l zenter numbers until entry is zero wnz [ll {a$} a3 = # ts = {t$ + a$} i$ = {i$} + 1 end [l] zcalculate mean into real variable m = t$ / i$ :evaluation and output ?{m} This program could be stored in a file and if executed on a unix operating system might be executed as follows Udo Sequence 7. S udc «silent < average.u l2 d) 8) 8)