BSD 1 development
[unix-history] / puman / puman3.n
CommitLineData
5bd13011
BJ
1.if \n(xx .bp
2.if !\n(xx \{\
3.so tmac.p \}
4.if n 'ND
5.nr H1 2
6.NH
7Error diagnostics
8.PP
9This section of the
10.UM
11discusses the error diagnostics of the programs
12.PI
13and
14.X .
15.I Pix
16is a simple but useful program which invokes
17.PI
18and
19.X
20to do all the real processing.
21See its manual section
22.IX
23(VI)
24and section 5.2 below for more details.
25.NH 2
26Translator syntax errors
27.PP
28A few comments on the general nature of the syntax errors usually
29made by Pascal programmers
30and the recovery mechanisms of the current translator may help in using
31the system.
32.SH
33Illegal characters
34.PP
35Characters such as `$', `!', and `@' are not part of the language Pascal.
36If they are found in the source program,
37and are not part of a constant string, a constant character, or a comment,
38they are considered to be
39`illegal characters'.
40This can happen if you leave off an opening string quote `\(aa'.
41Note that the character `"', although used in English to quote strings,
42is not used to quote strings in Pascal.
43Most non-printing characters in your input are also illegal except
44in character constants and character strings.
45Except for the tab and form feed characters,
46which are used to ease formatting of the program,
47non-printing characters in the input file print as the character `?'
48so that they will show in your listing.
49.SH
50String errors
51.PP
52There is no character string of length 0 in Pascal.
53Consequently the input `\(aa\(aa' is not acceptable.
54Similarly, encountering an end-of-line after an opening string quote `\(aa'
55without encountering the matching closing quote yields the diagnostic
56``Unmatched \(aa for string''.
57It is permissible to use the character `#'
58instead of `\''
59to delimit character and constant strings for portability reasons.
60For this reason, a spuriously placed `#' sometimes causes the diagnostic
61about unbalanced quotes.
62Similarly, a `#' in column one is used when preparing programs which are to
63be kept in multiple files.
64See section 5.9 for details.
65.SH
66Comments in a comment, non-terminated comments
67.PP
68As we saw above, these errors are usually caused by leaving off a comment
69delimiter.
70You can convert parts of your program to comments
71without generating this diagnostic
72since there are two different kinds of comments \- those delimited by
73`{' and `}', and those delimited by `(*' and `*)'.
74Thus consider:
75.LS
76{ This is a comment enclosing a piece of program
77a := functioncall; (* comment within comment *)
78procedurecall;
79lhs := rhs; (* another comment *)
80}
81.LE
82.PP
83By using one kind of comment exclusively in your program you can use
84the other delimiters when you need to
85``comment out''
86parts of your program\*(dg.
87.FS
88\*(dgIf you wish to transport your program,
89especially to the 6000-3.4 implementation,
90you should use the character sequence `(*' to delimit comments.
91For transportation over the
92.I rcslink
93to Pascal 6000-3.4, the character `#' should be used to delimit characters
94and constant strings.
95.FE
96In this way you will also allow the translator to help by detecting
97statements accidentally placed within comments.
98.PP
99If a comment does not terminate before the end of the input file,
100the translator will point to the beginning of the comment,
101indicating that the comment is not terminated.
102In this case processing will terminate immediately.
103See the discussion of ``QUIT'' below.
104.SH
105Digits in numbers
106.PP
107This part of the language is a minor nuisance.
108Pascal requires digits in real numbers both before and after the decimal
109point.
110Thus the following statements, which look quite reasonable to
111.SM
112FORTRAN
113.NL
114users, generate diagnostics in Pascal:
115.LS .ID
116.so digitsout
117.LE
118These same constructs are also illegal as input to the Pascal interpreter
119.I px .
120.SH
121Replacements, insertions, and deletions
122.PP
123When a syntax error is encountered in the input text,
124the parser invokes an error recovery procedure.
125This procedure examines the input text immediately after the point
126of error and considers a set of simple corrections to see whether they
127will allow the analysis to continue.
128These corrections involve replacing an input token with a different
129token,
130inserting a token,
131or replacing an input token with a different token.
132Most of these changes will not cause fatal syntax errors.
133The exception is the insertion of or replacement with a symbol
134such as an identifier or a number;
135in this case the recovery makes no attempt to determine
136.I which
137identifier or
138.I what
139number should be inserted,
140hence these are considered fatal syntax errors.
141.PP
142Consider the following example.
143.LS
144% \*bpix -l synerr.p\fR
145.tr --
146.so synerrout
147%
148.LE
149The only surprise here may be that Pascal does not have an exponentiation
150operator, hence the complaint about `**'.
151This error illustrates that, if you assume that the language has a feature
152which it does not, the translator diagnostic may not indicate this,
153as the translator is unlikely to recognize the construct you supply.
154.SH
155Undefined or improper identifiers
156.PP
157If an identifier is encountered in the input but is undefined,
158the error recovery will replace it with an identifier of the
159appropriate class.
160Further references to this identifier will be summarized at the
161end of the containing
162.B procedure
163or
164.B function
165or at the end of the
166.B program
167if the reference occurred in the main program.
168Similarly,
169if an identifier is used in an inappropriate way,
170e.g. if a
171.B type
172identifier is used in an assignment statement,
173or if a simple variable
174is used where a
175.B record
176variable is required,
177a diagnostic will be produced and an identifier of the appropriate
178type inserted.
179Further incorrect references to this identifier will be flagged only
180if they involve incorrect use in a different way,
181with all incorrect uses being summarized in the same way as undefined
182variable uses are.
183.SH
184Expected symbols, malformed constructs
185.PP
186If none of the above mentioned corrections appear reasonable, the
187error recovery will examine the input
188to the left of the point of error to see if there is only one symbol
189which can follow this input.
190If this is the case, the recovery will print a diagnostic which
191indicates that the given symbol was `Expected'.
192.PP
193In cases where none of these corrections resolve the problems
194in the input,
195the recovery may issue a diagnostic that indicates that the
196input is ``malformed''.
197If necessary, the translator may then skip forward in the input to
198a place where analysis can continue.
199This process may cause some errors in the text to be missed.
200.PP
201Consider the following example:
202.LS .ID
203% \*bpix -l synerr2.p\fR
204.so synerr2out
205%
206.LE
207Here we misspelled
208.I input
209and gave a
210.SM FORTRAN
211style variable declaration
212which the translator diagnosed as a `Malformed declaration'.
213When, on line 6, we used `(' and `)' for subscripting
214(as in
215.SM FORTRAN )
216rather than the `[' and `]' which are used in Pascal,
217the translator noted that
218.I a
219was not defined as a
220.B procedure .
221This occurred because
222.B procedure
223and
224.B function
225argument lists are delimited by parentheses in Pascal.
226As it is not permissible to assign to procedure calls the translator
227diagnosed a malformed statement at the point of assignment.
228.SH
229Expected and unexpected end-of-file, ``QUIT''
230.PP
231If the translator finds a complete program, but there is more non-comment text
232in the input file, then it will indicate that an end-of-file was expected.
233This situation may occur after a bracketing error, or if too many
234.B end s
235are present in the input.
236The message may appear
237after the recovery says that it
238``Expected \`.\'\|''
239since `.' is the symbol that terminates a program.
240.PP
241If severe errors in the input prohibit further processing
242the translator may produce a diagnostic followed by ``QUIT''.
243One example of this was given above \-
244a non-terminated comment;
245another example is a line which is longer than 160
246characters.
247Consider also the following example.
248.LS .ID
249% \*bpix -l mism.p\fR
250.so mismout
251%
252.LE
253.NH 2
254Translator semantic errors
255.PP
256The extremely large number of semantic diagnostic messages which the translator
257produces make it unreasonable to discuss each message or group of messages
258in detail.
259The messages are, however, very informative.
260We will here explain the typical formats and the terminology used in the error
261messages so that you will be able to make sense out of them.
262In any case in which a diagnostic is not completely comprehensible you can
263refer to the
264.I "User Manual"
265by Jensen and Wirth for examples.
266.SH
267Format of the error diagnostics
268.PP
269As we saw in the example program above, the error diagnostics from
270the Pascal translator include the number of a line in the text of the program
271as well as the text of the error message.
272While this number is most often the line where the error occurred, it
273is occasionally the number of a line containing a bracketing keyword
274like
275.B end
276or
277.B until .
278In this case, the diagnostic may refer to the previous statement.
279This occurs because of the method the translator uses for sampling line
280numbers.
281The absence of a trailing `;' in the previous statement causes the line
282number corresponding to the
283.B end
284or
285.B until .
286to become associated with the statement.
287As Pascal is a free-format language, the line number associations
288can only be approximate and may seem arbitrary to some users.
289This is the only notable exception, however, to reasonable associations.
290.bp
291.SH
292Incompatible types
293.PP
294Since Pascal is a strongly typed language, many semantic errors manifest
295themselves as type errors.
296These are called `type clashes' by the translator.
297The types allowed for various operators in the language are summarized on page
298108 of the
299Jensen-Wirth
300.I "User Manual" .
301It is important to know that the Pascal translator, in its diagnostics,
302distinguishes between the following type `classes':
303.br
304.ne 8
305.TS
306center;
307lew(10) le le le le.
308array Boolean char file integer
309pointer real record scalar string
310.TE
311These words are plugged into a great number of error messages.
312Thus, if you tried to assign an
313.I integer
314value to a
315.I char
316variable you would receive a diagnostic like the following:
317.LS
318.so clashout
319.LE
320In this case, one error produced a two line error message.
321If the same error occurs more than once, the same explanatory
322diagnostic will be given each time.
323.SH
324Scalar
325.PP
326The only class whose meaning is not self-explanatory is
327`scalar'.
328Scalar has a precise meaning in the
329Jensen-Wirth
330.I "User Manual"
331where, in fact, it refers to
332.I char ,
333.I integer ,
334.I real ,
335and
336.I Boolean
337types as well as the enumerated types.
338For the purposes of the Pascal translator,
339scalar
340in an error message refers to a user-defined, enumerated
341type, such as
342.I ops
343in the example above or
344.I color
345in
346.LS
347\*btype\fP color = (red, green, blue)
348.LE
349For integers, the more explicit denotation
350.I integer
351is used.
352Although it would be correct, in the context of the
353.I "User Manual"
354to refer to an integer variable as a
355.I scalar
356variable
357.PI
358prefers the more specific identification.
359.SH
360Function and procedure type errors
361.PP
362For built-in procedures and functions, two kinds of errors occur.
363If the routines are called with the wrong number of arguments a message similar to:
364.LS
365.so sinout1
366.LE
367is given.
368If the type of the argument is wrong, a message like
369.LS
370.so sinout2
371.LE
372is produced.
373A few functions and procedures implemented in Pascal 6000-3.4 are
374diagnosed as unimplemented in
375.UX
376Pascal, notably those related to
377.B segmented
378files.
379.SH
380Can't read and write scalars, etc.
381.PP
382The messages which state that scalar (user-defined) types
383cannot be written to and from files are often mysterious.
384It is in fact the case that if you define
385.LS
386\*btype\fP color = (red, green, blue)
387.LE
388the translator does not associate these constants with the strings
389`red', `green', and `blue' in any way.
390If you wish such an association to be made, you will have to write a routine
391to make it.
392Note, in particular, that you can only read characters, integers and real
393numbers from text files.
394You cannot read strings or Booleans.
395It is possible to make a
396.LS
397\*bfile of\fP color
398.LE
399but the representation is binary rather than string.
400.SH
401.bp
402Expression diagnostics
403.PP
404The diagnostics for semantically ill-formed expressions are very explicit.
405Consider this sample translation:
406.LS .ID
407% \*bpi -l expr.p\fP
408.so exprout
409%
410.LE
411This example is admittedly far-fetched, but illustrates that the error
412messages are sufficiently clear to allow easy determination of the
413problem in the expressions.
414.SH
415Type equivalence
416.PP
417Several diagnostics produced by the Pascal translator complain about
418`non-equivalent types'.
419In general,
420.UX
421Pascal considers variables to have the same type only if they were
422declared with the same constructed type or with the same type identifier.
423Thus, the variables
424.I x
425and
426.I y
427declared as
428.LS
429\*bvar\fP
430 x: ^ integer;
431 y: ^ integer;
432.LE
433do not have the same type.
434The assignment
435.LS
436x := y
437.LE
438thus produces the diagnostics:
439.LS
440.so typequout
441.LE
442Thus it is always necessary to declare a type such as
443.LS
444\*btype\fP intptr = ^ integer;
445.LE
446and use it to declare
447.LS
448\*bvar\fP x: intptr; y: intptr;
449.LE
450Note that if we had initially declared
451.LS
452\*bvar\fP x, y: ^ integer;
453.LE
454then the assignment statement would have worked.
455The statement
456.LS
457x^ := y^
458.LE
459is allowed in either case.
460Since the parameter to a
461.B procedure
462or
463.B function
464must be declared with a
465type identifier rather than a constructed type,
466it is always necessary, in practice,
467to declare any type which will be used in this way.
468.SH
469Unreachable statements
470.PP
471.UX
472Pascal flags unreachable statements.
473Such statements usually correspond to errors in the program logic.
474Note that a statement is considered to be reachable
475if there is a potential path of control,
476even if it can never be taken.
477Thus, no diagnostic is produced for the statement:
478.LS
479\*bif\fP false \*bthen\fP
480 writeln('impossible!')
481.LE
482.SH
483Goto's into structured statements
484.PP
485The translator detects and complains about
486.B goto
487statements which transfer control into structured statements (\c
488.B for ,
489.B while ,
490etc.)
491It does not allow such jumps, nor does it allow branching from the
492.B then
493part of an
494.B if
495statement into the
496.B else
497part.
498Such checks are made only within the body of a single procedure or
499function.
500.SH
501Unused variables, never set variables
502.PP
503Although
504.UX
505Pascal always clears variables to 0 at
506.B procedure
507and
508.B function
509entry, it is
510.B not
511good programming practice to rely on this initialization.
512To discourage this practice, and to help detect errors in program logic,
513.PI
514flags as a `w' warning error:
515.IP
516.RS
517.HP 1)
518Use of a variable which is never assigned a value.
519.IP 2)
520A variable which is declared but never used, distinguishing
521between those variables for which values are computed but which are never
522used, and those completely unused.
523.RE
524.LP
525In fact, these diagnostics are applied to all declared items.
526Thus a
527.B constant
528or a
529.B procedure
530which is declared but never used is flagged.
531The
532.B w
533option of
534.PI
535may be used to suppress these warnings;
536see sections 5.1 and 5.2.
537.NH 2
538Translator panics, i/o errors
539.SH
540Panics
541.PP
542One class of error which rarely occurs, but which causes termination
543of all processing when it does is a panic.
544A panic indicates a translator-detected internal inconsistency.
545A typical panic message is:
546.LS
547snark (rvalue) line=110 yyline=109
548Snark in pi
549.LE
550If you receive such a message, the translation will be quickly and perhaps
551ungracefully terminated.
552You should contact a teaching assistant or a member of the system staff,
553after saving a copy of your program for later inspection.
554If you were making changes to an existing program when the problem
555occurred, you may
556be able to work around the problem by ascertaining which change caused the
557.I snark
558and making a different change or correcting an error in the program.
559You should report the problem in any case.
560Pascal system bugs cannot be fixed unless they are reported.
561.SH
562Out of memory
563.PP
564The only other error which will abort translation when no errors are
565detected is running out of memory.
566All tables in the translator, with the exception of the parse stack,
567are dynamically allocated, and can grow to take up the full available
568process space of 64000 bytes.
569Generally, the size of the largest translatable program is directly related to
570.B procedure
571and
572.B function
573size.
574A number of non-trivial Pascal programs, including
575some with more than 2000 lines and 2500 statements
576have been translated and interpreted using
577.UX
578Pascal.
579Notable among these are the Pascal-S
580interpreter,
581a large set of programs for automated generation of
582code generators,
583and a general context-free parsing program which has been used to
584parse sentences with a grammar for a superset of English.
585.PP
586If you receive an out of space message from the translator
587during translation of a large
588.B procedure
589or
590.B function
591or one containing a large number of string constants
592you may yet be able
593to translate your program if you break this one
594.B procedure
595or
596.B function
597into several routines.
598.SH
599I/O errors
600.PP
601Other errors which you may encounter when running
602.PI
603relate to input-output.
604If
605.PI
606cannot open the file you specify,
607or if the file is empty,
608you will be so informed.
609If your disk space quota\*(dg is exceeded while
610.PI
611is creating the file
612.I obj ,
613or if the system runs out of disk space you will be notified;
614in this case you should remove unneeded files.
615.FS
616\*(dgDisk quotas are also a modification at Berkeley
617and may not exist at your installation.
618.FE
619.NH 2
620Run-time errors
621.PP
622We saw, in our second example, a run-time error.
623We here give the general description of run-time errors.
624The more unusual interpreter error messages are explained
625briefly in the manual section for
626.I px
627(VI).
628.SH
629Start-up errors
630.PP
631These errors occur when the object file to be executed is not available
632or appropriate.
633Typical errors here are caused by the specified object file not existing,
634not being a Pascal object, or being inaccessible to the user.
635.SH
636Program execution errors
637.PP
638These errors occur when the program interacts with the Pascal runtime
639environment in an inappropriate way.
640Typical errors are values or subscripts out of range,
641bad arguments to built-in functions,
642exceeding the statement limit because of an infinite loop,
643or running out of memory\*(dd.
644.FS
645\*(ddThe checks for running out of memory are not foolproof and there
646is a chance that the interpreter will fault, producing a core image
647when it runs out of memory.
648This situation occurs very rarely.
649.FE
650The interpreter will produce a backtrace after the error occurs,
651showing all the active routine calls,
652unless the
653.B p
654option was disabled when the program was translated.
655Unfortunately, no variable values are given and no way of extracting them
656is available.
657.PP
658As an example of such an error, assume that we have accidentally
659declared the constant
660.I n1
661to be 6, instead of 7
662on line 2 of the program primes as given in section 2.6 above.
663If we run this program we get the following response.
664.LS .ID
665% \*bpix primes.p\fP
666.so primeout3
667%
668.LE
669.PP
670Here the interpreter indicates that the program terminated
671abnormally due to a subscript out of range near line 14,
672which is eight lines into the body of the program primes.
673.SH
674Interrupts
675.PP
676If the program is interrupted while executing
677and the
678.B p
679option was not specified,
680then a backtrace will be printed.\*(dg
681.FS
682\*(dgOccasionally, the Pascal system will be in an inconsistent
683state when this occurs,
684e.g. when an interrupt terminates a
685.B procedure
686or
687.B function
688entry or exit.
689In this case, the backtrace will only contain the current line.
690A reverse call order list of procedures will not be given.
691.FE
692The file
693.I pmon.out
694of profile information will be written if the program was translated
695with the
696.B z
697option enabled to
698.PI
699or
700.IX .
701.SH
702I/O interaction errors
703.PP
704The final class of interpreter errors results from inappropriate
705interactions with files, including the user's terminal.
706Included here are bad formats for integer and real numbers (such as
707no digits after the decimal point) when reading.
708.SH
709Panics
710.PP
711A small number of panics are possible with
712.I px .
713These should be reported to a teaching assistant or to the system
714staff if they occur.