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

📄 m3

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
字号:
.NHIMPLEMENTATION.PPRatforwas originally written inC[4]on the.UC UNIXoperating system[5].The language is specified by a context free grammarand the compiler constructed usingthe.UC YACCcompiler-compiler[6]..PPTheRatforgrammar is simple and straightforward, being essentially.P1prog	: stat 	| prog   statstat	: \f3if\fP (...) stat 	| \f3if\fP (...) stat \f3else\fP stat	| \f3while\fP (...) stat	| \f3for\fP (...; ...; ...) stat	| \f3do\fP ... stat	| \f3repeat\fP stat	| \f3repeat\fP stat \f3until\fP (...)	| \f3switch\fP (...) { \f3case\fP ...: prog ...			\f3default\fP: prog }	| \f3return\fP	| \f3break\fP	| \f3next\fP	| digits   stat	| { prog }	| anything unrecognizable.P2The observationthatRatforknows no Fortranfollows directly from the rule that says a statement is``anything unrecognizable''.In fact most of Fortran falls into this category,since any statement that does not begin with one of the keywordsis by definition ``unrecognizable.''.PPCode generation is also simple.If the first thing on a source line isnot a keyword(like.UL if ,.UL else ,etc.)the entire statement is simply copied to the outputwith appropriate character translation and formatting.(Leading digits are treated as a label.)Keywords cause only slightly more complicated actions.For example, when.UL ifis recognized, two consecutive labels L and L+1are generated and the value of L is stacked.The condition is then isolated, and the code.P1if (.not. (condition)) goto L.P2is output.The .ulstatementpart of the.UL ifis then translated.When the end of the statement is encountered(which may be some distance away and include nested \f3if\fP's, of course),the code.P1L	continue.P2is generated, unless there is an.UL elseclause, in which casethe code is.P1	goto L+1L	continue.P2In this latter case,the code.P1L+1	continue.P2is produced after the.ulstatementpart of the.UL else.Code generation for the various loops is equally simple..PPOne might argue that more care should be takenin code generation.For example,if there is no trailing.UL else ,.P1	if (i > 0) x = a.P2should be left alone, not converted into.P1	if (.not. (i .gt. 0)) goto 100	x = a100	continue.P2But what are optimizing compilers for, if not to improve code?It is a rare program indeed where this kind of ``inefficiency''will make even a measurable difference.In the few cases where it is important,the offending lines can be protected by `%'..PPThe use of a compiler-compiler is definitely the preferred methodof software development.The language is well-defined,with few syntactic irregularities.Implementation is quite simple;the original construction took under a week.The languageis sufficiently simple, however, that an.ulad hocrecognizer can be readily constructed to do the same jobif no compiler-compiler is available..PPThe C version of Ratforis used on.UC UNIXand on the Honeywell.UC GCOSsystems.C compilers are not as widely available as Fortran, however,so there is also aRatforwritten in itselfand originally bootstrapped with the C version.TheRatforversionwas written so as to translate into the portable subsetof Fortran described in [1],so it is portable,having been run essentially without changeon at least twelve distinct machines.(The main restrictions of the portable subset are:only one character per machine word;subscripts in the form.ulc*v\(+-c;avoiding expressions in places like.UC DOloops;consistency in subroutine argument usage,and in .UC COMMONdeclarations.Ratforitself will not gratuitously generate non-standard Fortran.).PPTheRatforversion is about 1500 lines ofRatfor(compared to about 1000 lines of C);this compiles into 2500 lines of Fortran.This expansion ratio is somewhat higher than average,since the compiled code contains unnecessary occurrencesof.UC COMMONdeclarations.The execution time of theRatforversion is dominated bytwo routines that read and write cards.Clearly these routines could be replacedby machine coded local versions;unless this is done, the efficiency of other parts of the translation processis largely irrelevant.

⌨️ 快捷键说明

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