The Implementation Of A Special Language Interpreter

(A Thesis Presented to The Faculty of the Department of Applied Science The College of William and Mary in Virginia - August 1975)
by James Thomas Lee, Jr. 07/05/97

Section IV. THE DIAGNOSTIC SYSTEM {2,576 words}

The Interpreter when executing a program must be constantly aware of the user's statement structure; otherwise the program may continue indefinitely, and cause the Interpreter to overwrite itself, or if a check is not made on the user's declared variables, the Interpreter may not be able to function efficiently with the input program. The need for a precise diagnostic system can continue indefinitely. The reader should understand though, that the error checks require exactness by the user, because without them, the Interpreter may misinterpret the real need of the user.

To coordinate the overall diagnostic system is a short cyclic routine called SKIP4. When an error is found, the Interpreter loads the first word address of the error message and the character count and jumps to SKIP4. From there, the current instruction address is loaded and printed, and then the error is printed (see Figure 8). The entire message is bordered by asterisks above and below. Next, the current count of diagnostics is incremented and checked. If the count is less than ten, then the Interpreter returns to SKIP3 to pick up execution with the next statement. From Figure 8 the reader will note that the diagnostic, in statements 21 and 60-actually is not complete. The Interpreter made note that C was not found in the variable name tables. If the reader will refer to statement 12, he will find that A is a duplicate variable name entry. Thus, when the Interpreter found the error, it printed the error and moved on to the next instruction.

---------------------------------------------------------------------------------------------------------------------------

Figure 8. Above is a sample of the diagnostic messages.

---------------------------------------------------------------------------------------------------------------------------

***********************************************
STATEMENT NUMBER    0000012
DUPLICATE NAME ENTRY
***********************************************

***********************************************
STATEMENT NUMBER    0000060
DATA NAME NOT FOUND IN TABLES
***********************************************

***********************************************
STATEMENT NUMBER    0000021
DATA NAME NOT FOUND IN TABLES
***********************************************

***********************************************
STATEMENT NUMBER    0000049
ILLEGAL OPERATOR IN EXPRESSION
***********************************************

***********************************************
STATEMENT NUMBER    0000096
DATA NAME NOT FOUND IN TABLES
***********************************************

ADDRESS REQUEST 00052520
ADDRESS		PROGRAM LISTING		REGISTERS		COUNTERS
0000000		REAL A,B		A  06000001		PROG		00115
0000007		STRING K		Q  00006325		COUNT		00001
0000012		REAL A,C,B		Bl 00000162		STMTPTR	00011
0000021		C(l)=B-1		B2 00000004		POINTER	00012
0000030		STRING (3) P		B3 00000022		DATAPTR	00001
0000038		BOOLEAN L
0000043		L="T"
0000049		L=(L.GE.L)
0000060		DATA C(l),.0316228,C(2),.Ol,C(3),.001
0000096		L= (H.LT."THE")
0000111		TERMINATE

---------------------------------------------------------------------------------------------------------------------------

The variable C was never declared to the Interpreter because the statement had been aborted due to the duplicate variable name error. Once statement 12 is corrected, another execution will result in an error in statements 21 and 60 which says that an array has been used but has not been declared. The reader might question the Interpreter's needing two separate executions to discover all the errors in the user's program. The Interpreter cannot uncover every error because if the Interpreter returned to the same line after printing the diagnostic message instead of moving to the next instruction, it may lose system control when it tries to pick up execution of the statement. It should be noted that the Interpreter discovers all errors while trying to execute the instruction, but when an error is found, the Interpreter no longer attempts to execute the statement. There is no presearch to check for errors. Another example of the same situation can be found in Statement 96. In the first execution attempt, the Interpreter printed that H could not be found in the variable name table because it had not been declared. When the user declares the variable, the next execution attempt will site the same instruction for an illegal operator; that is, the LT operator is not valid for string variables (see Section IIB, para la3).

From the above discussion, the reader can see that the Interpreter may require several execution attempts before the bugs will be completely removed. To assist the user in understanding the diagnostic messages which are printed, each message will be discussed.

	1.  "COUNTER ERROR AT XXXX"--This error appears when the user has exceeded the input 
            storage restrictions.  The five counters which appear in the right corner of the 
            data dump--PROG, COUNT, STMTPTR, DATAFTR, and POINTER--are the measures of core used 
            by the user's program.  The limits assigned to each of these counters are as
            follows:

		(a)  PROG--PROG counts the number of characters in the User's permanent program 
                     and is restricted to 4000 (decimal) characters which will normally figure 
                     to be a 500 instruction program.

		(b)  COUNT--COUNT counts the number of characters read into the current
                     instruction and its limit is 160 decimal characters.  The main reason for 
                     the extreme length allowance is to handle the variable length of the string
                     variables.  The reader might recall that a string variable is limited to a 
                     length of 150 characters.

		(c)  STMTPTR-STMTPTR counts the number of instructions.  Its actual purpose is
                     to point to the table which contains the statement character addresses, 
                     STMTTAB.  The limit for this counter is 500 which will assume, as does 
                     PROG, that the average instruction length will be 8 characters.

		(d)  DATAPTR--DATAPTR points to the data tables, DATATAB.  The limit of data 
                     values is set to 1000 words.  The data tables are mixed up with integers, 
                     floating point numbers, and variable length string characters, all of which
                     require a different number of words in core; thus, it is nearly impossible
                     to estimate how far this limitation will extend.  With 1000 words of core, 
                     though, the user should have enough storage to handle most problems.

		(e)  POINTER--POINTER counts the number of declared variables and statement 
                     numbers.  As the reader will recall from Section IIA, para 2, the 
                     Interpreter uses TABLES to store all variable names and statement numbers;
                     thus, POINTER prevents TABLES from being overflowed.  The limit of variable
                     identifiers is fifty,

	After the counter error is printed, the address of the error location within the 
