This file contains hidden or 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
; prefix notation ---> infix notation | |
; https://gist.github.com/yamasushi/2f940393e46de5c4f90422047f8ce267 | |
(define-module pre2i | |
(export prefix->infix)) | |
(select-module pre2i) | |
; S -> <op> S S | <digit> | |
(define digit? #[0-9]) |
This file contains hidden or 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
; postfix notation --> infix notation | |
; Compilers 1st ed. ex. 2.8 (p.79) | |
; Compilers 2nd ed. ex. 2.3.2 (p.60) | |
; https://gist.github.com/yamasushi/a333611fa259b7f60f0984ba98f5b3ec | |
(define-module post2i | |
(export postfix->infix)) | |
(select-module post2i) | |
; S --> S S <op> | <digit> |
This file contains hidden or 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
; roman numeral --> integer | |
; Compilers 2nd ed. ex. 2.3.4 (p. 60) | |
; https://gist.github.com/yamasushi/379df533cd0d58e8b56e2080f2fee95e | |
(define-module r2i | |
(export roman->integer)) | |
(select-module r2i) | |
;----------------------------------------------- | |
; roman numeral ---> integer |
This file contains hidden or 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
; integer --> roman numeral | |
; Compilers 1st ed. ex. P2.1 (p. 81) | |
; Compilers 2nd ed. ex. 2.3.3 (p. 60) | |
; https://gist.github.com/yamasushi/f0febd8f53c34e4c97a025d1691a4d1d | |
(define-module i2r | |
(export integer->roman)) | |
(select-module i2r) | |
(define num-table #( |
This file contains hidden or 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
; positive binary number | |
; https://gist.github.com/yamasushi/bb2728ca917c677eea1b6aa07f180358 | |
; Compilers 2nd ed. ex. 5.4.3 (p. 337) | |
; B -> B1 0 { B.syn = 2 * B1.syn } | |
; | B1 1 { B.syn = 2 * B1.syn + 1} | |
; | 1 {B.syn = 1} | |
; B -> 1 {R.inh = 1} R {B.syn = R.syn} | |
; R -> 0 {R1.inh = R.inh * 2} R1 {R.syn = R1.syn} |
This file contains hidden or 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
gosh$ (tree '(2 ^ < 6 - 7 > + 3 * 4)) | |
(+ (^ 2 (- 6 7)) (* 3 4)) |
This file contains hidden or 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
; test calc | |
; https://gist.github.com/yamasushi/c956ae30eb20adef2c7c7afd0b70311a | |
(load "./lex") | |
(import lex) | |
(load "./calc") | |
(import calc) | |
(use gauche.generator) |
This file contains hidden or 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
gosh$ (i2p '(2 ^ < 6 - 7 > + 3 * 4)) | |
(6 7 - ^ 3 4 * +) |
This file contains hidden or 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
%% Erlang Programming(Francesco, Cesarini & Simon Thompson) | |
%% p.212, Exercise 9-5: Existing High-Order Functions | |
%% https://gist.github.com/yamasushi/b051d2ee88cfaa04dddc0fd2e05db01b | |
-module(hof). | |
-compile(export_all). | |
all(_P, []) -> true; | |
all(P, [H|T]) -> P(H) and all(P, T). | |
any(_P, []) -> false; |
This file contains hidden or 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
%% Erlang Programming(Francesco Cesarini & Simon Thompson) | |
%% P.197, Lazy Evaluation and Lists | |
%% https://gist.github.com/yamasushi/65b93369fed6c056470ee6e88974be55 | |
-module(lseq). | |
-compile(export_all). | |
%% for test | |
dump(Lseq) -> | |
lseq:foreach(fun (X)->io:format("~w~n",[X]) end, Lseq). |