⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 puman2.n

📁 早期freebsd实现
💻 N
📖 第 1 页 / 共 2 页
字号:
was expected before the keyword.B beginin the.B forstatement.If we examine the.I statementsyntax chart on page 118 of theJensen-Wirth.I "User Manual"we will discover that.B dois a necessary part of the.B forstatement.Similarly, we could have referred to section C.3 of theJensen-Wirth.I "User Manual"to learn about the.B forstatement and gotten the same information there.It is often useful to refer to these syntax charts and to therelevant sections of this book..PPWe can correct this problem by first scanning for the keyword.B forin the file and then substituting the keyword.B doto appear in front of the keyword.B beginthere.Thus:.LS:\*b/for\fR	for i := 0 to lim begin:\*bs/begin/do &\fR	for i := 0 to lim do begin:.LEThe 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 undefined variable and, later,that a `)' was missing in the statement.It should be stressed that.PIis not suggesting that you should insert a `)' before the `;'.It is only indicating that making this change will help it to be able tocontinue analyzing the program so as to be able to diagnose furthererrors.You must then determine the true cause of the error and make theappropriate correction to the source text..PPThis error also illustrates the fact that one error in the input may leadto multiple error diagnostics..I Piattemptsto give only one diagnostic for each error,but single errors in the input sometimes appear to be more thanone error.It is also the case that.PImay not detect an error when it occurs, but may detect it later inthe input.This would have happenedin this example if we had typed `x' instead of `x9'..PPThe translator next detected, on line 19, that the function.I Roundand the variable.I hwere undefined.It does not know about.I Roundbecause.UPnormally distinguishes between upper and lower case.\*(dg.FS\*(dgIn ``standard'' Pascal no distinction is made based on case..FEOn.UXlower-case is preferred\*(dd,.FS\*(ddOne good reason for using lower-case is that it is easier to type..FEand all keywords and built-in.B procedureand.B functionnames are composed of lower-case letters,just as they are in the Jensen-Wirth.I "Pascal Report" .Thus we need to use the function.I roundhere.As far as.I his concerned,we can see why it is undefined if we look back to line 9and note that its definition was lost in the non-terminatedcomment.This diagnostic need not, therefore, concern us..PPThe next error which occurred in the program caused the translatorto insert a `;' before the statement calling.I writelnon line 23.If we examine the program around the point of error we will seethat the actual error is that the keyword.B untiland an associated expression have been omitted here.Note that the diagnostic from the translator does not indicate the actualerror, and is somewhat misleading.The translator made the correction which seemed to be most plausible.As the omission of a `;' character is a common mistake,the translator chose to indicate this as a possible fix here.It later detected that the keyword.B untilwas missing, but not until it saw the keyword.B endon line 24.The combination of these diagnostics indicate to us the true problem..PPThe final syntactic error message indicates that the translator needed an.B endkeyword to match the.B begin at line 15.Since the.B endat line 24 is supposed to match this.B begin ,we can infer that another.B beginmust have been mismatched, and have matched this.B end .Thus we see that we need an.B endto match the.B beginat line 16,and to appear before the final.B end .We can make these corrections:.LS:\*b/x9/s//x)\fR                y := exp(-x) * sin(i * x);:\*b+s/Round/round\fR                n := round(s * y) + h;:\*b/write\fR                        write(' ');:\*b/\fR                writeln('*'):\*binsert\fR                \*buntil n = 0;\fR\&\*b.\fR:\*b$\fRend.:\*binsert\fR        \*bend\fR\&\*b.\fR:.LE.PPAt the end of each.B procedureor.B functionand the end of the.B programthe translator summarizes references to undefined variablesand improper usages of variables.It also giveswarnings about potential errors.In our program, the summary errors do not indicate any further problemsbut the warning that.I cis unused is somewhat suspicious.Examining the program we see that the constant was intendedto be used in the expression which is an argument to.I sin ,so we can correct this expression, and translate the program.We have now made a correction for each diagnosed errorin our program..LS:\*b?i ?s//c /\fR		y := exp(-x) * sin(c * x);:\*bwrite\fR"bigger.p" 26 lines, 538 characters:\*bquit\fR% \*bpi bigger.p\fR%.LEIt should be noted that the translator suppresses warningdiagnostics for a particular.B procedure ,.B functionor the main.B programwhen it finds severe syntax errors in that part of the sourcetext.This is to prevent possibly confusing andincorrect warning diagnostics from being produced.Thus these warning diagnostics may not appear in a program withbad syntax errors until these errors are corrected..KS.PPWe are now ready to execute our program for the firsttime.We will do so in the next section after giving a listingof the corrected program for reference purposes..LS% \*bcat -n bigger.p\fR.so bigger6.p%.LE.NH 2Executing the second example.PPWe are now ready to execute the second example.The following output was produced by our first run..LS% \*bpx\fR.so bigout2%.LEHere 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 writtenthe statement `x := d / i' instead of `x := d * i'.We can correct this and rerun the program:.LS% \*bex bigger.p\fR"bigger.p" 26 lines, 538 characters:\*b17\fR        x := d / i:\*bs'/'*\fR        x := d * i:\*bwrite\fR"bigger.p" 26 lines, 538 characters:\*bq\fR% \*bpix bigger.p\fR.so bigout3%.LE.KS.PPThis appears to be the output we wanted.We could now save the output in a file if we wished by using the shellto redirect the output:.LS% \*bpx > graph\fR.LE.KEWe can use.I cat(1) to see the contents of the file graph.We can also make a listing of the graph on the line printer withoutputting it into a file, e.g..LS% \*bpx | lpr\fR.so bigout4%.LENote 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 thesyntax `|\|&' to the shell rather than `|', i.e.:.LS% \*bpx |\|& lpr\fR%.LEor we can translate the program with the.B poption disabled on the command line as we did above.This will disable all post-mortem dumping including the statistics line,thus:.LS% \*bpi -p bigger.p\fR% \*bpx | lpr\fR%.LEThis option also disables the statement limit which normally guardsagainst infinite looping.You should not use it until your program is debugged.Also if.B pis specified and an error occurs, you willnot get run time diagnostic information to help youdetermine what the problem is..NH 2Formatting the program listing.PPIt is possible to use special lines within the source text of a programto 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 linewithout a line number.A line containing only a control-l (form-feed) characterwill cause a page eject in the listing with the corresponding line numbersuppressed.This corresponds to an `eject' pseudo-instruction.See also section 5.2 for details on the.B nand.B ioptions of.PI ..NH 2Execution profiling.PPAn execution profile consists of a structured listing of (all or part of)a program with information about the number of times each statement inthe 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 loopingor recursion or by a program fault, the counts can facilitate locationof the error.Zero counts mark portions of the program which were not executed;during the early debugging stages they should prompt new test data ora re-examination of the program logic.The profile is perhaps most valuable, however, in drawingattention to the (typically small)portions of the program that dominate execution time.This information can be used for source level optimization..SHAn example.PPA prime number is a number which is divisible only by itself and thenumber one.The program.I primes ,written by Niklaus Wirth,determines the first few prime numbers.In translating the program we have specified the.B zoption to.IX .This option causes the translator to generate counters and count instructionssufficient in number to determine the number of times each statement in theprogram was executed.\*(dg.FS\*(dgThe countsare completely accurate only in the absence of runtime errors and nonlocal.B gotostatements.This is not generally a problem, however, as in structured programsnonlocal.B gotostatements occur infrequently,and counts are incorrect after abnormal termination only when the.I "upward look"described below to get a count passes a suspended call point..FEWhen execution of the program completes, either normally or abnormally,this count data is written to the file.I pmon.outin the current directory.\*(dd.FS\*(dd\c.I Pmon.outhas a name similar to.I mon.outthe monitor file produced by the profiling facility of the C compiler.I cc(1).See.I prof(1) for a discussion of the C compiler profiling facilities..FEIt is then possible to prepare an execution profile by giving.XPthe name of the file associated with this data, as was done in the followingexample..LS% \*bpix -l -z primes.p\fR.so primeout1%.LE.SHDiscussion.PPThe header lines of the outputs of.IXand.XPin this example indicate the version of the translator and executionprofiler 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 modification of the program source file.This time serves to.I "version stamp"the input program..I Pxpalso indicates the time at which the profile data was gathered..LS% \*bpxp -z primes.p\fR.so primeout2%.LE.KE.PPTo determine the number of times a statement was executed,one looks to the left of the statement and finds the correspondingvertical bar `|'.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`|' which directly above the original one which has a count and thatis the answer.Thus, in our example,.I kwas incremented 157 times on line 18,while the.I writeprocedure call on line 24 was executed 48 times as given by the counton the.B repeat ..PPMore information on.I pxpcan be found in its manual section.XP(1)and in sections 5.4, 5.5 and 5.10.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -