Ex2.3 英語以外の文法でgenerate
r5rsの内容をちょっとコピーしてみる。
ただし、実行するとスタックオーバーフローする。< だめじゃん…。
;;; Exercise 2.3 [h] Write a trivial grammar for some other language. This can be a ;;; natural language other than English, or perhaps a subset of computer language. (defvar *scheme-subset-grammar*) (setf *scheme-subset-grammar* '((<expression> -> <variable> <literal> <procedure-call> <lambda-expression> <conditional>) (<literal> -> <self-evaluating>) (<self-evaluating> -> <boolean> <number> <character> <string>) (<procedure-call> -> (|(| <operator> <operand>* |)|)) (<operator> -> <expression>) (<operand>* -> () (<operand> <operand>*)) (<operand> -> <expression>) (<lambda-expression> -> (|(| lambda <formals> <body> |)|)) (<formals> -> (|(| <variable>* |)|) <variable> (|(| <variable>+ |.| <variable> |)|)) (<body> -> (<sequence>)) (<sequence> -> (<command>* <expression>)) (<command>* -> () (<command> <command>*)) (<command> -> <expression>) (<conditional> -> (|(| if <test> <consequent> <alternate> |)|)) (<test> -> <expression>) (<consequent> -> <expression>) (<alternate> -> <expression> <empty>) (<empty> -> ()) (<variable>+ -> (<variable> <variable>*)) (<variable>* -> () (<variable> <variable>*)) ;; simple case (<variable> -> x y z a b c d e f g) (<boolean> -> |#f| |#t|) (<number> -> 0 1 2 3 4 5 6 7 8 9) (<character> -> |#\a| |#\b|) (<string> -> "foo" "bar" "bazz") )) (setf *grammar* *scheme-subset-grammar*) (format nil "~a" (generate '<expression>))