Interpreter will be printed.  Thus, the user, if he understands COMPASS, may wish to examine the 
Interpreter.  If not, the user can use the current statement number printed above the error to 
trace his error.

	2.  "INSTRUCTION FORMAT ERROR IN STATEMENT NUMBER XXXXXXX"--As discussed in Section IIA,
            para 1, DETRMN is a routine used to locate the instruction type which has been used.
            If the routine cannot determine the instruction used, it will print this error.

	3. "ARRAY HAS TOO MANY DIMENSIONS"--An array because of storage limitations must be 
           limited to only six fields.  The limit although small is not unreasonable, because
           few arrays extend any deeper.

	4.  "END OF NAME NOT FOUND--VARIABLE LENGTH ERROR"--The Interpreter limits the length of 
            variable names to four characters.  In the execution of the routine, TABSCAN, when 
            the Interpreter is searching the variable name and statement number table, if the 
            variable name which it is searching for is found to be too long, this error will
            occur.

	5.  "DATA NAME NOT FOUND IN TABLES"--This diagnostic indicates that the user has not 
            declared one of the variable names or statement numbers properly.  The user should
            review his declaration statements and his statement numbers to resolve this problem.

	6.  "LAST CARD NOT TERMINATE"--This error can be fatal to the Interpreter if not 
            remedied.  When this error occurs, the Interpreter prints the message of the console 
            typewriter instead of the printer, and aborts the program.

	7.  "ARRAY USED--NOT DECLARED"--Earlier in this section, mention was made of the 
            variable 'C' (see Figure 4) which had been used as an array but not declared in the 
            standard array format.  With that error, this is the message to the user.

	8.  "ARRAY DECLARED--NOT USED"--The converse to the previous error is the case when the 
            user has declared the array, but tried to use the array as a simple variable.  In
            either situation, the Interpreter becomes confused by the statement and must abort
            the instruction by one of the above two messages.

	9.  "EXPRESSION TOO LONG"--In any case where the Interpreter deals with expressions, 
            this error may occur.  The purpose of this diagnostic is not just to restrict the
            user, but primarily to return control to the Interpreter when the user has failed
            to place a delimiter his statement.  The restrictions imposed by this diagnostic
            are:

		(a)  In the FILE Statement, the limit on the number of column parameters is 
                     eight.  Similarly, the time input for this statement is eight digits for 
                     the date time group, MODAHRMN.  If either restriction is violated, this 
                     message is printed.

		(b)  In the MAT Statement, a check is made to guarantee that the user has not 
                     tried to format too many spaces for data items.  For real numbers, the 
                     maximum format is F15.7; for integers, it is I7; and for characters, it is
                     C150.  In addition, the statement is limited to only ten variable names by 
                     this diagnostic.

		(c)  In a Boolean expression, the expression is limited to twelve characters on
                     each side of the operator.

	10. "NAME TOO LONG"--This error is very similar to the preceding diagnostic. Whenever
            this message appears, the user should first look for any variable name which exceeds 
            four characters in length.  If that is not the error, some other instances where
            this message may appear are:

		(a)  In the FILE Statement, the allowable length for a station identifier is 
                     eight digits.

		(b)  In the GOTO Statement, the Interpreter ensures that the statement number 
                     does not exceed three digits (see Section IIA, para 2).

		(c)  In the MAT Statement the maximum length which can be formatted is 150 for a 
                     lengthy character string.

	11. "UNMATCHED PARENTHESES"--The Interpreter must demand precise notation from the user 
            when dealing with numerical expressions.  Otherwise, if the user is slack in setting 
            his equation, the Interpreter will not be able to ensure that it has evaluated the 
            expression as the user had intended.

	12.  "NO END PAREN ON NAME"--This error is used to relate to the user that he has not 
             placed an end parenthesis on the array used, on the left side of the expression.

	13.  "ILLEGAL EXPRESSION IN PARENTHESIS"--This error is obvious.  Some of its uses are:
		(a)  In specifying the length of string variables in the STRING Statement, if
                     the input is not numeric, then this error will result.
		(b)  In three of the functions, FACT, IN, and SQRT, the operand must be 
                     positive.  If they are not, then this error is indicated.

	14.  "SIMPLE VARIABLE NOT DECLARED"--The Interpreter prints this message if the user has 
             tried to use an array in the operand of his function.

	15.  "ILLEGAL TRIG EXPRESSION"--This error occurs when the Interpreter finds that 
             COS X=O when calculating TAN X. This error is also a divide fault, but the message 
             printed is more precise.

	16.  "TOO MANY SIMULTANEOUS LOOPS"--The Interpreter allows only six nested loops at one 
             time.  The total is derived from the number of FOR Statements used at the same
             time.

	17.  "ITERATION VARIABLE MUST BE AN INTEGER"--In the FOR Statement, the iteration 
             variable must be an integer and can only be incremented by integer values.

	18.  "ERROR IN LOOP LIMIT"--In the FOR Statement, the iteration variable cannot 
             decrement to a negative number.  It may only increment by one to a positive integer 
             value.  Likewise, if the initial value of the loop counter is greater than the 
             limit declared in the FOR Statement, then this error message will apply.

	19.  "DIVIDE FANT, CANNOT DIVIDE BY ZERO"--This message is obvious.  Somewhere in 
             calculating an expression, the Interpreter is told to divide by zero, which is of 
             course arithmetically undefined.

	20.  "STATEMENT NUMBER MUST BE NUMERIC"--As stated earlier, (Section IIA, para 2), the 
             statement number must be numeric.  Otherwise, the Interpreter may confuse statement 
             numbers and variable names since they are both stored in TABLES.

	21.  "UNMATCHED DATA ENTRY AND DATA TYPE"--When the user has failed to have both sides
             of an expression to be of the same data type, it is an error.  Of note, in dealing
             with Boolean expressions or other logical expressions, the final value or solution
             must be a Boolean value; however, this does not preclude the use of numeric values 
             in the expression.  Thus, below are examples of the type of error indicated by this 
             diagnostic.

			CASE A			CASE B
			INTEGER B		INTEGER B
			BOOLEAN A		BOOLEAN A
			A=(B.GE.0)		A= (B.EQ."ABC")
			    .			      .
			    .			      .
			    .			      .
			TERMINATE		TERMINATE

