Home
UNIX Pascal User`s Manual Version 1.0
Contents
1. t No runtime tests Disabling runtime tests also causes assert statements to be treated as comments t Card image 72 column input u Turning the u option on either on the command line or in a comment causes the input to be treated as card images with sequence numbers and truncated to 72 columns Thus pix u cards p Suppress warning diagnostics w The w option which defaults on allows the translator to print a number of warnings about inconsis tencies it finds in the input program Turning this option off with a comment of the form w or on the command line pi w tryme p suppresses these usually useful diagnostics Generate counters for an execution profile z The z option which defaults off enables the production of execution profiles By specifying z on the command line i e pi z foo p or by enabling it in a comment before the program statement we cause pi to insert operations in the inter preter code to count the number of times each statement was executed An example of using was given in section 2 6 its options are described in section 5 5 See section A 1 for a description of assert statements 5 3 Px The first argument to px is the name of the fi le containing the program to be interpreted If no argu ments are given then the fi le obj is executed If more arguments are given they are available to the Pascal program by using the built ins argc and argv as described in
2. Floating divide by zero Error at graph1 2 near line 17 Execution terminated abnormally 2 statements executed in 0 01 seconds cpu time Here the interpreter is presenting us with a runtime error diagnostic It detected a division by zero at line 17 Examining line 17 we see that we have written the statement x d 1 instead of x d 1 We can correct this and rerun the program ex bigger p bigger p 26 lines 538 characters 17 xi d i is x d i write bigger p 26 lines 538 characters Ipix pix bigger p Execution begins Execution terminated 2550 statements executed in 0 27 seconds cpu time q This appears to be the output we wanted We could now save the output in a file if we wished by using the shell to redirect the output px gt graph We can use cat I to see the contents of the file graph We can also make a listing of the graph on the line printer without putting it into a fi le e g px lpr Execution begins Execution terminated 2550 statements executed in 0 32 seconds cpu time Note here that the statistics lines came out on our terminal The statistics line comes out on the diagnostic output unit 2 There are two ways to get rid of the statistics line We can redirect the statistics message to the printer using the syntax l to the shell rather than I i e px Ipr or we can translate the progr
3. 3 5 7 11 13 17 19 23 29 37 41 43 47 53 59 61 67 71 79 83 89 97 101 103 107 109 113 131 137 139 149 151 157 163 167 173 181 191 193 197 199 211 223 227 229 Execution terminated 1404 statements executed in 0 17 seconds cpu time Discussion The header lines of the outputs of pix and in this example indicate the version of the translator and execution profiler in use at the time this example was prepared The time given with the file name also on the header line indicates the time of last modifi cation of the program source file This time serves to version stamp the input program Pxp also indicates the time at which the profi le data was gathered pxp z primes p UNIX Pascal PXP Version 1 0 September 10 1977 Sat Sep 10 13 19 1977 primes p Profi led Sat Sep 10 13 19 1977 1 1 Ilprogram primes output 2 Iconst 2 n 50 2 nl 7 nl sqrt n 3 Ivar 3 i k x inc lim square 1 integer 4 prim boolean 5 p v array 1 n1 of integer 6 Ibegin 7 write 2 6 3 6 7 1 2 8 x 8 ince 4 8 lim 1 8 square 9 9 fori 3 ton do begin fi nd next prime 9 48 repeat 11 76 x x inc 11 inc 6 inc 12 if square lt x then begin 13 5 lim lim 1 14 v lim square 14 square sqr p lim 1 14 end 16 I ker 16 prim true 17 while prim and k lt lim do begin 18 157 k k4 1 19 if v k lt x then
4. 3 begin 4 for j 1 to 20 begin EE ee Replaced with a pupeo Core ae Tnserted keyword do 5 write j 6 1 2 j e _ Inserted 7 E_ Inserted identifi er 7 writeln i Fst a Deleted Y 8 end 9 end The only surprise here may be that Pascal does not have an exponentiation operator hence the complaint about This error illustrates that if you assume that the language has a feature which it does not the translator diagnostic may not indicate this as the translator is unlikely to recognize the construct you sup ply Undefi ned or improper identifi ers If an identifi er is encountered in the input but is undefi ned the error recovery will replace it with an identifi er of the appropriate class Further references to this identifi er will be summarized at the end of the containing procedure or function or at the end of the program if the reference occurred in the main pro gram Similarly if an identifi er is used in an inappropriate way e g if a type identifi er is used in an assign ment statement or if a simple variable is used where a record variable is required a diagnostic will be pro duced and an identifi er of the appropriate type inserted Further incorrect references to this identifi er will be fhgged only if they involve incorrect use in a different way with all incorrect uses being summarized in the same way as undefi ned variable uses are Ex
5. null where 7 is an integer and a is a string variable assigns the possibly truncated or blank padded i th argument of the invocation of the current UNIX process to the variable a The range of valid i is 0 to argc 1 assigns the current date to the alfa variable a in the format dd mmm yy where mmm is the fi rst three characters of the month i e Apr writes the output buffered for Pascal fi le f into the associated UNIX fi le terminates the execution of the program with a control fbw backtrace with f a textfi le and x an integer expression causes the program to be abnor mally terminated if more than x lines are written on file f If x is less than 0 then no limit is imposed causes the parameters which have the format of those to the built in proce dure write to be written unbuffered on the diagnostic unit 2 almost always the user s terminal a procedure of no arguments which does absolutely nothing It is useful as a place holder and is generated by in place of the invisible empty statement remove a reset f a rewrite f a stlimit i time a Non standard functions argc card x clock expo x random x seed i sysclock Currently ignored by px where a is a string causes the UNIX fi le whose name is a with trailing blanks eliminated to be removed where a is a string causes the fi le whose name is a with blanks trimmed to be associated with fin addition to the
6. Added types operators procedures and functions Additional predefi ned types The type alfa is predefi ned as type alfa packed array 1 10 of char The type intset is predefi ned as type intset set of 0 127 In most cases the context of an expression involving a constant set allows the translator to determine the type of the set even though the constant set itself may not uniquely determine this type In the cases where it is not possible to determine the type of the set from local context the expression type defaults to a set over the entire base type unless the base type is integer In the latter case the type defaults to the current binding of intset which must be type set of a subrange of integer at that point Note that if intset is redefi ned via type intset set of 0 58 then the default integer set is the implicit intset of Pascal 6000 3 4 Additional predefi ned operators The relationals lt and gt of proper set inclusion are available With a and b sets note that not a lt b lt gt a gt b The current translator makes a special case of the construct if in and enforces only the more lax restriction on 16 bit arithmetic given above in this case As an example consider the sets a 0 2 and b 1 The only relation true between these sets is lt gt Non standard procedures argv i a date a flish f halt linelimit f x message x
7. Here we have used the shell s syntax to redirect the program input from a file in primes in which we had placed the output of our prime number program of section 2 6 It is also possible to pipe input to this pro gram much as we piped input to the line printer daemon lpr I before Thus the same output as above would be produced by cat primes pix kat p All of these examples use the shell to control the input and output from fi les One very simple way to associate Pascal fi les with named UNIX fi les is to place the file name in the program statement For exam ple suppose we have previously created the file data We then use it as input to another version of a listing program cat data line one line two line three is the end pix l copydata p UNIX Pascal PI Version 1 0 September 8 1977 Fri Sep 9 18 49 1977 copydata p 1 program copydata data output 2 var 3 ch char 4 data text 5 begin 6 reset data 7 while not eof data do begin 8 while not eoln data do begin 9 read data ch 10 write ch 11 end 12 readIn data 13 writeln 14 end 15 end copydata Execution begins line one line two line three is the end Execution terminated 134 statements executed in 0 04 seconds cpu time By mentioning the file data in the program statement we have indicated that we wish it to correspond to the UNIX file data Then when we reset data the Pascal system opens our
8. Temporary fi les are removed automatically when their scope is exited The program statement The syntax of the program statement is program lt id gt lt fi le id gt lt fileid gt The fi le identifi ers other than input and output must be declared as variables of file type in the global dec laration part The files input and output The formal parameters input and output are associated with the UNIX standard input and output and have a somewhat special status The following rules must be noted 1 The program heading must contains the formal parameter output If input is used explicitly or implicitly then it must also be declared here 2 Unlike all other files the Pascal fi les input and output must not be defi ned in a declaration as their declaration is automatically var input output text 3 The procedure reset may be used on input If no UNIX file name has ever been associated with input and no file name is given then an attempt will be made to rewind input If this fails a run time error will occur Rewrite calls to output act as for any other file except that output initially has no associated file This means that a simple rewrite output associates a temporary name with output Details for files If a file other than input is to be read then reading must be initiated by a call to the procedure reset which causes the Pascal system to attempt to open the associated UNIX file for reading I
9. pix bigger p 9 h 34 Character position of x axis W eeens iania nese in a comment 16 for i 0 to lim begin e _ _ Inserted keyword do 18 y exp x9 sin i x E_ _ Undefi ned variable e eee ee eee a Inserted y 19 n Round s y h E_ _ Undefi ned function E_ _ Undefi ned variable 23 writeln e_ _ Inserted Ai 24 end Biss ieee Expected keyword until e_ f Inserted keyword end matching begin on line 15 In program graph1 w constant c is never used E x9 undefi ned on line 18 E Round undefi ned on line 19 E h undefined on line 19 Execution suppressed due to compilation errors Since there were fatal E errors in our program no code was generated and execution was necessar ily suppressed One thing which would be useful at this point is a listing of the program with the error mes sages We can get this by using the command pi l bigger p There is no point in using pix here since we know there are fatal errors in the program This command will produce the output at our terminal If we are at a terminal which does not produce a hard copy we may wish to print this listing off line on a line printer We can do this with the command pi l bigger p lpr In the next few sections we will illu
10. 19 42 v k v k 2 p k 20 prim x lt gt v k 20 end 20 luntil prim 23 ifi lt nl then 23 5 pi x 24 write x 6 24 l 141 25 if l1 10 then begin 26 5 writeln 26 1 0 26 end 26 end 29 writeln 29 lend To determine the number of times a statement was executed one looks to the left of the statement and fi nds the corresponding vertical bar Il If this vertical bar is labelled with a count then that count gives the number of times the statement was executed If the bar is not labelled we look up in the listing to find the first I which directly above the original one which has a count and that is the answer Thus in our exam ple k was incremented 157 times on line 18 while the write procedure call on line 24 was executed 48 times as given by the count on the repeat More information on pxp can be found in its manual section VI and in sections 5 4 5 5 and 5 10 3 Error diagnostics This section of the User s Manual discusses the error diagnostics of the programs pi and px Pix is a simple but useful program which invokes pi and px to do all the real processing See its manual section pix VI and section 5 2 below for more details 3 1 Translator syntax errors A few comments on the general nature of the syntax errors usually made by Pascal programmers and the recovery mechanisms of the current translator may help in using the system Illegal ch
11. 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 930 statements executed in 0 22 seconds cpu time kat This is a line of text This is a line of text The next line contains only an end of fi le an invisible control d The next line contains only an end of fi le an invisible control d 287 statements executed in 0 09 seconds cpu time Thus we see that if it is given arguments kat will like cat copy each one in turn If no arguments are given it copies from the standard input Thus it will work as it did before with kat lt primes now equivalent to kat primes although the mechanisms are quite different in the two cases Note that if kat is given a bad file name for example kat xxxxqqq xxxxqqq No such fi le or directory Error at kat 5 near line 11 4 statements executed in 0 06 seconds cpu time it will give a diagnostic and a post mortem control fbw backtrace for debugging If we were going to use kat we might want to translate it differently e g pi pb kat p mv obj kat Here we have disabled the post mortem statistics printing so as not to get the statistics or the traceback on error The b option will cause the system to block buffer the input output so that the program will run more effi ciently on large fi les We could have also specifi ed the t option to turn off run
12. As the omission of a character is a common mistake the translator chose to indicate this as a possible fi x here It later detected that the keyword until was miss ing but not until it saw the keyword end on line 24 The combination of these diagnostics indicate to us the true problem The final syntactic error message indicates that the translator needed an end keyword to match the begin at line 15 Since the end at line 24 is supposed to match this begin we can infer that another begin must have been mismatched and have matched this end Thus we see that we need an end to match the begin at line 16 and to appear before the fi nal end We can make these corrections x9 s x y exp x sin i x s Round round n round s y h write write writeln insert until n 0 end insert end At the end of each procedure or function and the end of the program the translator summarizes ref erences to undefi ned variables and improper usages of variables It also gives warnings about potential errors In our program the summary errors do not indicate any further problems but the warning that c is unused is somewhat suspicious Examining the program we see that the constant was intended to be used in the expression which is an argument to sin so we can correct this expression and translate the program We have now made a correction for each diagnosed error in our program jOne good reaso
13. Pascal or use it as a medium are available The books by Wirth Sys tematic Programming and Algorithms Data Structures Programs use Pascal as a vehicle for teaching programming and data structure concepts respectively They are both recommended Other books on Pas cal are listed in the references below 1 6 Pascal documents The UNIX Implementation This section describes the documentation which is available describing the UNIX implementation of Pascal User s Manual The document you are reading is the User s Manual for UNIX Pascal We often refer the reader to the Jensen Wirth User Manual mentioned above a different document with a similar name Manual sections The sections relating to Pascal in the UNIX Programmer s Manual are pix VI pi VD pec VI px VD pxp VI and pxref VI These sections give a description of each program summarize the available options indicate fi les used by the program give basic information on the diagnostics produced and include a list of known bugs Implementation notes For those interested in the internal organization of the UNIX Pascal system there are a series of Imple mentation Notes describing these details The PI 1 0 Implementation Notes describe the structure of the Pascal translator pi the PX 1 0 Implementation Notes describe the Pascal interpreter px and the PXP 1 0 Implementation Notes describe the structure of the execution profi ler pxp 1 7 References UNIX Doc
14. a pseudo Pascal statement The fi lenames of included fi les must end in 1 An example of the use of included fi les in a main program would be ome program compiler input output obj include globals i include scanner i include parser i include semantics i begin main program end At the point the include pseudo statement is encountered in the input the lines from the included fi le are interpolated into the input stream For the purposes of translate and run time diagnostics and statement numbers in the listings and post mortem backtraces the lines in the included file are numbered from 1 Nested includes are possible up to 10 deep See the descriptions of the i and n options of pi in section 5 2 above these can be used to control list ing when include fi les are present Include control lines are never printed in a listing If the n option is not set they are replaced by a line containing the file name and a character This is the default setting If the n new page option is enabled then the include line is replaced with a banner line similar to the first line of a listing This line is placed on a new page in the listing When a non trivial line is encountered in the source text after an include fi nishes the popped fi le name is printed in the same manner as above For the purposes of error diagnostics when not making a listing the fi lename will be printed before each diagnostic i
15. are possible with px These should be reported to a teaching assistant or to the system staff if they occur jOccasionally the Pascal system will be in an inconsistent state when this occurs e g when an interrupt termi nates a procedure or function entry or exit In this case the backtrace will only contain the current line A reverse call order list of procedures will not be given 4 Input output This section describes features of the Pascal input output environment with special consideration of the features peculiar to an interactive implementation 4 1 Introduction Our first sample programs in section 2 used the fi le output We gave examples there of redirecting the output to a file and to the line printer using the shell Similarly we can read the input from a file or another program Consider the following Pascal program which is similar to the program cat I pix l kat p lt primes UNIX Pascal PI Version 1 0 September 8 1977 Fri Sep 9 18 49 1977 kat p 1 program kat input output 2 var 3 ch char 4 begin 5 while not eof do begin 6 while not eoln do begin 7 read ch 8 write ch 9 end 10 readln 11 writeln 12 end 13 end kat Execution begins 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 Execution terminated 925 statements executed in 0 27 seconds cpu time
16. been designed so that an initial read is not necessary At any given time the Pascal system may or may not know whether the end of file or end of line conditions are true Thus internally t is not possible in practice to determine whether the input is a terminal as the input may appear to be a file but actually be a pipe the output of a program which is reading from the terminal these functions can have three values true false and I don t know yet if you ask me I ll have to find out All files remain in this last indeterminate state until the Pascal program requires a value for eof or eoln either explicitly or implicitly e g in a call to read The important point to note here is that if you force the Pascal system to determine whether the input is at the end of fi le or the end of line it will be necessary for it to attempt to read from the input Thus consider the following example code while not eof do begin write number please read 1 writeln that was a i 2 end At first glance this may be appear to be a correct program for requesting reading and echoing numbers Notice however that the while loop asks whether eof is true before the request is printed This will force the Pascal system to decide whether the input is at the end of fi le The Pascal system will give no mes sages it will simply wait for the user to type a line By producing the desired prompting before testing eof the follow
17. digits followed by the character b or B The forms write a n oct and write a n hex cause the internal representation of expression a which must be Boolean character integer pointer or a user defi ned enumerated type to be written in octal or hexadecimal respectively Assert statement An assert statement causes a Boolean expression to be evaluated each time the statement is executed A runtime error results if any of the expressions evaluates to be false The assert statement is treated as a comment if run time tests are disabled The syntax for assert is assert lt expr gt A 2 Resolution of the undefi ned specifi cations File name file variable associations Each Pascal fi le variable is associated with a named UNIX file Except for input and output which are exceptions to some of the rules a name can become associated with a fi le in any of three ways 1 If a global Pascal file variable appears in the program statement then it is associated with UNIX fi le of the same name 2 If a file was reset or rewritten using the extended two argument form of reset or rewrite then the given name is associated 3 If a file which has never had UNIX name associated is reset or rewritten without specifying a name via the second argument then a temporary name of the form tmp x is associated with the file Temporary names start with tmp 1 and continue by incrementing the last character in the USASCII ordering
18. file data for reading More sophisticated but less portable examples of using UNIX fi les will be given in sections 4 5 and 4 6 There is a portability problem even with this simple example Some Pascal systems attach meaning to the ordering of the fi le in the program statement fi le list UNIX Pascal does not do so 4 2 Eof and eoln An extremely common problem encountered by new users of Pascal especially in the interactive environment offered by UNIX relates to the defi nitions of eof and eoln These functions are supposed to be defi ned at the beginning of execution of a Pascal program indicating whether the input device is at the end of a line or the end of a file Setting eof or eoln actually corresponds to an implicit read in which the input is inspected but no input is used up In fact there is no way the system can know whether the input is at the end of fi le or the end of line unless it attempts to read a line from it If the input is from a previously created file then this reading can take place without run time action by the user However if the input is from a terminal then the input is what the user types If the system were to do an initial read automati cally at the beginning of program execution and if the input were a terminal the user would have to type some input before execution could begin This would make it impossible for the program to begin by prompting for input or printing a herald UNIX Pascal has
19. in the program It may be specifi ed in combination with the z option or separately Enable and control the profile z The z profile option is very similar to the i listing control option of pi If z is specified on the com mand line then all arguments up to the source fi le argument which ends in p are taken to be the names of procedures and functions or include fi les which are to be profi led If this list is null then the whole fi le is to be profiled A typical command for extracting a profi le of part of a large program would be pxp z test parser i compiler p This specifi es that profi les of the routines in the fi le parseri and the routine fest are to be made 5 5 Formatting programs using pxp The program can be used to reformat programs by using a command of the form pxp dirty p gt clean p Note that since the shell creates the output file clean p before executes so clean p and dirty p must not be the same fi le Pxp automatically paragraphs the program performing housekeeping chores such as comment align ment and treating blank lines lines containing exactly one blank and lines containing only a form feed character as though they were comments preserving their vertical spacing effect in the output Pxp distin guishes between four kinds of comments 1 Left marginal comments which begin in the fi rst column of the input line and are placed in the first column of an output line
20. lead to multiple error diagnostics Pi attempts to give only one diagnostic for each error but single errors in the input sometimes appear to be more than one error It is also the case that pi may not detect an error when it occurs but may detect it later in the input This would have happened in this example if we had typed x instead of x9 The translator next detected on line 19 that the function Round and the variable h were undefi ned It does not know about Round because UNIX Pascal normally distinguishes between upper and lower case On UNIX lower case is preferred and all keywords and built in procedure and function names are com posed of lower case letters just as they are in the Jensen Wirth Pascal Report Thus we need to use the function round here As far as h is concerned we can see why it is undefi ned if we look back to line 9 and note that its defi nition was lost in the non terminated comment This diagnostic need not therefore con cern us The next error which occurred in the program caused the translator to insert a before the statement calling writeln on line 23 If we examine the program around the point of error we will see that the actual error is that the keyword until and an associated expression have been omitted here Note that the diagnos tic from the translator does not indicate the actual error and is somewhat misleading The translator made the correction which seemed to be most plausible
21. printing characters are printed as the character in the listing Multi fi le programs It is also possible to prepare programs whose parts are placed in more than one file The files other than the main one are called include fi les and have names ending with 1 The contents of an include fi le are referenced through a pseudo statement of the form include fi le i 679 The character must be the first character on the line The file name may be delimited with or characters Nested includes are possible up to 10 deep More details are given in sections 5 9 and 5 10 The standard procedure write If no minimum field length parameter is specified for a write the following default values are assumed integer 10 real 22 Boolean 10 char 1 string length of the string oct 11 hex 8 The end of each line in a text file should be explicitly indicated by writeln f where writeln output may be written simply as writeln For UNIX the built in function page f puts a single ASCI form feed char acter on the output file For programs which are to be transported the fi lter pcc can be used to interpret car riage control as UNIX does not normally do so The character generated by a control i indents to the next tab stop Tab stops are set every 8 columns in UNIX Tabs thus provide a quick way of indenting in the program A 3 Restrictions and limitations Files Files cannot be
22. section 4 6 Px may also be invoked automatically by the shell In this case whenever a Pascal object fi le name is given as a command the command will be executed with px prepended to it that is obj primes will be converted by the shell to read px obj primes This feature makes using Pascal programs much more convenient 5 4 Pxp Pxp takes on its command line a list of options followed by the program fi le name which must end in p as it must for pi and pix will produce an execution profi le if any of the z t or options are specifi ed on the command line If none of these options are specifi ed then functions as a program reformatter See section 5 5 for more details It is important to note that only the z option of and the n u and w options which are common to pi and can be controlled in comments All other options must be specified on the command line to have any effect The following options are relevant to profi ling with Include the bodies of all routines in the profile a Pxp normally suppresses printing the bodies of routines which were never executed to make the pro fi le more compact This option forces all routine bodies to be printed Extract profi le data from the file core c This option causes to extract the data from the file core in the current directory This is used in debugging the Pascal system and should not normally be needed When an abnormal termination occurs in px it write
23. use of the function chr characters as arguments to ord and comparisons of characters since the character set ordering differs between the two machines The Pascal 6000 3 4 compiler uses a less strict notion of type equivalence In UNIX Pascal types are considered identical only if they are represented by the same type identifier Thus in particular unnamed types are unique to the variables fi elds declared with them Pascal 6000 3 4 doesn t recognize our option fags so it is wise to put the control of UNIX Pascal options to the end of option lists or better yet restrict the option list length to one For Pascal 6000 3 4 the ordering of fi les in the program statement has signifi cance It is desirable to place input and output as the fi rst two fi les in the program statement The s option does not however check that identifi ers differ in the first 8 characters Pi also does not check the semantics of packed
24. 2 Aligned comments which are preceded by no input tokens on the input line These are aligned in the output with the running program text 3 Trailing comments which are preceded in the input line by a token with no more than two spaces separating the token from the comment 4 _ Right marginal comments which are preceded in the input line by a token from which they are separated by at least three spaces or a tab These are aligned down the right margin of the out put currently to the first tab stop after the 40th column from the current left margin Consider the following program cat comments p This is a left marginal comment program hello output var i integer This is a trailing comment ji integer This is aright marginal comment k array 1 10 of array 1 10 of integer Marginal but past the margin An aligned multi line comment which explains what this program is all about begin i 1 Trailing i comment A left marginal comment An aligned comment jc 1 Right marginal comment k 1 1 writelni j k 1 end When formatted by the following output is produced pxp comments p This is a left marginal comment program hello output var i integer This is a trailing comment j integer This is a right marginal comment k array 1 10 of array 1 10 of integer Marginal but past the margin An aligned multi line comment which explains what this progr
25. UNIX Pascal User s Manual Version 1 0 November 1977 William N Joy Susan L Graham Charles B Haley Computer Science Division Department of Electrical Engineering and Computer Science University of California Berkeley Berkeley California 94720 ABSTRACT UNIX Pascal is designed for interactive instructional use and runs on the PDP 11 45 and PDP 11 70 computers It produces interpretive code providing fast translation at the expense of slower execution speed An execution profiler and Wirth s cross reference program are also available with the system The system supports full Pascal with the exception of procedure and function names as parameters The language accepted is very close to standard Pascal with only a small number of extensions for the UNIX sys tem The User s Manual gives a list of sources relating to the UNIX system the Pascal language and the UNIX Pascal system Basic usage examples are provided for the Pascal interpreter components pi px pix and Errors commonly encountered in these programs are discussed Details are given of spe cial considerations due to the interactive implementation A number of examples are provided including many dealing with input output An appendix supplements Wirth s Pascal Report to form the full definition of the UNIX implementation of the language 16 January 2004 UNIX Pascal User s Manual Version 1 0 November 1977 William N Joy Susan L Graham Ch
26. ables the run time tests option t since it defaults on In additon to inverting the default settings of pi options on the command line it is also possible to control the pi options within the body of the program by using comments of a special form illustrated by l Here we see that the opening comment delimiter which could also be a is immediately followed by the character After this which signals the start of the option list we can place a sequence of let ters and option controls separated by characters The most basic actions for options are to set them thus l Enable listing or to clear them t p No run time tests no post mortem analysis Notice that always enables an option and always disables it no matter what the default is Thus has a different meaning in an option comment than it has on the command line As shown in the examples normal comment text may follow the option list As pix uses pi to translate Pascal programs it takes the options of pi also We refer to them here however as pi options This format was chosen because it is used by Pascal 6000 3 4 In general the options common to both imple mentations are controlled in the same way so that comment control in options is mostly portable It is recom mended however that only one control be put per comment for maximum portability as the Pascal 6000 3 4 implementation will ignore controls af
27. al The text editor ex is an enhanced version of the text editor ed It is designed for use by people who have not used a text editor before as well as those experienced editor users who wish to use its new fea tures This document summarizes the features of ex For persons with little previous editor experience the tutorials listed above are also recommended 1 5 Pascal documents The language This section describes the documents on the Pascal language which are likely to be most useful to the UNIX Pascal user Complete references for these documents are given in section 1 7 Pascal User Manual By Kathleen Jensen and Niklaus Wirth the User Manual provides a tutorial introduction to the fea tures of the language Pascal and serves as an excellent quick reference to the language The reader with no familiarity with Algol like languages may prefer one of the Pascal text books listed below as they provide more examples and explanation Particularly important here are pages 116 118 which define the syntax of the language Sections 13 and 14 and Appendix F pertain only to the 6000 3 4 implementation of Pascal Pascal Report By Niklaus Wirth this document is bound with the User Manual It is the guiding reference for implementors and the fundamental defi nition of the language Some programmers find this report too con cise to be of practical use preferring the User Manual as a reference Books on Pascal Several good books which teach
28. am is all about begin i 1 Trailing i comment A left marginal comment An aligned comment j 1 Right marginal comment k 1 1 writeln i j k 1 end The following formatting related options are currently available in The options f and j described in the previous section may also be of interest Strip comments s The s option causes to remove all comments from the input text Underline keywords _ A command line argument of the form _ as in pxp _ dirty p can be used to cause to underline all keywords in the output for enhanced readability Specify indenting unit 23456789 The normal unit which uses to indent a structure statement level is 4 spaces By giving an argument of the form d with d a digit 2 lt d lt 9 you can specify that d spaces are to be used per level instead 5 6 Pec and carriage control The UNIX system printer driver does not implement FORTRAN style carriage control Thus the func tion page on UNIX does not output a character 1 in column 1 of a line but rather puts out a form feed character For those who wish to use carriage control the filter pcc is available which interprets this con trol A sample usage is px pee or pix prog p pec Ipr for printer copy Pcc is fully described by its manual documentation pcc VI 5 7 Pxref The cross reference program pxref may be used to make cross referenced listings of Pascal programs T
29. am with the p option disabled on the command line as we did above This will disable all post mortem dumping including the statistics line thus pi p bigger p px lpr This option also disables the statement limit which normally guards against infi nite looping You should not use it until your program is debugged Also if p is specified and an error occurs you will not get run time diagnostic information to help you determine what the problem is 2 5 Formatting the program listing It is possible to use special lines within the source text of a program to format the program listing An empty line one with no characters on it corresponds to a space macro in an assembler leaving a completely blank line without a line number A line containing only a control l form feed character will cause a page eject in the listing with the corresponding line number suppressed This corresponds to an eject pseudo instruction See also section 5 2 for details on the n and i options of pi 2 6 Execution profi ling An execution profile consists of a structured listing of all or part of a program with information about the number of times each statement in the program was executed for a particular run of the program These profiles can be used for several purposes In a program which was abnormally terminated due to excessive looping or recursion or by a program fault the counts can facilitate location of the error Zero counts mark
30. and name as we did with the substitute command here We have also used the shell escape command here to execute other commands with a shell without leaving the editor t should be noted that the obj works only with a modifi ed shell This modifi cation has been made at Berke ley It may not be available if you are elsewhere In this case you can use the syntax with px specifi ed explic obj will have the same effect Some examples of different ways to execute the program follow px Hello world 1 statement executed in 0 02 seconds cpu time pi p first p px obj Hello world pix p fi rst p Hello world Note that px will assume that obj is the fi le we wish to execute if we don t tell it otherwise The last two translations use the p no post mortem option to eliminate execution statistics and Execution begins and Execution terminated messages See section 5 2 for more details If we now look at the files in our directory we will see ls fi rst p obj We can give our object program a name other than obj by using the move command mv I Thus to name our program hello mv obj hello hello Hello world ls first p hello Finally we can get rid of the Pascal object code by using the rm I remove fi le command e g rm hello ls fi rst p For small programs which are being developed pix tends to be more convenient to use than pi an
31. aracters 8 Characters such as and are not part of the language Pascal If they are found in the source program and are not part of a constant string a constant character or a comment they are consid ered to be illegal characters This can happen if you leave off an opening string quote Note that the character although used in English to quote strings is not used to quote strings in Pascal Most non printing characters in your input are also illegal except in character constants and character strings Except for the tab and form feed characters which are used to ease formatting of the program non printing charac ters in the input fi le print as the character so that they will show in your listing String errors 67 7 9 There is no character string of length 0 in Pascal Consequently the input is not acceptable Sim ilarly encountering an end of line after an opening string quote without encountering the matching clos ing quote yields the diagnostic Unmatched for string It is permissible to use the character instead of to delimit character and constant strings for portability reasons For this reason a spuriously placed sometimes causes the diagnostic about unbalanced quotes Similarly a in column one is used when preparing programs which are to be kept in multiple fi les See section 5 9 for details Comments in a comment non t
32. arles B Haley Computer Science Division Department of Electrical Engineering and Computer Science University of California Berkeley Berkeley California 94720 Introduction The UNIX Pascal User s Manual consists of fi ve major sections and an appendix In section we give sources of information about UNIX about the programming language Pascal and about the UNIX implemen tation of the language Section 2 introduces the UNIX implementation and provides a number of basic examples Section 3 discusses the error diagnostics produced by the translator pi and the runtime inter preter px Section 4 describes input output with special attention given to features of the interactive imple mentation and to features unique to UNIX Section 5 gives details on the components of the system and explanation of all relevant options The User s Manual concludes with an appendix to Wirth s Pascal Report with which it forms a precise defi nition of the implementation History of the implementation The first UNIX Pascal system was written by Ken Thompson in early 1976 The main features of the present system result from the work of Charles Haley and William Joy during the latter half of 1976 Ear lier versions of this system have been in use since January 1977 Acknowledgement The fi nancial support of the fi rst and second authors work by the National Science Foundation under grant MCS74 07644 A03 and the first author s work by an IBM Fellows
33. bject code file obj using pi The program pi translates Pascal programs but stores the object code instead of executing itt ex first p fi rst p 4 lines 59 characters 1 print program fi rst output s program fi rst output write fi rst p 4 lines 60 characters tpi lpi fi rst p quit oy The first command issued from ex with the involved the use of the character which stands in this command for the file we are editing Ex made this substitution and then echoed back the expanded line before executing the command When the command fi nished the editor echoed the character so that we would know it was done If we now use the UNIX s list files command we can see what fi les we have ls fi rst p obj The fi le obj here contains the Pascal interpreter code We can execute this by typing px obj Hello world 1 statement executed in 0 02 seconds cpu time Alternatively obj will be noticed to contain a Pascal object by the shell so that the command The standard Pascal warnings occur only when the associated s translator option is enabled The s option is discussed in sections 5 1 and A 6 below Warning diagnostics are discussed at the end of section 3 2 the associ ated w option is described in section 5 2 This script indicates some other useful approaches to debugging Pascal programs As in ed we can shorten commands in ex to an initial prefi x of the comm
34. ce VI It is possible to obtain a copy of a manual section by using the man VI command To get the Pascal documentation just described one could issue the command man pi to the shell The user input here is shown in bold face the which was printed by the shell as a prompt is not Similarly the command man man asks the man command to describe itself 1 4 Text editing documents The following documents introduce the various UNIX text editors In addition to the documents described here there is an implementation of the text editor teco available locally No documentation on this editor is available currently however Text editing with UNIX This series of documents is used for the short course given at the Computer Center on text editing It can also be used for self study and is the best tutorial currently available on basic text editing For those not in Computer Science Division courses the associated short course at the Computer Center on text edit ing is strongly recommended A Tutorial Introduction to the UNIX Text Editor This document written by Brian Kernighan of Bell Laboratories is the standard tutorial for the UNIX text editor ed This document also introduces you to the very basics of text editing but does not discuss using the system itself at the same time For this reason this document is recommended as supplemental reading along with the document Text editing with UNIX Ex Reference Manu
35. d px Except for absence of the obj file after a pix run a pix command is equivalent to a pi command followed by a px command For larger programs where a number of runs testing different parts of the program are to be made pi is useful as this obj fi le can be executed any desired number of times 2 2 A larger program Suppose that we have used the editor to put a larger program in the file bigger p We can list this program with line numbers by using the program number i e itly if the number program is not available Ino may be It is similar but aligns the line numbers in a different less pleasant way number bigger p 1 2 Graphic representation of a function 3 f x exp x sin 2 pi x 4 x 5 program graphl output 6 const 7 d 0 0625 1 16 16 lines for interval x x 1 8 s 32 32 character width for interval x x 1 9 h 34 Character position of x axis 10 c 6 28138 2 pi 11 lim 32 12 var 13 X y real 14 i n integer 15 begin 16 for i 0 to lim begin 17 x d 1 18 y exp x9 sin i x 19 n Round s y h 20 repeat 21 write 22 n n 1 23 writeln 24 end This program is similar to program 4 9 on page 30 of the Jensen Wirth User Manual A number of prob lems have been introduced into this example for pedagogical reasons If we attempt to translate and execute the program using pix we get the following response
36. dentical to that used in Pascal 6000 3 4 One places the character as the first character of the comment and follows it by a comma separated list of directives Thus an equivalent to the command line example given above would be l s listing on standard Pascal as the first line of the program The T option is more appropriately specifi ed on the command line since it is extremely unlikely in an interactive environment that one wants a listing of the program each time it is translated Directives consist of a letter designating the option followed either by a to turn the option on or by a to turn the option off The b option takes a single digit instead of a or Notes on the listings The fi rst page of a listing includes a banner line indicating the version and date of generation of pi It also includes the UNIX path name supplied for the source fi le and the date of last modifi cation of that fi le Within the body of the listing lines are numbered consecutively and correspond to the line numbers for the editor Currently two special kinds of lines may be used to format the listing a line consisting of a form feed character control which causes a page eject in the listing and a line with no characters which causes the line number to be suppressed in the listing creating a truly blank line These lines thus corre spond to eject and space macros found in many assemblers Non
37. e and that in effect the Pascal system always reads one charac ter ahead of the Pascal read commands For instance in response to read ch the system sets ch to the current input character and gets the next input character If the current input character is the last character of the line then the next input character from the fi le is the new line character the normal UNIX line separa tor When the read routine gets the new line character it replaces that character by a blank causing every line to end with a blank and sets eoln to true Eoln will be true as soon as we read the last character of the line and before we read the blank character corresponding to the end of line Thus it is almost always a mistake to write a program which deals with input in the following way in Pascal terms read ch corresponds to ch input get input read ch if eoln then Done with line else Normal processing as this will almost surely have the effect of ignoring the last character in the line The read ch belongs as part of the normal processing Given this framework it is not hard to explain the function of a readin call which is defi ned as while not eoln do get input get input This advances the file until the blank corresponding to the end of line is the current input symbol and then discards this blank The next character available from read will therefore be the first character of the next line if one exi
38. e listed while translating All arguments after the i fhg up to the name of the fi le being translated which ends in p are in this list Typical uses would be pix i scanner i compiler p to make a listing of the routines in the fi le scanner i and pix i scanner compiler p to make a listing of only the routine scanner This option is especially useful for conservation minded pro grammers making partial program listings Make a listing 1 The option enables a listing of the program The l option defaults off When specifi ed on the com mand line it causes a header line identifying the version of the translator in use and a line giving the modi fi cation time of the fi le being translated to appear before the actual program listing The l option is pushed and popped by the i option at appropriate points in the program Eject new pages for include files n The n option causes pi to eject a new page in the listing and print a header line at include fi le bound aries providing automatic pagination control To have effect either the l or i option should also be speci fi ed or the input should contain listing control in comments An example would be pi in scan i c p Post mortem dump p The p option defaults on and causes the runtime system to initiate a post mortem backtrace when an error occurs It also cause px to count statements in the executing program enforcing a statement limit to prevent inf
39. e statement syntax chart on page 118 of the Jensen Wirth User Manual we will discover that do is a necessary part of the for statement Similarly we could have referred to section C 3 of the Jensen Wirth User Manual to learn about the for statement and gotten the same information there It is often useful to refer to these syntax charts and to the relevant sections of this book We can correct this problem by fi rst scanning for the keyword for in the fi le and then substituting the keyword do to appear in front of the keyword begin there Thus for for i 0 to lim begin s begin do amp for i 0 to lim do begin The next error in the program is easy to pinpoint On line 18 we didn t hit the shift key and got a 9 instead of a The translator diagnosed that x9 was an undefi ned variable and later that a was miss ing in the statement It should be stressed that pi is not suggesting that you should insert a Y before the It is only indicating that making this change will help it to be able to continue analyzing the program so as to be able to diagnose further errors You must then determine the true cause of the error and make the appropriate correction to the source text At Berkeley the line printer for the Cory Hall system is in Room 199B The line printers for the Computer Center systems are in the basement of Evans Hall This error also illustrates the fact that one error in the input may
40. ed the Pascal fi le data with the fi le primes in our example in section 3 1 by doing reset data primes instead of a simple reset data In this case it is not essential to mention data in the program statement but it is still a good idea because is serves as an aid to program documentation The second parameter to reset and rewrite may be any string value including a variable Thus the names of UNIX files to be associated with Pascal file variables can be read in at run time Full details on fi le name fi le variable associations are given in section A 3 4 6 Arge and argv Each UNIX process receives a variable length sequence of arguments each of which is a variable length character string The built in function argc and the built in procedure argv can be used to access and process these arguments The value of the function argc is the number of arguments to the process By convention the arguments are treated as an array and indexed from 0 to argc 1 with the zeroth argument being the name of the program being executed The rest of the arguments are those passed to the command on the command line Thus the command obj etc motd usr dict words hello will invoke the program in the fi le obj with argc having a value of 4 The zeroth element accessed by argv will be obj the first etc motd etc Pascal does not provide variable size arrays nor does it allow character strings of varying length For
41. erminated comments As we saw above these errors are usually caused by leaving off a comment delimiter You can con vert parts of your program to comments without generating this diagnostic since there are two different kinds of comments those delimited by and and those delimited by and Thus consider This is a comment enclosing a piece of program a functioncall comment within comment procedurecall lhs rhs another comment By using one kind of comment exclusively in your program you can use the other delimiters when you need to comment out parts of your programy In this way you will also allow the translator to help by detecting statements accidentally placed within comments If a comment does not terminate before the end of the input file the translator will point to the begin ning of the comment indicating that the comment is not terminated In this case processing will terminate immediately See the discussion of QUIT below Digits in numbers This part of the language is a minor nuisance Pascal requires digits in real numbers both before and after the decimal point Thus the following statements which look quite reasonable to FORTRAN users gen erate diagnostics in Pascal 4 r 0 f you wish to transport your program especially to the 6000 3 4 implementation you should use the character sequence to delimit comments For transportation ove
42. f the current fi lename has changed since the last fi lename was printed A Appendix to Wirth s Pascal Report This section is an appendix to the defi nition of the Pascal language in Niklaus Wirth s Pascal Report and with that Report precisely defi nes the UNIX implementation This appendix includes a summary of extensions to the language gives the ways in which the undefi ned specifi cations were resolved gives limi tations and restrictions of the current implementation and lists the added functions and procedures avail able It concludes with a list of differences with the commonly available Pascal 6000 3 4 implementation and some comments on standard and portable Pascal A 1 Extensions to the language Pascal This section defi nes non standard language constructs available in UNIX Pascal The s standard Pas cal option of the translator pi can be used to detect these extensions in programs which are to be trans ported String padding UNIX Pascal will pad constant strings with blanks in expressions and as value parameters to make them as long as is required The following is a legal UNIX Pascal program program x output var z packed array 13 of char begin Z red writeln z end The padded blanks are added on the right Thus the assignment above is equivalent to z red which is standard Pascal Octal constants octal and hexadecimal write Octal constants may be given as a sequence of octal
43. f this fails then a runtime error occurs Writing of a file other than output must be initiated by a rewrite call which causes the Pascal system to create the associated UNIX file and to then open the fi le for writing only Buffering The buffering for output is determined by the value of the b option at the end of the program state ment If it has its default value 1 then output is buffered in blocks of up to 512 characters flished when ever a writeln occurs and at each reference to the file input If it has the value 0 output is unbuffered Any value of 2 or more gives block buffering without line or input reference flashing All other output files are always buffered in blocks of 512 characters All output buffers are flashed when the files are closed at scope exit whenever the procedure message is called and can be flished using the built in procedure flush An important point for an interactive implementation is the defi nition of input If input is a tele type and the Pascal system reads a character at the beginning of execution to defi ne input then no prompt could be printed by the program before the user is required to type some input For this reason input is not defi ned by the system until its defi nition is needed reading from a fi le occurring only when necessary The character set Seven bit USASCTII is the character set used on UNIX The standard Pascal symbols and or not
44. hip are gratefully acknowledged 1 Sources of information This section lists the resources available on the UC Berkeley campus for information about general features of UNIX UNIX text editing the Pascal language and the UNIX Pascal implementation concluding with a list of references The available documents include both so called standard documents those dis tributed with all UNIX system and documents such as this one written at Berkeley 1 1 Where to get documentation On the UC Berkeley campus documentation is available at the Computer Center Library room 218B Evans Hall The library is open from 8 00 A M to 5 00 P M Monday through Friday For classes in the Computer Science Division Pascal documentation is usually available through a department office The best source for general UNIX documentation is however the Computer Center Library Current documentation for most of the UNIX system is also available on line at your terminal Details on getting such documentation interactively are given in section 1 3 on UNIX documentation 1 2 Computer Center short courses For those not enrolled in Computer Science Division courses and who have no prior experience using UNIX the short courses offered by the staff of the Computer Center are highly recommended These courses are offered free of charge and are usually held at the beginning of each quarter The two most valuable short courses for the UNIX Pascal user are the
45. i nite loops Specifying p on the command line disables these checks and the ability to give this post mortem analysis It does make smaller and faster programs however It is also possible to control the Anclude fi les are discussed in section 5 9 p option in comments To prevent the post mortem backtrace on error p must be off at the end of the pro gram statement Thus the Pascal cross reference program was translated with pi pbt pxref p Standard Pascal only s The s option causes many of the features of the UNIX implementation which are not found in standard Pascal to be diagnosed as s warning errors This option defaults off and is enabled when mentioned on the command line Some of the features which are diagnosed are non standard procedures and functions extensions to the procedure write and the padding of constant strings with blanks In addition all letters are mapped to lower case except in strings and characters so that the case of keywords and identifi ers is effectively ignored The s option is most useful when a program is to be transported thus pi s isitstd p Runtime tests t The t option controls the generation of tests that subrange variable values are within bounds at run time By default these tests are generated If the t option is specified on the command line or in a com ment which turns it off then the tests are not generated Thus the first line of a program to run without tests might be
46. ing code avoids this problem write number please while not eof do begin read 1 writeln that was a 1 2 write number please end The user must still type a line before the while test is completed but the prompt will ask for it This exam ple however is still not correct To understand why it is fi rst necessary to know as we will discuss below that there is a blank character at the end of each line in a Pascal text file The read procedure when reading integers or real numbers is defi ned so that if there are only blanks left in the fi le it will return a zero value and set the end of fi le condition If however there is a number remaining in the file the end of fi le condi tion will not be set even if it is the last number as read never reads the blanks after the number and there is always at least one blank Thus the modifi ed code will still put out a spurious that was a0 at the end of a session with it when the end of fi le is reached The simplest way to correct the problem in this example is to use the procedure readin instead of read here In general unless we test the end of fi le condition both before and after calls to read or readin there will be inputs for which our program will attempt to read past end of fi le 4 3 More about eoln To have a good understanding of when eoln will be true it is necessary to know that in any file there is a special character indicating end of lin
47. iscussed in section 5 4 5 Files reset and rewrite It is possible to use extended forms of the built in functions reset and rewrite to get more general associations of UNIX file names with Pascal file variables When a file other than input or output is to be read or written then the reading or writing must be preceded by a reset or rewrite call In general if the Pascal fi le variable has never been used before there will be no UNIX fi lename associated with it As we saw in section 2 9 by mentioning the file in the program statement we could cause a UNIX file with the same name as the Pascal variable to be associated with it If we do not mention a file in the program state ment and use it for the first time with the statement reset f or rewrite f then the Pascal system will generate a temporary name of the form tmp x for some character x and as sociate this UNIX fi le name name with the Pascal file The first such generated name will be tmp 1 and the names continue by incrementing their last character through the ASCII set The advantage of using such temporary fi les is that they are automatically removed by the Pascal system as soon as they become inacces sible They are not removed however if a runtime error causes termination while they are in scope To cause a particular UNIX pathname to be associated with a Pascal file variable we can give that name in the reset or rewrite call e g we could have associat
48. later inspection If you were making changes to an existing program when the problem occurred you may be able to work around the problem by ascertaining which change caused the snark and making a different change or correcting an error in the program You should report the problem in any case Pascal system bugs cannot be fi xed unless they are reported Out of memory The only other error which will abort translation when no errors are detected is running out of mem ory All tables in the translator with the exception of the parse stack are dynamically allocated and can grow to take up the full available process space of 64000 bytes Generally the size of the largest translat able program is directly related to procedure and function size A number of non trivial Pascal programs including some with more than 2000 lines and 2500 statements have been translated and interpreted using UNIX Pascal Notable among these are the Pascal S interpreter a large set of programs for automated gen eration of code generators and a general context free parsing program which has been used to parse sen tences with a grammar for a superset of English If you receive an out of space message from the translator during translation of a large procedure or function or one containing a large number of string constants you may yet be able to translate your pro gram if you break this one procedure or function into several routines I O errors Other errors which yo
49. le first p A sample editing session to create this fi le would begin ex first p fi rst p No such file or directory We didn t expect the fi le to exist so the error diagnostic doesn t bother us The editor now knows the name of the fi le we are creating The prompt indicates that it is ready for command input We can add the text for our program using the append command as follows append program first output begin writeln Hello world end The line containing the single character here indicated the end of the appended text The prompt indi cates that ex is ready for another command As the editor operates in a temporary work space we must now store the contents of this work space in the file first p so we can use the Pascal translator and executor pix on it write fi rst p 4 lines 59 characters quit We wrote out the file from the edit buffer here with the write command and ex indicated the number of lines and characters written We then quit the editor and now have a prompt from the shell We are ready to try to translate and execute our program pix first p 2 begin e_ _ Inserted eee Execution begins Hello world Execution terminated 1 statement executed in 0 01 seconds cpu time The translator fi rst printed a syntax error diagnostic The number 2 here indicates that the rest of the line is an image of the second line of our
50. lt gt lt gt and the uparrow P for pointer qualifi cation are recognized Less portable are the syn onyms tilde for not amp for and and I for or gt Upper and lower case are considered distinct Keywords and built in procedure and function names are composed of all lower case letters Thus the identifi ers GOTO and GOto are distinct both from each other and from the keyword goto The standard type boolean is also available as Boolean Character strings and constants may be delimited by the character or by the character the lat ter is sometimes convenient when programs are to be transported Note that the character has special meaning when it is the fi rst character on a line see Multi file programs below The standard types The standard type integer is conceptually defi ned as type integer minint maxint Integer is implemented with 32 bit twos complement arithmetic Predefi ned constants of type integer are const maxint 2147483647 minint 2147483648 The standard type char is conceptually defi ned as type char minchar maxchar Built in character constants are minchar and maxchar bell and tab ord minchar 0 ord maxchar 127 The type real is implemented using 64 bit fbating point arithmetic The fbating point arithmetic is done in rounded mode and provides approximately 17 digits of precision with nu
51. lthough it would be correct in the context of the User Manual to refer to an integer variable as a scalar variable pi prefers the more specifi c identifi ca tion Function and procedure type errors For built in procedures and functions two kinds of errors occur If the routines are called with the wrong number of arguments a message similar to E 12 sin takes exactly one argument is given If the type of the argument is wrong a message like E 12 sin s argument must be integer or real not char is produced A few functions and procedures implemented in Pascal 6000 3 4 are diagnosed as unimple mented in UNIX Pascal notably those related to segmented fi les Can t read and write scalars etc The messages which state that scalar user defi ned types cannot be written to and from fi les are often mysterious It is in fact the case that if you defi ne type color red green blue the translator does not associate these constants with the strings red green and blue in any way If you wish such an association to be made you will have to write a routine to make it Note in particular that you can only read characters integers and real numbers from text files You cannot read strings or Booleans It is possible to make a file of color but the representation is binary rather than string Expression diagnostics The diagnostics for semantically ill formed expressions are very explicit Consider thi
52. mbers as small as 10 to the negative 38th power and as large as 10 to the 38th power Comments Comments can be delimited by either and Y or by and If the character appears in a comment delimited by and a warning diagnostic is printed A similar warning will be printed if the sequence appears in a comment delimited by and The restriction implied by this warning is not part of standard Pascal but detects many otherwise subtle errors Option control Options of the translator may be controlled in two distinct ways A number of options may appear on the command line invoking the translator These options are given as one or more strings of letters pre ceded by the character and cause the default setting of each given option to be changed This method of communication of options is expected to predominate for UNIX Thus the command pi ls foo p translates the fi le foo p with the listing option enabled as it normally is off and with only standard Pascal features available On many terminals and printers the up arrow is represented as a circumfex These are not distinct charac ters but rather different graphic representations of the same internal codes If more control over the portions of the program where options are enabled is required then option control in comments can and should be used The format for option control in comments is i
53. members of fi les or members of dynamically allocated structures Arrays sets and strings The calculations involving array subscripts and set elements are done with 16 bit arithmetic This restricts the types over which arrays and sets may be defined The lower bound of such a range must be greater than or equal to 32768 and the upper bound less than 32768 In particular strings may have any length from 1 to 32767 characters and sets may contain no more than 32767 elements Line and symbol length There is no intrinsic limit on the length of identifiers Identifi ers are considered to be distinct if they differ in any single position over their entire length There is a limit however on the maximum input line length This is quite generous however currently exceeding 160 characters Procedure and function nesting and program size At most 20 levels of procedure and function nesting are allowed There is no fundamental transla tor defi ned limit on the size of the program which can be translated The ultimate limit is supplied by the hardware and the fact that the ppp 11 has a 16 bit address space If one runs up against the ran out of memory diagnostic the program may yet translate if smaller procedures are used as a lot of space is freed by the translator at the completion of each procedure or function in the current implementation Overflow There is currently no checking for overfbw on arithmetic operations at run time A 4
54. n equivalent types In gen eral UNIX Pascal considers variables to have the same type only if they were declared with the same con structed type or with the same type identifi er Thus the variables x and y declared as var x T integer y T integer do not have the same type The assignment Xi y thus produces the diagnostics E 7 Type clash non identical pointer types Type of expression clashed with type of variable in assignment Thus it is always necessary to declare a type such as type intptr T integer and use it to declare var x intptr y intptr Note that if we had initially declared var x y T integer then the assignment statement would have worked The statement xT yTt is allowed in either case Since the parameter to a procedure or function must be declared with a type identifi er rather than a constructed type it is always necessary in practice to declare any type which will be used in this way Unreachable statements UNIX Pascal fags unreachable statements Such statements usually correspond to errors in the pro gram logic Note that a statement is considered to be reachable if there is a potential path of control even if it can never be taken Thus no diagnostic is produced for the statement if false then writeln impossible Goto s into structured statements The translator detects and complains about goto statements which transfer control into structured statements for
55. n for using lower case is that it is easier to type i s c y exp x sin c x write bigger p 26 lines 538 characters pi lpi bigger p quit It should be noted that the translator suppresses warning diagnostics for a particular procedure function or the main program when it fi nds severe syntax errors in that part of the source text This is to prevent possi bly confusing and incorrect warning diagnostics from being produced Thus these warning diagnostics may not appear in a program with bad syntax errors until these errors are corrected We are now ready to execute our program for the first time We will do so in the next section after giving a listing of the corrected program for reference purposes number bigger p 1 AADNKRWN Graphic representation of a function f x exp x sin 2 pi x program graph1 output const d 0 0625 1 16 16 lines for interval x x 1 s 32 32 character width for interval x x 1 h 34 Character position of x axis c 6 28138 2 pi lim 32 var x y real i n integer begin for i 0 to lim do begin x d i y exp x sin c x n round s y h repeat write n n 1 until n 0 writeln end end 2 4 Executing the second example We are now ready to execute the second example The following output was produced by our first run px Execution begins
56. n seconds since 00 00 00 GMT January 1 1970 A 5 Remarks on standard and portable Pascal It is occasionally desirable to prepare Pascal programs which will be acceptable at other Pascal installations While certain system dependencies are bound to creep in judicious design and programming practice can usually eliminate most of the non portable usages Wirth s Pascal Report concludes with a standard for implementation and program exchange In particular the following differences may cause trouble when attempting to transport programs between this implementation and Pascal 6000 3 4 Using the s translator option may serve to indicate many problem areas Features not available in UNIX Pascal Formal parameters which are procedure or function Segmented fi les and associated functions and procedures The function trunc with two arguments Arrays whose indices exceed the capacity of 16 bit arithmetic Features available in UNIX Pascal but not in Pascal 6000 3 4 The procedures reset and rewrite with fi le names The functions argc seed sysclock and wallclock The procedures argv flush and remove Message with arguments other than character strings Write with keyword hex The assert statement Other problem areas Sets and strings are more general in UNIX Pascal see the restrictions given in the Jensen Wirth User Manual for details on the 6000 3 4 restrictions The character set differences may cause problems especially the
57. next line is the last line in the file 3 writeln j EEES Unexpected end of fi le QUIT 3 2 Translator semantic errors The extremely large number of semantic diagnostic messages which the translator produces make it unreasonable to discuss each message or group of messages in detail The messages are however very informative We will here explain the typical formats and the terminology used in the error messages so that you will be able to make sense out of them In any case in which a diagnostic is not completely com prehensible you can refer to the User Manual by Jensen and Wirth for examples Format of the error diagnostics As we saw in the example program above the error diagnostics from the Pascal translator include the number of a line in the text of the program as well as the text of the error message While this number is most often the line where the error occurred it is occasionally the number of a line containing a bracketing keyword like end or until In this case the diagnostic may refer to the previous statement This occurs because of the method the translator uses for sampling line numbers The absence of a trailing in the previous statement causes the line number corresponding to the end or until to become associated with the statement As Pascal is a free format language the line number associations can only be approximate and may seem arbitrary to some users This is the only notable exception however to reas
58. normal function of reset is analogous to reset above where i is an integer sets the statement limit to be statements Specifying the p option to pc disables statement limit counting causes the current time in the form hh mm ss to be assigned to the alfa variable a returns the count of arguments when the Pascal program was invoked Argc is always at least 1 returns the cardinality of the set x i e the number of elements contained in the set returns an integer which is the number of central processor milliseconds of user time used by this process yields the integer valued exponent of the fbating point representation of x expo x entier log2 abs x where x is a real parameter evaluated but otherwise ignored invokes a linear congruential random number generator Successive seeds are generated as seed a c mod m and the new random number is a normalization of the seed to the range 0 0 to 1 0 a is 62605 c is 113218009 and m is 536870912 The initial seed is 7774755 where i is an integer sets the random number generator seed to i and returns the previous seed Thus seed seed i has no effect except to yield value i an integer function of no arguments returns the number of central processor milliseconds of system time used by this process undefi ned x a Boolean function Its argument is a real number and it always returns false wallclock an integer function of no arguments returns the time i
59. o produce a cross reference of the program in the file foo p one can execute the command pxref foo p The cross reference is unfortunately not block structured Full details on pxref are given in its manual sec tion pxref VI 5 8 Pascals A version of Wirth s subset Pascal translator pascals is available on UNIX It was translated to inter preter code by pi and is invoked by a command of the form pascals prog p The program in the file given is translated to interpretive code which is then immediately executed Pascals is thus similar to pix Only small programs can be handled Pascals is most interesting to those wishing to study its error recovery techniques which are described in Wirth s book Algorithms Data Structures Programs 5 9 Multi fi le programs A text inclusion facility is available with UNIX Pascal This facility allows the interpolation of source text from other files into the source stream of the translator It can be used to divide large programs into more manageable pieces for ease in editing listing and maintenance The include facility is based on that of the UNIX C compiler To trigger it you can place the character in the first portion of a line and then after an arbitrary number of blanks or tabs the word include fol lowed by a filename enclosed in single or double quotation marks The file name may be followed by a semicolon if you wish to treat this as
60. onable associa tions Incompatible types Since Pascal is a strongly typed language many semantic errors manifest themselves as type errors These are called type clashes by the translator The types allowed for various operators in the language are summarized on page 108 of the Jensen Wirth User Manual It is important to know that the Pascal translator in its diagnostics distinguishes between the following type classes array Boolean char fi le integer pointer real record scalar string These words are plugged into a great number of error messages Thus if you tried to assign an integer value to a char variable you would receive a diagnostic like the following E 7 Type clash integer is incompatible with char Type of expression clashed with type of variable in assignment In this case one error produced a two line error message If the same error occurs more than once the same explanatory diagnostic will be given each time Scalar The only class whose meaning is not self explanatory is scalar Scalar has a precise meaning in the Jensen Wirth User Manual where in fact it refers to char integer real and Boolean types as well as the enumerated types For the purposes of the Pascal translator scalar in an error message refers to a user defi ned enumerated type such as ops in the example above or color in type color red green blue For integers the more explicit denotation integer is used A
61. ones dealing with basic use of UNIX and with UNIX text editing If you are unable to attend the short courses documents for these courses are available at the Computer Center Library and are recommended The documents are in a tutorial format so it is possible to use them on your own 1 3 Documentation describing UNIX The following documents are those recommended as tutorial and reference material about the UNIX system We give the documents with the introductory and tutorial materials first the reference materials last Communicating with UNIX This set of documents should be read by every new UNIX user The documents written by Ricki Blau of the Computer Center Staff introduce the basic use of the UNIX command language processor the shell and the most commonly used commands The author makes no assumptions about prior experi ence with interactive computing or with UNIX The six documents which comprise the set introduce most of the UNIX system features which will be needed by the new Pascal user in order to survive with UNIX Pas cal UNIX For Beginners This document is the basic tutorial for UNIX available with the standard system It is a useful intro duction to UNIX but does not provide as much explanation as Communicating with UNIX The document is not up to date with the current status of the Berkeley system but is very useful as a supplement to Commu nicating with UNIX The UNIX Time Sharing System By the
62. pected symbols malformed constructs If none of the above mentioned corrections appear reasonable the error recovery will examine the input to the left of the point of error to see if there is only one symbol which can follow this input If this is the case the recovery will print a diagnostic which indicates that the given symbol was Expected In cases where none of these corrections resolve the problems in the input the recovery may issue a diagnostic that indicates that the input is malformed If necessary the translator may then skip forward in the input to a place where analysis can continue This process may cause some errors in the text to be missed Consider the following example pix l synerr2 p UNIX Pascal PI Version 1 0 September 8 1977 Fri Sep 9 18 50 1977 synerr2 p 1 program synerr2 input outpu 2 integer a 10 E_ T_ Malformed declaration 3 begin 4 read b E_ T_ Undefi ned variable 5 for c 1 to 10 do E_ T_ Undefi ned variable 6 a c b c E_ _ Undefi ned procedure E_ _ Malformed statement 7 end E File outpu listed in program statement but not declared e 1 The fi le output must appear in the program statement fi le list In program synerr2 E a undefi ned on line 6 E b undefi ned on line 4 E c undefi ned on lines 5 6 Execution suppressed due to compilation errors Here
63. portions of the program which were not executed during the early debugging stages they should prompt new test data or a re examination of the program logic The profile is perhaps most valu able however in drawing attention to the typically small portions of the program that dominate execution time This information can be used for source level optimization An example A prime number is a number which is divisible only by itself and the number one The program primes written by Niklaus Wirth determines the first few prime numbers In translating the program we have specifi ed the z option to pix This option causes the translator to generate counters and count instruc tions suffi cient in number to determine the number of times each statement in the program was executed When execution of the program completes either normally or abnormally this count data is written to the fi le pmon out in the current directory It is then possible to prepare an execution profile by giving the name of the fi le associated with this data as was done in the following example pix l z primes p The syntax l as well as gt and gt gt are also local modifi cations at Berkeley They redirect unit 2 the diagnostic output with unit 1 the standard output otherwise corresponding to I gt and gt gt This capability is not present in the standard version 6 shell and a different syntax is expected to be used wi
64. primary authors of UNIX Dennis Ritchie and Ken Thompson this excellent award winning article appeared in the Communications of the ACM in July 1974 and describes the general features of UNIX in an advanced setting It provides useful details on the design philosophy and inner workings of the UNIX system It makes interesting reading after you have experimented with the system for a while UNIX Programmer s Manual This manual is the major source of details on the components of the UNIX system It consists of an Introduction a permuted index and eight command sections Section I consists of descriptions of most of the commands of UNIX Most of the other sections have limited relevance to the user of UNIX Pascal being of interest mainly to system programmers Portions of the manual are available from the Computer Center Library UNIX documentation often refers the reader to sections of the manual Such a reference consists of a command name and a section number An example of such a reference would be pi VI Here pi is a command name the Pascal interpretive translator and VI indicates that the command is part of Section VI of the manual The other pieces of the UNIX Pascal system are the Pascal interpretive executor px VI the combined Pascal translator and interpretive executor pix VI the Pascal execution profi ler VI the Pascal cross reference generator pxref VI and the filter which interprets carriage control p
65. program The translator is saying that it expected to find a x before the keyword begin on this line If we look at the Pascal syntax charts in the Jensen Wirth User Manual or at some of the sample programs therein we will see that we have omitted the terminating of the program statement on the fi rst line of our program One other thing to notice about the error diagnostic is the letter e at the beginning It stands for error indicating that our input was not legal Pascal The fact that it is an e rather than an E indicates that the translator managed to recover from this error well enough that generation of code and execution could take place Execution is possible whenever no fatal E errors occur during translation The other classes of diagnostics are w warnings which do not necessarily indicate errors in the program but point out inconsistencies which are likely to be due to program bugs and s standard Pascal violations t After completing the translation of the program to interpretive code the Pascal system indicates that execution of the translated program began The output from the execution of the program then appeared At program termination the Pascal runtime system indicated the number of statements executed and the amount of cpu time used with the resolution of the latter being 1 60 th of a second Let us now fix the error in the program and translate it to a permanent o
66. r the reslink to Pascal 6000 3 4 the character should be used to delimit characters and constant strings eae cas Digits required after decimal point 5 r 0 ree reser eee Digits required before decimal point 6 r 1 e10 Ferment em Digits required after decimal point 7 r 05e 10 gc Digits required before decimal point These same constructs are also illegal as input to the Pascal interpreter px Replacements insertions and deletions When a syntax error is encountered in the input text the parser invokes an error recovery procedure This procedure examines the input text immediately after the point of error and considers a set of simple corrections to see whether they will allow the analysis to continue These corrections involve replacing an input token with a different token inserting a token or replacing an input token with a different token Most of these changes will not cause fatal syntax errors The exception is the insertion of or replacement with a symbol such as an identifi er or a number in this case the recovery makes no attempt to determine which identifi er or what number should be inserted hence these are considered fatal syntax errors Consider the following example pix l synerr p UNIX Pascal PI Version 1 0 September 8 1977 Fri Sep 9 18 49 1977 synerr p 1 progran syn output e_ f Replaced identifi er with a keyword program 2 vari j are integer prosili Replaced identifi er with a
67. running out of memory are not foolproof and there is a chance that the interpreter will fault producing a core image when it runs out of memory This situation occurs very rarely available As an example of such an error assume that we have accidentally declared the constant n to be 6 instead of 7 on line 2 of the program primes as given in section 2 6 above If we run this program we get the following response pix primes p Execution begins 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167Subscript out of range Error at primes 8 near line 14 Execution terminated abnormally 941 statements executed in 0 17 seconds cpu time Here the interpreter indicates that the program terminated abnormally due to a subscript out of range near line 14 which is eight lines into the body of the program primes Interrupts If the program is interrupted while executing and the p option was not specifi ed then a backtrace will be printed The fi le pmon out of profi le information will be written if the program was translated with the z option enabled to pi or pix I O interaction errors The final class of interpreter errors results from inappropriate interactions with files including the user s terminal Included here are bad formats for integer and real numbers such as no digits after the deci mal point when reading Panics A small number of panics
68. s sample trans lation pi l expr p UNIX Pascal PI Version 1 0 September 6 1977 Thu Sep 1 21 46 1977 expr p 1 program x output 2 var 3 a set of char 4 b Boolean S c red green blue 6 p integer 7 A alfa 8 B packed array 1 5 of char 9 begin 10 b true 11 c red 12 new p 13 a 14 A Hello yellow 15 b a and b 16 a a 3 17 if input lt 2 then writeln boo 18 if p lt 2 then writeln sure nuff 19 if A B then writeln same 20 if c true then writeln hue s and color s 21 end E 14 Constant string too long E 15 Left operand of and must be Boolean not set E 16 Cannot mix sets with integers and reals as operands of E 17 files may not participate in comparisons E 18 pointers and integers cannot be compared operator was lt E 19 Strings not same length in comparison E 20 scalars and Booleans cannot be compared operator was e 20 Input is used but not defi ned in the program statement In program x w constant green is never used w constant blue is never used w variable B is used but never set This example is admittedly far fetched but illustrates that the error messages are suffi ciently clear to allow easy determination of the problem in the expressions Type equivalence Several diagnostics produced by the Pascal translator complain about no
69. s the data to the fi le pmon out The z option enables profi ling with data from this fi le Suppress declaration parts from a profile d Normally a profi le includes declaration parts Specifying d on the command line suppresses declara tion parts Eliminate include directives e Normally preserves include directives to the output when reformatting a program as though they were comments Specifying e causes the contents of the specified files to be reformatted into the output stream instead This is an easy way to eliminate include directives e g before transporting a program Fully parenthesize expressions f Normally This requires a modifi ed shell Such a shell is standard at Berkeley prints expressions with the minimal parenthesization necessary to preserve the structure of the input This option causes pxp to fully parenthesize expressions Thus the statement which prints as d a bmodc e with minimal parenthesization the default will print as d a b mod c e with the f option specifi ed on the command line Left justify all procedures and functions j Normally each procedure and function body is indented to ref ct its static nesting depth This option prevents this nesting and can be used if the indented output would be too wide Print a table summarizing procedure and function calls t The t option causes to print a table summarizing the number of calls to each procedure and function
70. strate various aspects of the UNIX Pascal system by correcting this program 2 3 Correcting the first errors Most of the errors which occurred in this program were syntactic errors those in the format and structure of the program rather than its content Syntax errors are flagged by printing the offending line and then a line which flags the location at which an error was detected The flag line also gives an explana tion stating either a possible cause of the error a simple action which can be taken to recover from the error so as to be able to continue the analysis a symbol which was expected at the point of error or an indication that the input was malformed In the last case the recovery may skip ahead in the input to a point where analysis of the program can continue In this example the first error diagnostic indicates that the translator detected a comment within a comment While this is not considered an error in standard Pascal it usually corresponds to an error in the program which is being translated In this case we have accidentally omitted the trailing of the comment on line 8 We can begin an editor session to correct this problem by doing ex bigger p bigger p 24 lines 512 characters 8s s 32 32 character width for interval x x 1 The second diagnostic given after line 16 indicates that the keyword do was expected before the keyword begin in the for statement If we examine th
71. sts 4 4 Output buffering A final point about Pascal input output must be noted here This concerns the buffering of the file output It is extremely ineffi cient for the Pascal system to send each character to the user s terminal as the program generates it for output even less effi cient if the output is the input of another program such as the line printer daemon lpr I To gain efficiency the Pascal system buffers the output characters i e it saves them in memory until the buffer is full and then emits the entire buffer in one system interaction However to allow interactive prompting to work as in the example given above this prompt must be printed before the Pascal system waits for a response For this reason Pascal normally prints all the output which has been generated for the fi le output whenever 1 A writeln occurs or 2 The program reads from the terminal or 3 The procedure message or flush is called Thus in the code sequence for i 1 to 5 do begin write i 2 Compute a lot with no output end writeln the output integers will not print until the writeln occurs The delay can be somewhat disconcerting and you should be aware that it will occur By setting the b option to 0 before the program statement by insert ing a comment of the form b0 we can cause output to be completely unbuffered with a corresponding horrendous degradation in program effi ciency Option control in comments is d
72. ter the fi rst one which it does not recognize 5 2 Pi and pix We now summarize the options of pi These options may also be specified on the command line to pix before the name of the file to be translated Arguments to pix after the name of the fi le to be translated are passed to the executed program run by px With each option we give its default setting the setting it would have if it appeared on the command line and a sample command using the option Most options are on off valued with the b option taking a single digit value Buffering of the file output b The b option controls the buffering of the file output The default is line buffering with flishing at each reference to the fi le input and under certain other circumstances detailed in section 5 below Mention ing b on the command line e g pi b assembler p causes standard output to be block buffered where a block is 512 characters The b option may also be controlled in comments It unique among the UNIX Pascal options takes a single digit value rather than an on or off setting A value of 0 e g b0 causes the file output to be unbuffered Any value 2 or greater causes block buffering and is equivalent to the fhg on the command line The option control comment setting b must precede the program statement Include fi le listing i The i option takes a list of include fi les procedure and function names and causes these portions of the program to b
73. th the standard ver sion 7 shell iThe counts are completely accurate only in the absence of runtime errors and nonlocal goto statements This is not generally a problem however as in structured programs nonlocal goto statements occur infrequently and counts are incorrect after abnormal termination only when the upward look described below to get a count passes a suspended call point 4Pmon out has a name similar to mon out the monitor fi le produced by the profi ling facility of the C compiler cc D See prof I for a discussion of the C compiler profi ling facilities UNIX Pascal PI Version 1 0 September 8 1977 Sat Sep 10 13 19 1977 primes p CADNHWN KE NNNNNNNND e FB BB RR Re AAYDNMNPWNRFTOAAIANHWNK CO 29 30 program primes output const n 50 nl 7 n1 sqrt n var i k x inc lim square integer prim boolean p v array 1 n1 of integer begin write 2 6 3 6 1 2 x 1 inc 4 lim 1 square 9 fori 3 to n do begin fi nd next prime repeat x x inc inc 6 inc if square lt x then begin lim lim 1 v lim square square sqr p lim 1 end k 2 prim true while prim and k lt lim do begin k k 1 if v k lt x then v k v k 2 p k prim x lt gt v k end until prim ifi lt n1 then p i x write x 6 1 1 if 1 10 then begin writeln 1 0 end end writeln end Execution begins 2 31 73 127 179
74. the Computer Center Library at the University of Cali fornia Berkeley Charles B Haley and William N Joy PI 1 0 Implementation Notes In preparation November 1977 William N Joy Susan L Graham and Charles B Haley UNIX Pascal User s Manual Version 1 0 November 1977 William N Joy PX 1 0 Implementation Notes In preparation November 1977 William N Joy PXP 1 0 Implementation Notes In preparation November 1977 2 Basic UNIX Pascal The following sections explain the basics of using UNIX Pascal In examples here we use the text edi tor ex VI Users of the text editor ed should have little trouble following these examples as ex is similar to ed We use ex because it allows us to make clearer examples The new UNIX user will find it helpful to read one of the text editor documents described in section 1 4 before continuing with this section 2 1 A first program To prepare a program for UNIX Pascal we first need to have an account on UNIX and to login to the system on this account These procedures are described in the documents Communicating with UNIX and UNIX for Beginners Once we are logged in we need to choose a name for our program let us call it first as this is the first example We must also choose a name for the file in which the program will be stored The UNIX Pas cal system requires that programs reside in fi les which have names ending with the sequence p so we will call our fi
75. this reason argv is a procedure and has the syntax argv i a where is an integer and a is a string variable This procedure call assigns the possibly truncated or blank padded i th argument of the current process to the string variable a The file manipulation routines reset and rewrite will strip trailing blanks from their optional second arguments so that this blank padding is not a problem in the usual case where the arguments are fi le names We are now ready to give a UNIX Pascal program kat based on that given in section 3 1 above which can be used with the same syntax as the UNIX system program cat I cat kat p program kat input output var ch char i integer name packed array 1 100 of char begin i 1 Sections 4 6 and 4 7 deal with more advanced and system related issues that may not be of general interest repeat if i lt argc then begin argv i name reset input name i i 1 end while not eof do begin while not eoln do begin read ch write ch end readln writeln end until i gt argc end kat Note that the reset call to the fi le input here which is necessary for a clear program may be disallowed on other systems As this program deals mostly with argc and argv and UNIX system dependent considera tions portability is of little concern If this program is in the fi le kat p then we can do pi kat p mv obj kat kat primes 2 3 5 7 11 13 17 19 23 29 31
76. time tests if that was felt to be a speed hindrance to the program Thus we can try the last examples again kat xxxxqqq xxxxqqq No such fi le or directory kat primes 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 The interested reader may wish to try writing a program which accepts command line arguments like pi does using argc and argv to process them 5 Details on the components of the system 5 1 Options The programs pi and take a number of options There is a standard UNIX convention for passing options to programs on the command line and this convention is followed by the UNIX Pascal system programs As we saw in the examples above option related arguments consisted of the character followed by a single character option name In fact it is possible to place more than one option letter after a single thus pi lz foo p and pi l z foo p are equivalent There are 26 options one corresponding to each lower case letter Except for the b option which takes a single digit value each option may be set on enabled or off disabled When an on off valued option appears on the command line of pi or Table of Contents it inverts the default setting of that option Thus pi l foo p enables the listing option I since it defaults off while pi t foo p dis
77. u may encounter when running pi relate to input output If pi cannot open the fi le you specify or if the fi le is empty you will be so informed If your disk space quotatis exceeded while pi is creating the fi le obj or if the system runs out of disk space you will be notifi ed in this case you should remove unneeded fi les 3 4 Run time errors We saw in our second example a run time error We here give the general description of run time errors The more unusual interpreter error messages are explained briefly in the manual section for px VI Start up errors These errors occur when the object fi le to be executed is not available or appropriate Typical errors here are caused by the specifi ed object fi le not existing not being a Pascal object or being inaccessible to the user Program execution errors These errors occur when the program interacts with the Pascal runtime environment in an inappropri ate way Typical errors are values or subscripts out of range bad arguments to built in functions exceeding the statement limit because of an infi nite loop or running out of memoryt The interpreter will produce a backtrace after the error occurs showing all the active routine calls unless the p option was disabled when the program was translated Unfortunately no variable values are given and no way of extracting them is Disk quotas are also a modifi cation at Berkeley and may not exist at your installation The checks for
78. uments Ricki Blau Communicating With UNIX Computer Center and Computer Science Division University of California Berkeley July 1977 William N Joy Ex Reference Manual Version 1 1 Computer Center University of California Berkeley November 1977 James Joyce Text editing with UNIX Computer Center University of California Berkeley July 1977 Brian W Kernighan A Tutorial Introduction to the UNIX Text Editor Bell Laboratories Murray Hill New Jersey Brian W Kernighan UNIX for Beginners Bell Laboratories Murray Hill New Jersey Dennis M Ritchie and Ken Thompson The UNIX Time Sharing System Communications of the ACM July 1974 365 378 Ken Thompson and Dennis M Ritchie UNIX Programmer s Manual Version 6 Bell Laboratories Murray Hill New Jersey May 1975 Pascal Language Documents Conway Gries and Zimmerman A Primer on PASCAL Winthrop Cambridge Mass 1976 433 pp Kathleen Jensen and Niklaus Wirth Pascal User Manual and Report Springer Verlag New York 1975 167 pp C A G Webster Introduction to Pascal Heyden and Son New York 1976 129pp At Berkeley a revised version of this manual is available and to be preferred Niklaus Wirth Algorithms Data structures Programs Prentice Hall New York 1976 366 pp Niklaus Wirth Systematic Programming Prentice Hall New York 1973 169 pp UNIX Pascal documents The following documents are available from
79. we misspelled input and gave a FORTRAN style variable declaration which the translator diagnosed as a Malformed declaration When on line 6 we used and yY for subscripting as in FORTRAN rather than the P and which are used in Pascal the translator noted that a was not defined as a procedure This occurred because procedure and function argument lists are delimited by parentheses in Pascal As it is not permissible to assign to procedure calls the translator diagnosed a malformed statement at the point of assignment Expected and unexpected end of fi le QUIT If the translator finds a complete program but there is more non comment text in the input file then it will indicate that an end of fi le was expected This situation may occur after a bracketing error or if too many ends are present in the input The message may appear after the recovery says that it Expected since is the symbol that terminates a program If severe errors in the input prohibit further processing the translator may produce a diagnostic fol lowed by QUIT One example of this was given above a non terminated comment another example is a line which is longer than 160 characters Consider also the following example pix l mism p UNIX Pascal PI Version 1 0 September 8 1977 Sat Sep 10 15 18 1977 mism p 1 program mismatch output 2 begin e_ T_ Inserted i 3 writeln 4 The
80. while etc It does not allow such jumps nor does it allow branching from the then part of an if statement into the else part Such checks are made only within the body of a single procedure or func tion Unused variables never set variables Although UNIX Pascal always clears variables to 0 at procedure and function entry it is not good programming practice to rely on this initialization To discourage this practice and to help detect errors in program logic pi fhgs as a w warning error 1 Use of a variable which is never assigned a value 2 A variable which is declared but never used distinguishing between those variables for which values are computed but which are never used and those completely unused In fact these diagnostics are applied to all declared items Thus a constant or a procedure which is declared but never used is fhgged The w option of pi may be used to suppress these warnings see sections 5 1 and 5 2 3 3 Translator panics i o errors Panics One class of error which rarely occurs but which causes termination of all processing when it does is a panic A panic indicates a translator detected internal inconsistency A typical panic message is snark rvalue line 110 yyline 109 Snark in pi If you receive such a message the translation will be quickly and perhaps ungracefully terminated You should contact a teaching assistant or a member of the system staff after saving a copy of your program for
Download Pdf Manuals
Related Search
Related Contents
Copyright © All rights reserved.
Failed to retrieve file