Move 1988-2004 entries into subdirs
We we move 1988-2004 entries from all of a year's winning entries in a single directory to each winner being in their own sub-directory under the given year directory.
This commit is contained in:
1 parent
1e82e8aa3e
commit
d2a42f42e8
478 files changed
No files matched your search
@@ -0,0 +1,321 @@
|
||||
/*T } ¶ ;
|
||||
ˆ
|
||||
;
|
||||
|
||||
;
|
||||
}
|
||||
{
|
||||
|
||||
{ ; ;
|
||||
; 1 {
|
||||
è { !
|
||||
} {
|
||||
; é ;
|
||||
|
||||
;
|
||||
{
|
||||
|
||||
|
||||
{ ]- } ; ; |
|
||||
í ; Q
|
||||
;
|
||||
´ë ; ; ; "û }
|
||||
} Ü; ; -ýl
|
||||
|
||||
}
|
||||
} t dÀ ;
|
||||
; +
|
||||
t2 { ì ;
|
||||
|
||||
} 1; C
|
||||
i
|
||||
; = } ; ;
|
||||
|
||||
;
|
||||
ì ; {
|
||||
|
||||
{ ê
|
||||
} { � { ï } }
|
||||
|
||||
; . {
|
||||
␍ { é } } ;
|
||||
{ ;
|
||||
; /nÈ; 5
|
||||
} ; Ú␍{ ;
|
||||
; { 1 ; } ; ¨ý } {
|
||||
|
||||
; { ; . { ; } ; ;
|
||||
; T ;
|
||||
{
|
||||
; ; Ä; ; {
|
||||
;
|
||||
{ { ; ;
|
||||
ì; ‘ ; ; ï; n!t }
|
||||
; ì!; G; t; ø; ¤ } ;
|
||||
|
||||
;
|
||||
} ; "; è# }
|
||||
;
|
||||
{
|
||||
; �$ {
|
||||
;
|
||||
; &
|
||||
|
||||
; d˜
|
||||
{
|
||||
|
||||
¶; {
|
||||
; Sé'
|
||||
{ d; ; è); �c
|
||||
{
|
||||
; ;
|
||||
; &ï*; ␍ ;
|
||||
— {
|
||||
;
|
||||
$; ¢; ,; ; $ˆd } —; ˆ; ë/Î; Î
|
||||
; a; Í ; {
|
||||
} ; j; #è1;
|
||||
}
|
||||
; Ä ; { ê5a; û␍ Ät { ï4a }
|
||||
}
|
||||
|
||||
; £;
|
||||
Û2; -
|
||||
; 8
|
||||
|
||||
} ; }
|
||||
; è8; ; Ú6Q ; aÌ { ; { ˆ
|
||||
ì }
|
||||
†; v:
|
||||
{
|
||||
?
|
||||
}
|
||||
|
||||
{ ?
|
||||
|
||||
{ ; 4r
|
||||
;
|
||||
; v=b; Û
|
||||
;
|
||||
;
|
||||
} ;
|
||||
; ; ; Þ { ú>
|
||||
} }
|
||||
{ ;
|
||||
{ Õ`
|
||||
}
|
||||
;
|
||||
;
|
||||
!;
|
||||
; 1; ; >; Ì } 1; X
|
||||
; } p ;
|
||||
;
|
||||
|
||||
; ; ;
|
||||
; ; 2 } ; vm
|
||||
2; ;1íJ
|
||||
;
|
||||
; ; Ï }
|
||||
; ÉJc; ›; d }
|
||||
} ÞG; i }
|
||||
; ; §F
|
||||
{ vl¶þV; z
|
||||
n
|
||||
¶éOc; s
|
||||
; ; ÑÞ;
|
||||
uh¶ëR } hRs; A cl,;
|
||||
; ; Z; {
|
||||
x
|
||||
lw¶êUch�{ }
|
||||
} ; àîVc }
|
||||
; Ž; >ÈD
|
||||
; G ; ; †
|
||||
;
|
||||
îX; ’ˆ
|
||||
;
|
||||
|
||||
; 2 } { é[;
|
||||
{ }
|
||||
; Þj; å; ë_; ␍y
|
||||
; D; T; ; ?j; .n; ; ã {
|
||||
|
||||
; Ú]; !; Ë; 0a
|
||||
} J ;
|
||||
; ^; .
|
||||
{ { { îc; ␍X ; ; ´;
|
||||
J {
|
||||
; ;
|
||||
} — { êf;
|
||||
; {
|
||||
; ; : } {
|
||||
{
|
||||
|
||||
; (h} ␍ }
|
||||
{ }
|
||||
} ; ; {
|
||||
; ûD; Tì Cr; ␍; I; WèsÎWQ
|
||||
; ;
|
||||
×; W { û }
|
||||
; ( ; ; }
|
||||
} ; {
|
||||
; ÿn{ k; © ; ‚; ?; %Ùk; ;
|
||||
|
||||
{ ïv;
|
||||
3{ (; h {
|
||||
|
||||
; ; z
|
||||
|
||||
; ; ]{ ; ˜ïx; S; { * } ˜; z} ; î;
|
||||
{ ; ~
|
||||
;
|
||||
U; ö
|
||||
; { ‡
|
||||
; í~;
|
||||
Ob } ; ò; UU; U{ -{ %Ú|1èƒ;
|
||||
; Q
|
||||
;
|
||||
µ{ w{ š; ;
|
||||
{ í‡; ‚; ü�
|
||||
|
||||
…
|
||||
} Ù†; ?; u
|
||||
{
|
||||
|
||||
|
||||
ƒ
|
||||
} } ; » ; ´ ; ; }
|
||||
; è
|
||||
{
|
||||
|
||||
; ; }
|
||||
; p ; ; ; Q; Ü�{ ; ; K; $ì“
|
||||
p; 1}
|
||||
4; $;
|
||||
2Q ; } {
|
||||
; $î— } ; #;
|
||||
T; 1
|
||||
; ; +; ± }
|
||||
; ;
|
||||
. ; {
|
||||
{ ; š{
|
||||
;
|
||||
{
|
||||
; ; }
|
||||
|
||||
|
||||
; { [ { ; £{ ; �; 0{
|
||||
{ ôr ; éŸ
|
||||
;
|
||||
} =; w
|
||||
|
||||
?; ;
|
||||
ä; B®lwx
|
||||
; h�h
|
||||
|
||||
} ; pj
|
||||
; ; ; ö { û§; 'n
|
||||
; ; { ) {
|
||||
; ú¤;
|
||||
;
|
||||
Q
|
||||
; f; 'r
|
||||
{
|
||||
? { ë¬; %lÂf}
|
||||
; ~©{ qÛ¨;
|
||||
{
|
||||
{ ÿ; ÂÛ¬{ œÚžl,u
|
||||
; & ;
|
||||
|
||||
{ í; G }
|
||||
; k
|
||||
; }
|
||||
;
|
||||
{
|
||||
|
||||
|
||||
; hR; ; Wß´;
|
||||
} ;
|
||||
|
||||
; ; —e; Z; ž{ N; =
|
||||
} ; <
|
||||
{ ]- Bšretur; ¡if
|
||||
else
|
||||
whil; do; nt
|
||||
char
|
||||
{ ; { pu{ }
|
||||
{ ; =
|
||||
} B
|
||||
} {
|
||||
; ø¿`ˆ; dÀ; ´ } �
|
||||
} } ; ø`; waÌ { •ma; >
|
||||
{ ; oJ
|
||||
} ÈD
|
||||
{ ; ; ; · ;
|
||||
|
||||
; Á ; ; ; ; ;
|
||||
{
|
||||
; ; €Õ; @ë ; Á; L {
|
||||
|
||||
; ØÈ ;
|
||||
*/int m[Z];
|
||||
|
||||
#define U(x)s--;T=x
|
||||
#define C(l,s)I(o==l){s;}E
|
||||
#define Q(l,o)C(l,r=P;T=T o r)
|
||||
#define O(l,o)C(l,T=o T)
|
||||
#define H(l,s)C(l,U(s))
|
||||
int
|
||||
main(){int*q,s,f,r,o,l,p,c,b;
|
||||
char*d;
|
||||
d=" \t\n;{}\0AÊP€³²‰Š@ɵ�gEÏͱ°Œ0�Ž‹q";
|
||||
b=256;
|
||||
q=m;
|
||||
g;
|
||||
o=g;
|
||||
c=g;
|
||||
c=c+g*b;
|
||||
p=c;
|
||||
I(o){W(p){o=g;
|
||||
C(59,r=2)C('{',r=5)C('}',r=8)r=0;
|
||||
I(r){r=r+g%4;
|
||||
l=1-g-r;
|
||||
W(r--){*q=q[l];
|
||||
q++;
|
||||
p--;
|
||||
}}E{I((o==32)+(o==9)+(o==10)){r=g;
|
||||
o=o%4+(r+(r==123))%8*3;
|
||||
I(8<o)o=o+g%4*9;
|
||||
o=d[o]+b;
|
||||
}*q++=o%b;
|
||||
p--;
|
||||
}}W(g!=12);
|
||||
g;
|
||||
}E{W(p--)*q++=g;
|
||||
}s=Z;
|
||||
p=0;
|
||||
W(1){o=L;
|
||||
O(17,!)O(18,-)Q(12,+)D C(10,r=T;
|
||||
s=f;
|
||||
p=X 1];
|
||||
f=X 2];
|
||||
l=X 3];
|
||||
R)C(22,s++)C(27,return T)C(21,r=T;
|
||||
U(r))C(23,T=m[T])C(19,T=m[T]++)C(25,T=m[T]--){l=o%16;
|
||||
o=o/16;
|
||||
I(l==7){l=B;
|
||||
l=l+B*b;
|
||||
}E I(7<l)l=l+B*8-1;
|
||||
H(2,f+l)H(4,f-l-4)H(3,m[f+l])H(5,m[f-l-4])H(6,c+l)H(7,m[c+l])H(12,l)H(8,l)C(9,U(p);
|
||||
p=p+l)C(11,r=X -l/2];
|
||||
I(r<3){I(r)r=putchar(T);
|
||||
E
|
||||
r=g;
|
||||
R;
|
||||
}E{X 1]=p;
|
||||
X 2]=f;
|
||||
X 3]=l;
|
||||
f=s;
|
||||
s=s-19;
|
||||
p=r;
|
||||
})C(13,p=l)C(15,I(P)p=l)C(14,I(!P)p=l);
|
||||
}}}
|
||||
@@ -0,0 +1,231 @@
|
||||
Best of Show:
|
||||
|
||||
Lennart Augustsson
|
||||
CR&T
|
||||
Stora Badhusgatan 18-20
|
||||
S-411 21 Goteborg
|
||||
Sweden
|
||||
|
||||
|
||||
Judges' comments:
|
||||
|
||||
To use:
|
||||
make august
|
||||
cat august.c test.oc | ./august > test.oo
|
||||
./august < test.oo
|
||||
|
||||
NOTE: Some compilers will compile this code into infinite loops!
|
||||
If the above cat line does not execute in a very short amount
|
||||
of time, then you may need to fix your compiler or use gcc.
|
||||
|
||||
Try:
|
||||
cat august.c fac.oc | ./august > fac.oo
|
||||
./august < fac.oo
|
||||
|
||||
Or try:
|
||||
cat august.c fac.oc | ./august | ./august
|
||||
|
||||
And try:
|
||||
cat august.c parse.oc | ./august > parse.oo
|
||||
cat parse.oo fac.oc | ./august | ./august
|
||||
|
||||
This entry can feed on itself. If you C preprocess the source,
|
||||
you compile the interpreter:
|
||||
|
||||
make august.oc
|
||||
|
||||
We can now compile the interpreter as follows:
|
||||
|
||||
cat august.c august.oc | ./august > august.oo
|
||||
|
||||
and use the compiled interpreter to execute some previously
|
||||
compiled code:
|
||||
|
||||
cat august.oo test.oo | ./august
|
||||
|
||||
And we can have the compiled interpreter interpret itself which
|
||||
inturn compiles the test program:
|
||||
|
||||
cat august.oo august.oo fac.oo | ./august
|
||||
|
||||
And if you have lots of spare time, you can recurse one level deeper:
|
||||
|
||||
cat august.oo august.oo august.oo fac.oo | ./august
|
||||
|
||||
We (the judges) recommend that you spend some time studying this
|
||||
entry as it surely will make the 'best of the IOCCC' list. It was
|
||||
very well received by those who attended the IOCCC BOF.
|
||||
|
||||
|
||||
Selected notes from the author:
|
||||
|
||||
This program is a bytecode interpreter. This fact is not
|
||||
particularly obfuscated; any experienced C programmer can see that
|
||||
in about a minute.
|
||||
|
||||
The interpreter reads the bytecode from the standard input. What
|
||||
remains of the standard input after this is left as standard input for
|
||||
the interpreted program.
|
||||
|
||||
Having an interpreter but no code isn't any fun. But within a comment
|
||||
in the beginning of the interpreter is a sequence of bytes that is
|
||||
code that the interpreter understands. It is in fact the code for a
|
||||
compiler that compiles from OC (Obfuscated C, a subset of C) into the
|
||||
byte code that the interpreter understands.
|
||||
|
||||
The language the compiler understands is a subset of C (the grammar
|
||||
is in grammar.small) with the functions getchar() and putchar()
|
||||
available. The subset has the types `int', `char', and pointers to
|
||||
those (it has function pointers too, but not with the proper
|
||||
syntax). Arrays can only be global. There is a rather limited set
|
||||
of operators, and control constructs.
|
||||
|
||||
The compiler has absolutely no error checking, so things
|
||||
can go wrong. But this is what seasoned C progammers are used to.
|
||||
|
||||
Assume that the interpreter has been compiled (source in prog.c and
|
||||
binary in prog) and that we have this in a file named test.oc:
|
||||
|
||||
main() { putchar('!'); putchar('\n'); exit(0); }
|
||||
|
||||
We can then compile by
|
||||
|
||||
cat august.c test.oc | ./august > test.oo
|
||||
|
||||
And run the compiled program by
|
||||
|
||||
./august < test.oo
|
||||
|
||||
Or even simpler:
|
||||
|
||||
cat august.c test.oc | ./august | ./august
|
||||
|
||||
A larger example is included fac.oc.
|
||||
|
||||
The compiler for OC is naturally written in OC (where did you think
|
||||
the byte code came from?). It is in the file parse.oc.
|
||||
|
||||
Hmm... So now we have an interpreter written in OC and a compiler
|
||||
for OC, can we compile the interpreter? Yes, we can! The OC
|
||||
compiler does not have a preprocessor (hey, what do you expect from
|
||||
a program that is this small), so we need to use an external one.
|
||||
To preprocess august.c use the command from the build file, but add
|
||||
the -E flag and change 60000 to 40000, i.e.:
|
||||
|
||||
cc -E -DZ=40000 .... august.c > prog.oc
|
||||
|
||||
If prog.oc contain some junk line starting with a `#' (most likely
|
||||
it does) then remove it.
|
||||
|
||||
OK, we can now compile the interpreter:
|
||||
|
||||
cat august.c prog.oc | ./august > prog.oo
|
||||
|
||||
And we can run it:
|
||||
|
||||
cat prog.oo test.oo | ./august
|
||||
|
||||
Here we have the interpreter interpreting another interpreter that runs
|
||||
the program. Did you think that was too fast? Just throw in another
|
||||
level of interpretation:
|
||||
|
||||
cat prog.oo prog.oo test.oo | ./august
|
||||
|
||||
And another...
|
||||
|
||||
cat prog.oo prog.oo prog.oo test.oo | ./august
|
||||
|
||||
*****
|
||||
|
||||
Fitting the byte code for the compiler into the initial comment
|
||||
was a challenge. I had to strip the compiler/interpreter of
|
||||
a lot of functionality to bring down their sizes. The initial
|
||||
version had a full set of binary operators as well as prefix &.
|
||||
Given a handful more bytes it would be easy to put them back.
|
||||
|
||||
Anyway, the bytecode from the compiler is first optimized in
|
||||
an external optimizer (not supplied here); this brings down the
|
||||
size of it by about 30%. The remaining code is then LZ-compressed
|
||||
(roughly) with a sliding window of 255 bytes. The most common
|
||||
occuring bytes are then encoded using " \n\t;{}" to avoid having
|
||||
them counted as significant. About 200 bytes of the interpreter
|
||||
handles the unpacking of the byte code (this is a lot, but it pays
|
||||
off).
|
||||
|
||||
Despite all this work I still had to put a lot of code in the
|
||||
compilation command. This disturbs me. It is possible to compress
|
||||
the code further with a better entropy coder (e.g. an arithmetic
|
||||
coder), but decompression then takes up too much code. Maybe this
|
||||
would be a way to fit it all into the 1536 bytes, but I'm don't have
|
||||
time to try it.
|
||||
|
||||
*****
|
||||
|
||||
Execution starts at main(). Nothing can be used before it is
|
||||
defined. getchar() and putchar() are predefined functions.
|
||||
|
||||
The following is a description of the OC grammar:
|
||||
|
||||
OC grammar
|
||||
==========
|
||||
Terminals are in quotes, () is used for bracketing.
|
||||
|
||||
program: decl*
|
||||
|
||||
decl: vardecl
|
||||
fundecl
|
||||
|
||||
vardecl: type NAME ;
|
||||
type NAME "[" INT "]" ;
|
||||
|
||||
fundecl: type NAME "(" args ")" "{" body "}"
|
||||
|
||||
args: /*empty*/
|
||||
( arg "," )* arg
|
||||
|
||||
arg: type NAME
|
||||
|
||||
body: vardecl* stmt*
|
||||
|
||||
stmt: ifstmt
|
||||
whilestmt
|
||||
dowhilestmt
|
||||
"return" expr ";"
|
||||
expr ";"
|
||||
"{" stmt* "}"
|
||||
";"
|
||||
|
||||
ifstmt: "if" "(" expr ")" stmt
|
||||
"if" "(" expr ")" stmt "else" stmt
|
||||
|
||||
whilestmt: "while" "(" expr ")" stmt
|
||||
|
||||
dowhilestmt: "do" stmt "while" "(" expr ")" ";"
|
||||
|
||||
expr: expr binop expr
|
||||
unop expr
|
||||
expr "[" expr "]"
|
||||
"(" expr ")"
|
||||
expr "(" exprs ")"
|
||||
NAME
|
||||
INT
|
||||
CHAR
|
||||
STRING
|
||||
|
||||
exprs: /*empty*/
|
||||
(expr ",")* expr
|
||||
|
||||
binop: "+" | "-" | "*" | "/" | "%" |
|
||||
"=" |
|
||||
"<" | "==" | "!="
|
||||
|
||||
unop: "!" | "-" | "*"
|
||||
|
||||
type: "int" stars
|
||||
"char" stars
|
||||
|
||||
stars: "*"*
|
||||
|
||||
*****
|
||||
|
||||
Well, that is enough ranting for now.
|
||||
@@ -0,0 +1,321 @@
|
||||
/*T } ¶ ;
|
||||
ˆ
|
||||
;
|
||||
|
||||
;
|
||||
}
|
||||
{
|
||||
|
||||
{ ; ;
|
||||
; 1 {
|
||||
è { !
|
||||
} {
|
||||
; é ;
|
||||
|
||||
;
|
||||
{
|
||||
|
||||
|
||||
{ ]- } ; ; |
|
||||
í ; Q
|
||||
;
|
||||
´ë ; ; ; "û }
|
||||
} Ü; ; -ýl
|
||||
|
||||
}
|
||||
} t dÀ ;
|
||||
; +
|
||||
t2 { ì ;
|
||||
|
||||
} 1; C
|
||||
i
|
||||
; = } ; ;
|
||||
|
||||
;
|
||||
ì ; {
|
||||
|
||||
{ ê
|
||||
} { � { ï } }
|
||||
|
||||
; . {
|
||||
␍ { é } } ;
|
||||
{ ;
|
||||
; /nÈ; 5
|
||||
} ; Ú␍{ ;
|
||||
; { 1 ; } ; ¨ý } {
|
||||
|
||||
; { ; . { ; } ; ;
|
||||
; T ;
|
||||
{
|
||||
; ; Ä; ; {
|
||||
;
|
||||
{ { ; ;
|
||||
ì; ‘ ; ; ï; n!t }
|
||||
; ì!; G; t; ø; ¤ } ;
|
||||
|
||||
;
|
||||
} ; "; è# }
|
||||
;
|
||||
{
|
||||
; �$ {
|
||||
;
|
||||
; &
|
||||
|
||||
; d˜
|
||||
{
|
||||
|
||||
¶; {
|
||||
; Sé'
|
||||
{ d; ; è); �c
|
||||
{
|
||||
; ;
|
||||
; &ï*; ␍ ;
|
||||
— {
|
||||
;
|
||||
$; ¢; ,; ; $ˆd } —; ˆ; ë/Î; Î
|
||||
; a; Í ; {
|
||||
} ; j; #è1;
|
||||
}
|
||||
; Ä ; { ê5a; û␍ Ät { ï4a }
|
||||
}
|
||||
|
||||
; £;
|
||||
Û2; -
|
||||
; 8
|
||||
|
||||
} ; }
|
||||
; è8; ; Ú6Q ; aÌ { ; { ˆ
|
||||
ì }
|
||||
†; v:
|
||||
{
|
||||
?
|
||||
}
|
||||
|
||||
{ ?
|
||||
|
||||
{ ; 4r
|
||||
;
|
||||
; v=b; Û
|
||||
;
|
||||
;
|
||||
} ;
|
||||
; ; ; Þ { ú>
|
||||
} }
|
||||
{ ;
|
||||
{ Õ`
|
||||
}
|
||||
;
|
||||
;
|
||||
!;
|
||||
; 1; ; >; Ì } 1; X
|
||||
; } p ;
|
||||
;
|
||||
|
||||
; ; ;
|
||||
; ; 2 } ; vm
|
||||
2; ;1íJ
|
||||
;
|
||||
; ; Ï }
|
||||
; ÉJc; ›; d }
|
||||
} ÞG; i }
|
||||
; ; §F
|
||||
{ vl¶þV; z
|
||||
n
|
||||
¶éOc; s
|
||||
; ; ÑÞ;
|
||||
uh¶ëR } hRs; A cl,;
|
||||
; ; Z; {
|
||||
x
|
||||
lw¶êUch�{ }
|
||||
} ; àîVc }
|
||||
; Ž; >ÈD
|
||||
; G ; ; †
|
||||
;
|
||||
îX; ’ˆ
|
||||
;
|
||||
|
||||
; 2 } { é[;
|
||||
{ }
|
||||
; Þj; å; ë_; ␍y
|
||||
; D; T; ; ?j; .n; ; ã {
|
||||
|
||||
; Ú]; !; Ë; 0a
|
||||
} J ;
|
||||
; ^; .
|
||||
{ { { îc; ␍X ; ; ´;
|
||||
J {
|
||||
; ;
|
||||
} — { êf;
|
||||
; {
|
||||
; ; : } {
|
||||
{
|
||||
|
||||
; (h} ␍ }
|
||||
{ }
|
||||
} ; ; {
|
||||
; ûD; Tì Cr; ␍; I; WèsÎWQ
|
||||
; ;
|
||||
×; W { û }
|
||||
; ( ; ; }
|
||||
} ; {
|
||||
; ÿn{ k; © ; ‚; ?; %Ùk; ;
|
||||
|
||||
{ ïv;
|
||||
3{ (; h {
|
||||
|
||||
; ; z
|
||||
|
||||
; ; ]{ ; ˜ïx; S; { * } ˜; z} ; î;
|
||||
{ ; ~
|
||||
;
|
||||
U; ö
|
||||
; { ‡
|
||||
; í~;
|
||||
Ob } ; ò; UU; U{ -{ %Ú|1èƒ;
|
||||
; Q
|
||||
;
|
||||
µ{ w{ š; ;
|
||||
{ í‡; ‚; ü�
|
||||
|
||||
…
|
||||
} Ù†; ?; u
|
||||
{
|
||||
|
||||
|
||||
ƒ
|
||||
} } ; » ; ´ ; ; }
|
||||
; è
|
||||
{
|
||||
|
||||
; ; }
|
||||
; p ; ; ; Q; Ü�{ ; ; K; $ì“
|
||||
p; 1}
|
||||
4; $;
|
||||
2Q ; } {
|
||||
; $î— } ; #;
|
||||
T; 1
|
||||
; ; +; ± }
|
||||
; ;
|
||||
. ; {
|
||||
{ ; š{
|
||||
;
|
||||
{
|
||||
; ; }
|
||||
|
||||
|
||||
; { [ { ; £{ ; �; 0{
|
||||
{ ôr ; éŸ
|
||||
;
|
||||
} =; w
|
||||
|
||||
?; ;
|
||||
ä; B®lwx
|
||||
; h�h
|
||||
|
||||
} ; pj
|
||||
; ; ; ö { û§; 'n
|
||||
; ; { ) {
|
||||
; ú¤;
|
||||
;
|
||||
Q
|
||||
; f; 'r
|
||||
{
|
||||
? { ë¬; %lÂf}
|
||||
; ~©{ qÛ¨;
|
||||
{
|
||||
{ ÿ; ÂÛ¬{ œÚžl,u
|
||||
; & ;
|
||||
|
||||
{ í; G }
|
||||
; k
|
||||
; }
|
||||
;
|
||||
{
|
||||
|
||||
|
||||
; hR; ; Wß´;
|
||||
} ;
|
||||
|
||||
; ; —e; Z; ž{ N; =
|
||||
} ; <
|
||||
{ ]- Bšretur; ¡if
|
||||
else
|
||||
whil; do; nt
|
||||
char
|
||||
{ ; { pu{ }
|
||||
{ ; =
|
||||
} B
|
||||
} {
|
||||
; ø¿`ˆ; dÀ; ´ } �
|
||||
} } ; ø`; waÌ { •ma; >
|
||||
{ ; oJ
|
||||
} ÈD
|
||||
{ ; ; ; · ;
|
||||
|
||||
; Á ; ; ; ; ;
|
||||
{
|
||||
; ; €Õ; @ë ; Á; L {
|
||||
|
||||
; ØÈ ;
|
||||
*/int m[Z];
|
||||
|
||||
#define U(x)s--;T=x
|
||||
#define C(l,s)I(o==l){s;}E
|
||||
#define Q(l,o)C(l,r=P;T=T o r)
|
||||
#define O(l,o)C(l,T=o T)
|
||||
#define H(l,s)C(l,U(s))
|
||||
int
|
||||
main(){int*q,s,f,r,o,l,p,c,b;
|
||||
char*d;
|
||||
d=" \t\n;{}\0AÊP€³²‰Š@ɵ�gEÏͱ°Œ0�Ž‹q";
|
||||
b=256;
|
||||
q=m;
|
||||
g;
|
||||
o=g;
|
||||
c=g;
|
||||
c=c+g*b;
|
||||
p=c;
|
||||
I(o){W(p){o=g;
|
||||
C(59,r=2)C('{',r=5)C('}',r=8)r=0;
|
||||
I(r){r=r+g%4;
|
||||
l=1-g-r;
|
||||
W(r--){*q=q[l];
|
||||
q++;
|
||||
p--;
|
||||
}}E{I((o==32)+(o==9)+(o==10)){r=g;
|
||||
o=o%4+(r+(r==123))%8*3;
|
||||
I(8<o)o=o+g%4*9;
|
||||
o=d[o]+b;
|
||||
}*q++=o%b;
|
||||
p--;
|
||||
}}W(g!=12);
|
||||
g;
|
||||
}E{W(p--)*q++=g;
|
||||
}s=Z;
|
||||
p=0;
|
||||
W(1){o=L;
|
||||
O(17,!)O(18,-)Q(12,+)D C(10,r=T;
|
||||
s=f;
|
||||
p=X 1];
|
||||
f=X 2];
|
||||
l=X 3];
|
||||
R)C(22,s++)C(27,return T)C(21,r=T;
|
||||
U(r))C(23,T=m[T])C(19,T=m[T]++)C(25,T=m[T]--){l=o%16;
|
||||
o=o/16;
|
||||
I(l==7){l=B;
|
||||
l=l+B*b;
|
||||
}E I(7<l)l=l+B*8-1;
|
||||
H(2,f+l)H(4,f-l-4)H(3,m[f+l])H(5,m[f-l-4])H(6,c+l)H(7,m[c+l])H(12,l)H(8,l)C(9,U(p);
|
||||
p=p+l)C(11,r=X-l/2];
|
||||
I(r<3){I(r)r=putchar(T);
|
||||
E
|
||||
r=g;
|
||||
R;
|
||||
}E{X 1]=p;
|
||||
X 2]=f;
|
||||
X 3]=l;
|
||||
f=s;
|
||||
s=s-19;
|
||||
p=r;
|
||||
})C(13,p=l)C(15,I(P)p=l)C(14,I(!P)p=l);
|
||||
}}}
|
||||
@@ -0,0 +1,44 @@
|
||||
/* A factorial program */
|
||||
int
|
||||
putstr(char *s)
|
||||
{
|
||||
while(*s)
|
||||
putchar(*s++);
|
||||
}
|
||||
|
||||
int
|
||||
fac(int n)
|
||||
{
|
||||
if (n == 0)
|
||||
return 1;
|
||||
else
|
||||
return n*fac(n-1);
|
||||
}
|
||||
|
||||
int
|
||||
putn(int n)
|
||||
{
|
||||
if (9 < n)
|
||||
putn(n / 10);
|
||||
putchar((n%10) + '0');
|
||||
}
|
||||
|
||||
int
|
||||
facpr(int n)
|
||||
{
|
||||
putstr("factorial ");
|
||||
putn(n);
|
||||
putstr(" = ");
|
||||
putn(fac(n));
|
||||
putstr("\n");
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
i = 0;
|
||||
while(i < 10)
|
||||
facpr(i++);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,463 @@
|
||||
int curloc;
|
||||
int lexval;
|
||||
int token;
|
||||
int pusharg;
|
||||
int thechar;
|
||||
int nglob;
|
||||
int nlocal;
|
||||
int nfun;
|
||||
int strsize;
|
||||
int narg;
|
||||
int curgloboffs;
|
||||
int nsym;
|
||||
int pushop;
|
||||
int argids[50 ];
|
||||
int globids[300 ];
|
||||
int globoffs[300 ];
|
||||
int globscalar[300 ];
|
||||
int funids[300 ];
|
||||
int funoffs[300 ];
|
||||
int localids[50 ];
|
||||
char symbol[5000 ];
|
||||
char code[5000 ];
|
||||
char names[5000 ];
|
||||
int
|
||||
digit(int c)
|
||||
{
|
||||
return (( '/' < c ) * ( c < ':' )) ;
|
||||
}
|
||||
int
|
||||
letter(int c)
|
||||
{
|
||||
return (( '`' < c ) * ( c < '{' ))
|
||||
;
|
||||
}
|
||||
int
|
||||
eqstr(char *p, char *q)
|
||||
{
|
||||
while(*p) {
|
||||
if (*p++ != *q++)
|
||||
return 0;
|
||||
}
|
||||
return !*q;
|
||||
}
|
||||
int
|
||||
lookup(char *name)
|
||||
{
|
||||
int i;
|
||||
char *ns;
|
||||
ns = names;
|
||||
i = 0;
|
||||
while(i < nsym) {
|
||||
if (eqstr(ns, name)) {
|
||||
return i;
|
||||
}
|
||||
while(*ns++)
|
||||
;
|
||||
i++;
|
||||
}
|
||||
while(*ns++ = *name++)
|
||||
;
|
||||
return nsym++;
|
||||
}
|
||||
int
|
||||
next()
|
||||
{
|
||||
int r;
|
||||
r = thechar;
|
||||
thechar = getchar();
|
||||
return r;
|
||||
}
|
||||
int
|
||||
gobble(int t, int rr, int r)
|
||||
{
|
||||
if (thechar == t) {
|
||||
next();
|
||||
return rr;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
int
|
||||
getstring(int delim)
|
||||
{
|
||||
int c;
|
||||
strsize = 0;
|
||||
while((c = next()) != delim) {
|
||||
if (c == '\\') {
|
||||
if ( (c = next()) == 'n') c = '\n';
|
||||
if (c == 't') c = '\t';
|
||||
if (c == '0') c = 0;
|
||||
}
|
||||
symbol[strsize++] = c;
|
||||
}
|
||||
symbol[strsize++] = 0;
|
||||
}
|
||||
int
|
||||
getlex()
|
||||
{
|
||||
int c;
|
||||
char *p;
|
||||
while( (( 0 < (c = next()) ) * ( c < '!' )) )
|
||||
;
|
||||
if ((( c == -1 ) + (
|
||||
(( c == '(' ) + (
|
||||
(( c == ')' ) + (
|
||||
(( c == '[' ) + (
|
||||
(( c == ']' ) + (
|
||||
(( c == '{' ) + (
|
||||
(( c == '}' ) + (
|
||||
(( c == ',' ) + (
|
||||
c == ';' )) )) )) )) )) )) )) )) )
|
||||
return c;
|
||||
if (c == '/') {
|
||||
if (thechar == '*') {
|
||||
while((( next() != '*' ) + ( thechar != '/' )) )
|
||||
;
|
||||
next();
|
||||
return getlex();
|
||||
} else
|
||||
return 1115 ;
|
||||
}
|
||||
if (c == '*') return 1114 ;
|
||||
if (c == '%') return 1116 ;
|
||||
if (c == '-')
|
||||
return gobble(c,1225 ,1013 );
|
||||
if (c == '<')
|
||||
return 808 ;
|
||||
if (c == '=')
|
||||
return gobble(c,806 ,101 );
|
||||
if (c == '+')
|
||||
return gobble(c,1219 ,1012 );
|
||||
if (c == '!')
|
||||
return gobble('=',807 ,1217 );
|
||||
if (c == '\'') {
|
||||
getstring(c);
|
||||
lexval = symbol[0];
|
||||
return 257 ;
|
||||
}
|
||||
if (c == '"') {
|
||||
getstring(c);
|
||||
return 258 ;
|
||||
}
|
||||
if (digit(c)) {
|
||||
lexval = c - '0';
|
||||
while(digit(thechar)) {
|
||||
lexval = lexval * 10 + next() - '0';
|
||||
}
|
||||
return 257 ;
|
||||
}
|
||||
p = symbol;
|
||||
*p++ = c;
|
||||
while(letter(thechar))
|
||||
*p++ = next();
|
||||
*p = 0;
|
||||
if ( (lexval = lookup(symbol)) < 7 ) {
|
||||
if (lexval == 6 )
|
||||
return 517 ;
|
||||
return lexval + 512 ;
|
||||
}
|
||||
return 256 ;
|
||||
}
|
||||
int
|
||||
istoken(int t)
|
||||
{
|
||||
if (token == t) {
|
||||
token = getlex();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
type()
|
||||
{
|
||||
istoken( 517 ) ;
|
||||
while(istoken(1114 ))
|
||||
;
|
||||
}
|
||||
int
|
||||
name()
|
||||
{
|
||||
int r;
|
||||
r = lexval;
|
||||
token = getlex();
|
||||
return r;
|
||||
}
|
||||
int
|
||||
emit(int opc)
|
||||
{
|
||||
code[curloc++] = opc;
|
||||
}
|
||||
int
|
||||
emitat(int a, int c)
|
||||
{
|
||||
code[a++] = c;
|
||||
code[a] = c/256;
|
||||
}
|
||||
int
|
||||
emitop(int rator, int rand)
|
||||
{
|
||||
int r;
|
||||
emit(rator+ 7 );
|
||||
r = curloc;
|
||||
emit(rand);
|
||||
emit(rand/256);
|
||||
return r;
|
||||
}
|
||||
int
|
||||
pushloop(int puop, int max, int *arr)
|
||||
{
|
||||
int i;
|
||||
i = 0;
|
||||
pushop = puop;
|
||||
while (i < max) {
|
||||
if (arr[i] == lexval) {
|
||||
pusharg = i;
|
||||
return 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
pushval()
|
||||
{
|
||||
int lval;
|
||||
lval = 1;
|
||||
if (pushloop(64 , nlocal, localids)) {
|
||||
} else if (pushloop(32 , narg, argids)) {
|
||||
pusharg = narg-pusharg-1;
|
||||
} else if (pushloop(96 , nglob, globids)) {
|
||||
lval = globscalar[pusharg];
|
||||
pusharg = globoffs[pusharg];
|
||||
} else {
|
||||
lval = 0;
|
||||
if (pushloop(192 , nfun, funids)) {
|
||||
pusharg = funoffs[pusharg];
|
||||
} else if (lexval < 9 ) {
|
||||
pusharg = lexval- 7 ;
|
||||
}
|
||||
}
|
||||
emitop(pushop, pusharg);
|
||||
return lval;
|
||||
}
|
||||
int
|
||||
pderef(int l)
|
||||
{
|
||||
if (l)
|
||||
emit(23 );
|
||||
}
|
||||
int
|
||||
expr(int needval, int prec)
|
||||
{
|
||||
int na;
|
||||
int islval;
|
||||
int jdst;
|
||||
int op;
|
||||
int any;
|
||||
int opprec;
|
||||
islval = 0;
|
||||
if (istoken(257 )) {
|
||||
emitop(128 , lexval);
|
||||
} else if (istoken(258 )) {
|
||||
emitop(144 , strsize);
|
||||
any = 0;
|
||||
while(any < strsize)
|
||||
emit(symbol[any++]);
|
||||
} else if (istoken(256 )) {
|
||||
islval = pushval();
|
||||
} else if (istoken('(')) {
|
||||
islval = expr(0, 0 );
|
||||
istoken( ')' ) ;
|
||||
} else if (istoken(1217 )) {
|
||||
expr(1, 100 );
|
||||
emit(17 );
|
||||
} else if (istoken(1013 )) {
|
||||
expr(1, 100 );
|
||||
emit(18 );
|
||||
} else if (istoken(1114 )) {
|
||||
expr(1, 100 );
|
||||
islval = 1;
|
||||
}
|
||||
any = 1;
|
||||
while(any) {
|
||||
op = token % 100 ;
|
||||
if (istoken('(')) {
|
||||
pderef(islval);
|
||||
na = 0;
|
||||
if (!istoken(')')) {
|
||||
do {
|
||||
expr(1, 0 );
|
||||
na++;
|
||||
} while(istoken(','));
|
||||
istoken( ')' ) ;
|
||||
}
|
||||
emitop(176 , na*2);
|
||||
islval = 0;
|
||||
} else if (istoken('[')) {
|
||||
pderef(islval);
|
||||
expr(1, 0 );
|
||||
emit(12 );
|
||||
istoken( ']' ) ;
|
||||
islval = 1;
|
||||
} else if (istoken(1219 )) {
|
||||
emit(op);
|
||||
islval = 0;
|
||||
} else if (istoken(1225 )) {
|
||||
emit(op);
|
||||
islval = 0;
|
||||
} else
|
||||
any = 0;
|
||||
}
|
||||
opprec = token / 100 ;
|
||||
while (prec < opprec) {
|
||||
if ( (op = token % 100 ) != 1 ) {
|
||||
pderef(islval);
|
||||
}
|
||||
{
|
||||
token = getlex();
|
||||
expr(1, opprec);
|
||||
emit(op);
|
||||
}
|
||||
islval = 0;
|
||||
opprec = token / 100 ;
|
||||
}
|
||||
if (needval) {
|
||||
pderef(islval);
|
||||
islval = 0;
|
||||
}
|
||||
return islval;
|
||||
}
|
||||
int
|
||||
pexpr()
|
||||
{
|
||||
istoken( '(' ) ;
|
||||
expr(1, 0 );
|
||||
istoken( ')' ) ;
|
||||
}
|
||||
int
|
||||
stmt()
|
||||
{
|
||||
int jdest;
|
||||
int tst;
|
||||
if (istoken('{')) {
|
||||
while(!istoken('}'))
|
||||
stmt();
|
||||
} else if (istoken(513 )) {
|
||||
pexpr();
|
||||
jdest = emitop (224 , 0);
|
||||
stmt();
|
||||
if (istoken(514 )) {
|
||||
tst = emitop (208 , 0);
|
||||
emitat(jdest, curloc);
|
||||
stmt();
|
||||
emitat(tst, curloc);
|
||||
} else {
|
||||
emitat(jdest, curloc);
|
||||
}
|
||||
} else if (istoken(515 )) {
|
||||
tst = curloc;
|
||||
pexpr();
|
||||
jdest = emitop (224 , 0);
|
||||
stmt();
|
||||
emitop (208 , tst);
|
||||
emitat(jdest, curloc);
|
||||
} else if (istoken(516 )) {
|
||||
jdest = curloc;
|
||||
stmt();
|
||||
istoken( 515 ) ;
|
||||
pexpr();
|
||||
emit(17 );
|
||||
emitop (224 , jdest);
|
||||
} else if (istoken(512 )) {
|
||||
expr(1, 0 );
|
||||
istoken( ';' ) ;
|
||||
emit(10 );
|
||||
} else if (istoken(';')) {
|
||||
} else {
|
||||
expr(1, 0 );
|
||||
emit(22 );
|
||||
istoken( ';' ) ;
|
||||
}
|
||||
}
|
||||
int
|
||||
parse()
|
||||
{
|
||||
int objid;
|
||||
token = getlex();
|
||||
while(1) {
|
||||
if (token < 0)
|
||||
return 1;
|
||||
type();
|
||||
objid = name();
|
||||
if (istoken('(')) {
|
||||
funids[nfun] = objid;
|
||||
funoffs[nfun++] = curloc;
|
||||
narg = 0;
|
||||
if (!istoken(')')) {
|
||||
do {
|
||||
type();
|
||||
argids[narg++] = name();
|
||||
} while(istoken(','));
|
||||
istoken( ')' ) ;
|
||||
}
|
||||
istoken( '{' ) ;
|
||||
nlocal = 0;
|
||||
while(token == 517 ) {
|
||||
type();
|
||||
do {
|
||||
localids[nlocal++] = name();
|
||||
} while (istoken(','));
|
||||
istoken( ';' ) ;
|
||||
}
|
||||
while(!istoken('}'))
|
||||
stmt();
|
||||
emit(10 );
|
||||
} else {
|
||||
globoffs[nglob] = curgloboffs;
|
||||
if (istoken('[')) {
|
||||
istoken( 257 ) ;
|
||||
curgloboffs = curgloboffs + lexval;
|
||||
istoken( ']' ) ;
|
||||
globscalar[nglob] = 0;
|
||||
} else {
|
||||
curgloboffs++;
|
||||
globscalar[nglob] = 1;
|
||||
}
|
||||
globids[nglob++] = objid;
|
||||
istoken( ';' ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
int
|
||||
main(
|
||||
)
|
||||
{
|
||||
int n;
|
||||
char *p;
|
||||
char *q;
|
||||
nsym = 9 ;
|
||||
p = names;
|
||||
q = "return\0if\0else\0while\0do\0int\0char\0getchar\0putchar" ;
|
||||
n = 48 ;
|
||||
do
|
||||
*p++ = *q++;
|
||||
while(n--);
|
||||
curloc = 7;
|
||||
thechar = getchar();
|
||||
parse();
|
||||
n = curloc;
|
||||
curloc = 0;
|
||||
lexval = lookup("main");
|
||||
pushval();
|
||||
emitop(176 , 0);
|
||||
emit(27 );
|
||||
putchar(0);
|
||||
putchar(0);
|
||||
putchar(n);
|
||||
putchar(n/256);
|
||||
p = code;
|
||||
while(n--) {
|
||||
putchar(*p++);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
main() { putchar('!'); putchar('\n'); exit(0); }
|
||||
Reference in new issue
Block a user