Last active
April 10, 2017 18:54
-
-
Save antonijn/7ffdc62b602a26dd1427 to your computer and use it in GitHub Desktop.
PATH interpreter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define b ;break;case | |
#define w (c=getc(f)) | |
int c,x=1,y,u,r=1;char m[30000],*s=m;int main(int i,char**j){FILE*f=fopen(j[1],"r");while(w-'$'){++x;y+=c=='\n'?x=1:0;}for(;;){switch w{case'#':return fclose(f);b'\\':i=u;u=-r;r=-i;b'/':i=u;u=r;r=i;b'}':s++b'{':s--b',':*s=getchar()b'.':putchar(*s)b'^':u=*s?(r=0)+1:u;b'<':r=*s?(u=0)-1:r;b'v':u=*s?(r=0)-1:u;b'>':r=*s?(u=0)+1:r;b'+':++*s;b'-':--*s;b'!':x+=r;y-=u;}x+=r;y-=u;rewind(f);for(i=0;i<y;i+=w=='\n');for(i=0;i<x;++i)w;}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define b ;break;case | |
#define w (c=getc(f)) | |
// c is input char, x the x position in the file, y the y position in the file | |
// u for up, 1 if going up, -1 if going down, 0 if neither | |
// r similar to u, but 'right' instead | |
int c, x = 1, y, u, r = 1; | |
// the memory and memory pointer respectively | |
char m[30000], *s = m; | |
// i is used as an interation int throughout main() | |
int main(int i, char**j) | |
{ | |
FILE *f = fopen(j[1], "r"); | |
while (w - '$') { | |
++x; | |
y += c == '\n' ? x = 1 : 0; | |
} | |
for (;;) { | |
switch w { | |
case '#': | |
return fclose(f); | |
b '\\': | |
i = u; | |
u = -r; | |
r = -i; | |
b '/': | |
i = u; | |
u = r; | |
r = i; | |
b '}': | |
s++ | |
b '{': | |
s-- | |
b ',': | |
*s = getchar() | |
b '.': | |
putchar(*s) | |
b '^': | |
u = *s ? (r = 0) + 1 : u; | |
b '<': | |
r = *s ? (u = 0) - 1 : r; | |
b 'v': | |
u = *s ? (r = 0) - 1 : u; | |
b '>': | |
r = *s ? (u = 0) + 1 : r; | |
b '+': | |
++*s; | |
b '-': | |
--*s; | |
b '!': | |
x+=r;y-=u; | |
} | |
x += r; | |
y -= u; | |
rewind(f); | |
for (i = 0; i < y; i += w== '\n') | |
; | |
for (i = 0; i < x; ++i) | |
w; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment