Name: Anonymous 2010-07-24 16:33
Write a C compiler. It doesn't have to follow any rules/syntax/standards except to compile "hello world" and fibs.
#!/usr/bin/perl
# Compiles (and automatically runs) C programs
# according to which purpose the program has,
# with no intermediate executable.
# Not to be confused with the C interpreter
# that this program is identical to.
my ($file, $option) = @ARGV;
die "Error 404: File not found: $file" unless -e $file;
if ($option eq "--hello-world") {
print "200 OK: Hello, World!";
} elsif ($option eq "--fibs") {
print "200 OK: ";
my $i = 0;
while (rand > 0.1) {
print int ($i * (1 + sqrt 5)) + 0.5) . " ";
$i += 0.5;
}
} else {
die "Error 500: Internal server error (syntax)\n";
}
#include <string.h>
int main(int argc, char **argv) {
if (!strcmp(argv[1], "hello_world.c"))
puts("compiled");
else if (!strcmp(argv[1], "fibs.c"))
puts("compiled");
else
puts("failed");
return 0;
}
int
main(int argc, char* argv[])
{
if (file =~ fib) /* Left as an exercise for the reader. */
output_fibs_bin(); /* Generated by a m4 macro. */
else if (file =~ hello)
output_hello_bin();
return 0;
}
#include <stdio.h>
#define k *(int*)
#define a if(
#define c ad()
#define i else
#define p while(
#define x *(char*)
#define b ==
#define V =calloc(1,99999)
#define f ()
#define J return
#define l ae(
#define n e)
#define u d!=
#define F int
#define y (j)
#define r m=
#define t +4
F d,z,C,h,P,K,ac,q,G,v,Q,R,D,L,W,M;E(n{x D++=e;}o f{a L){h=x L++;a h b 2){L=0;h=W;}}i h=fgetc(Q);}X f{J isalnum(h)|h b 95;}
Y f{a h b 92){o f;a h b 110)h=10;}}c{F e,j,m;p isspace(h)|h b 35){a h b 35){o f;c;a d b 536){c;E(32);k d=1;k(d t)=D;}p h!=10){
E(h);o f;}E(h);E(2);}o f;}C=0;d=h;a X f){E(32);M=D;p X f){E(h);
o f;}a isdigit(d)){z=strtol(M,0,0);d=2;}i{x D=32;d=strstr(R,M-)-R;x D=0;d=d*8+256;a d>536){d=P+d;a k d b 1){L=k(d t);W=h;o f;
c;}}}}i{o f;a d b 39){d=2;Y f;z=h;o f;o f;}i a d b 47&h b 42){o
f;p h){p h!=42)o f;o f;a h b 47)h=0;}o f;c;}i{e="++#m--%am*@R<^1c/@%[_[H3c%@%[_[H3c+@.B#d-@%:_^BKd<<Z/03e>>`/03e<=0f>=/f<@.f>@1f==&g!='g&&k||#l&@.BCh^@.BSi|@.B+j~@/%Yd!@&d*@b";
p j=x e++){r x e++;z=0;p(C=x e++-98)<0)z=z*64+C+64;a j b d&(m b h|m b 64)){a m b h){o f;d=1;}break;}}}}}
l g){p g&&g!=-1){x q++=g;g=g>>8;}}A(n{F g;p n{g=k e;k e=q-e-4;
e=g;}}s(g,n{l g);k q=e;e=q;q=q t;J e;}H(n{s(184,n;}B(n{J s233,n;
}S(j,n{l 1032325);J s(132+j,n;}Z(n{l 49465);H(0);l 15);l e+144);
l 192);}N(j,n{l j+131);s((e<512)<<7|5,n;}T y{F g,e,m,aa;g=1;a d b 34){H(v);
p h!=34){Y f;x v++=h;o f;}x v=0;v=v t&-4;o f;c;}i{aa=C;r z;
e=d;c;a e b 2){H(m);}i a aa b 2){T(0);s(185,0);a e b 33)Z(m);
i l m);}i a e b 40){w f;c;}i a e b 42){c;e=d;c;c;a d b 42){
c;c;c;c;e=0;}c;T(0);a d b 61){c;l 80);w f;l 89);l 392+(e b 56));
}i a n{a e b 256)l 139);i l 48655);q++;}}i a e b 38){N(10,k d);
c;}i{g=k e;a!g)g=dlsym(0,M);a d b 61&j){c;w f;N(6,g);}i a u 40){
N(8,g);a C b 11){N(0,g);l z);c;}}}}a d b 40){a g b 1)l 80);
r s(60545,0);c;j=0;p u 41){w f;s(2393225,j);a d b 44)c;j=j t;
}k r j;c;a!g){e=e t;k e=s(232,k n;}i a g b 1){s(2397439,j);j=j t;}i{s(232,g-q-5);}a j)s(50305,j);}}O y{F e,g,m;a j--b 1)T(1);i{
O y;r 0;p j b C){g=d;e=z;c;a j>8){r S(e,m);O y;}i{l 80);O y;l 89);
a j b 4|j b 5){Z(n;}i{l n;a g b 37)l 146);}}}a m&&j>8){r S(e,m);
H(e^1);B(5);A(m);H(n;}}}w f{O(11);}U f{w f;J S(0,0);}I y{F ,g,e;
a d b 288){c;c;r U f;c;I y;a d b 312){c;g=B(0);A(m);I y;A(g);}
i{A(m);}}i a d b 352|d b 504){e=d;c;c;a e b 352){g=q;r U f;}i{
a u 59)w f;c;g=q;r 0;a u 59)r U f;c;a u 41){e=B(0);w f;B(g-q-5);
A(n;g=e t;}}c;I(&m);B(g-q-5);A(m);}i a d b 123){c;ab(1);p u 125)I y;c;}i{a d b 448){c;a u 59)w f;K=B(K);}i a d b 400){c;k j=B(k j);}i a u 59)w f;c;}}ab y{F m;p d b 256|u-1&!j){a d b 256){c;
p u 59){a j){G=G t;k d=-G;}i{k d=v;v=v t;}c;a d b 44)c;}c;}i{
A(k(d t));k d=q;c;c;r 8;p u 41){k d=m;r m t;c;a d b 44)c;}c;
K=G=0;l 15042901);r s(60545,0);I(0);A(K);l 50121);k r G;}}}
main(g,n{Q=stdin;a g-->1){e=e t;Q=fopen(k e,"r");}
D=strcpy(R V," int if else while break return for define main ")+48;v V;q=ac V;P V;o f;c;ab(0);J(*(int(*)f)k(P+592))(g,n;}
yousuck.c:24:67: error: expected expression before ‘)’ token
yousuck.c:29:62: error: ‘s233’ undeclared (first use in this function)
yousuck.c:29:67: error: expected ‘;’ before ‘)’ token
yousuck.c:29:67: error: expected statement before ‘)’ token
yousuck.c:43:64: error: expected identifier or ‘(’ before ‘,’ token
yousuck.c:44:20: error: ‘m’ undeclared (first use in this function)
yousuck.c:44:45: error: ‘g’ undeclared (first use in this function)
yousuck.c:45:35: error: ‘e’ undeclared (first use in this function)
max_execution_time is exceeded. I found a SQL query to be the most convenient way to show what the server would be doing in this case, and why it wouldn't timeout.