In case A, the Boolean expression requires that the final solution be a Boolean value, but this 
will happen because B, which is an integer, can be compared to the quantity zero.  In case B the 
expression is not matching data and data type; thus the error woulb be caught.

	22.  "ILLEGAL VARIABLE IN EXPRESSION"--The message of this diagnostic is the best words 
             for the type of error.  Mostly the diagnostic is to ensure that the user has not
             tried to incorrectly use Boolean variable names in normal expression.

	23.  "DUPLICATE NAME ENTRY"--The message here is equally obvious.  A variable should 
             always be declared once, but it should never be declared more than once; thus, when 
             the Interpreter finds the same variable declared in more than one place, it prints
             the error.

	24.  "ILLEGAL OPERATOR IN EXPRESSION"--This diagnostic occurs when the user has 
             incorrectly tried to use an invalid operator in Boolean and character string 
             expressions.  In these two cases, the only operators allowed are EQ and NE (see 
             Section IIB, para la3).  In another situation, that of the FILE Statement parameter 
             list, this error can be found.  The Interpreter must be able to read the data 
             parameter request of the statement, or it is an error.  If the list has for some 
             reason been misproported, the error will occur.

	25.  "ERROR IN FORMATTED OUTPUT"--This error is designed to catch the Interpreter if the 
             MAT Statement has been improperly constructed.  Without such a means to regain 
             control, the Interpreter could easily write out core.  The type of error which this 
             refers to is when the proper delimiter has been omitted.  The Interpreter, in this 
             case, could continue to write until it had overwritten all core.

	26.  "EXPRESSION IN WHILE STATEMENT DOES NOT CONVERGE"--The WHILE Statement is probably 
             the most vulnerable in the Interpreter.  If the user fails to properly converge
             the variable in the expression to the limit, the Interpreter may become locked in
             the loop.  To overcome this problem, the Interpreter makes use of the computer's 
             internal clock to check the duration of the statement.  If the time of execution of 
             the loop exceeds the limit set (about 10 seconds), the Interpreter will print this 
             error and move on.  Of note, the Interpreter does not abort the program until ten 
             diagnostics have occurred, so the message will actually be printed ten times in
             most cases.  The advantage here is that the Interpreter will continue to print the 
             next ten solutions so that the user may actually observe the divergence of his
             variable.

	27.  "INVALID WHILE LOOP"--To terminate the WHILE Statement, the user must close the 
             loop with a BACK Statement, or the WHILE loop is invalid, and the message will be 
             printed.

Now the user and reader have completed the investigation of the Interpreter both in theory and in operation. In every instance, thought has been directed toward the needs of the user. However, even as the Interpreter nears completion, there are several closing thoughts which must be entered as possible improvements for the system. These ideas will be discussed in the following and final section.

Section V. CLOSING COMMENTS

Back To The Table Of Contents

Back To TLEE's Home Page

Send email to: tlee6040@aol.com