📄 awkc++.ps
字号:
10 R f
( if)1 92( Similarly,)1 454( again.)1 272(until its value is needed)4 964 4 1834 2290 t
10 CW f
($0)3647 2290 w
10 R f
(is explicitly assigned to, that invali-)5 1458 1 3798 2290 t
(dates)936 2410 w
10 CW f
($1)1166 2410 w
10 R f
( some form of lazy evaluation is called for.)8 1716( Thus)1 250(, etc.)1 191 3 1286 2410 t
( the interpreter,)2 624( In)1 139(To make all of this work, it is necessary to intercept every reference to any field.)15 3307 3 1186 2540 t
( a run-)2 264( requires)1 349( That)1 236(there is type information in each variable that indicates whether the variable is a field.)14 3471 4 936 2660 t
( fields as)2 357(time test for each access to any variable, so it seems better in the generated C++ code to implement)18 3963 2 936 2780 t
(a separate type, thus moving the test to compile-time.)8 2137 1 936 2900 t
(Thus fields are implemented as a new type, called a)9 2152 1 1186 3030 t
10 CW f
(Field)3373 3030 w
10 R f
( initial try was to derive)5 1007(. The)1 240 2 3673 3030 t
10 CW f
(Field)4956 3030 w
10 R f
(from)936 3150 w
10 CW f
(Awk)1159 3150 w
10 R f
( this doesn't work because operations performed)6 1958(, so that most operations would be inherited, but)8 1959 2 1339 3150 t
( and conversion operations in favor of implicit ones)8 2112(on derived objects may bypass the explicit assignment)7 2208 2 936 3270 t
(and thus avoid the code meant to trap references to fields.)10 2303 1 936 3390 t
(A)1186 3520 w
10 CW f
(Field)1295 3520 w
10 R f
(really isn't an)2 573 1 1632 3520 t
10 CW f
(Awk)2242 3520 w
10 R f
(, since it may never be used as a plain)9 1625 1 2422 3520 t
10 CW f
(Awk)4085 3520 w
10 R f
(without taking the side)3 953 1 4303 3520 t
( a)1 69( Thus)1 250(effects into account.)2 806 3 936 3640 t
10 CW f
(Field)2086 3640 w
10 I f
(contains)2411 3640 w
10 R f
(an)2775 3640 w
10 CW f
(Awk)2894 3640 w
10 R f
(:)3074 3640 w
9 CW f
( an individual field)3 1080( //)1 270(class Field {)2 702 3 1224 3810 t
(private:)1332 3920 w
(Awk a;)1 324 1 1656 4030 t
(void rvalue\(\), lvalue\(\);)2 1296 1 1656 4140 t
(operator double\(\) { rvalue\(\); return \(double\) a; })7 2700 1 1656 4250 t
(public:)1332 4360 w
(friend double operator +\(Field &x, int d\) { return \(double\) x + d; })13 3672 1 1656 4470 t
(Field &operator =\(Field &x\) { x.rvalue\(\); lvalue\(\); ... })8 3078 1 1656 4580 t
(// ...)1 324 1 1656 4690 t
(};)1224 4800 w
10 R f
( of the field will be used, a function)8 1647(Within this class definition, in every context where the value)9 2673 2 936 4980 t
10 CW f
(Field::rvalue)936 5100 w
10 R f
( any context where)3 759( In)1 134( necessary field-building is performed.)4 1548(is called to ensure that any)5 1072 4 1743 5100 t
(a field will be assigned to, a function)7 1476 1 936 5220 t
10 CW f
(Field::lvalue)2437 5220 w
10 R f
(is called to build fields and to record any informa-)9 2014 1 3242 5220 t
( The)1 211(tion about invalid state.)3 957 2 936 5340 t
10 CW f
(lvalue)2135 5340 w
10 R f
(function must also be called from a few functions such as)10 2346 1 2526 5340 t
10 CW f
(sub)4902 5340 w
10 R f
(and)5112 5340 w
10 CW f
(gsub)936 5460 w
10 R f
(that can alter fields implicitly.)4 1202 1 1201 5460 t
( explicit variables of type)4 1043(With one exception, there are no)5 1332 2 1186 5590 t
10 CW f
(Field)3593 5590 w
10 R f
(; rather, fields are members of an)6 1363 1 3893 5590 t
(array managed by a class called)5 1265 1 936 5710 t
10 CW f
(Fields:)2226 5710 w
9 CW f
( manages an array of Field's)5 1512( //)1 216(class Fields {)2 756 3 1224 5880 t
(private:)1332 5990 w
(Field fields[100];)1 972 1 1656 6100 t
(public:)1332 6210 w
(Field &operator\(\)\(int n\) { return fields[n]\); })6 2538 1 1656 6320 t
(};)1224 6430 w
( the fields are stored here)5 1458( //)1 486(Fields F;)1 486 3 1224 6650 t
10 R f
(The only)1 365 1 936 6830 t
10 CW f
(Fields)1333 6830 w
10 R f
(operator is)1 431 1 1725 6830 t
10 CW f
(\(\))2189 6830 w
10 R f
(, which is used to access an individual)7 1582 1 2309 6830 t
10 CW f
(Field)3924 6830 w
10 R f
( constructions like)2 749(. Thus)1 283 2 4224 6830 t
10 CW f
(F\(0\))936 6950 w
10 R f
(,)1176 6950 w
10 CW f
(F\(i+j\))1226 6950 w
10 R f
(, and so on return a reference to the corresponding)9 2005 1 1586 6950 t
10 CW f
(Field)3616 6950 w
10 R f
(.)3916 6950 w
(Since a)1 298 1 1186 7080 t
10 CW f
(Field)1516 7080 w
10 R f
(does not inherit from an)4 992 1 1849 7080 t
10 CW f
(Awk)2874 7080 w
10 R f
(, and since a)3 517 1 3054 7080 t
10 CW f
(Field)3604 7080 w
10 R f
(can be converted to an)4 929 1 3937 7080 t
10 CW f
(Awk)4899 7080 w
10 R f
(and)5112 7080 w
( possible combinations of)3 1046(vice versa, it is again necessary to provide overloaded operators for all)11 2903 2 936 7200 t
10 CW f
(Field)4917 7200 w
10 R f
(s)5217 7200 w
cleartomark
showpage
saveobj restore
end
%%PageBoundingBox: 83 56 543 728
%%EndPage: 6 6
%%Page: 7 7
%%PageBoundingBox: (atend)
DpostDict begin
/saveobj save def
mark
7 pagesetup
10 R f
(with other types, and to add some operators to class)9 2064 1 936 840 t
10 CW f
(Awk)3025 840 w
10 R f
(for combinations of)2 788 1 3230 840 t
10 CW f
(Awk)4043 840 w
10 R f
(and)4248 840 w
10 CW f
(Field)4417 840 w
10 R f
(.)4717 840 w
(It is also necessary to deal with the)7 1451 1 1186 970 t
8 R f
(AWK)2670 970 w
10 R f
(built-in variable)1 650 1 2894 970 t
10 CW f
(NF)3578 970 w
10 R f
(, which records the current number of)6 1558 1 3698 970 t
(fields. If)1 374 1 936 1090 t
10 CW f
(NF)1346 1090 w
10 R f
( easiest way to do this)5 930( The)1 215( least counted.)2 594(is referred to, the fields must be computed, or at)9 2015 4 1502 1090 t
( make)1 245(turned out to be to)4 745 2 936 1210 t
10 CW f
(NF)1955 1210 w
10 R f
(a variable of type)3 707 1 2104 1210 t
10 CW f
(Field)2840 1210 w
10 R f
(and to add a bit of special code in the)9 1525 1 3169 1210 t
10 CW f
(lvalue)4723 1210 w
10 R f
(and)5112 1210 w
10 CW f
(rvalue)936 1330 w
10 R f
( another type and another 75 functions to)7 1688( thought of adding)3 760( \(The)1 246(routines to handle it correctly.)4 1233 4 1329 1330 t
(manage it was more than I could bear.\))7 1557 1 936 1450 t
10 B f
(5. Arrays)1 424 1 936 1690 t
8 R f
(AWK)1186 1820 w
10 R f
(arrays are implemented as a separate class)6 1725 1 1409 1820 t
10 CW f
(Array)3167 1820 w
10 R f
(. Thus)1 283 1 3467 1820 t
10 CW f
(Awk v[10])1 513 1 3783 1820 t
10 R f
(is not an)2 355 1 4329 1820 t
8 R f
(AWK)4717 1820 w
10 R f
(array in)1 315 1 4941 1820 t
(the traditional sense, but)3 1016 1 936 1940 t
10 CW f
(Array v)1 398 1 1990 1940 t
10 R f
( specific implementation of an array doesn't matter here; the)9 2522(is. The)1 309 2 2425 1940 t
( test, and element)3 756(only visible operations are subscripting to implement associative arrays, membership)9 3564 2 936 2060 t
(deletion:)936 2180 w
9 CW f
(class Array {)2 702 1 1224 2350 t
(private:)1332 2460 w
(// standard hash table here)4 1458 1 1656 2570 t
( install if not found)4 1134( //)1 270(Awk &lookup\(cchar *\);)2 1134 3 1656 2680 t
(public:)1332 2790 w
(Array\(\);)1656 2900 w
( return lookup\(s\); })3 1080( {)1 486(Awk &operator []\(Awk &s\))3 1296 3 1656 3120 t
( return lookup\(s\); })3 1080( {)1 378(Awk &operator []\(Field &s\))3 1404 3 1656 3230 t
( return lookup\(s\); })3 1080( {)1 378(Awk &operator []\(cchar *s\))3 1404 3 1656 3340 t
( return lookup\(ftoa\(f\)\); })3 1404( {)1 378(Awk &operator []\(double f\))3 1404 3 1656 3450 t
( return lookup\(ftoa\(i\)\); })3 1404( {)1 540(Awk &operator []\(int i\))3 1242 3 1656 3560 t
(// etc.)1 378 1 1656 3670 t
(};)1224 3780 w
10 R f
(Again, an explicit rule is needed for)6 1529 1 936 3960 t
10 CW f
(int)2506 3960 w
10 R f
(; otherwise,)1 482 1 2686 3960 t
10 CW f
(x[0])3209 3960 w
10 R f
(is ambiguous since)2 795 1 3490 3960 t
10 CW f
(0)4327 3960 w
10 R f
(is a)1 153 1 4429 3960 t
10 CW f
(double)4624 3960 w
10 R f
(and a)1 230 1 5026 3960 t
10 CW f
(char*)936 4080 w
10 R f
(.)1236 4080 w
10 B f
( Statements)1 496(6. Print)1 347 2 936 4320 t
10 R f
(The treatment of the)3 848 1 1186 4450 t
8 R f
(AWK)2071 4450 w
10 CW f
(print)2300 4450 w
10 R f
(and)2638 4450 w
10 CW f
(printf)2820 4450 w
10 R f
( In)1 146(statements present some interesting problems.)4 1892 2 3218 4450 t
8 R f
(AWK)936 4570 w
10 R f
(, one writes)2 463 1 1127 4570 t
9 CW f
( print values of 3 expressions)5 1620( #)1 486(print e1, e2, e3)3 864 3 1224 4740 t
( print e4, redirecting into file e5)6 1890( #)1 648(print e4 > e5)3 702 3 1224 4850 t
( print e6 and e7, piping output into e8)8 2106( #)1 432(print e6, e7 | e8)4 918 3 1224 4960 t
10 R f
(The)936 5140 w
10 CW f
(e)1129 5140 w
10 R f
( like this,)2 398( goal is to generate code that looks as much as possible)11 2343( The)1 218(s are arbitrary expressions.)3 1108 4 1189 5140 t
( translation has to be legal C++)6 1292( The)1 212(something that is natural for human readers and reasonably efficient.)9 2816 3 936 5260 t
(and provide)1 477 1 936 5380 t
8 R f
(AWK)1436 5380 w
10 R f
( are separated by the value of the variable)8 1685( values)1 308(semantics when executed:)2 1048 3 1655 5380 t
10 CW f
(OFS)4725 5380 w
10 R f
(\(usually)4934 5380 w
(a space\) and an)3 611 1 936 5500 t
10 CW f
(ORS)1572 5500 w
10 R f
(\(usually a newline\) is added at the end.)7 1558 1 1777 5500 t
( number of arguments of a single)6 1368(One solution is to define a print function that takes a fixed \(large\))12 2702 2 1186 5630 t
( that will be)3 499( are defined that make a print arg from each kind of object)12 2435( Constructors)1 570(type, a ``print arg''.)3 816 4 936 5750 t
( arguments are used to)4 926( Default)1 356( a default value that marks the end of the real arguments.)11 2344( is)1 98(printed. There)1 596 5 936 5870 t
(convert calls into the full-length list; short versions are provided for common cases.)12 3343 1 936 5990 t
cleartomark
showpage
saveobj restore
end
%%PageBoundingBox: 83 177 536 728
%%EndPage: 7 7
%%Page: 8 8
%%PageBoundingBox: (atend)
DpostDict begin
/saveobj save def
mark
8 pagesetup
9 CW f
(class Prarg {)2 702 1 1224 830 t
(int t;)1 324 1 1656 940 t
(union {)1 378 1 1656 1050 t
(cchar *sval;)1 756 1 2088 1160 t
(int ival;)1 702 1 2088 1270 t
(double dval;)1 702 1 2088 1380 t
(};)1656 1490 w
(public:)1332 1600 w
( void marks the end)4 1026( //)1 216( t = 'v'; ival = 0; })7 1134(Prarg\(\) {)1 1350 4 1656 1710 t
( t = 'i'; ival = n; })7 1134( {)1 702(Prarg\(int n\))1 648 3 1656 1820 t
( t = 'd'; dval = d; })7 1134( {)1 540(Prarg\(double d\))1 810 3 1656 1930 t
( t = 's'; sval = s; })7 1134( {)1 540(Prarg\(cchar *s\))1 810 3 1656 2040 t
( t = 's'; sval = a; })7 1134( {)1 648(Prarg\(Awk &a\))1 702 3 1656 2150 t
( a.rvalue\(\); t = 's'; sval = a; })8 1782( {)1 540(Prarg\(Field &a\))1 810 3 1656 2260 t
(};)1224 2370 w
( will mark end of list)5 1188( //)1 594( Prarg0;)1 540(extern Prarg)1 702 4 1224 2600 t
( etc.)1 270( //)1 216( Prarg& = Prarg0, const Prarg& = Prarg0,)7 2160(void print\(const)1 1026 4 1224 2820 t
(const Prarg& = Prarg0, const Prarg& = Prarg0\);)7 2484 1 1980 2930 t
10 R f
(Now)936 3110 w
10 CW f
(print)1161 3110 w
10 R f
(statements look exactly the same as they do in)8 1896 1 1492 3110 t
8 R f
(AWK)3419 3110 w
10 R f
( the list of expressions must)5 1149(, except that)2 497 2 3610 3110 t
(be parenthesized in all cases and there is an upper limit on the number of arguments.)15 3377 1 936 3230 t
(Redirection is handled by a separate class:)6 1691 1 1186 3360 t
9 CW f
(class Redir {)2 702 1 1224 3530 t
(char *buf;)1 540 1 1656 3640 t
(public:)1332 3750 w
( buf = s; })4 594( {)1 162(Redir\(char *s\))1 756 3 1656 3860 t
(friend void operator >\(const Redir &r, cchar *f\);)7 2646 1 1656 4080 t
(friend void operator |\(const Redir &r, cchar *f\);)7 2646 1 1656 4190 t
(};)1224 4300 w
10 R f
(A function named)2 775 1 936 4480 t
10 CW f
(Fprint)1763 4480 w
10 R f
(, which is analogous to)4 1027 1 2123 4480 t
10 CW f
(print)3202 4480 w
10 R f
(, creates a string that can be printed by)8 1754 1 3502 4480 t
10 CW f
(Redir::operator >\(Fprint,filename\))1 2009 1 936 4600 t
10 R f
(or)2973 4600 w
10 CW f
(operator |\(Fprint,filename\))1 1588 1 3084 4600 t
10 R f
( permits)1 328(. This)1 256 2 4672 4600 t
(translation of an)2 649 1 936 4720 t
8 R f
(AWK)1610 4720 w
10 R f
(statement like)1 558 1 1826 4720 t
9 CW f
(print e1, e2, e3 > e4)5 1134 1 1224 4890 t
10 R f
(into)936 5070 w
9 CW f
(Fprint\(e1, e2, e3\) > e4;)4 1296 1 1224 5240 t
10 R f
(What about)1 480 1 1186 5430 t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -