lisps - A Lisp Interpreter written in Postscript

980 views
813 views

Published on

Code available at:
https://github.com/grill/lisps

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
980
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

lisps - A Lisp Interpreter written in Postscript

  1. 1. LISPSby Alex & Gabriel
  2. 2. A Lisp Interpreter in Postscript● Scheme dialect based on Peter Norvigs lispy (lisp interpreter in python) http://norvig.com/lispy.html● Scheme dialect ○ variables var ○ conditional (if test conseq alt) ○ definition / assignment (define var value) ○ procedure (lambda (var...) exp) ○ sequencing (begin exp...) ○ procedure call (procedure exp...)
  3. 3. Good use of Concepts● Parser ○ List with arbitrary length /pdict_default << 40 { count 0 eq { mark } { isMark not { mark } if } ifelse mark } %( 41 { isMark { pop } { genStr transit } ifelse eval mark } % ) 32 { isMark not { genStr transit mark } if } % >> def readline { dup pdict exch known % is current character in dict { pdict exch get exec } % execute mapped code if } forall % for all characters in readline
  4. 4. Good use of Concepts● Dictionaries / Parser ○ state change with dictionaries /pdict pdict_default def /pdict_states << (lambda) { /pdict pdict_lambda def mark } (quote) { /pdict pdict_quote def } >> def /pdict_lambda << 40 { } % ( do not delete 41 { isMark { pop } { genStr } ifelse ] mark /pdict pdict_default def } % ) 32 { isMark not { genStr mark } if } % >> def
  5. 5. Good use of Concepts● eval ○ reorder with stack /eval % op p1..pn - { p1..pn { op } exec } { counttomark -1 roll dup dictionary exch known % test if command is known { dictionary exch get exec } { { call_fun } } ifelse 0 ] cvx dup dup length 1 sub {exec} putinterval } def
  6. 6. Good use of Concepts● Dictionaries ○ map for variables ○ bind Scheme commands to PostScript words/dictionary << ... (if) {{myif}} (quote) {{quote}} (define) {{mydef}} (set!) {{myset}} (lambda) {lambda} (begin) { prebegin {mybegin}} (equal?) {{eq}} (eq?) {{eq}} (length) {{getVal length}} (cons) {{cons}} (car) {{getVal 0 get}} (cdr) {{cdr}} (append) {{append}} (list) { list } (list?) {{isList}} (null?) {{null}}>> def
  7. 7. Good use of Concepts● Lists ○ example: Scheme command begin (begin) {prebegin {mybegin}} /prebegin { ] mark exch % make an array of all parameters begin will get andrecreate the used mark for parser } def /mybegin { mark exch % set mark where this commands parameter begins { getVal } forall % evaluate each subexpression in right order ] dup length 1 sub get % make array of all outputs and get last one } def
  8. 8. Good use of Concepts● lambda ○ code Injection /lambda { 12 array dup 0 % workaround { null % function that is executed null % array of par_names isCall 3 array dup 0 { set_pars getVal clearpars } putinterval cvx { exch lambda append_par_arr } ifelse } putinterval cvx dup 1 5 -1 roll put dup 0 4 -1 roll put } def
  9. 9. FinAny Questions?Code available:https://github.com/grill/lisps

×