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