Skip to content

Instantly share code, notes, and snippets.

@nst
Last active December 5, 2023 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nst/dce7b3fca2a6aba15714a4d4fe31b95a to your computer and use it in GitHub Desktop.
Save nst/dce7b3fca2a6aba15714a4d4fe31b95a to your computer and use it in GitHub Desktop.
A tiny Brainfuck interpreter in PostScript
% A Brainfuck interpreter written in PostScript
% 2023-12-05 Nicolas Seriot https://github.com/nst/bfps
% ps2pdf bf_tiny.ps && open bf_tiny.ps
/P(+[-[<<[+[--->]-[<<<]]]>>>-]>-.---.>..>.<<<<-.<+.>>>>>.>.<<.<-.)def
/Courier findfont 12 scalefont setfont 32 740 moveto
/p 0 def/M 30000 string def/m 0 def/V{M m get}def/j P length array def 0 1 P
length 1 sub{/i exch def/c P i 1 getinterval def c([)eq{i}if c(])eq{/x exch def
j i x put j x i put}if}for/_{V add 255 and M m 3 -1 roll put}def{p P length ge{
exit}if/C P p 1 getinterval def C(+)eq{1 _}if C(-)eq{-1 _}if C(>)eq{/m m 1 add
def}if C(<)eq{/m m 1 sub def}if C([)eq{V 0 eq{/p j p get def}if}if C(])eq{V 0
ne{/p j p get def}if}if C(.)eq{/s 1 string def s 0 V put s show}if C(,)eq{/f
(%lineedit)(r)file def f read pop M m 3 -1 roll put}if/p p 1 add def}loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment