Home

The MFT processor

image

Contents

1. 8 88 E Las EEE Y Os o o vd Ro 4 S e 3 S SS XA AL OQ E RH DE DIT 3 La BS MMH RE TS Cae OEC VES HS ZAR vun ES S Sz E x e x e u pem o A Ox mp ovog S L res LLL E xx ESR nies ee E 27 SS N TFAAR YPI saw SS SSSZIILS WE us Cu E oes x amp Ec pudo NE m Ve BO NN NT S S S Ars g B vu gt ORSSISITITITE Seas HL gran A AAA a oR I 2 090909029 I u O 4 BH wd 9 00045 HBP 3 o o 3 s Ri ord M seks OU AS E PFESSE ES SEL DOPO ee See ee E ZUZL LLL LLA VDD RRS SR RR AAA Hl S RS zi Er RR ES e nn A a a z xm SS m E E p TER BOKVPVAICK Hs 330 048 nass Ae oa SS Sy Se Oe Sui cl d ax SS Se NN XL oo Aaa a a a a Rz zz 7r oc o gt cu ZU MEC ende bo Y S un g 943 dH Oo ne Ts so Hu BAVA ODE SF SFM NAHE H P He lt o s e Z e s ce oz z dede H SAS ASS E nn nm 2 202 2 hel m 4S H s is p O g sag 929 20 254 545 404 00H 4 0 O O mz gt 2 2 Ff c m c m u u FA ZT Zu Zu Zu O SO SOS SO O OO OOOO OO OO O OO IDU Zu Zn om eS IIa SS SS SS SAS ESE RE Et Ga 2 6 2 Do en om ee o gd ze s P oa uous o E A gt A E E E E E E E E z P P H H B z 9 9 rz E m dU UN mE TE PENA AA RUD d NN XL m Sa Sara PARR ARR A gt gt gt AAR RR ERE ee SS m m qz AT ve Sh oz E oo 8 d oo gs
2. 30 The error locations can be indicated by using the global variables loc line styling and changing which tell respectively the first unlooked at position in buffer the current line number and whether or not the current line is from style file or change file or mf file This routine should be modified on systems whose standard text editor has special line numbering conventions Print error location based on input buffer 30 begin if styling then print u styleufileu else if changing then print changeufile else print C print_In 1 line 1 if loc gt limit then limit else loc for k 1 tol do print xchr buffer k 1 print the characters already read new_line for k 1 tol do print space out the next line for k 4 l 1 to limit do print zchr buffer k 1 print the part not yet read end This code is used in section 29 31 The jump_out procedure just cuts across all active procedure levels and jumps out of the program This is the only non local goto statement in MFT It is used when no recovery from a particular error has been provided Some Pascal compilers do not implement non local goto statements In such cases the code that appears at label end of MFT should be copied into the jump out procedure followed by a call to a system procedure that terminates the program define fatal error begin new_line print error mark fatal jump_out end E
3. styling boolean if true the current line is from style file 35 As we change changing from true to false and back again we must remember to swap the values of line and other line so that the err print routine will be sure to report the correct line number define change changing changing changing temp line other line other line line line lt temp line line other line y 36 When changing is false the next line of change_file is kept in change buffer 0 change_limit for purposes of comparison with the next line of mf file After the change file has been completely input we set change limit lt 0 so that no further matches will be made Globals in the outer block 9 change_buffer array 0 buf size of ASCIL code change_limit 0 buf_size the last position occupied in change buffer y 37 Here s a simple function that checks if the two buffers are different function lines dont match boolean label exit var k 0 buf size index into the buffers begin lines dont match true if change limit limit then return if limit gt 0 then for k 0 to limit 1 do if change buffer k Z buffer k then return lines dont match false exit end 38 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 0 A changing if and only if the
4. if b lt out ptr then for k b 1 to out ptr do out buf k b out buf k out ptr out ptr b end 88 MFT calls flush buffer out ptr false before it has input anything We initialize the output variables so that the first line of the output file will be input mftmac Set initial values 10 out ptr 1 out buf 1 u out line 1 write tex file Ninput mftmac 89 When we wish to append the character c to the output buffer we write out c this will cause the buffer to be emptied if it was already full Similarly out c c2 appends a pair of characters A line break will occur at a space or after a single nonletter TEX control sequence define oot if out_ptr line_length then break_out incr out_ptr out buf out_ptr tt define oot1 oot tt end define oot amp oot 1t oot1 define oot3 oot 1t oot2 define oot4 oot t oot3 define oot5 oot t oot4 define out begin oot1 define out2 begin oot2 define out3 begin oot3 define out4 begin oot4 define out5 begin oot5 890 MFT LOW LEVEL OUTPUT ROUTINES 433 90 The break_out routine is called just before the output buffer is about to overflow To make this routine a little faster we initialize position 0 of the output buffer to this character isn t really output Set initial values 10 out buf 0 91 A long line is broken at a blank space
5. index into byte mem begin for k byte start p to byte start p 1 1 do out byte_mem k end 434 LOW LEVEL OUTPUT ROUTINES MFT 894 94 The out_name subroutine is used to output a symbolic token Unusual characters are translated into forms that won t screw up procedure out_name p name_pointer outputs a name var k 0 max bytes index into byte mem t name pointer translation of character being output if any begin for k byte start p to byte_start p 1 1 do begin t translation byte mem k if t 0 then out byte_mem k else out str t end end 3 95 We often want to output a name after calling a numeric macro e g 1 foo procedure out_mac_and_name n ASCII code p name_pointer begin out out n if length p 1 then out name p else begin out out name p out end end El 96 Here s a routine that simply copies from the input buffer to the output buffer procedure copy first_loc integer output buffer first_loc loc 1 var k 0 buf size 4 buffer location being copied begin for k first loc to loc 1 do out buffer k end 897 MFT TRANSLATION 485 97 Translation The main work of MFT is accomplished by a routine that translates the tokens one by one with a limited amount of lookahead lookbehind Automata theorists might loosely call this a finite state transducer because the flow of control
6. t translation auch tr4 N A M tramp cur tok tr4 N B L tr skip cur_tok tr4 N S H tr sharp cur_tok tr4 N P S tr ps cur tok tr4 N 1 e tr le cur tok tr4 N g e tr ge cur_tok tr4 N n e tr ne cur tok tr5 N q u a a tr quad tale This code is used in section 112 74 Globals in the outer block 9 tr_le tr_ge tr_ne tr_amp tr sharp tr_skip tr ps tr_quad name_pointer special translations 875 MFT INPUTTING THE NEXT TOKEN 429 75 Inputting the next token MFT s lexical scanning routine is called get next This procedure inputs the next token of METAFONT input and puts its encoded meaning into two global variables cur_type and cur_tok Globals in the outer block 9 cur_type eight_bits type of token just scanned cur_tok integer hash table or buffer location prev_type eight bits previous value of cur type prev_tok integer previous value of cur tok 76 Set initial values 10 cur_type lt end of line cur_tok 0 77 Two global state variables affect the behavior of get next A space will be considered significant when start_of_line is true and the buffer will be considered devoid of information when empty buffer is true Globals in the outer block 9 start of line boolean has the current line had noth
7. 7S7 zchr 124 T schr 125 U zchr 126 V zchr 127 E W7 zchr 130 X zchr 131 Y zchr 182 E Z zchr 133 4 zchr 134 e MX schr 135 17 zchr 136 7 7 zchr 137 E _ schr 140 4 zchr 141 lt 4 a zchr 142 b zchr 143 c zchr 144 lt d schr 145 e zchr 146 zchr 147 8 zschr 150 h zchr 151 4 i zchr 152 j zchr 153 k zchr 154 1 zxchr 155 m xchr 156 lt 4 n achr 157 E To zxchr 160 p xchr 161 lt q zchr 162 r xchr 163 4 s achr 164 t xchr 165 u zchr 166 v xchr 167 w zchr 170 7x7 xchr 171 y xchr 172 E z xchr 173 1 zchr 174 E 717 achr 175 Y xchr 176 777 17 The ASCII code is standard only to a certain extent since many computer installations have found it advantageous to have ready access to more than 94 printing characters If MFT is being used on a garden variety Pascal for which only standard ASCII codes will appear in the input and output files it doesn t really matter what codes are specified in zchr 0 37 but the safest policy is to blank everything out by using the code shown below However other settings of zchr will make MFT more friendly on computers that have an extended character set so that use
8. Command pr5 i n p u t input command pra e J m a on p Cu e bold pr2 i f command pr2 E i ER pr4 Ne 2 s e command pr e J 1 s J e i nt command pr4 t x a e Bold pr a 1 s e bold pri n e 2 1 p C1 ne t u or e Bold pr a a 1 1 p e a bold pr7 o b n a n e bold pr10 r J e J a a s e t i Jom Cg bold pro p e n Jive C2 Cre 2 Ce bold pr4 g o o a special tag pr n as i pr vu Yl as is pr e t i Cr yr as is pra 1 as is pr 1 9 8 829 as is pr4 1 9 inei pr ul zy 1 C as is pro 1 9 Cass pri Jie Cr binary pr s C9 e Co command 867 MFT Does anybody out there remember the commercials that went LS MFT INITIALIZING THE PRIMITIVE TOKENS 424 67 A S S Re dus Ds A Ro Ede E SE 3 n 2 3 es e o x E 25s um nn Innen on dies a CR a gt TENE ng 3 Y wn rz S aH s m m in 3 An a Sim E z Eu Z a C a a o 3 soon Des eee o o 5 SE E 2 Q S ers Qc u a x e 2 H P 2 PHAMSSABMEYEO o 2 xXXXXX E e ee u z ae om 2 5 E mom D amp E E 3 orsongwon
9. a t e a binary pr s J 1 a m 2 e a binary pr s c a J 1 e a inary pr s J he 1 1 Ct e a binary pri EEES Cz n e a binary pr x Jis e a 17 e Ca binary pr y Jis e a C 1 ne Ca binary pr z sr rar ra binary IT ran je e nr ns e e ee na to n EIn e s binary pr n u n e inr 1 e type name pr6 s ntes rin n g tupe name pr v o J o 1 e a n pe name pr4 p a e n type name pr3 p e n type name prp rin c e a Cr e pe name po str type name prd p a i lx type name 427 INITIALIZING THE PRIMITIVE TOKENS MFT 71 e n e i e s bold 1 e command 3 S S SG 3 3 S Y Sr 3 3 3 3 3 3 E en m E E E d E E E E E EES E vo S S Q oo Q S ES 3 3 O SO S 3 E SA S oa FEES S wa i SUomB ES 27 PC 9 TEE n S LLL SS LL 18 S8s83 S8 g ee 27257 CI EZGZICGREECIIZGCIO E 23 2 uw SA SP ESETROREE EPS S So Tu Hm c de 2339 2355 2r E nn nn uu nn rn ARAS rn A t u Ss rn 4 A zov z Aa AA A HOO HOES E ws EE w Eff Owe EH B Gs op zm GE oz WO SEF QHME F O0o u o am E lt lt DO EO O o Q c m o 233 0 z NE NNN EN a EEE on n aS P
10. bold 17 internal code for tokens like nullpen typename 18 internal code for tokens like numeric path join 19 internal code for the token colon 20 internal code for the token semicolon 21 internal code for the token backslash 22 internal code for the token V double back 23 internal code for the token less_or_equal 24 internal code for the token lt greater_or_equal 25 internal code for the token gt not_equal 26 internal code for the token lt gt sharp 27 internal code for the token comment 28 internal code for the token recomment 29 internal code used to resume a comment after l min_suffic 30 smallest code for symbolic tokens in suffixes internal 30 internal code for tokens like pausing input_command 31 internal code for tokens like input special_tag 32 internal code for tags that take at most one subscript tag 33 internal code for nonprimitive tokens Assign the default value to ilk p 63 ilk p tag This code is used in section 62 864 MFT INITIALIZING THE PRIMITIVE TOKENS 421 64 We have to get METAFONT s primitives into the hash table and the simplest way to do this is to insert them every time MFT is run A few macros permit us to do the initialization with a compact program We use the fact that the longest primiti
11. text_file boolean inputs a line or returns false var final_limit 0 buf_size limit without trailing blanks begin limit 0 final_limit 0 if eof f then input In false else begin while eoln f do begin buffer limit E zord f1 get f ier limit if buffer limit 1 4 u then final limit limit if limit buf size then begin while eoln f do get f decr limit keep buffer buf size empty if final limit gt limit then final limit limit print nl Input line too long loc 0 error end end read In f limit final limit input ln lt true end end 410 REPORTING ERRORS TO THE USER MFT 829 29 Reporting errors to the user The command err_print Error message will report a syntax error to the user by printing the error message at the beginning of a new line and then giving an indication of where the error was spotted in the source file Note that no period follows the error message since the error routine will automatically supply a period The actual error indications are provided by a procedure called error define err print begin new line print error end Error handling procedures 29 procedure error prints and location of error message var k l 0 buf_size indices into buffer begin Print error location based on input buffer 30 update terminal mark error end See also section 31 This code is used in section 3
12. 2 e zm H Qe Q Zins YN n Q Oo o 5 Doc cod Sa 8 05 E Hc HB OI BAT e HET S DAS E 2 RRR Tor u PS un nu nun Y I NS RE Ct 37 OD ow 2 occ E o On n E E 2 d o 0 e pz ne ny o js Ban Mr sc mH Mold nw E 2 E e Soc E AN A aa ao 3 Zehn EL mcm ETUR acu cale ccu car ee Sa podus nun u eo Ban IA NSS RRR RRB SS FP Fea HS SS Fa e Fa FS Ss gt 19 IS IIS EE N a a E ara 4 o t ASS Re SS n 2 z z z E mo co mE d gt x g o UD un g a o e a0 o 0555 pe O Ge aan Sg H poz poset 3 oss g Mot 2 ww nn zzz cz w oe Swa a ie a II a uu So o v_ unnnueueueuennung un en NT Nur gg u 3 BARS ES E A D aa Eu pu e at coru es ann o AEDEP 2 H poo so AF MDP ovn HOWE FOF FURR uno z 2 zz E Mm LI f fas B A AL A IT IT TAL S S S S Aaa ac Ti ON EE nn ZE R5 mom Auer ee en Pace nr aaa ren aa Ban em pcc prs E Pu ul E EU ul Vo ES PIPER ao A Le P A AS art Oo DD Soo A oe oS oo A NN 44 ggeno F n n 3 Q o d E mm um 009 a onnu Oz BF UNE VHS HME NSNSSH 4 08 u nn Yew 2 cz ANA Ww 2 cz fs TI III II I DI IS OT I ON C C o C O00 a AS C coco IP Aa oe ee t LL EEE oL A amp A amp Lo A amp A LR oL oL EEE EEE LE Lo oL A amp A amp A amp A A amp A A amp A amp A EE ej py SS ee EX EN AAA E R A R A Ex Ex Ex EX AA A A AA Eh EX ANNE R WH 428 INITIALIZI
13. 44 46 47 48 49 Line had to be broken 92 line_length 8 86 87 89 91 lines_dont_match 37 42 link 50 51 52 60 loc 28 30 34 39 43 44 45 48 49 80 81 82 85 96 104 105 108 109 110 lookup 55 58 64 80 loop 6 INDEX 443 mark_error 9 29 mark_fatal 9 31 mark_harmless 9 92 max bytes 8 51 53 58 62 93 94 mazx_class 78 max names 8 51 52 62 MF file ended 42 mf_file 3 23 24 30 34 36 42 46 49 MFT 3 mft_comment 63 71 97 98 111 mftmac 1 88 min_action_type 63 98 min_suffiz 63 106 107 min_symbolic_token 63 111 n 42 95 name_pointer 52 53 58 72 74 93 94 95 name_ptr 52 53 54 58 60 62 72 new_line 20 29 30 31 92 nil 6 not_equal 63 70 102 not_found 5 numeric_token 63 81 97 106 107 Only symbolic tokens 111 oot 89 ooti 89 oot2 89 oot3 89 oot4 89 oot5 89 op 63 65 67 100 open_input 24 44 ord 15 other_line 34 35 44 49 othercases 7 others 7 out 89 93 94 95 96 98 104 105 106 107 108 110 out_buf 86 87 88 89 90 91 92 108 109 out_line 86 87 88 92 out_mac_and_name 95 100 103 106 out_name 94 95 101 106 107 out_ptr 86 87 88 89 91 92 97 108 109 out_str 93 94 97 98 102 106 out2 89 98 99 101 105 106 107 108 outs 89 out4 89 108 110 out5 89 103 104 105 overflow 33 62 p 58 93 94 95 pass_digits 80 81 pa
14. a procedure call format return nil format loop xclause 404 INTRODUCTION MFT 87 7 We assume that case statements may include a default case that applies if no matching label is found Thus we shall use constructions like case x of 1 code for x 1 3 code for x 3 othercases code for z Z 1 and x 3 endcases since most Pascal compilers have plugged this hole in the language by incorporating some sort of default mechanism For example the compiler used to develop WEB and TEX allows others as a default label and other Pascals allow syntaxes like else or otherwise or otherwise etc The definitions of othercases and endcases should be changed to agree with local conventions Of course if no default mechanism is available the case statements of this program must be extended by listing all remaining cases define othercases others default for cases not listed explicitly define endcases end follows the default case in an extended case statement format othercases else format endcases end 8 The following parameters are set big enough to handle the Computer Modern fonts so they should be sufficient for most applications of MFT Constants in the outer block 8 max_bytes 10000 the number of bytes in tokens must be less than 65536 maz names 1000 number of tokens hash size 353 should be prime buf_size 100 maximum length of input line line_lengt
15. also present in the Pascal version of TEX where they are used in a similar but more complex way System dependent portions of MFT can be identified by looking at the entries for system dependencies in the index below The banner line defined here should be changed whenever MFT is modified define banner This is MFT Version 2 0 83 MFT INTRODUCTION 403 3 The program begins with a fairly normal header made up of pieces that will mostly be filled in later The MF input comes from files mf_file change_file and style_file the TEX output goes to file tex_file If it is necessary to abort the job because of a fatal error the program calls the jump_out procedure which goes to the label end_of_ MFT define end_of MFT 9999 go here to wrap it up Compiler directives 4 program MFT mf file change file style_file tex file label end_of_ MFT go here to finish const Constants in the outer block 8 type Types in the outer block 12 var Globals in the outer block 9 Error handling procedures 29 procedure initialize var Local variables for initialization 14 begin Set initial values 10 end 4 The Pascal compiler used to develop this system has compiler directives that can appear in comments whose first character is a dollar sign In our case these directives tell the compiler to detect things that are out of range Compiler directives 4 0 amp C A D C range check catch ar
16. backslash out str translation pyth_sub out_str tr_ps less_or_equal out_str tr_le greater or equal out str tr ge not equal out str tr ne ampersand out str tr amp 103 The remaining primitive is slightly special Cases that translate primitive tokens 100 input_command begin out mac and name 2 cur tok out5 N h b o x Scan the file name and output it in typewriter type 104 end MFT 8100 8104 MFT TRANSLATION 437 104 File names have different formats on different computers so we don t scan them with get_next Here we use a rule that probably covers most cases satisfactorily We ignore leading blanks then consider the file name to consist of all subsequent characters up to the first blank semicolon comment or end of line A carriage_return appears at the end of the line Scan the file name and output it in typewriter type 104 while buffer loc u do incr loc out t VY reu while buffer loc 4 u A buffer loc 4 buffer loc zz A loc lt limit do begin out buffer loc incr loc end out This code is used in section 103 105 Translate a numeric token or a fraction 105 if buffer loc then if char class buffer loc 1 digit class then it s a fraction begin out5 N r a c copy cur_tok get_next out2 get_nezt copy cur_tok out end else copy cur_tok else
17. line that didn t match any relevant line in mf file Check that all changes have been read 49 if change limit 4 0 then changing is false begin for loc 0 to change limit do buffer loc change buffer loc limit change limit changing true line other line loc change limit err print Change file entry did not match end This code is used in section 112 850 MFT DATA STRUCTURES 417 50 Data structures MFT puts token names into the large byte_mem array which is packed with eight bit integers Allocation is sequential since names are never deleted An auxiliary array byte_start is used as a directory for byte_mem the link and ilk arrays give further information about names These auxiliary arrays consist of sixteen bit items Types in the outer block 12 eight_bits 0 255 unsigned one byte quantity sizteen_bits 0 65535 unsigned two byte quantity 51 MFT has been designed to avoid the need for indices that are more than sixteen bits wide so that it can be used on most computers Globals in the outer block 9 byte mem packed array 0 max bytes of ASCII code characters of names byte start array 0 max names of sixteen bits directory into byte mem link array 0 max names of sixteen bits hash table links ilk array 0 max_names of sixteen bits type codes 52 The names of tokens are found by computing a hash address h and
18. or just before a backslash that isn t preceded by another backslash In the latter case a 4 is output at the break This policy has a known bug in the rare situation that the backslash was in a string constant that s being output verbatim procedure break out finds a way to break the output line label exit var k 0 line_length index into out buf d ASCII code character from the buffer begin k out ptr loop begin if k 0 then Print warning message break the line return 92 d out buf k if d u then begin lush buffer k false return end if d A out buf k 1 4 then in this case k gt 1 begin flush_buffer k 1 true return end decr k end 7 exit end 92 We get to this module only in unusual cases that the entire output line consists of a string of backslashes followed by a string of nonblank non backslashes In such cases it is almost always safe to break the line by putting a just before the last character Print warning message break the line return 92 begin print_nl Line had to be broken output 1 out line 1 print lIn for k 1 to out ptr 1 do print zchr out buf k new_line mark harmless flush buffer out_ptr 1 true return end This code is used in section 91 93 To output a string of bytes from byte mem we call out str procedure out str p name_pointer outputs a string var k 0 max bytes
19. restart or reswitch 111 begin start_of_line false get_next t cur type while cur type gt min symbolic token do begin get nezt if cur type gt min symbolic token then ilk cur tok lt t end if cur type end of line then if cur type A mft comment then begin err print Only usymbolic tokens should appear after A44 goto reswitch end empty buffer true goto restart end This code is used in section 97 440 THE MAIN PROGRAM MFT 8112 112 The main program Let s put it all together now MFT starts and ends here begin initialize beginning of the main program print_In banner print a banner line Store all the primitives 65 Store all the translations 73 Initialize the input system 44 do_the_translation Check that all changes have been read 49 end_of_MFT here files should be closed if the operating system requires it Print the job history 113 end 113 Some implementations may wish to pass the history value to the operating system so that it can be used to govern whether or not other programs are started Here we simply report the history to the user Print the job history 113 case history of spotless print_nl No errors were found harmless message print nl Did you see the warning message above error message print nl Pardon me uibut I think 1 spotted something wrong jm y fatal message print nl That was a
20. though there now are more than 64 such characters while other Pascals consider char to be a 64 element subrange of a larger data type that has some other name In order to accommodate this difference we shall use the name tert_char to stand for the data type of the characters that are converted to and from ASCIL code when they are input and output We shall also assume that text_char consists of the elements chr first text char through chr last text char inclusive The following definitions should be adjusted if necessary define text_char char the data type of characters in text files define first_text_char 0 ordinal number of the smallest element of text_char define last_text_char 255 ordinal number of the largest element of text_char Types in the outer block 12 tert_file packed file of tert char 14 Local variables for initialization 14 i 0 255 See also section 56 This code is used in section 3 15 The MFT processor converts between ASCII code and the user s external character set by means of arrays zord and chr that are analogous to Pascal s ord and chr functions Globals in the outer block 9 zord array tert_char of ASCIL code specifies conversion of input characters zchr array ASCII code of text char specifies conversion of output characters 406 THE CHARACTER SET MFT 816 16 Since we are assuming that our Pascal system is able to read and write the visible characters
21. to one of the following types define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define indentation 0 internal code for space at beginning of a line end_of_line 1 internal code for hypothetical token at end of a line end_of file 2 internal code for hypothetical token at end of the input verbatim 3 internal code for the token 4 set_format 4 internal code for the token 44 mft_comment 5 internal code for the token 444 min_action_type 6 smallest code for tokens that produce real output numeric token 6 internal code for tokens like 3 14159 string token 7 internal code for tokens like pie min_symbolic_token 8 smallest internal code for a symbolic token op 8 internal code for tokens like sqrt command 9 internal code for tokens like addto endit 10 internal code for tokens like fi binary 11 internal code for tokens like and abinary 12 internal code for tokens like bbinary 13 internal code for tokens like step ampersand 14 internal code for the token amp pyth_sub 15 internal code for the token asis 16 internal code for tokens like
22. 38 42 80 91 97 f 28 false 28 35 36 37 42 44 47 85 87 88 91 97 98 111 fatal_error 31 32 33 fatal message 9 113 final_limit 28 first_loc 96 first_text_char 13 18 8115 MFT flush_buffer 87 88 91 92 97 found 5 58 60 61 80 81 get 28 get_line 34 45 85 get_next 75 77 80 97 101 104 105 106 107 111 greater_or_equal 63 70 102 h 56 58 harmless_message 9 113 hash 52 55 57 60 hash_size 8 55 56 57 58 59 history 9 10 113 Hmm n of the preceding 43 i 14 58 72 id_first 55 58 59 61 62 64 80 81 108 109 id_loc 55 58 59 61 62 65 80 ik 50 51 63 64 80 111 Incomplete string 83 incr 6 28 39 40 42 46 47 48 59 61 62 72 80 81 82 87 89 104 108 indentation 63 81 97 initialize 3 112 Input line too long 28 input command 63 66 103 input_has_ended 34 42 44 46 85 input in 28 39 40 42 46 47 48 integer 34 42 75 86 96 97 internal 63 68 69 97 106 Invalid character 84 invalid_class 78 79 81 isolated_classes 78 81 Jo S jump_out 3 31 k 29 37 38 42 58 87 91 93 94 96 97 Knuth Donald Ervin 1 l 29 58 last_text_char 13 18 left_bracket_class 78 79 length 52 60 95 106 less_or_equal 63 70 102 letter_class 78 79 limit 28 30 34 37 39 40 41 43 44 45 46 48 49 79 82 85 104 108 109 110 line 30 34 35 39 40 42
23. 79 81 string_token 63 82 97 style_file 3 23 24 30 34 47 styling 30 34 44 45 47 switch 80 81 83 84 system dependencies 2 3 4 7 13 16 17 20 21 22 24 26 28 30 31 78 112 113 114 t 94 97 tag 63 97 106 temp line 34 35 term out 20 21 22 tex file 3 25 26 87 88 text char 13 15 20 tert_file 13 20 23 25 28 This can t happen 32 tr_amp 73 74 102 irge 73 74 102 tr le 73 74 102 irme 73 74 102 tr_ps 73 74 102 tr_quad 73 74 97 tr_sharp 73 74 106 tr_skip 73 74 98 translation 72 73 94 102 true 6 28 34 35 37 42 44 46 49 77 85 87 91 92 97 108 111 wis T2 ird 72 73 tro Ta tr4 72 73 irb 72 73 tri T2 ttr2 72 ttr3 72 ttr4 72 ttrd 72 type_name 63 70 100 update_terminal 22 29 user manual 1 verbatim 63 71 97 Where is the match 39 43 48 write 20 87 88 8115 MFT INDEX 445 writeln 20 87 zchr 15 16 17 18 30 87 92 xclause 6 zord 15 18 28 446 NAMES OF THE SECTIONS MFT 8115 Assign the default value to ilk p 63 Used in section 62 Branch on the class scan the token return directly if the token is special or goto found if it needs to be looked up 81 Used in section 80 Bring in a new line of input return if the file has ended 85 Used in section 80 Cases that translate primitive tokens 100 101 102 103 Used in section 97 Change the translation f
24. KENS 65 The intended use of the macros above might not be immediately obvious but the riddle is answered by the following Store all the primitives 65 id loc 18 pr path join pri C as is pri 1 as is pr1 as_is pr1 as_is pr1 colon pr2 colon pra 1 IPC colon pr2 as is pr1 as is pri semicolon pri N backslash pre N N double back pr5 a a a t o command pr2 a t bbinary pr a J t 1 e a e t op pr10 o e g 1 n g Cx o u p command pr amp o o a EN A pr4 c u 1 1 command pr ra lo pr10 a e LA Ca C37 ne Ce nr Cs command pr a Ji s b 1 a Cy command pra e n a g or o v p endl pra e Jive rogo Cro command pr6 e x i ce m vi f command pr11 e J x Epa n a na C e Ce re command pr4 r o n binary pra in mn Han rin n o w binary pr 1 J m t e Cr Cm command pr3 1 e t command pri n e ran ir 9 e ne Cr e a P2 Command pr2 o command pr10 o J p e n u 2 9 ta 0 e command pr10 x a a a o m s Ce e a command pr4 s a v
25. NG THE PRIMITIVE TOKENS MFT 872 72 We also want to store a few other strings of characters that are used in MFT s translation to TEX code define ttr1 byte_mem byte_ptr 1 cur tok name_ptr incr name_ptr byte_start name_ptr byte ptr define ttr2 byte mem byte ptr 2 define ttr3 byte mem byte ptr 3 byte mem byte ptr 4 define ttr5 byte mem byte ptr 5 define ttr4 define tr incr byte ptr ttr1 define tr2 byte ptr byte ptr 2 ttr2 define tr3 byte ptr byte ptr 3 ttr3 define tr byte_ptr byte ptr 4 ttr4 define tr5 byte_ptr byte_ptr 5 ttr5 Globals in the outer block 9 d ttri tir2 tird ttr4 translation array ASCII_code of name_pointer i ASCILcode index into translation 73 Store all the translations 73 i 0 for i 0 to 255 do translation i tr2 translation pow tr2 translation cur tok tr2 amp translation amp cur tok tr2 translation cur tok tr2 N Y translation cur tok tr2 _ translation _ cur tok tr2 translation cur_tok trg N B S translation N cur tok trg N H A translation E cur tok tr4 N T I translation cur tok tr5 N a s
26. O0 O An d d d d d d d dz Qooo G8 Ep Hoz oz sacs cS SS Went er mo c m x Al A Do e O O SO SO SO NO SO NS NO ISO O O O O MO MU a a a AA ENS ES SAI ASI EIA TI FIT FIT FRI FT ars bm en ae A oS SS S m mj zum Jen nn Hd o a fF Q 2 gt wyHDPOOOOOOOoOOoO z d gt KeA Anu H un u c x XA AS OS Saa I 00 AT M A o o ocu 2 ekrketktctttcttctcettctttecettctette 2828222822822 amp amp amp amp amp amp amp amp amp amp amp amp amp E E amp E 2 2 426 INITIALIZING THE PRIMITIVE TOKENS MFT 870 70 Still more Store all the primitives 65 pri abinary pri abinary pri abinary pr1 as is pr binary pr puth sub pra var a a binary pr o r binary pri as is pr2 lt less_or_equal pri as is pr gt greater_or_equal pri as is pr2 not equal pro s J u b s t nr r2 n Cg command pr s J u b b a J t a command pr13 A N e tne Cre o Pe iom e command pr p Jio 1 Ce command pr10 p r e c o n tr n0 2 command pri b o sre ne Cro mone eoo P2 command pro p e ENE e Ce command pri amp ampersand pr r ron t
27. The MFT processor Version 2 0 October 1989 Section Page unde Ne a T E i o Gat Re RE ER ENTER d dad op EP Sd 11 Ina A A en 19 Reporting errors to tho user asia aa 29 eran ERE Sa di a ea ee ee En 34 Data sim va ea era aeg 50 Inialzins the primitive TOKENS aussagen esa dE AAA AA 63 Inputtine The next TOKON vc ctaccastdncemecce dats sa ee 15 Tora SD TOMES asides ones ee ee oak quad ia die gk 86 Translation P 99 deca st uat a Puis P dade qu qud bl qd d 97 The gna prOUPANH res adi 112 oystein dependent change silence 114 pr Arr ENTER TEE OEL TELORTERO ENTER EN oatabasneteeaead 115 The preparation of this report was supported in part by the National Science Founda tion under grants IST 8201926 MCS 8300984 and CCR 8610181 and by the System Development Foundation TEX is a trademark of the American Mathematical Society METAFONT is a trademark of Addison Wesley Publishing Company 402 405 408 410 412 417 420 429 432 435 440 441 442 402 INTRODUCTION MFT 8 1 Introduction This program converts a METAFONT source file to a TEX file It was written by D E Knuth in June 1985 a somewhat similar SAIL program had been developed in January 1980 The general idea is to input a file called say foo mf and to produce an output file called say foo tex The latter file when processed by TEX will yield a prettyprinted representation of the input file Line breaks in the input are carried over into the output mo
28. ange_changing now it s false incr line if input_In mf file then begin err_print MF file ended during ya change input has ended true return end if lines dont match then incr n end exit end 43 If the current line starts with y report any discrepancies and return 43 if limit gt 1 then if buffer 0 6 then begin if buffer 1 gt X A buffer 1 Z then buffer 1 buffer 1 z 2 lowercasify if buffer 1 x buffer 1 z then begin loc 2 err print Where is the matching Gy end else if buffer 1 y then begin if n gt 0 then begin loc 2 err print ly Hmm u n 1 of the preceding lines failed to match end return end end This code is used in section 42 844 MFT INSERTING THE CHANGES 415 44 Here s what we do to get the input rolling Initialize the input system 44 begin open_input line 0 other line 0 changing true prime the change buffer change changing styling true limit 0 loc 1 buffer 0 u input has ended false end This code is used in section 112 45 The get line procedure is called when loc gt limit it puts the next line of merged input into the buffer and updates the other variables appropriately procedure get line inputs the next line label restart begin restart if styling then Read from style file and maybe turn off styling 47 if sty
29. any headaches 20 Terminal output is done by writing on file term_out which is assumed to consist of characters of type text_char define print write term_out print means write on the terminal define print In 3 write_ln term_out print and then start new line define new line write In term out start new line on the terminal define print nl t print information starting on a new line begin new line print end Globals in the outer block 9 term out text file the terminal as an output file 21 Different systems have different ways of specifying that the output on a certain file will appear on the user s terminal Here is one way to do this on the Pascal system that was used in WEAVE s initial development Set initial values 10 rewrite term out TTY send term out output to the terminal 22 The update terminal procedure is called when we want to make sure that everything we have output to the terminal so far has actually left the computer s internal buffers and been sent define update terminal break term out empty the terminal output buffer 23 The main input comes from mf file this input may be overridden by changes in change file If change file is empty there are no changes Furthermore the style_file is input first it is unchangeable Globals in the outer block 9 mj file text_file primary input change file text file updates style f
30. change file is exhausted This procedure is called only when changing is true hence error messages will be reported correctly procedure prime the change buffer label continue done exit var k 0 buf_size index into the buffers begin change_limit E 0 this value will be used if the change file ends Skip over comment lines in the change file return if end of file 39 Skip to the next nonblank line return if end of file 40 Move buffer and limit to change_buffer and change_limit 41 exit end 839 MFT INSERTING THE CHANGES 413 39 While looking for a line that begins with x in the change file we allow lines that begin with as long as they don t begin with y or z which would probably indicate that the change file is fouled up Skip over comment lines in the change file return if end of file 39 loop begin incr line if input In change file then return if limit lt 2 then goto continue if buffer 0 4 6 then goto continue if buffer 1 gt X buffer 1 Z then buffer 1 buffer 1 z Zz lowercasify if buffer 1 x then goto done if buffer 1 y buffer 1 z then begin loc 2 err print Where is the matching Ox end continue end done This code is used in section 38 40 Here we are looking at lines following the ex Skip to the next nonblank line return if end of file 40 repeat incr line if input_In change_file then begin err
31. copy cur tok This code is used in section 97 106 Translate a tag and possible subscript 106 begin if length cur tok 1 then out name cur tok else out mac and name N cur tok get next if byte mem byte start prev tok then goto reswitch case prev type of internal begin if cur type numeric token cur type gt min suffiz then out2 N goto reswitch end special tag if cur type lt min suffiz then goto reswitch else begin out cur_type internal goto reswitch end tag begin if cur type tag then if byte mem byte start cur tok 7 then goto reswitch a sequence of primes goes on the main line if cur type numeric token cur type gt min suffiz then Translate a subscript 107 else if cur type sharp then out_str tr_sharp else goto reswitch end end there are no other cases end This code is used in section 97 438 TRANSLATION MFT 8107 107 Translate a subscript 107 begin out2 _ loop begin if cur type gt min_suffiz then out_name cur_tok else copy cur_tok if prev_type special_tag then begin get_next goto done end get_next if cur_type lt min_suffix then if cur_type numeric token then goto done if cur_type prev_type then if cur_type numeric_token then out2 else if char class byte mem byte start cur tok char_class byte mem byte start prev tok then if byte mem byte start prev tok 4 the
32. e command pr10 s c a n t Co K e a s command pr s n 1 p o u t command pr4 s e e p bbinary pr3 s t r command pri e rer a s C2 o n op pr2 t o bbinary pro u n amp i 2 bbinary pr3 a e command pr6 v a r a e command See also sections 66 67 68 69 70 and 71 This code is used in section 112 866 MFT 66 INITIALIZING THE PRIMITIVE TOKENS 423 There are so many primitives it s necessary to break this long initialization code up into pieces so as yP gt y not to overflow WEAVE s capacity Store all the primitives 65 pr10 p r i a a Cr y Ca ne C command pr12 s e c o m a a Cr y Cra ne command pri ee ore Cra oy Cra oe command pr e n ran ran e t end pr3 o r command pri CESE Ps C n o Py Ce Cs command pr o r Jive Cv e 7 command pr e J n a Ji o J r Cendit pro a u o e command pr4 e x p x command pr6 s u i x command pri e e x 6 command pr p ren 1 J n a 1 y command pro s J e c o n a a Cy command pra tn nen r ne Cri na or Cy
33. e rules just stated apply to lines that contain one two or three signs in a row Comments to MFT can follow 444 Five or more 4 signs should not be used Beside the normal input file MFT also looks for a change file e g foo ch which allows substitutions to be made in the translation The change file follows the conventions of WEB and it should be null if there are no changes Changes usually contain verbatim instructions to compensate for the fact that MFT cannot format everything in an optimum way There s also a third input file e g plain mft which is input before the other two This file normally contains the formatting commands that are necessary to tune MFT to a particular style of METAFONT code so it is called the style file The output of MFT should be accompanied by the macros in a small package called mftmac tex Caveat This program is not as bulletproof as the other routines produced by Stanford s TEX project It takes care of a great deal of tedious formatting but it can produce strange output because METAFONT is an extremely general language Users should proofread their output carefully 2 MFT uses a few features of the local Pascal compiler that may need to be changed in other installations 1 Case statements have a default 2 Input output routines may need to be adapted for use with a particular character set and or for printing messages on the user s terminal These features are
34. egin out_str tr_skip goto restart end else if cur_type mft_comment then goto restart This code is used in section 97 99 Let s start with some of the easier translations so that the harder ones will also be easy when we get to them A string like cat comes out X7 cat Translate a string token 99 begin out2 7 copy cur_tok end This code is used in section 97 436 TRANSLATION 100 Similarly the translation of sqrt is i sqrt Cases that translate primitive tokens 100 op out_mac_and_name 1 cur_tok command out mac and name 2 cur tok type_name if prev type command then out mac and name 1 cur tok else out_mac_and_name 2 cur tok endit out_mac_and_name 3 cur tok bbinary out mac and name 4 cur tok bold out mac and name 5 cur tok binary out mac and name 6 cur tok path join out mac_and_name 8 cur tok colon out_mac_and_name cur tok See also sections 101 102 and 103 This code is used in section 97 101 Here are a few more easy cases Cases that translate primitive tokens 100 as_is sharp abinary out name cur tok double back out N semicolon begin out name cur tok get next if cur type end of line then if cur type endit then out U goto reswitch end 102 Some of the primitives have a fixed output independent of cur tok Cases that translate primitive tokens 100
35. fatal error my friend end there are no other cases This code is used in section 112 8114 MFT SYSTEM DEPENDENT CHANGES 441 114 System dependent changes This module should be replaced if necessary by changes to the program that are necessary to make MFT work at a particular installation It is usually best to design your change file so that all changes to previous modules preserve the module numbering then everybody s version will be consistent with the printed program More extensive changes which introduce new modules can be inserted here then only the index itself will get a new module number 442 INDEX 115 Index NI 98 106 107 101 100 106 X 101 AM etc 73 frac 105 input mftmac 88 par 108 110 1 100 2 100 3 100 4 100 5 100 6 100 7 99 8 100 9 108 Q 98 abinary 63 70 98 101 ampersand 63 70 98 102 as_is 63 65 66 70 101 ASCII code 11 ASCILcode 12 13 15 27 28 36 51 72 78 80 86 91 95 b 87 backslash 63 65 102 banner 2 112 bbinary 63 65 98 100 binary 63 66 70 98 100 bold 63 66 71 100 boolean 28 34 37 77 87 break 22 break_out 89 90 91 buf_size 8 27 28 29 34 36 37 38 42 55 58 96 97 buffer 27 28 29 30 37 39 41 42 43 44 46 48 49 55 58 59 61 62 64 79 80 81 82 85 96 104 105 108 byte_mem 50 51 52 53 58 61 62 72 93 94 106 107 by
36. h 80 lines of TEX output have at most this many characters should be less than 256 This code is used in section 3 9 A global variable called history will contain one of four values at the end of every run spotless means that no unusual messages were printed harmless_message means that a message of possible interest was printed but no serious errors were detected error message means that at least one error was found fatal message means that the program terminated abnormally The value of history does not influence the behavior of the program it is simply computed for the convenience of systems that might want to use such information define spotless 0 history value for normal jobs define harmless message 1 history value when non serious info was printed define error message 2 history value when an error was noted define fatal message 3 history value when we had to stop prematurely define mark harmless if history spotless then history harmless message define mark error history error message define mark fatal history fatal message Globals in the outer block 9 history spotless fatal message how bad was this run See also sections 15 20 23 25 27 34 36 51 53 55 72 74 75 77 78 and 86 This code is used in section 3 10 Set initial values 10 history spotless See also sections 16 17 18 21 26 54 57 76 79 88 and 90 This code is used
37. ile text_file formatting bootstrap 24 The following code opens the input files Since these files were listed in the program header we assume that the Pascal runtime system has already checked that suitable file names have been given therefore no additional error checking needs to be done procedure open_input prepare to read the inputs begin reset mf_file reset change_file reset style file end 25 The main output goes to tex_file Globals in the outer block 9 tex file text file 26 The following code opens ez file Since this file was listed in the program header we assume that the Pascal runtime system has checked that a suitable external file name has been given Set initial values 10 rewrite tex_file 27 Input goes into an array called buffer Globals in the outer block 9 buffer array 0 buf_size of ASCII_code 828 MFT INPUT AND OUTPUT 409 28 The input n procedure brings the next line of input from the specified file into the buffer array and returns the value true unless the file has already been entirely read in which case it returns false The conventions of TEX are followed i e ASCI_code numbers representing the next line of the file are input into buffer 0 buffer 1 buffer limit 1 trailing blanks are ignored and the global variable limit is set to the length of the line The value of limit must be strictly less than buf size function input_In var f
38. in section 3 811 MFT THE CHARACTER SET 405 11 The character set MFT works internally with ASCII codes like all other programs associated with TEX and METAFONT The present section has been lifted almost verbatim from the METAFONT program 12 Characters of text that have been converted to METAFONT s internal form are said to be of type ASCIL code which is a subrange of the integers Types in the outer block 12 ASCII code 0 255 eight bit numbers See also sections 13 50 and 52 This code is used in section 3 13 The original Pascal compiler was designed in the late 60s when six bit character sets were common so it did not make provision for lowercase letters Nowadays of course we need to deal with both capital and small letters in a convenient way especially in a program for font design so the present specification of MFT has been written under the assumption that the Pascal compiler and run time system permit the use of text files with more than 64 distinguishable characters More precisely we assume that the character set contains at least the letters and symbols associated with ASCII codes 40 through 176 If additional characters are present MFT can be configured to work with them too Since we are dealing with more characters than were present in the first Pascal compilers we have to decide what to call the associated data type Some Pascals use the original name char for the characters in text files even
39. ing but spaces so far empty buffer boolean is it time to input a new line 78 The 256 ASCII code characters are grouped into classes by means of the char_class table Individual class numbers have no semantic or syntactic significance expect in a few instances defined here There s also maz_class which can be used as a basis for additional class numbers in nonstandard extensions of METRFONT define digit class 0 the class number of 0123456789 define period class 1 the class number of define space class 2 the class number of spaces and nonstandard characters define percent class 3 the class number of define string_class 4 the class number of define right paren class 8 the class number of define isolated classes 5 6 7 8 characters that make length one tokens only define letter class 9 letters and the underline character define left bracket class 17 U define right bracket class 18 1 define invalid class 20 bad character in the input define end line class 21 end of an input line MFT only define max class 21 the largest class number Globals in the outer block 9 char_class array ASCIL code of 0 maa_class the class numbers 430 INPUTTING THE NEXT TOKEN MFT 879 79 If changes are made to accommodate non ASCII character sets they should be essentially the same in MFT as in METAFONT However MFT has an additional class nu
40. is comparatively simple procedure do_the_translation label restart reswitch done exit var k 0 buf_size looks ahead in the buffer t integer type that spreads to new tokens begin restart if out_ptr gt 0 then flush buffer out_ptr false empty_buffer lt true loop begin get_nezt if start_of_line then Do special actions at the start of a line 98 reswitch case cur_type of numeric_token Translate a numeric token or a fraction 105 string_token Translate a string token 99 indentation out_str tr_quad end_of_line mft_comment Wind up a line of translation and goto restart or finish a segment and goto reswitch 110 end_of_file return Cases that translate primitive tokens 100 comment recomment Translate a comment and goto restart unless there s a segment 108 verbatim Copy the rest of the current input line to the output then goto restart 109 set_format Change the translation format of tokens and goto restart or reswitch 111 internal special_tag tag Translate a tag and possible subscript 106 end all cases have been listed end exit end 98 Do special actions at the start of a line 98 if cur type gt min action type then begin out start of line false case cur type of endil out binary abinary bbinary ampersand pyth_sub out2 othercases do_nothing endcases end else if cur_type end_of_line then b
41. ithmetic overflow no debug overhead This code is used in section 3 5 Labels are given symbolic names by the following definitions We insert the label exit just before the end of a procedure in which we have used the return statement defined below the label restart is occasionally used at the very beginning of a procedure and the label reswitch is occasionally used just prior to a case statement in which some cases change the conditions and we wish to branch to the newly applicable case Loops that are set up with the loop construction defined below are commonly exited by going to done or to found or to not_found and they are sometimes repeated by going to continue define exit 10 go here to leave a procedure define restart 20 go here to start a procedure again define reswitch 21 go here to start a case statement again define continue 22 go here to resume a loop define done 30 go here to exit a loop define found 31 go here when you ve found it define not found 32 go here when you ve found something else 6 Here are some macros for common programming idioms define incr amp amp 4 1 increase a variable by unity define decr amp amp 1 decrease a variable by unity define loop while true do repeat over and over until a goto happens define do_nothing empty statement define return goto exit terminate
42. lass i invalid class 80 And now we re ready to take the plunge into get next itself define switch 25 a label in get next define pass digits 85 another define pass fraction 86 and still another although goto is considered harmful procedure get neri sets cur type and cur tok to next token label switch pass digits pass fraction done found exit var c ASCII code the current character in the buffer class ASCII code its class number begin prev type cur type prev tok cur tok if empty buffer then Bring in a new line of input return if the file has ended 85 switch c buffer loc id first loc incr loc class char_class c Branch on the class scan the token return directly if the token is special or goto found if it needs to be looked up 81 found id loc loc cur tok lt lookup cur type ilk cur tok exit end 881 MFT INPUTTING THE NEXT TOKEN 431 81 define emit begin cur type cur tok id_first return end Branch on the class scan the token return directly if the token is special or goto found if it needs to be looked up 81 case class of digit class goto pass digits period_class begin class char class buffer loc if class gt period class then goto switch ignore isolated else if class lt period_class then goto pass fraction class digit class y end space class if start of line then emit i
43. ling then begin if changing then Read from change file and maybe turn off changing 48 if changing then begin Read from mf file and maybe turn on changing 46 if changing then goto restart end end end 46 Read from mf_file and maybe turn on changing 46 begin incr line if input_In mf file then input_has_ended lt true else if limit change_limit then if buffer 0 change_buffer 0 then if change limit gt 0 then check change end This code is used in section 45 47 Read from style file and maybe turn off styling 47 begin incr line if input In style file then begin styling false line 0 end end This code is used in section 45 416 INSERTING THE CHANGES MFT 848 48 Read from change_file and maybe turn off changing 48 begin incr line if input_In change_file then begin err_print Change file ended without 02 buffer 0 Q buffer 1 z limit 2 end if limit gt 1 then check if the change has ended if buffer 0 then begin if buffer 1 gt X A buffer 1 Z then buffer 1 buffer 1 z 2 lowercasify if buffer 1 x buffer 1 y then begin loc 2 err print Where is the matching Gz end else if buffer 1 z then begin prime_the_change_buffer change_changing end end end This code is used in section 45 49 At the end of the program we will tell the user if the change file had a
44. mber the end_line_class which is used only for the special character carriage_return that is placed at the end of the input buffer define carriage return 15 special code placed in buffer limit Set initial values 10 for i 0 to 9 do char class i digit class char class period class char class lt space class char_class lt percent class char_class amp string_class char_class lt 5 char_class 6 char class E 7 char_class E right_paren_class for i A to Z do char _class i letter_class for i a to z do char class i letter class char_class _ lt letter class char class 10 char_class 10 char class lt 10 char class 10 char_class lt 10 char class lt 11 char class lt 11 char_class lt 12 char class lt 12 char class lt 13 char class 13 char_class E 13 char class lt 14 char_class lt 14 char_class 15 char_class amp lt 15 char_class 15 char_class E 15 char class 16 char class lt 16 char_class left_bracket_class char_class lt right bracket class char class 19 char class lt 19 for i 0 to u 1 do char class i invalid class char class carriage return end line class for i 127 to 255 do char_c
45. mpty buffer lt false end This code is used in section 80 432 LOW LEVEL OUTPUT ROUTINES MFT 886 86 Low level output routines The TEX output is supposed to appear in lines at most line length characters long so we place it into an output buffer During the output process out line will hold the current line number of the line about to be output Globals in the outer block 9 out buf array 0 line length of ASCII code assembled characters out ptr 0 line_length number of characters in out buf outline integer coordinates of next line to be output 87 The flush buffer routine empties the buffer up to a given breakpoint and moves any remaining characters to the beginning of the next line If the per cent parameter is true a 4 is appended to the line that is being output in this case the breakpoint b should be strictly less than line_length If the per cent parameter is false trailing blanks are suppressed The characters emptied from the buffer form a new line of output procedure flush buffer b eight bits per_cent boolean outputs out buf 1 b where b out ptr label done var j k 0 line length begin j b if per_cent then remove trailing blanks loop begin if 0 then goto done if out buf j 4 u then goto done decr j end done for k 1 to j do write tex file xchr out buf k if percent then write tex_file zchr write_ln tex_file incr out line
46. n 58 60 If the token is new it will be placed in position p name ptr otherwise p will point to its existing location Compute the name location p 60 p hash hj while p Z 0 do begin if length p l then Compare name p with current token goto found if equal 61 p link pl end p name_ptr the current token is new link p lt hash h hash h p insert p at beginning of hash list found This code is used in section 58 61 Compare name p with current token goto found if equal 61 begin i id_first k byte start p while i lt id_loc A buffer i byte mem Kk do begin incr i incr k end if i id loc then goto found all characters agree end This code is used in section 60 862 MFT DATA STRUCTURES 419 62 When we begin the following segment of the program p name_ptr Enter a new name into the table at position p 62 begin if byte ptr 1 gt maz_bytes then overflow byte memory if name_ptr 1 gt max names then overflow name i id first get ready to move the token into byte mem while 7 lt id loc do begin byte mem byte ptr buffer i incr byte ptr incr i end incr name ptr byte start name ptr byte ptr Assign the default value to ilk p 63 end This code is used in section 58 420 INITIALIZING THE PRIMITIVE TOKENS MFT 863 63 Initializing the primitive tokens Each token read by MFT is recognized as belonging
47. n out else out2 end done out goto reswitch end This code is used in section 106 108 The tricky thing about comments is that they might contain We scan ahead for this and replace the second by a carriage_return Translate a comment and goto restart unless there s a segment 108 begin if cur_type comment then out2 9 id first lt loc while loc lt limit buffer loc 4 do incr loc copy id first if loc limit then begin start of line true iner loc k lt loc while k lt limit A buffer k 4 do iner k buffer k carriage_return end else begin if out buf out_ptr then out u out4 p a x goto restart end end This code is used in section 97 109 Copy the rest of the current input line to the output then goto restart 109 begin id first lt loc loc lt limit copy id_first if out_ptr 0 then begin out_ptr 1 out buf 1 u end goto restart end This code is used in section 97 8110 MFT TRANSLATION 439 110 Wind up a line of translation and goto restart or finish a segment and goto reswitch 110 begin out if loc lt limit A cur_type end_of_line then begin cur_type recomment goto reswitch end else begin out4 p a r goto restart end end This code is used in section 97 111 Change the translation format of tokens and goto
48. ndentation else goto switch end line class emit end_of line string_class Get a string token and return 82 isolated classes goto found invalid_class Decry the invalid character and goto switch 84 othercases do nothing letters etc endcases while char_class buffer loc class do incr loc goto found pass digits while char_class buffer loc digit_class do incr loc if buffer loc 4 then goto done if char_class buffer loc 1 4 digit_class then goto done incr loc pass fraction repeat incr loc until char_class buffer loc Z digit class done emit numeric token This code is used in section 80 82 Get a string token and return 82 loop begin if buffer loc then begin incr loc emit string token end if loc limit then Decry the missing string delimiter and goto switch 83 iner loc end This code is used in section 81 83 Decry the missing string delimiter and goto switch 83 begin err_print Incomplete string will be ignored goto switch end This code is used in section 82 84 Decry the invalid character and goto switch 84 begin err print Invalid character will be ignored goto switch end This code is used in section 81 85 Bring in a new line of input return if the file has ended 85 begin get_line if input_has_ended then emit end_of_file buffer limit carriage return loc 0 start of line true e
49. of standard ASCII although not necessarily using the ASCII codes to represent them the following assignment statements initialize most of the zchr array properly without needing any system dependent changes On the other hand it is possible to implement MFT with less complete character sets and in such cases it will be necessary to change something here Set initial values 10 schr 40 y zchr 41 zchr 42 E zchr 43 zchr 44 55 schr 45 A zchr 46 7 amp 7 zchr 47 E 7777 zchr 50 4 C zchr 51 7 zchr 52 E 7 7 zchr 53 zchr 54 7 7 zchr 55 7 7 zchr 56 7 7 zchr 57 7 7 zchr 60 0 zchr 61 717 xachr 62 E 2 zchr 63 3 zchr 64 747 xachr 65 5 zchr 66 767 achr 67 7 schr 70 8 zchr 71 E 797 zchr 72 E 7 7 zchr 73 7 7 zchr 74 E lt schr 75 zchr 76 gt xchr 77 E zchr 100 707 xchr 101 A zxchr 102 4 B xchr 103 C achr 104 lt D zchr 105 E zchr 106 F zchr 107 G schr 110 4 H xchr 111 lt 1 xchr 112 E 737 xchr 113 E K zchr 114 E L schr 115 4 M7 zchr 116 N zchr 117 E 707 zchr 120 P zchr 121 Q zchr 122 E R zchr 123
50. ormat of tokens and goto restart or reswitch 111 Used in section 97 Check that all changes have been read 49 Used in section 112 Compare name p with current token goto found if equal 61 Used in section 60 Compiler directives 4 Used in section 3 Compute the hash code h 59 Used in section 58 Compute the name location p 60 Used in section 58 Constants in the outer block 8 Used in section 3 Copy the rest of the current input line to the output then goto restart 109 Used in section 97 Decry the invalid character and goto switch 84 Used in section 81 Decry the missing string delimiter and goto switch 83 Used in section 82 Do special actions at the start of a line 98 Used in section 97 Enter a new name into the table at position p 62 Used in section 58 Error handling procedures 29 31 Used in section 3 Get a string token and return 82 Used in section 81 Globals in the outer block 9 15 20 23 25 27 34 36 51 53 55 72 74 75 77 78 86 Used in section 3 If the current line starts with y report any discrepancies and return 43 Used in section 42 Initialize the input system 44 Used in section 112 Local variables for initialization 14 56 Used in section 3 Move buffer and limit to change buffer and change_limit 41 Used in sections 38 and 42 Print error location based on input buffer 30 Used in section 29 Print the job history 113 Used in section 112 Print warning message break the line re
51. print Change file ended after 0x return end until limit gt 0 This code is used in section 38 41 Move buffer and limit to change_buffer and change_limit 41 begin change_limit limit if limit gt 0 then for k 0 to limit 1 do change buffer k buffer k end This code is used in sections 38 and 42 414 INSERTING THE CHANGES MFT 842 42 The following procedure is used to see if the next change entry should go into effect it is called only when changing is false The idea is to test whether or not the current contents of buffer matches the current contents of change_buffer If not there s nothing more to do but if so a change is called for All of the text down to the y is supposed to match An error message is issued if any discrepancy is found Then the procedure prepares to read the next line from change_file procedure check_change switches to change_file if the buffers match label exit var n integer the number of discrepancies found k 0 buf_size index into the buffers begin if lines_dont_match then return n 0 loop begin change_changing now it s true y incr line if input In change file then begin err print Change file ended before Cy change limit 0 change changing false again return end If the current line starts with y report any discrepancies and return 43 Move buffer and limit to change_buffer and change_limit 41 ch
52. reover blank spaces at the beginning of a line are converted to quads of indentation in the output Thus the user has full control over the indentation and line breaks Each line of input is translated independently of the others A slight change to METAFONT s comment convention allows further control Namely indicates that the remainder of an input line should be copied verbatim to the output this interrupts the translation and forces MFT to produce a certain result Furthermore token token introduces a change in MFT s formatting rules all tokens after the first will henceforth be translated according to the current conventions for token The tokens must be symbolic i e not numeric or string tokens For example the input line 44 addto fill draw filldraw says that the fill draw and filldraw operations of plain METAFONT should be formatted as the primitive token addto i e in boldface type Without such reformatting commands MFT would treat fill like an ordinary tag or variable name In fact you need a reformatting command even to get parentheses to act like delimiters METAFONT comments which follow a single 4 sign should be valid TEX input But METRFONT material can be included in within a comment this will be translated by MFT as if it were not in a comment For example a phrase like make x2r zero will be translated into make x_ 2r zero Th
53. rror handling procedures 29 procedure jump out begin goto end of MFT end 32 MFT REPORTING ERRORS TO THE USER 411 32 Sometimes the program s behavior is far different from what it should be and MFT prints an error message that is really for the MFT maintenance person not the user In such cases the program says confusion indication of where we are define confusion t fatal error This can t happen C t 7 33 An overflow stop occurs if MFT s tables aren t large enough define overflow fatal error Sorry u 8 ucapacity exceeded 412 INSERTING THE CHANGES MFT 834 34 Inserting the changes Let s turn now to the low level routine get line that takes care of merging change_file into mf file The get line procedure also updates the line numbers for error messages This routine was copied from WEAVE but updated to include styling Globals in the outer block 9 line integer the number of the current line in the current file other line integer the number of the current line in the input file that is not currently being read temp_line integer used when interchanging line with other line limit 0 buf_size the last character position occupied in the buffer loc 0 buf size the next character position to be read from the buffer input has ended boolean if true there is no more input changing boolean if true the current line is from change file
54. rs can type things like instead of lt gt and so that MFT can echo the page breaks found in its input People with extended character sets can assign codes arbitrarily giving an zchr equivalent to whatever characters the users of MFT are allowed to have in their input files Appropriate changes to MFT s char class table should then be made Unlike TEX each installation of METAFONT has a fixed assignment of category codes called the char_class Such changes make portability of programs more difficult so they should be introduced cautiously if at all Set initial values 10 for i 0 to 87 do zchr i for ic 177 to 377 do zchr i y 818 MFT THE CHARACTER SET 407 18 The following system independent code makes the zord array contain a suitable inverse to the infor mation in zchr Note that if zchr i xchr j where i lt j lt 177 the value of zord zchr i will turn out to be j or more hence standard ASCII code numbers will be used instead of codes below 40 in case there is a coincidence Set initial values 10 for i first text char to last text char do xord chr i lt 177 for i 200 to 377 do zord rchr i lt i for i 1 to 176 do zord xchr i i 408 INPUT AND OUTPUT MFT 819 19 Input and output The I O conventions of this program are essentially identical to those of WEAVE Therefore people who need to make modifications should be able to do so without too m
55. sn gA i de T N IN ON ON ON ON oN oN OS oo a 2 2 mm E soos 8 E 2 E Pp a DOR 2 Henn OU sh O AHA LI pm Se A NA A A IN a S Si a nn N N TAT om o ss amp en S dl S B gt un Ea PBaOOTHKR EH YO WH GAH m T T7 e 9 e um e cu e a m um m gt 2 w E v p a H O G d Qoo w Usdoptu amp E m T 30m um ee a 305 us um dm gt TR c E WEN O NENNEN A NE 9 2 22725 A ou 2 p ouvonAaovs oomno S SSA Bu L zz A AIDA Bu Nani A A A ign m p aes T age ETA Tros T an SS SS OS Tagan Ta Tar RX AAA A s I es z E im m mum um xim im ncm ms o p 4 o T 80 nn 8 ka S b0 amp 0 80 0 0 0 0 60 60 50 50 50 Es d MEPA Scr anase com DE IE JEDE en OR L2 X2 xXx nn SIR Dan nn Ei A RN a oo oS S t ES pu ur ur a0 z qe tue 5 de 8 52 Prae od cz A E DANDO dS a aaa dddqdadsd a es E Y E 9r A ER Sp P P P CER RA amp a U E EE E EC er O nn nn SS dl M NN NN NNN nN oom AA AAAA Innen SA SSA a ZG o memo S e um E S VEDO AS fo r4 ARS HH GOES OE CECE ARR RR SEO OE OO A AA A A A A A A Ad zz B9 ARA OS A ISSN rae UA oc m EEE A es 9 RR RR ea NNN RN No NE RR NNN TN ON ON TN ee TN OTN eT ae ooo oe E nn ea iO o B aa Oo Clu cm gm m m OE ES mS m 4m m 0m de d EH vv O00 00 00 0 u un Za EX g PR E S p EX SE H EH H s s S s Ea 2 508 S 9 ml ei Nn R ED A dE m nr a Neu Re Tr Re A RE G D cem nm
56. ss_fraction 80 81 path_join 63 65 100 444 INDEX per_cent 87 percent_class 78 79 period_class 78 79 81 prev_tok 75 80 106 107 prev_type 75 80 100 106 107 prime_the_change_buffer 38 44 48 print 20 29 30 31 92 print_In 20 30 92 112 print_nl 20 28 92 113 pri 64 65 70 71 pr10 64 65 66 67 69 70 71 prii 64 65 66 67 68 69 70 71 pri2 64 66 68 69 71 pr13 64 67 68 70 71 pri4 64 67 68 pri5 64 68 pri6 64 68 71 pr17 64 70 pr2 64 65 66 70 71 pr3 64 65 66 67 69 70 71 pr4 64 65 66 67 69 70 71 pr5 64 65 66 67 69 70 71 pr6 64 65 66 67 69 70 pr7 64 65 66 67 69 70 71 pr8 64 65 66 67 69 71 pr9 64 66 69 70 71 pyth_sub 63 70 98 102 read_In 28 recomment 63 97 110 reset 24 restart 5 45 97 98 108 109 110 111 reswitch 5 97 101 106 107 110 111 return 5 6 rewrite 21 26 right_bracket_class 78 79 right_paren_class 78 79 semicolon 63 65 101 set_format 63 71 97 sharp 63 71 101 106 sizteen_bits 50 51 55 Sorry x capacity exceeded 33 space_class 78 79 81 special_tag 63 66 97 106 107 spotless 9 10 113 sprl 64 spr10 64 sprii 64 spr12 64 spr13 64 sprl4 64 spr15 64 spr16 64 MFT 8115 spr17 64 spr2 64 spr3 64 spr4 64 sprd 64 spr6 64 spr7 64 spr8 64 spr9 64 start_of_line 77 81 85 97 98 108 111 string_class 78
57. t character is buffer id first and the last is buffer id_loc 1 Globals in the outer block 9 id first O buf size where the current token begins in the buffer id_loc O buf_size just after the current token in the buffer hash array 0 hash_size of sixteen bits heads of hash lists 56 Initially all the hash lists are empty Local variables for initialization 14 h 0 hash_size index into hash head array 418 DATA STRUCTURES MFT 857 57 Set initial values 10 for h 0 to hash size 1 do hash h 0 58 Here now is the main procedure for finding tokens function lookup name pointer finds current token label found var i 0 buf size index into buffer h 0 hash_size hash code k 0 max bytes index into byte mem l 0 buf size length of the given token p name_pointer where the token is being sought begin l id loc id_first compute the length Compute the hash code h 59 Compute the name location p 60 if p name_ptr then Enter a new name into the table at position p 62 lookup p end 59 A simple hash code is used If the sequence of ASCII codes is c C2 Cm its hash value will be 2912 42720 cn mod hash size Compute the hash code h 59 h buffer id first i id_first 1 while i lt id loc do begin h h h buffer i mod hash size incr i end This code is used in sectio
58. te_ptr 52 53 54 62 72 byte_start 50 51 52 53 54 55 61 62 72 93 94 106 107 c 80 carriage_return 79 85 104 108 Change file ended 40 42 48 Change file entry did not match 49 change_buffer 36 37 38 41 42 46 49 change_changing 35 42 44 48 MFT 8115 change_file 3 23 24 30 34 36 39 40 42 48 change_limit 36 37 38 41 42 46 49 changing 30 34 35 36 38 42 44 45 49 char 13 char_class 17 78 79 80 81 105 107 character set dependencies 17 79 check_change 42 46 chr 13 15 18 class 80 81 colon 63 65 100 command 63 65 66 70 71 100 comment 63 71 97 108 confusion 32 continue 5 38 39 copy 96 99 105 107 108 109 cur_tok 64 72 73 75 76 80 81 99 100 101 102 103 105 106 107 111 cur_type 75 76 80 81 97 98 101 106 107 108 110 111 d 91 decr 6 28 87 91 digit_class 78 79 81 105 do_nothing 6 81 98 do_the_translation 97 112 done 5 38 39 80 81 87 97 107 double_back 63 65 101 eight_bits 50 75 87 else 7 emit 81 82 85 empty_buffer 77 80 85 97 111 end 7 end_line_class 78 79 81 end_of_file 63 85 97 end_of_line 63 76 81 97 98 101 110 111 end_of MFT 3 31 112 endcases 7 endit 63 65 66 71 98 100 101 eof 28 eoln 28 err_print 29 35 39 40 42 43 48 49 83 84 111 error 28 29 31 error message 9 113 exit 5 6 37
59. then looking at strings of bytes signified by hash h link hash h link link hash h until either finding the desired name or encountering a zero A name_pointer variable which signifies a name is an index into byte start The actual sequence of characters in the name pointed to by p appears in positions byte start p to byte_start p 1 1 inclusive of byte mem We usually have byte start name ptr byte_ptr which is the starting position for the next name to be stored in byte mem define length byte start tt 1 byte start t the length of a name Types in the outer block 12 name pointer 0 max_names identifies a name 53 Globals in the outer block 9 name_ptr name pointer first unused position in byte_start byte_ptr 0 max_bytes first unused position in byte mem 54 Set initial values 10 byte start 0 0 byte ptr 0 byte start 1 0 this makes name 0 of length zero name_ptr 1 55 The hash table described above is updated by the lookup procedure which finds given name and returns a pointer to its index in byte start The token is supposed to match character by character If it was not already present it is inserted into the table Because of the way MFT s scanning mechanism works it is most convenient to let lookup search for a token that is present in the buffer array Two other global variables specify its position in the buffer the firs
60. tms unm unm um m S nm E SANAR AA AAA 4AVAG 2 ZA i cd E Um SES ES m m 0m R0 m Ro m 0m Ex ume e mU m IE ELE A m mt 2mo im Re Reim Dm m m dee ee ee Gp dom m a Hd owdddogddodgdgg s ue 9 M P o gt M E SJ P x o E 4 Es E E P P P a H A 9 A n 9 eh 80 o E MC UE E A E E OE A NC EE NC ec NC NR Past CO AA IAN WT LL AA AAA Sit NC an Sai Sa nn E g N ON NN NN NN nN oom RR RR RN RR RRR RR RR oN EE nn CO Z F FF FE Q OF O gt om s SS ae eS mo zm dam umm et a HH HH HH HHHHHM Eu e ME ee CGU ears m Horti dur m Hope E crura um m I Te I Si lt Nri a a a a td YA STA Sto B oett um OS um unm unm um my T umm mH EL IT IT IT IT IN IT IN EL IT IN IT IN E gt IN IN N N IN INN N TTS zo O ds e 2 o 2c q oz 2 2 sS jq c x c m coco 2 2 d Oz S anu PPPPPPPPPPPP e 2 M B8 A p H B B 2 A S El A P A A ta Es A B B 2 S nu o m 2 S Sau eye ee E T CERE dn Wa II opa e Cast pur SS ng es A EX wm Me d son Y MA C 9 C C O0 C c 95 95 10 BOO c XO SO XO KO ce N N mn An lo R OCTO TO INT kee 2 ee ee oL oL oL S Sg A A A LEE Se GE Ee LEE A A O amp E LAN j amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp amp E amp E amp E Q E Y n 28282228222 QA Y 68 425 INITIALIZING THE PRIMITIVE TOKENS MFT 869
61. turn 92 Used in section 91 Read from change_file and maybe turn off changing 48 Used in section 45 Read from mf_file and maybe turn on changing 46 Used in section 45 Read from style_file and maybe turn off styling 47 Used in section 45 Scan the file name and output it in typewriter type 104 Used in section 103 Set initial values 10 16 17 18 21 26 54 57 76 79 88 90 Used in section 3 Skip over comment lines in the change file return if end of file 39 Used in section 38 Skip to the next nonblank line return if end of file 40 Used in section 38 Store all the primitives 65 66 67 68 69 70 71 Used in section 112 Store all the translations 73 Used in section 112 Translate a comment and goto restart unless there s a segment 108 Used in section 97 Translate a numeric token or a fraction 105 Used in section 97 Translate a string token 99 Used in section 97 Translate a subscript 107 Used in section 106 Translate a tag and possible subscript 106 Used in section 97 Types in the outer block 12 13 50 52 Used in section 3 Wind up a line of translation and goto restart or finish a segment and goto reswitch 110 Used in section 97
62. ve is intersectiontimes which is 17 letters long define spr17 buffer 17 E cur tok lt lookup ilk cur tok define spr16 buffer 16 spr17 define spr15 buffer 15 spr16 define spr14 buffer 14 spr15 define spr13 buffer 13 spr14 define spr12 buffer 12 tt spr13 define spr11 buffer 11 spr12 define spr10 buffer 10 spr11 define spr9 buffer 9 spr10 define spr amp buffer 8 t spr9 define spr7 s buffer v E spr8 define spr6 buffer 6 spr7 define spr5 tt buffer 5 spr6 define spr4 buffer 4 sprd define spr3 buffer 3 spr4 define spr2 buffer 2 E tt spr3 define spr amp buffer 1 spr2 define pr id first 17 spr17 define pr2 id first 16 spr16 define pr id first 15 spr15 define pr4 id first 14 spr14 define prd id first 13 spr13 define pr6 id first 12 spr12 define pr7 id first 11 spr11 define pr id first 10 spr10 define pr9 id first 9 spr9 define pr10 id first 8 spr amp define pri1 id first lt 7 spr7 define pr12 id first 6 spr6 define pr13 id first 5 sprd define pr 4 id_first 4 spr4 define pr 5 id first 3 spr3 define pr16 id first 2 spr2 define pr17 id first 1 spri 422 INITIALIZING THE PRIMITIVE TO

Download Pdf Manuals

image

Related Search

Related Contents

Dossier de presse    INT-22  取扱説明書 - GENTOS  OK - Dungs  Eシリーズ電磁流量計(分離形)  HP Jornada Série 520 Pocket PC Guia do Usuário  目 次 - 山崎産業  Samsung SGH-X480 Manual de utilizare  radio-navigationssystem amundsen+ betriebsanleitung  

Copyright © All rights reserved.
Failed to retrieve file