(Message inbox:715)
Return-Path: <beth@mit-heracles>
Received: from mit-heracles (mit-heracles.ARPA) by mit-theseus (4.12/4.7)
	id AA01517; Wed, 1 Aug 84 19:25:22 edt
Received: by mit-heracles (4.12/4.7)
	id AA09158; Wed, 1 Aug 84 19:26:21 edt
Date: Wed, 1 Aug 84 19:26:21 edt
From: beth@mit-heracles (Beth L Anderson)
Message-Id: <8408012326.AA09158@mit-heracles>
To: lbm@mit-heracles
Subject: .mss file for "Essential PASCAL"
Cc: cadmin@mit-heracles

Return-Path: <KEN@MIT-JCF>
Received: from mit-charon (mit-charon.ARPA) by mit-heracles (4.12/4.7)
	id AA29990; Mon, 30 Jul 84 18:52:25 edt
Received: by mit-charon (4.12/4.7)
	id AA04473; Mon, 30 Jul 84 18:49:49 edt
Message-Id: <8407302249.AA04473@mit-charon>
From: Ken Szajda <KEN@MIT-JCF>
Date:  30-JUL-1984 18:53
Subject:  This is the scribe file for Essential Pascal   ---Ken
Apparently-To: BETH@HERACLES

@make(article, Form 1)
@style(spacing 1, indent 0, bottommargin .5 inch)
@device(imgall)
Junk
@newpage
@begin(flushright, Font TitleFontX)
@b(Essential Pascal)
@end(flushright)
@begin(flushright, Font TitleFont3)
Kenneth Szajda
Project Athena
July 28, 1984
@end(flushright)
@blankspace(.25 inch)
This document contains the minimum amount of information you need to know in
order to use the Pascal language on Project Athena computers.  With this
document you may not be able to take full advantage of the Pascal facilities
on Project Athena, but you will be able to confidently create, compile,
and execute Pascal programs.  For further information concerning the
Berkley Pascal implementation, consult the @i(Berkley Pascal User's Manual),
available from IPS.

@section(Creating Pascal Programs)
@blankspace(.1 inches)
Creating Pascal programs is done using the @b(emacs) text editor.  Unlike
C, emacs does not provide a special mode for Pascal.  For further information
on using the emacs text editor, see @i(Essential Emacs), available in any
of the Project Athena clusters.
@blankspace(.25 inches)
@section(Special Notes about the Berkley Implementation)
@blankspace(.1 inches)
Berkley Pascal fully supports standard Pascal as defined in Jensen and Wirth's
@i(Pascal Users Manual).  However, there are a few peculiarities that
exist with the berkley implementation.  Unlike most Pascal systems, the
Berkley implementation differentiates between upper and lower case in
the source program.  All keywords must be entered in lower case; upper case
keywords are not recognized.  Furthermore, any predefined constants, functions,
and procedures must also be referenced to in lowercase only.  For example,
the statement
@fileexample[
     PROGRAM main(INPUT,OUTPUT);
]
would not be recognized by the software; whereas
@fileexample[
     program main(input,output);
]
would be correct.  The differentiation between upper and lower case
will cause unusual results.  This is most evident in the
use of the file variables @i(input) and @i(output).  If these variables are
not entered in lower case on the program statement line, all references to
@i(write), @i(writeln), @i(read), and @i(readln) referring to standard input
or output will be marked as errors.  The Berkley implementation also supports
many nonstandard functions and procedures; a full list of these is available
in the Berkley Pascal User's Manual, mentioned above.
@section(Preparing Pascal Programs for Execution)
@blankspace(.1 inches)
Unlike most other programming languages available on Project Athena, both
an interpreter and a compiler are available for Pascal.  Both the interpreter
and the compiler provide accurate, verbose error messages, but the compiler
provides faster execution times than the interpreter.  At this time,
both the interpreter (@b[pi]) and the compiler (@b[pc]) are supported by
Project Athena, but this is likely to change in the future.  Both are
described in the following sections; you may choose whichever tool serves
your particular needs.
@blankspace(.25 inches)
@section(PC, the Pascal Compiler)
@blankspace(.1 inches)
Pc provides quicker execution at the sacrifice of longer compile times.  Note
that all files on the pc command line must have either
a @b(.p) (for Pascal source files) or a @b(.o) (for object files) filename
extention.  If pc is given object files (with
the @b[.o] extension) it will load them into one executable image.  For
source files (with the @b[.p] extention), pc first compiles each file into
an object module with a @b[.o] extention and then loads each object module
into an executable image.  In both cases, the executable image is named
@b(a.out) by default.  Mixing of source files and object files on the same
command line is permitted--pc will compile all source files before loading
all of the object files together.  For example, typing
@fileexample[
     % pc main.p
]
will cause both main.o, the object file, and a.out, the executable image,
to be created.  Furthermore, typing
@fileexample[
     % pc main.p proclib.o
]
will also cause main.o to be created, but proclib.o will be loaded along with
main.o when the executable image a.out is created.  For this reason, object
libraries can be created using pc.  That, however, is beyond the scope of
this document; for further information see the @i(Berkley Pascal
User's Manual) mentioned above.
A few options available from pc allow changes and extentions to be made to the
compiling process.  A few of the more interesting and useful ones are:

@begin(format)
@tabclear@tabset(10,22)

@\@b(-c)@\will prevent pc from loading the object modules (used for
@\@\compiling procedure and function libraries)

@\@b(-o) @i(filename)@\will cause the executable image to be named @i(filename)
@\@\instead of @b(a.out)

@\@b(-w)@\will prevent pc from producing warning diagnostics

@\@b(-z)@\will cause pc to create additional symbol information for use by
@\@\@i(pxp), the Pascal execution profiler
@end(format)
There are many other options available with pc, many of which will be useful
only to the advanced Pascal programmer.  For further information on these
options, type @b(man pc) at the Shell level.
@blankspace(.25 inches)
@section(PI, the Pascal Interpreter)
@blankspace(.1 inches)
Pi, like pc, will translate Pascal source files into an executable image.
Unlike pc, however, programs interpreted using pi may be executed using
@b(px), which is a software tool specifically developed to execute
interpreted Pascal programs.  For this reason, the command @b(pix) is often
used instead of pi; pix does the interpretation and the execution in one step.
Pi is less flexible than pc.  Pi does not permit multiple files on a single
command line, and will not perform any of the loading functions of pc.
Instead, pi will take a complete Pascal program and translate it into a file
named @b(obj), which is in a form readable for px to execute.  Pi will
translate programs much faster than pc will compiler them; however, programs
translated using pi take longer to execute.  Note that, like pc, pi requires
the extention @b(.p) at the end of source files.  Since pi does not
perform the loading functions that pc does, however, no object modules can
be passed to pi, and an error will result if an object file is passed on the
command line.  All of the options listed above for pc (except @b[-o])
are handled by pi.
The @b(-o) option is not available with pix either, since pix generates the
object
file internally and deletes it at the conclusion of execution.  The average
Pascal programmer will most likely find pc easier to use; furthermore, the
greater flexibility available with pc makes its use preferable.
@blankspace(.25 inches)
@section(Executing Pascal Programs)
@blankspace(.1 inches)
As with all of the language compilers currently available on the Athena
system, the Pascal translators use the permissions on executable images
to allow or disallow execution.  If serious errors are detected during the
translation process, the permissions on the executable image will not allow
execute access.  Of course, this can always be changed using the @b(chmod)
command; however, the program will not execute correctly anyway since the
translation was incomplete in the first place.  When a correct translation
takes place, the executable image will enable execute access.  To execute
the image, just type the executable image name to the shell "%" prompt.
For files created using pi, px may also be used to execute images.
@blankspace(.25 inches)
@section(Error Diagnostics)
@blankspace(.1 inches)
Both pc and pi produce the same compile-time error messages, all of which
are fairly straightforward.  Both also provide automatic correction
capability in which the compiler/interpreter will attempt to make standard
corrections (inserting semicolons and the like) when not-fatal errors are
discovered.  In general, the error diagnostics generated are verbose and
helpful, and the user should have no difficulty locating errors.  Furthermore,
each error detected is given a severity rating.  The codes range from "E" for
fatal errors to "w" for warning messages.  Other codes include "e" for
recoverable errors and "s" for non-standard Pascal syntax.

Execution-time error messages are very different between pc and px, the
pi code executer.  Pc
provides much faster execution times, but run-time error messages are
usually brief and uninformative.  It often takes a good looking over
for bugs to be found, since error messages are so terse.  A typical error
message produced by pc is @fileexample[Segmentation fault (core dumped).]
Px (and pix), on the other hand, produce informative run-time error messages.
When an error is discoverd, px will print the actual cause of the error,
the module the error was made in, and a range of lines where the error
occurred.  A typical px (or pix) error message might look like

@fileexample[
     Subscript out of range

          Error in "factorial"+8 near line 14.
     Execution terminated abnormally.
]

Furthermore, px will print the total number of statements executed and the
total time of execution regardless of whether the program terminated
normally or abnormally.
@blankspace(.25 inches)
@section(A Brief Look at Pxp, the Pascal Execution Profiler)
@blankspace(.1 inches)
Pxp acts as both a profiler and a pretty-printer for Pascal programs.  When
given just a Pascal source file, pxp produces a formatted version of the
source text.  When the @b(-z) option is used, pxp will produce a profile
of the last execution of the source file, with the number of times each
statement was executed.  This is helpful for debugging or optimizing
programs, since there is an indication of how many times each statement
was executed.  For further information on pxp, consult the above-mentioned
User's Manual or the Unix Programmer's Guide (available on-line by typing
@b[man pxp]).
@blankspace(.25 inches)
@section(For More Information)
@blankspace(.1 inches)
Interactive help is available for each of the utilities mentioned.  Information
on pc can be found by typing @b(man pc); terse information is available by
typing @b(pc).  Information on pi, px, pix, and pxp is also on-line in
the Unix Programmer's Manual.  To date there is very little other documentation
available; the Berkley Pascal User's Manual mentioned above is the best source
of additional
information to supplement the Unix Programmer's Manual.  In addition, it
gives many illustrative examples demonstrating the entire process described
in this document.  Information on
advanced facilities available through the software (including @b[pdx], the
Pascal debugger) can also be found in the
Berkley Pascal User's Manual.


