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

📄 cwebman.tex

📁 著名算法大师高爷爷设计的语言。此语言结合了Tex和C
💻 TEX
📖 第 1 页 / 共 5 页
字号:
The first line says that grammar rule 4 has just been applied, and \.{CWEAVE}currently has in its memory a sequence of chunks of \TEX/ code (called``scraps'') that are respectivelyof type \\{exp} (for expression), open-parenthesis,\\{exp} again, close-parenthesis, and further scraps that haven't yetbeen considered by the parser.  (The \.+ and \.- signs stipulate that\TEX/ should be in or out of math mode at the scrap boundaries. The \.* showsthe parser's current position.)Then rule 11 is applied, andthe sequence $(\,exp\,)$ becomes an \\{exp} and so on.  In theend the whole \CEE/ text has become one big scrap of type \\{function}.Sometimes things don't work as smoothly, and you get a bunch oflines lumped together.  This means that \.{CWEAVE} could notdigest something in your \CEE/ code.  For instance, suppose`\.{@<Argument definitions@>}' had appeared instead of`\.{char **argv;}' in the program above. Then \.{CWEAVE} would havebeen somewhat mystified, since it thinks that section namesare just \\{exp}s.  Thus it would tell \TEX/ to format`\X2:Argument declarations\X' on the same line as`$\\{main}(\\{argc},\39\\{argv}{}$)'.In this case you should help \.{CWEAVE} by putting `\.{@/}' after`\.{main(argc,argv)}'.\.{CWEAVE} automatically inserts a bit of extra space between declarationsand the first apparent statement of a block. One way to defeat thisspacing locally is$$\vbox{\halign{#\hfil\cr\.{int x;@+@t\}\\6\{@>}\cr\.{@<Other locals@>@;@\#}\cr}}$$the `\.{@\#}' will put extra space after `$\langle\,$Other locals$\,\rangle$'.\section Hypertext and hyperdocumentation.Many people have of course noticed analogies between \.{CWEB} and theWorld Wide Web. The \.{CWEB} macros are in fact set up so that the output of\.{CWEAVE} can be converted easily into Portable Document Format,with clickable hyperlinks that can be read with Adobe's Acrobat Reader,using a widely available open-source program called \.{dvipdfm} developedby Mark~A. Wicks. After using \.{CWEAVE} to convert \.{cob.w} into\.{cob.tex}, you can prepare and view a hypertext version of the programby giving the commands$$\vbox{\halign{\.{#}\hfil\crtex "\\let\\pdf+ \\input cob"\crdvipdfm cob\cracroread cob.pdf\cr}}$$instead of invoking \TeX\ in the normal way. (Thanks to Hans Hagen,C\'esar Augusto Rorato Crusius, and Julian Gilbeyfor the macros that make this work.)Alternatively, thanks to H\`an Th\^e\kern-.3em\raise.3ex\hbox{\'{}} Th\`anhand Andreas Scherer, you can generate \.{cob.pdf} in one step by simplysaying `\.{pdftex}~\.{cob}'.A more elaborate system called \.{CTWILL}, which extends the usual crossreferences of \.{CWEAVE} by preparing links from the uses of identifiersto their definitions, is also available---provided that you are willingto work a bit harder in cases where an identifier is multiply defined.\.{CTWILL} is intended primarily for hardcopy output, but its principlescould be used for hypertext as well.See Chapter 11 of {\sl Digital Typography\/} by D.~E. Knuth (1999), andthe program sources at \.{ftp://ftp.cs.stanford.edu/pub/ctwill}.\section Appendices.As an example of a real program written in \.{CWEB}, Appendix~Acontains an excerpt from the \.{CWEB} program itself.  The reader whoexamines the listings in this appendix carefully will get a goodfeeling for the basic ideas of \.{CWEB}.Appendix B is the file that sets \TEX/ up to acceptthe output of \.{CWEAVE}, and Appendix~C discusses how to use some of thosemacros to vary the output formats.A ``long'' version of this manual, which can be produced from the \.{CWEB}sources via the \UNIX/ command \.{make} \.{fullmanual}, also containsappendices D, E, and~F, which exhibit the complete source code for\.{CTANGLE} and \.{CWEAVE}.\vfil\eject\titletrue\def\runninghead{APPENDIX A --- {\tentt CWEB} FILE FORMAT}\section Appendix A: Excerpts from a \.{CWEB} Program.This appendix consistsof four listings.  The first shows the \.{CWEB} input thatgenerated sections 12--15 of the file \.{common.w}, which containsroutines common to \.{CWEAVE} and \.{CTANGLE}.Note that some of the lines are indented to show the program structure;the indentation is ignored by \.{CWEAVE} and \.{CTANGLE}, but users findthat \.{CWEB} files are quite readable if they have some such indentation.The second and third listingsshow corresponding partsof the \CEE/ code output by \.{CTANGLE} and ofthe corresponding \TEX/ code output by \.{CWEAVE}, when run on \.{common.w}.The fourth listing shows how that output looks when printed out.\vskip 6pt\begingroup \def\tt{\eighttt} \baselineskip9pt\verbatim@ Procedure |prime_the_change_buffer|sets |change_buffer| in preparation for the next matching operation.Since blank lines in the change file are not used for matching, we have|(change_limit==change_buffer && !!changing)| if and only ifthe change file is exhausted. This procedure is called only when|changing| is 1; hence error messages will be reported correctly.@cvoidprime_the_change_buffer(){  change_limit=change_buffer; /* this value is used if the change file ends */  @<Skip over comment lines in the change file; |return| if end of file@>;  @<Skip to the next nonblank line; |return| if end of file@>;  @<Move |buffer| and |limit| to |change_buffer| and |change_limit|@>;}@ While looking for a line that begins with \.{@@x} in the change file, weallow lines that begin with \.{@@}, as long as they don't begin with \.{@@y},\.{@@z}, or \.{@@i} (which would probably mean that the change file is fouled up).@<Skip over comment lines in the change file...@>=while(1) {  change_line++;  if (!!input_ln(change_file)) return;  if (limit<buffer+2) continue;  if (buffer[0]!!='@@') continue;  if (xisupper(buffer[1])) buffer[1]=tolower(buffer[1]);  if (buffer[1]=='x') break;  if (buffer[1]=='y' || buffer[1]=='z' || buffer[1]=='i') {    loc=buffer+2;    err_print("!! Missing @@x in change file");@.Missing @@x...@>  }}@ Here we are looking at lines following the \.{@@x}.@<Skip to the next nonblank line...@>=do {  change_line++;  if (!!input_ln(change_file)) {    err_print("!! Change file ended after @@x");@.Change file ended...@>    return;  }} while (limit==buffer);@ @<Move |buffer| and |limit| to |change_buffer| and |change_limit|@>={  change_limit=change_buffer-buffer+limit;  strncpy(change_buffer,buffer,limit-buffer+1);}!endgroup\endgroup\vfill\eject\def\runninghead{APPENDIX A  --- TRANSLATION BY {\tentt CTANGLE}}Here's the portion of the \CEE/ code generated by \.{CTANGLE} that correspondsto the source on the preceding page.  Notice that sections~13, 14 and~15have been tangled into section~12.\vskip6pt\begingroup \def\tt{\eighttt} \baselineskip9pt\verbatim/*:9*//*12:*/#line 247 "common.w"voidprime_the_change_buffer(){change_limit= change_buffer;/*13:*/#line 261 "common.w"while(1){change_line++;if(!!input_ln(change_file))return;if(limit<buffer+2)continue;if(buffer[0]!!='@')continue;if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);if(buffer[1]=='x')break;if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){loc= buffer+2;err_print("!! Missing @x in change file");}}/*:13*/#line 252 "common.w";/*14:*/#line 278 "common.w"do{change_line++;if(!!input_ln(change_file)){err_print("!! Change file ended after @x");return;}}while(limit==buffer);/*:14*/#line 253 "common.w";/*15:*/#line 288 "common.w"{change_limit= change_buffer-buffer+limit;strncpy(change_buffer,buffer,limit-buffer+1);}/*:15*/#line 254 "common.w";}/*:12*//*16:*/!endgroup\endgroup\vfill\eject\def\runninghead{APPENDIX A --- TRANSLATION BY {\tentt CWEAVE}}Here is the corresponding excerpt from \.{common.tex}.\vskip6pt\begingroup \def\tt{\eighttt} \baselineskip9pt\verbatim\M{12}Procedure \PB{\\{prime\_the\_change\_buffer}}sets \PB{\\{change\_buffer}} in preparation for the next matching operation.Since blank lines in the change file are not used for matching, we have\PB{$(\\{change\_limit}\E\\{change\_buffer}\W\R\\{changing})$} if and only ifthe change file is exhausted. This procedure is called only when\PB{\\{changing}} is 1; hence error messages will be reported correctly.!vskip-.5!baselineskip\Y\B\&{void} \\{prime\_the\_change\_buffer}(\,)\1\1\2\2\6${}\{{}$\1\6${}\\{change\_limit}\K\\{change\_buffer}{}$;\C{ this value is used if thechange file ends }\6\X13:Skip over comment lines in the change file; \PB{\&{return}} if end of file%\X;\6\X14:Skip to the next nonblank line; \PB{\&{return}} if end of file\X;\6\X15:Move \PB{\\{buffer}} and \PB{\\{limit}} to \PB{\\{change\_buffer}} and %\PB{\\{change\_limit}}\X;\6\4${}\}{}$\2\par\fi!vskip-.5!baselineskip\M{13}While looking for a line that begins with \.{@x} in the change file, weallow lines that begin with \.{@}, as long as they don't begin with \.{@y},\.{@z}, or \.{@i} (which would probably mean that the change file is fouledup).!vskip-.5!baselineskip\Y\B\4\X13:Skip over comment lines in the change file; \PB{\&{return}} if endof file\X${}\E{}$\6\&{while} (\T{1})\5${}\{{}$\1\6${}\\{change\_line}\PP;{}$\6\&{if} ${}(\R\\{input\_ln}(\\{change\_file})){}$\1\5\&{return};\2\6\&{if} ${}(\\{limit}<\\{buffer}+\T{2}){}$\1\5\&{continue};\2\6\&{if} ${}(\\{buffer}[\T{0}]\I\.{'@'}){}$\1\5\&{continue};\2\6\&{if} (\\{xisupper}(\\{buffer}[\T{1}]))\1\5${}\\{buffer}[\T{1}]\K\\{tolower}(\\{buffer}[\T{1}]);{}$\2\6\&{if} ${}(\\{buffer}[\T{1}]\E\.{'x'}){}$\1\5\&{break};\2\6\&{if} ${}(\\{buffer}[\T{1}]\E\.{'y'}\V\\{buffer}[\T{1}]\E\.{'z'}\V\\{buffer}[%\T{1}]\E\.{'

⌨️ 快捷键说明

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