Comput. Lang. Vol. 10, No. I, pp. 23-36, 1985 Printed in Great Britain. All rights reserved
0096-0551/85 $3.00+0.00 Copyright C 1985 Pergamon Press ktd
A P R O G R A M M I N G L A N G U A G E ENGINEERED FOR BEGINNERS HERMAN D. HUGHES Department of Computer Science, Michigan State University, East Lansing, MI 48824, U.S.A. (Received 27 September 1983; revision received 7 March 1984)
Abstract---As the complexity and size of programs increase, the programmer is challenged with the task of organizing his program in a manner which will enhance intellectual manageability. Thus, the structure and style are critical in regards to writing programs and verifying their correctness. In recent years, considerable emphasis has been placed on the correctness of programs and techniques for engineering them to be correct. However, more emphasis should be placed on designing languages which facilitate constructing correct programs. In an effort to partially address this problem, a language is described which permits users the convenient development of well-structured programs that are easy to read and understand, easy to correct (debug) and modify, and easy to verify the correctness of the program. The language presented permits the use of decision tables for expressing complex logic. Programminglanguages Structuredprogramming Decisiontables Top-downdesign
Flowcharts
1. I N T R O D U C T I O N In view of the significance of structured programming, programming languages should contain constructs that encourage the clearest possible statement of the program's goals. Furthermore, languages should be simple, powerful, and natural. They should aid programmers in both writing and reading programs. Programming languages must also provide convenient mechanisms for modifying programs and verifying their correctness. A good programming language must have structures that appeal to the user's thinking processes at the highest level of the design phase. Since there appears to be a relationship between the features of a programming language and the thinking habits of programmers using that language, the language should provide a set of features that stimulate problem-solving techniques which are transferable to other languages as well as applicable to problem-solving in general. The programming language described in this paper is referred to as "A Structured Programming Language" (ASPL). In Section 2, a discussion is presented on ASPL and its relationship to other languages, with emphasis on existing decision table processors. The general structure of ASF'L is then presented. This is followed by a description of features of the language relating to programming style. Most of the paper is devoted to the discussion of two examples. The first is a simulation of a finite state automata that illustrates the ability of ASPL to cope with a small problem, and the second is a solution to the black-jack game that illustrates the ability of ASPL to cope with more complex problems. Some data relative to an experimental project with ASPL at Michigan State University is presented in Section 4. The paper then concludes with a discussion of some implementation considerations and a summary. 2. ASPL A N D O T H E R L A N G U A G E S A few years ago, F O R T R A N and COBOL were the most frequently used high-level programming languages in university environments, However, due to current emphases on programming languages which enhance structured programming as well as programming flexibility, P A S C A L and C have gained popularity. Both languages (C and PASCAL) are relatively small compared to structured languages such as ADA, PL/I, and A L G O L 68 [14, 15, 16, 18]; but large compared to ASPL. P A S C A L was influenced by A L G O L 60 [17], and designed to allow for a structured approach to program development; whereas, the goal of C was to provide a wide range of applications [17]. 23
24
HERMAND. HUGHES
PASCAL programs are considered to be more reliable, readable, and portable than C programs because of its strong typing and rich set of data types. Nevertheless, both languages have recognized shortcomings compared to languages such as ADA and PL/I, and have been extended (e.g. UCSD, PASCAL, C O N C U R R E N T PASCAL, PORTABLE C COMPILER) to permit the use of additional features (e.g. enhanced character manipulation, real-time programming, etc.) [17]. The goal of ASPL was to provide a "small", structured language which permits the use of decision tables for expressing complex logic. Therefore, ASPL was influenced by decision table processors [11]. ASPL differs from other high-level structured languages (e.g. ADA, C, PASCAL, PL/I) in several ways: (1) it is a much smaller language, (2) it contains only the minimal basic structures, (3) it does not allow statement labels and GO TO statements, (4) only top-down programming is possible, (5) it requires the user to specify type on the variables only if they are to be declared as character, otherwise all variables and constants are treated as reals, (6) only simple I/O is supported, (7) it runs as an interpreter, and (8) as previously stated, it permits the use of decision tables. Since decision tables form an important feature of ASPL, it is only fitting to mention other uses of these tables for programming purposes. Several decision table processors are available and some of these were developed as early as the mid-1950's [9]. DETAB-X is a decision table preprocessor which accepts the decision tables as input and gives a form of COBOL coding as output [10]. FORTAB and CENTAB accept decision tables as input, and output a form of F O R T R A N coding [11]. More recently developed decision tables processors have been reported [12], all of which have characteristics similar to the previously developed processors. Since these processors were developed by private industries and government agencies, they are designed for specialized applications such as complex file maintenance problems [11]. Furthermore, the processors accept decision tables as input and output a form of programming language such as FORTRAN, COBOL, PL/I, etc. [11]. Hence, a three stage process: (1) decision table construction, (2) code generation, and (3) compilation and execution, is necessary for the user to obtain the final output from his program. This three stage procedure used by existing processors, coupled with the design specializations, make the available processors less appealing in a college or university environment. Also, programmers may encounter grave difficulties when attempting to debug their programs because of the excessive number of programming stages. Therefore, a language which is interpretive and also permits decision tables as one of its constructs, seems to have great promise. Since ASPL runs in an interpretative mode, the cost of running programs is slightly higher (about 10~o) than that for running the F O R T R A N equivalent programs. This extra cost can be justified on the basis that good run-time diagnostics (e.g. subscript range checking) are available to users, and that on the average fewer runs are required for the successful completion of programs.
3. S T R U C T U R E OF AN ASPL P R O G R A M In ASPL, there are three block structures: (1) P R O G R A M , (2) BLOCKS, and (3) SUBBLOCKS. These three structures form a hierarchy in which the P R O G R A M structure contains BLOCKS and SUBBLOCKS, and BLOCKS logically contain SUBBLOCKS. This hierarchy is depicted in Fig. 1. BLOCKS are disjoint structures, and may be thought of as mini-algorithms that make up a main algorithm. They correspond to breaking down an algorithm into large general steps. Each of these steps may have many details to complete before the general steps are done. In fact, these general steps are the intermediate goals that must be achieved before we can accomplish the overall goal of the algorithm. There is one additional structure to be considered along with P R O G R A M S and BLOCKS, and that is the SUBBLOCK. Although the general form of a SUBBLOCK is similar to a BLOCK, its logical relationship to a problem and to other program structures is somewhat different. A SUBBLOCK, like a subgoal, may have to be executed (reached) more than one before solving the problem, and different conditions may cause the SUBBLOCK to be invoked. In other words, this subgoal is a common subgoal.
A programming language engineered for beginners
25
PROGRAM N A M E 1 ---
BLOCK
1
PERFORM
1
.... 5
ENDBLOCK
L S UBBLOCK
'
i
1
---
2
PERFORM 2 --
-4
ENDBLOCK
6--
BLOCK
2
i i
I
ENDBLOCK
~
i
2
---3
ENDBLOCK
7---
ENDPROGAM
Fig. 1. Program structure with BLOCKS and SUBBLOCKS.
Figure 1 shows the logical relationship of B L O C K S and S U B B L O C K S to a program. The important thing to notice about the diagram is that for the execution of a program, only B L O C K S are automatically executed in the order of their appearance in the program. SUBBLOCKS, however, are skipped over because the p r o g r a m m e r must initiate the execution of a S U B B L O C K by using a P E R F O R M statement within a B L O C K or SUBBLOCK. The numbers opposite: the arrows indicate the sequence of flow (i.e. 1-, 2---,3-~ 4 ~ 5---,6 - , 7) for the program structure given in Fig. 1. For example, execution will begin at the statement P E R F O R M 1. Then, execution will proceed at the statement S U B B L O C K 1, and continue through the statement P E R F O R M 2, etc.
4. P R O G R A M M I N G
STYLE
The style used by programmers to structure their program is very important. Programming languages should be engineered in a way that a systematic indentation of users' programs is an inherent feature of the languages. Systematic indentation of programs makes them easy to read and can assist in locating logical errors since this hierarchical arrangement allows a quick grasp of the structure of the code. Also, the indentation of code segments facilitates their verification. In ASPL, programming style is enhanced by the availability of the following simple-minded features: (1) The automatic indentation of statements to emphasize the structures involved and the nesting of these structures. For example, the I F - T H E N - E L S E and E N D I F are placed on separate lines with the same margin. The code following the I F - T H E N - E L S E is also indented with the same margin. Other constructs placed on the same margin include: D O W H I L E and E N D O . B L O C K and E N D B L O C K , and S U B B L O C K and E N D B L O C K . Decision tables are aligned in columns to facilitate easy reading. (2) The restriction of relatively long, complicated statements within a program. For example, the statement Y = (13,X + 6 - 5 , Y ) - 6 , X + 4 , Y * * 3 / ( Y , X + 3,Y) + X - Y / 3 - 3 , ( X - Y ) + 3 , X is complex and probably should be written as two separate statements and then combined by a single statement. In ASPL, long statements are discouraged, since there are no provisions for the
26
HERMAN D. HUGHES
continuation of a statement onto the next line. NOTE: The maximum number of characters permitted in an ASPL statement is 80. (3) The mechanism which permits the construction of a program so that it is modular. In ASPL modularity can be achieved by the use of BLOCKS and SUBBLOCKS. The programmer is forced to use modular programming techniques in ASPL because it allows only one I F - T H E N - E L S E construct per BLOCK/SUBBLOCK. NOTE: ASPL automatically separates BLOCKS/ SUBBLOCKS by outputting a line of asterisks/slashes with the name of the B L O C K / S U B B L O C K centered. 5. S I M U L A T I N G A F I N I T E S T A T E A U T O M A T O N , AN E X A M P L E OF P R O B L E M - S O L V I N G IN ASPL ASPL is perhaps most powerful for solving the type of problems in which many conditions exist and there are several alternatives for satisfying these conditions. Problems which involve logic for playing games (e.g. Checkers, Black Jack, Roulette, Space War, etc.) are typical examples. Still another class of problems which lend themselves to ASPL solutions is in the area of simulation. The first example presented in this paper will illustrate the simulation of a finite state automata in ASPL.
Example 1 FSA (finite state automata) acceptors are fundamental to many areas of computer science including the theory of sequential circuits and the theory of compiling. Formally, a FSA is a six-tuple ( S , a , 1,0, & 2 ) such that S = a set of states called the initial state I = an input alphabet O = an output alphabet (optional) 6 = a transition function such that 6 = S x I--*S 2 = an output function (optional) 2 = S x I---,O
o~S =
Graphically, a FSA can be represented by the diagram presented in Fig. 2. This simple FSA recognizes expressions of the form (an), n > 0. In ASPL, you can write programs simulating the actions of FSA's quite easily using a D O W H I L E loop and an I F - T H E N - E L S E statement. As an example, let us take the string anbmc~ where n, m,/' > 0; (i.e. all strings of the form a . . . a b . . . b c . . . c where there can be any number of occurrences including 0, of each letter). The FSA accepting these strings is given in Fig. 3. A flowchart which describes the general solution to the simulation of the FSA is depicted by Fig. 4. The symbols "Y", " N " and " - " denote yes, no, and don't care, respectively.
Fig. 2. FSA for (an), n >~0.
27
A p r o g r a m m i n g l a n g u a g e e n g i n e e r e d for b e g i n n e r s G
o
b
b
Fig. 3. F S A for anbmd, n, m a n d ? >7 0, BLOCK FSA SEQ
]
1
t. 2.
DO 12
INITILIZE START STATE READ INPUT SYMBOL
WHILE NOT END-OF-FILE IF
3
THEN
SEQ
5
1. 2.
F S A IS I N S T A T E i I N P U T S Y M B O L ' a ' , "b', or 'c"
Y Y
N
1. 2. 3. 4.
CHANGE TO STATE j OUTPUT ERROR MSG OUTPUT INTERMEDIATE STOP
Y N Y N
N Y N Y
1.
READ NEXT SYMBOL
RESULTS
ENDBLOCK Fig. 4. G e n e r a l solution for F S A - I .
An
ASPL
program
PROGRAM FSA • FSA TO SIMULATE
that
simulates
STRINGS
OF THE
this machine
FORM
is:
A * * N , B * * M , C * * L . N, M. & L > 0
,,/!i///i,'/ii!lll!iiiliiillillli///ii,'i,'!lii!l!/i!/iii!!i/!li! BLOCK MACHINE STATE = 0 READ LETTER DOWHILE NOT EOF • **IF S T A T E M E N T D E F I N E S T H E T R A N S I T I O N F U N C T I O N IF S T A T E -: 0; Y Y Y S T A T E -: 1: -- -- -- Y Y Y -- -- -S T A T E = 2; Y YS T A T E = 3; Y L E T T E R = 'A'; Y -- Y -- -- N N N L E T T E R = "B'; -- Y -- -- Y -- Y N N L E T T E R - 'C'; -- -- Y -- -- Y -- Y Y • **THEN STATEMENT ASSIGNS NEXT STATE TO FSA THEN N X T S T A T = 1; Y----Y N X T S T A T = 2; -- Y -- -- Y -- Y ---N X T S T A T = 3; ---- Y ---- Y -- Y Y • **ELSE STATEMENT DEFINES ERROR CONDITION ELSE PRINT "ILLEGAL STRING', LETTER, 'IN STATE', STATE STOP ENDIF STATE = NXTSTAT READ LETTER ENDDO ENDBLOCK MACHINE
,iiii/ii!,'iiiii!!1ilii/i!1iili!i!ii!II,,'!!!//!1iliiili!illi!i/i ENDPROGRAM
FSA
28
HERMAND. HUGHES
As can be seen, the I F - T H E N - E L S E defines the transitions of the FSA from one state to another by checking the current state of the machine and the current input which defines what the next state will be. Note that if the input is A while we are in state 2, the string does not belong to the set of strings the FSA is looking for, so we print out an error message and stop; similarly for inputs A and B in state 3. It should be obvious that the FSA can be changed by simply making a change in the appropriate column of the decision table within the I F - T H E N construct. 6. B L A C K - J A C K
GAME,
ANOTHER
E X A M P L E OF ASPL
Although ASPL was designed primarily for beginning programmers, it may be used by skilled programmers to solve complex problems. This is illustrated by an example which involves an ASPL solution to a game called B L A C K J A C K . The rules of the game used by the ASPL program are consistent with the " s t a n d a r d " rules of B L A C K JACK. Now, using the only available structures of ASPL (i.e. sequential, iteration, and alternation), we proceed to formulate a solution to the problem by applying the top down process (refer to Fig. 5). Box 1 will initialize necessary variables, and boxes 2 and 3 simply indicate that the game will be played as long as players exist. A refinement of Fig. 5 is presented by Fig. 6. Note that playing the game (box 3 in Fig. 5) is defined by several subtasks, and these subtasks are performed in ASPL as SUBBLOCKS. Consider one of the sequential processes in box 3 of Fig. 6. For example, P E R F O R M F I R S T C A R D can be further refined to the structure given by Fig. 7. This figure depicts what happens when the first card is dealt. Notice that boxes 3 and 4 contain a statement P E R F O R M D E A L , so this can be further refined to the chart presented by Fig. 8. This refinement process may be continued until all logical components have been clearly defined. The total breakdown is not shown due to large numbers of SUBBLOCKS, but the reader can refer to the program listing in the appendix for additional details. BLOCK GAME
DO
1
INITIALIZE VARIABLES
2
DO WHILE NO. PLAYERS GT 0
SEQ J 3 PLAY GAME
ENDBLOCK Fig. 5. General solution of BLACK JACK. SUBBLOCK PLAY 1. Initialize Variables 2. Perform READNAMES
DO
2
DO WHILE NO. PLAYERS GT 0
SEQ ] 3
1. 2. 3. 4. 5. 6. 7. 8.
Perform READBETS Perform FIRSTCARD Perform MORECARDS Perform FINDMAXX Perform DEALERS Perform PAYOFF Perform NEWGAME Perform REINITIAL
ENDBLOCK Fig. 6. Refinement of Fig. 5.
A programming language engineered for beginners
29
Each S U B B L O C K of the model was designed and tested one at a time, starting with the top-level S U B B L O C K S (i.e. R E A D N A M E S , R E A D B E T S , F I R S T C A R D , etc.). D u m m y S U B B L O C K S were set up for those S U B B L O C K S in which code did not exist, so that top-level B L O C K S could be run and tested. After finding and correcting the errors in the upper-level routines, the d u m m y S U B B L O C K S that were set up for the top-level B L O C K S were filled in, and new dummies were established, if necessary, to keep the partially completed program running. For example, the main B L O C K ( B L A C K J A C K ) was designed and tested first. This B L O C K activates 9 S U B B L O C K S and these S U B B L O C K S call other SUBBLOCKS. The S U B B L O C K S were designed and tested in a parallel fashion (i.e. by levels) until the B L A C K J A C K program was completed. The ASPL interpreter provides a comprehensive set of compilation and execution-time diagnostic messages, and this made the debugging of" the program much easier. The compilation error messages immediately follows the statement which produced the message. For example, some of the messages which were produced are:
N E X T C A R D G E ( ( 5 2 * D E C K ) + 1;
T **********WARNING: E R R O R N U M B E R 36 N O N - F A T A L : VARIABLE NOT DEFINED
PERFORM FIRST **********COMPILATION: E R R O R N U M B E R 29 FATAL: N O (SUB) B L O C K D E C L A R A T I O N
Execution time error messages generated by ASPL are also useful. An example of an execution time error follows. **********EXECUTION: E R R O R N U M B E R 101: S U B S C R I P T O U T OF B O U N D S **********PROGRAM T E R M I N A T E D AT S T A T E M E N T N U M B E R 121 ASPL provides debug facilities which were useful for finding errors in the Program. A dump of all variables and their values is automatically produced when a fatal error is encountered during program execution. Alternatively, the user can specify that certain variables are dumped from selected B L O C K S / S U B B L O C K S for the purpose of tracing the execution of his program. A trace to indicate which rule of a decision table was activated for a B L O C K / S U B B L O C K is also available. The type of trace data was found to be valuable for debugging the Program. By changing entries in the decision table, one can modify an algorithm in a trivial manner. Since ASPL allows only one I F - T H E N - E L S E B L O C K per B L O C K / S U B B L O C K , this forced the program to be modular, and also imposed a natural partitioning of its components. For a complete listing of the ASPL implementation of the computer program, refer to the Appendix.
7. E X P E R I M E N T A L
PROJECT
W I T H ASPL
During the 1978 spring term, a group of beginning programmers were presented ASPL instead of F O R T R A N as the primary p r o g r a m m i n g language. This experimental group was given the same set of programming exercises as the regular F O R T R A N group, plus some additional programming assignments. One objective was to show that the students using ASPL could solve problems with fewer trials per problem than students using F O R T R A N . This objective was essential in order to justify the cost-effectiveness of programming in ASPL. Another objective was to show that the
30
HERMAND. HUGHES SUBBLOCK F I R S T C A R D J=l DO
I 2 D O W H I L E J LE NPLAYERS
Is QI 3 I. 2. 3.
P E R F O R M DEAL
Print Names (J) and the card dealt J=J+l
4 1. J = 6 2. P E R F O R M DEAL 3. PRINT "Dealer Is Dealt an unexposed card" ENDBLOCK Fig. 7. Refinement of Fig. 6. SUBBLOCK D E A L
Increment Card Count for Players (J) Deal Player (J) the Next card Increase Player (J): Total 4. Nextcard = Nextcard + 1 1. 2. 3.
THEN~
1. Nextcard G E ((52,Ndecks)+ 1) 2. Points (Card (Nextcard))= 11 3. Total (J) G T 21 4. ACE (J) G T 0
YYYNNN YNYYNY YYNYYN --y----y__
1. Perform Shuffle 2. Nextcard = 1 3. Ace(J) = Ace(J) + 1 4. Total ( J ) = T o t a l ( J ) - 10 5. Ace ( J ) = Ace ( J ) - 1
yyy-----yyy-------__y---Y Y--YY---y----y__
3
y
ENDBLOCK Fig. 8. Refinement of Fig. 7.
students who had ASPL could be taught to master F O R T R A N skills equivalent to the regular F O R T R A N students in a short time. Some statistics relating the performance of the two groups are given in Table 1. Because of the difficulty in setting up a meaningful experiment of this type, it is not possible to draw any hard conclusions from the above data. It can be observed, however, that the ASPL students generally solve the same problem as the F O R T R A N students in fewer trials per problem. On the average the ASPL students solve more problems than the F O R T R A N group. Perhaps the most impressive statistic is that the ASPL group was presented F O R T R A N in only 2 weeks and obtained a higher average on the F O R T R A N final exam than the regular F O R T R A N group. The ASPL group also did the last two F O R T R A N assignments both in ASPL and in FORTRAN. In general, the rating forms completed by students indicated a very positive attitude toward ASPL. Whether this language will become an alternative for teaching beginning programmers at MSU is uncertain at this time. 8.
SOME
IMPLEMENTATION
CONSIDERATIONS
is a language interpreter and is i m p l e m e n t e d in F O R T R A N I V o n a C D C C Y B E R 750. non-standard F O R T R A N features include: (1) m a s k and shift functions, (2) BUFFERIN/BUFFEROUT statements, and (3) the error recovery facility. The m e m o r y requirement for the language interpreter is 1 8 k words. ASPL
The
A p r o g r a m m i n g l a n g u a g e e n g i n e e r e d for beginners
31
Table l Activity
Experimental (26 students
Regular (36 students)
Assign. 1 Total runs Runs/student
28 1.22
6565 1.81
Assign.2 Total runs Runs/student
136 5.23
186 5.16
Assign. 3 Total runs Runs/student
143 5,50
220 6. l 1
Assign. 4 Total runs Runs/student
134 5.15
243 6.75
Assign. 5 Total runs Runs/student
201 7.73
302 8.39
Assign. 6 Total runs Runs/student
224 8.62
315 8.75
Avg. completed Assignments FORTRAN Final Exam average
11 out of 12
7.4 out of 8
65.42
62.79
Some programming restrictions in ASPL are cited below: (1) (2) (3) (4) (5)
Maximum of 60 rules in the condition part of a decision table. Maximum of 6 nested D O W H I L E s permitted. Only 1 and 2 dimensional arrays allowed. Only 1 decision table is permitted per BLOCK/SUBBLOCK. All data is converted to REAL, except character data, which must be declared as Hollerith. If an integer value is desired, then the integer function (INT) must be used. (6) ASPL scans the rules for the condition entries from left to right, and the first one found to be true will determine the action taken. No further scanning takes place. Functional components of the ASPL processor include: (1) Lexical Analyzer, (2) Parser, (3) Interpreter, and (4) Message Generator. A detailed discussion of the implementation of these components is not presented since this paper focuses on ASPL from a user's viewpoint. However, since decision tables used in ASPL are somewhat unique to compilers, a brief discussion of their implementation may be of interest. The method used for handling decision tables in ASPL is referred to as the "scanning and rule mask technique" (11). From the condition entries of the decision table, a YES M A T R I X (i.e. ones are inserted for all YES conditions, and zeros elsewhere) and a YES/NO M A T R I X (i.e. ones inserted for all YES/NO conditions, and zeros elsewhere) are formed by the P A R S E R and made available to the I N T E R P R E T E R . Similarly, a YES M A T R I X is formed by the PARSER from the action entries of the decision table. Finally, a transaction vector (i.e., ones indicate true conditions, and zeros denote false conditions) is generated after the I N T E R P R E T E R evaluates the condition entries. The transaction vector is multiplied (boolean multiplication) by each vector of the YES/NO M A T R I X and the results are compared (starting with rule 1, followed by rule 2, etc.) with the corresponding vectors in the YES M A T R I X to determine which action is to be performed. An IF register of the I N T E R P R E T E R contains a bit for the result of each comparison 1 indicates true, 0 indicates false. Refer to Fig. 9 for an illustration of the scanning and rule mask technique. Consider the decision table shown in Fig. 9. Since rule 2 produced the desired match, the action corresponding to this rule will be executed. 9. S U M M A R Y
Programming languages should be viewed only as tools for users to describe algorithms to computers. A programming language influences its uses at least with respect to (1) the style of
32
HERMAND. HUGHES R1 Y
CONDITIONS
ACTIONS
R2 N
R3 N
R4 N
--
Y
N
N
--
--
Y
N
Y
Y
Y y.
YES MATRIX
(MASKING) YES/NO MATRIX
R1
R2
R3
R4
1
0
0
0
0 0
1 0
0 1
0 0
R1
R2
R3
R4
1
1
1
1
0 0
1 0
1 1
1 1
PREPARE A TRANSACTION VECTOR: "1" (TRUE) "0" (FALSE) (i.e.
[1
~cond. 1--False, cond. 2--True, cond. 3--True)
RULE 1
1
TRANS. VECTOR 0
X
YES/NO VECTOR 1
0
YES VECTOR 1
1 1
X X
0 0
0 0
0 0
0 1
X X
1 1
0 1
0 1
1
X
0
0
0
"AND"
RESULT
EQUAL? NO
YES
Fig. 9. Scan and rule mask technique.
programming, (2) the conceptual understanding of how a problem can be solved by a computer and (3) the range of problems which can be attacked by programming. The amount of time required for programmers to become fluent in a particular language should be minimal (i.e. 1-2 days). Additionally, a programmer should not have to routinely reference a programming manual in order to be functional in that language (2). This suggests a need for languages which are simple, natural, efficient, and yet, powerful. A balance between these attributes is made at the design stage of the language. For most high-level languages, the emphasis has been on the power of the language. The language presented in this paper may serve as a model to illustrate that many desirable features can be incorporated into a relatively small language. ASPL was designed for beginning programmers, and therefore, it has the minimum basic constructs (sequential, D O - W H I L E , and IF-THEN-ELSE). It attempts to minimize syntactical details in the coding of programs, thereby enabling the user to concentrate on the logic of a problem. Since many users' errors are associated with the logical flow of their programs, ASPL handles this by permitting only one entry and one exit point per B L O C K / S U B B L O C K , and by allowing the use of decision tables to simplify complex logic. These decision tables also provide an excellent means of documentation because they are easy to read and construct by persons with varying technical backgrounds. Furthermore, by changing entries in the decision table, one can modify an algorithm in a trivial manner. We believe that ASPL has the simplicity and intellectual appeal of a well-formed language and will generate the motivation among programmers to adopt new standards of programming practice.
A programming language engineered for beginners In regard to future enhancements
to ASPL, the implementation
c o n t r i b u t e t o t h e p o w e r o f A S P L , a n d h e n c e t o its p r o b l e m - s o l v i n g (1) R e c u r s i v e c a l l s (2) A S P L calls t o F O R T R A N
33
o f t h e f o l l o w i n g f e a t u r e s will characteristics.
subroutines REFERENCES
I. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.
Wilkes M. V., Software engineering and structured programming. 1EEE Trans. Software Eng SE-2, 274~276 (1976). Mills H. D., Software development. IEEE Trans. Software Eng SE-2, 265-273 (1976). Devine D. J., Decision tables as a basis of a programming language. DPMA Q. 7, 461466 (1965). Freeman P., Toward improved review of software designs. Proe. National Computer ConJerence, pp. 329-334 (1975). Gannon J. D. and Horning J. J., Language for programming reliability, 1EEE Trans. Software Eng SE-I, 179-191 (1975). Wirth N., On the composition of well-structured programs. Comput. Surv. 6, 247-259 (1974). Hughes H., A tool designed to facilitate structured programming. Bull. SIGGSE, pp. 26-30 (February 1977). Dahl O. J., Dijkstra E. W. and Hoare C. A. R., Structured Programming. Academic Press, New York 11972). McDaniel H., An Introduction to Decision Logic Tables. Wiley, New York (1968). Chapman A. E. and Callahan M. A., A description of the basic algorithm used in the DETAB:65 preprocessor. Commun. A C M 10, 447~456 (1967). Pooch U. W., Translation of decision tables. A C M Comput. Surv. 6, 125 149 (1974). McDaniel H., Decision Table Software. Brandon/System Press (1970). Gerhart S. L., Knowledge about programs: A model and case study. Proc. Int. Conf. on Reliable So['tware, pp. 88-95 (1975). Barnes J. G. P., Programming in Ada. Addison-Wesley, Reading, Massachusetts (1981). Bowles K. L., Problem Solving Using Pascal. Springer, New York (1977). Kernighan B. W. and Ritchei D. M., The C Programming Language. Prentice-Hall, Englewood Cliffs, New Jersey (1978). Feuer A. R. and Gehani N. H., A comparison of the programming language C and PASCAL. ACM Comput. Surv. 14(1) (March 1982). Wasserman A. I., Tutorial: Programming Language Design. IEEE Computer Society, Silver Spring, Maryland (1980). Gries D., The Science of Programming. Springer, New York (1981). Gehani N. H., Program development by stepwise refinement and related topics. BSTJ 60(3) (March, 1981). About the Author--HERMAN D. HUGHES received the B.S. Degree in Mathematics from Stillman College
in 1959, the M.S. Degree in Chemistry from Tuskegee Institute in 1963, and the Ph.D. Degree from the University of Southwestern Louisiana in 1973. He has taught Mathematics at Tuskegee Institute, Grambling State University, and the University of Southwestern Louisiana. Dr Hughes has also worked at several locations for IBM, Americal Oil Company, Dow Chemical, and the Avionics Laboratory at Wright Patterson Air Force Base. He is currently an Associate Professor of Computer Science at Michigan State University, and his research interests include computer performance evaluation and local networks. Dr Hughes is a member of Pi Mu Epsilon, Upsilon Pi Epsilon, and the Association for Computing Machinery.
Ck
I0 I
{"
34
HERMAN D. HUGHES APPENDIX PROGRAM BLACKJACK MATRIX NAME$(6),DECKS(104),POINTS(104),HAND$(6,5),CARD(104),PLAYERIN(6) DATA NCARDS(6)/O/,TOTAL(6)/O/,ACE(6)/O/,MONEY(6)/2OOO/,BET(6)/O/,NPLAYERS/O/ DATA NEXTCARD/I/ ***************************** BLOCK INITIAL BLOCK INITIAL J=l DOWHILE J LE 104 READPF DECKS(J) ,POINTS(J) CARD(J)=J J=J+] ENDDO MONEY (6)=50000 ENDBLOCK BLOCK PLAYGAME
*************************
***** BLOCKPLAYGAME PERFORM READNAMES DOWH[LE NPLAYERS GT O PERFORM READBETS PERFORM FI RSTCARD PERFORM MORECARDS PERFORM FINDMAXX PERFORM DEALERS PERFORM PAYOFF PERFORM NEWGA~ME PERFORM REINITIAI E NDDO ENDBLOCK
********~ ~*********'~*********
,~tJBBLOC~ READNAMES
**************************
SUB,LOCK READNAMES PRINT "tJE'RE READY TO BEC[N." PRINT "HOW M~NY PEOPLE ARE GOING TO PLAY? ( 1 - 5 ) " READ NPLAYERfi OOWH[LE ~PLAYERS L r 1 OR NPLAYERS GT 5 PRINT "ONE TO FIVE PEOPLE MAY PLAY." PRINT " HOW MAN ~/ILL I T READ ~PLAYERS
BE?"
ENDDO J=l DOkII'.ILE J LE NPLAYERS PLAYERIN(J)=I PRINT "PLAYER",I,"TYPE UP TO [0 CHARACTERS OF YOUR NAME." READ NAMF$ (J) J=J+l ENDDO PRINT "HOW MANY DECKS DO YOU WANT TO USE?(I-2)" READ NDECKS DOWHILE NDECKS LT I OR NDECKS GT 2 PRINT "ONE OR TWO DECKS ARE THE ONLY CHOICES AVAILABLE." PRINT"WHICH IS IT?" READ NDECKS ENDDO PERFORM SHUFFLE ENDBLOCK ************************** ****************************** SUBBLOCK READBETS *****
SUBBLOCK READBETS PRINT "PLEASE ENTER YOUR BETS FOR Tills ROUND." J=l DOWHILE J LE NPLAYERS PRINT NAMES (J) ~ "WHAT DO YOU BET?" READ BET (J) DOWHILE BET (J) LE O OR BET(J) GT MONEY (J) PRINT "YOU MUST BET AN AMOUNT BETWEEN 0 AND "~MONEY(J) READ BET (J) ENDDO J=J+l ENDDO
ENDBLOCK
A programming language engineered for beginners **************************** *****
35
SUBBLOCK FIRSTCARD
SUBBLOCK FIRSTCARD J=l DOWHILE J LE N P L A Y E R S PERFORM DEAL PRINT NAMES(J), "IS DEALT A " , H A N D $ ( J , I ) J=J÷l ENDDO J=6 PERFOR#I DEAL PRINT "THE DEALER IS DEALT AN U N E X P O S E D C A R D . " ENDBLOCK ****************************** SUBBLOCK D E A L ***** SUBBLOCK DEAL NCARDS(J)=NCARDS(J)+I HAND$(J),NCARDS(J))=DECK$(CARD(NEXTCARD)) TOTAL(J)=TOTAL(J)+POINTS(CARD(NEXTCARD)) OLDCARD=NEXTCARD NEXTCARD=NEXTCARD+I IF N E X T C A R D UE ((52*NDECKS)+I; POINTS(CARD(NEXTCARD))=II; TOTAL(J) GT 21; ACE(J) GT O; THEN P E R F O R M SHUFFLE; NEXTCARD=I; ACE(J)=ACE(J)+I; TOTAL(J)=TOTAL(J)-10; ACE(J)=ACE(J)-I; ENDIF ENDBLOCK ***************************** S U B B L O C K SHUFFLE *****
Y Y Y -
YY NY Y N y-
y y y -
yy-yy - __ -
N N Y N YY - y
N Y N -
y _ _ y
y - y y y- y-
S U B B L O C K SHUFFLE A=52*NDECKS D O W H I L E A GT 1 R=RANDOM I=INT(R*A)+I TEMP=CARD(I) CARD(I)=CARD(A) CARD(A)=TEMP A=A-I ENDDO ENDBLOCK
****************************** *****
SUBBLOCK MORECARDS
SUBBLOCK MORECARDS J=l D O W H I L E J LE N P L A Y E R S PRINT NAMES(J), ",NIT OR STAND? (i OR 0)" READ HIT DOWHILE HIT=I P E R F O R M DEAL PRINT DECKS (CARD(OLDCARD)) IF TOTAL(J) GT 21; THEN HIT=O; PRINT "SORRY, YOU W E N T O V E R 21,"; TOTAL(J)=O; ELSE PRINT "HIT OR STAND? (l OR O)" READ HIT ENDIFF ENDDO J=J+l ENDDO ENDBLOCK ****************************** S U B B L O C K FINDMAXX ************************* ***** S U B B L O C K F I NDMAXX J=1 MAXX=O DOWHILE J LE N P L A Y E R S M A X X = M A X (MAXX , TOTAL ( J ) ) J=g+l ENDDO ENDBLOCK
36
HERMAN D. HUGHES ****************************** *****
SUBBLOCK
*************************
DEALERS
SUBBLOCK DEALERS P R I N T " D E A L E R S F I R S T C A R D W A S A", H A N D $ ( 6 ~ I ) J=6 CONTINUE=I DOWHILE CONTINUE=I IF ACE(6)=0; - - Y Y - - T O T A L ( 6 ) G E 17; N .N - Y Y - T O T A L ( 6 ) G T 21; - - Y .... T O T A L ( 6 ) = 21; . . . . . . Y N C A R D S ( 6 ) LT 5; Y Y Y Y Y NT O T A L ( 6 ) LT M A X X ; N Y - N Y - THEN TOTAL(6)=0; - - y .... CONTINUE=0; Y y Y - y Y PERFORM DEAL; Y - - Y - PRINT"CARD NO.",NCARDS(6),"WAS A",HAND$(6,NCARDS(6)); - Y - - Y - ENDIF ENDDO ENDBLOCK ****************************** SUBBLOCK PAYOFF ************************* ***** SUBBLOCK IF
PAYOFF TOTAL(1)=MAXX; TOTAL(2)=~X; TOTAL(3)=MAXX; TOTAL(4)=MAXX; TOTAL(5)~MAXX; TOTAL(6)=GE~X;
Y Y Y Y Y N
Y Y Y Y N N
Y Y Y N Y N
Y Y Y N N N
Y Y N Y Y N
Y Y N Y N N
Y Y N N Y N
Y Y N N N N
Y N Y Y Y N
Y N Y Y N N
Y N Y N Y N
Y N Y N N N
Y N N Y Y N
Y N N Y N N
Y N N N Y N
Y N N N N N
N Y Y Y Y N
N Y Y Y N N
N Y Y N Y N
N Y Y N N N
N Y N Y Y N
N Y N Y N N
N Y N N Y N
N Y N N N N
N N Y Y Y N
N N Y Y N N
N N N N N
N N N N Y
N N N Y N
N N N Y Y
N N Y N N
N N Y N Y
N N Y Y N
N N Y Y Y
N Y N N N
N Y N N Y
N Y N Y N
N Y N Y Y
N Y Y N N
N Y Y N Y
N Y Y Y N
N N Y Y Y
Y N N N N
Y N N N Y
Y N N Y N
Y N N Y Y
Y N Y N N
Y N Y N Y
Y N Y Y N
Y Y Y Y Y
Y Y N N N
Y Y N N Y
N N Y N Y N
N N Y N N N
N N N Y Y N
N N N Y N N
N N N N Y N
N N N N N N
Y
Y Y N Y N
Y Y N Y Y
Y Y Y N N
Y Y Y N Y
THEN BET(1)=-BET(1) BET(2)=-BET(2) BET(3)=-BET(3) BET(4)=-BET(4) BET(5)=-BET(5)
; ; ; ; ;
ENDIF J=l D O W H I L E J LE 5 M O N E Y (J )= M O N E Y (J )+ B E T (J) P R I N T N A M E S (J) , " N O W HAS $ " , M O N E Y ( J ) M O N E Y (6) = M O N E Y ( 6 ) - B E T (J) J=J+l ENDDO ENDBLOCK
******************************
SUBBLOCK
***********************~*
NEWGAME
***** SUBBLOCK NEWGAME P R I N T "DO Y O U W A N T TO Q U I T ? " P R I N T " Y E S O R NO" READ ANSWERS IF A N S W E R $ = " Y E S ''; THEN NPLAYERS=O PRINT "THANKS FOR ENRICHING ENDIF ENDBLOCK ****************************** ***** SUBBLOCK REINITIAL J=l D O W H I L E J LE 6 N C A R D S (J) =0 ACE(J)=O T O T A L (J )= 0 BET(J)=0 J=J+l ENDDO ENDBLOCK ENDPROGRAM
Y
THE COMPUTER
SUBBLOCK
CASINOL";
REINITIAL
Y Y
*************************
Y Y Y Y N
Y Y Y Y Y
Y Y Y Y