📄 puman2.n
字号:
.\" Copyright (c) 1980, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)puman2.n 8.1 (Berkeley) 6/8/93.\".if !\n(xx \{\.so tmac.p \}'if n 'ND.nr H1 1.NHBasic UNIX Pascal.PPThe following sectionsexplain the basics of using.UP .In examples here we use the text editor.I ex (1).Users of the text editor.I edshould have little trouble following these examples,as.I exis similar to.I ed .We use.I exbecause itallows us to make clearer examples.\(dg.FS\(dg Users with \s-2CRT\s0 terminals should find the editor.I vimore pleasant to use;we do not show its use here because its display oriented naturemakes it difficult to illustrate..FEThe new.UXuser will find it helpful to read one of the text editor documentsdescribed in section 1.4 before continuing with this section..NH 2A first program.PPTo prepare a program for.UPwe first need to have an account on.UXand to `login'to the system on this account.These procedures are described in the documents.I "Communicating with UNIX" and.I "UNIX for Beginners"..PPOnce 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.UPsystem requires that programs reside in files which have names ending withthe sequence `.p' so we will call our file `first.p'..PPA sample editing session to create this file would begin:.LS% \*bex first.p\fR"first.p" [New file]:.LEWe didn't expect the file to exist, so the error diagnostic doesn'tbother us.The editor now knows the name of the file 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..LS:\*bappend\fR.Bprogram first(output)begin writeln('Hello, world!')end.\&..R:.LEThe line containing the single `\*b.\fR' character here indicatedthe end of the appended text.The `:' prompt indicates that.I exis ready for another command.As the editor operates in a temporary work space we must now store the contentsof this work space in the file `first.p'so we can use the Pascal translator and executor.IXon it..LS:\*bwrite\fR"first.p" [New file] 4 lines, 59 characters:\*bquit\fR% .LEWe wrote out the file from the edit buffer here with the`write'command, and.I exindicated the number of lines and characters written.We then quit the editor, and now have a prompt from the shell.\(dd.FS\(dd Our examples here assume you are using.I csh..FE.KS.PPWe are ready to tryto translate and execute our program..DS.tr '\(aa^\(ua% \*bpix first.p\fR.so firstout.tr ''^^%.DE.KE.PPThe translator first printed a syntax error diagnostic.The number 2 here indicates that the rest of the line is an imageof the second line of our program.The translator is saying that it expected to find a `;' before thekeyword.B beginon this line.If we look at the Pascal syntax charts in the Jensen-Wirth.I "User Manual" ,or at some of the sample programs therein, we will see thatwe have omitted the terminating `;' of the.B program statement on the firstline of our program..PPOne 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 wellenough that generation of code and execution could take place.Execution is possible whenever no fatal `E' errorsoccur 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.\*(dg.FS\*(dgThe standard Pascal warnings occur only when the associated.B stranslator option is enabled.The.B soption is discussed in sections 5.1 and A.6 below.Warning diagnostics are discussed at the end of section 3.2,the associated.B woption is described in section 5.2..FE.PPAfter 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 thenumber of statements executed, and the amount of cpu timeused, with the resolution of the latter being 1/60'th of a second..PPLet us now fix the error in the program and translate it to a permanentobject code file.I objusing.PI .The program.PItranslates Pascal programs but stores the object code instead of executing it\*(dd..FS\*(ddThis script indicates some other useful approaches to debuggingPascal programs.As in.I edwe can shorten commands in.I exto an initial prefix of the command name as we didwith the.I substitutecommand here.We have also used the `!' shell escape command here to execute othercommands with a shell without leaving the editor..FE.LS% \*bex first.p\fR"first.p" 4 lines, 59 characters:\*b1 print\fRprogram first(output):\*bs/$/;\fRprogram first(output);:\*bwrite\fR"first.p" 4 lines, 60 characters:\*bquit\fR% \*bpi first.p\fR%.LEIf we now use the.UX.I lslist files command we can see what files we have:.LS% \*bls\fRfirst.pobj%.LEThe file `obj' here contains the Pascal interpreter code.We can execute this by typing:.LS% \*bpx obj\fR.so firstobjout%.LEAlternatively, the command:.LS% \*bobj\fR.LEwill have the same effect.Some examples of different ways to execute the program follow..LS% \*bpx\fR.so firstobjout% \*bpi -p first.p\fR% \*bpx obj\fR.so firstobjout2% \*bpix -p first.p\fR.so firstobjout2%.LE.PPNote that.I pxwill assume that `obj' is the file we wish to executeif we don't tell it otherwise.The last two translations use the.B \-pno-post-mortem option to eliminateexecution 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% \*bls\fRfirst.pobj%.LEWe can give our object program a name other than `obj' by using the movecommand.I mv(1).Thus to name our program `hello':.LS% \*bmv obj hello\fR% \*bhello\fRHello, world!% \*bls\fRfirst.phello%.LEFinally we can get rid of the Pascal object code by using the.I rm(1) remove file command, e.g.:.LS% \*brm hello\fR% \*bls\fRfirst.p%.LE.PPFor small programs which are being developed.IXtends to be more convenient to use than.PIand.X .Except for absence of the.I objfile after a.IXrun,a.IXcommand is equivalent to a.PIcommand followed by a.Xcommand.For larger programs,where a number of runs testing different parts of the program areto be made,.PIis useful as this.I objfile can be executed any desired number of times... >>> INSERT SECTION FOR PC <<<.NH 2A larger program.PPSuppose that we have used the editor to put a larger programin the file `bigger.p'.We can list this program with line numbers by using the program.I cat -ni.e.:.LS% \*bcat -n bigger.p\fR.so bigger3.p%.LEThis program is similar to program 4.9 on page 30 of theJensen-Wirth.I "User Manual" .A number of problems have been introduced into this example forpedagogical reasons..br.PPIf we attempt to translate and execute the program using.IXwe get the following response:.LS% \*bpix bigger.p\fR.so bigout1%.LE.PPSince there were fatal `E' errors in our program,no code was generated and execution was necessarily suppressed.One thing which would be useful at this point is a listing of theprogram with the error messages.We can get this by using the command:.LS% \*bpi -l bigger.p\fR.LEThere is no point in using.IXhere, 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 copywe may wish to print thislisting off-line on a line printer.We can do this with the command:.LS% \*bpi -l bigger.p | lpr\fR.LE.PPIn the next few sections we will illustrate various aspects of theBerkeleyPascal system by correcting this program..NH 2Correcting the first errors.PPMost of the errors which occurred in this program were.I syntacticerrors, those in the format and structure of the program rather thanits content.Syntax errors are flagged by printing the offending line, and then a linewhich flags the location at which an error was detected.The flag line also gives an explanationstating either a possible cause of the error,a simple action which can be taken to recover from the error soas 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 inputto a point where analysis of the program can continue..PPIn this example,the first error diagnostic indicates that the translator detecteda comment within a comment.While this is not considered an error in `standard'Pascal, it usually corresponds to an error in the program whichis being translated.In this case, we have accidentally omitted the trailing `*)' of the commenton line 8.We can begin an editor session to correct this problem by doing:.LS% \*bex bigger.p\fR"bigger.p" 24 lines, 512 characters:\*b8s/$/ *)\fR s = 32; (* 32 character width for interval [x, x+1] *):.LE.PPThe second diagnostic, given after line 16,indicates that the keyword.B do
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -