diff --git a/beautiful-racket/br/demo/hdl/DMux.hdl b/beautiful-racket/br/demo/hdl/DMux.hdl new file mode 100644 index 0000000..328c556 --- /dev/null +++ b/beautiful-racket/br/demo/hdl/DMux.hdl @@ -0,0 +1,20 @@ +#lang br/demo/hdl + +// This file is part of www.nand2tetris.org +// and the book "The Elements of Computing Systems" +// by Nisan and Schocken, MIT Press. +// File name: projects/01/DMux.hdl + +/** + * Demultiplexor: + * {a, b} = {in, 0} if sel == 0 + * {0, in} if sel == 1 + */ + +CHIP DMux { + IN in, sel; + OUT a, b; + + PARTS: + Not +} diff --git a/beautiful-racket/br/demo/hdl/Dmux.tst.rkt b/beautiful-racket/br/demo/hdl/Dmux.tst.rkt new file mode 100644 index 0000000..efaf4bd --- /dev/null +++ b/beautiful-racket/br/demo/hdl/Dmux.tst.rkt @@ -0,0 +1,30 @@ +#lang br/demo/hdl/tst + +// This file is part of www.nand2tetris.org +// and the book "The Elements of Computing Systems" +// by Nisan and Schocken, MIT Press. +// File name: projects/01/DMux.tst + +load DMux.hdl, +// output-file DMux.out, +// compare-to DMux.cmp, +// output-list in%B3.1.3 sel%B3.1.3 a%B3.1.3 b%B3.1.3; +output-list in, sel, a, b; + +set in 0, +set sel 0, +eval, +output; + +set sel 1, +eval, +output; + +set in 1, +set sel 0, +eval, +output; + +set sel 1, +eval, +output; diff --git a/beautiful-racket/br/demo/hdl/Mux.hdl b/beautiful-racket/br/demo/hdl/Mux.hdl new file mode 100644 index 0000000..57fe089 --- /dev/null +++ b/beautiful-racket/br/demo/hdl/Mux.hdl @@ -0,0 +1,23 @@ +#lang br/demo/hdl + +// This file is part of www.nand2tetris.org +// and the book "The Elements of Computing Systems" +// by Nisan and Schocken, MIT Press. +// File name: projects/01/Mux.hdl + +/** + * Multiplexor: + * out = a if sel == 0 + * b otherwise + */ + +CHIP Mux { + IN a, b, sel; + OUT out; + + PARTS: + // Put your code here: + Not(in=sel, out=sel-opposite); + And(a=a, b=sel-opposite, out=maybe-a); + Or(a=maybe-a, b=b, out=out); +} diff --git a/beautiful-racket/br/demo/hdl/Mux.tst.rkt b/beautiful-racket/br/demo/hdl/Mux.tst.rkt new file mode 100644 index 0000000..0f20c9c --- /dev/null +++ b/beautiful-racket/br/demo/hdl/Mux.tst.rkt @@ -0,0 +1,51 @@ +#lang br/demo/hdl/tst +// This file is part of www.nand2tetris.org +// and the book "The Elements of Computing Systems" +// by Nisan and Schocken, MIT Press. +// File name: projects/01/Mux.tst + +load Mux.hdl, +// output-file Mux.out, +// compare-to Mux.cmp, +// output-list a%B3.1.3 b%B3.1.3 sel%B3.1.3 out%B3.1.3; +output-list a, b, sel, out; + +set a 0, +set b 0, +set sel 0, +eval, +output; + +set sel 1, +eval, +output; + +set a 0, +set b 1, +set sel 0, +eval, +output; + +set sel 1, +eval, +output; + +set a 1, +set b 0, +set sel 0, +eval, +output; + +set sel 1, +eval, +output; + +set a 1, +set b 1, +set sel 0, +eval, +output; + +set sel 1, +eval, +output; diff --git a/beautiful-racket/br/demo/hdl/info.rkt b/beautiful-racket/br/demo/hdl/info.rkt new file mode 100644 index 0000000..e3d24be --- /dev/null +++ b/beautiful-racket/br/demo/hdl/info.rkt @@ -0,0 +1,3 @@ +#lang info + +(define module-suffixes '(#"hdl" #"tst" #"cmp")) \ No newline at end of file diff --git a/beautiful-racket/br/demo/hdl/tokenizer.rkt b/beautiful-racket/br/demo/hdl/tokenizer.rkt index 44e644b..9c4a490 100644 --- a/beautiful-racket/br/demo/hdl/tokenizer.rkt +++ b/beautiful-racket/br/demo/hdl/tokenizer.rkt @@ -9,7 +9,9 @@ (define get-token (lexer [(eof) eof] - [(seq "/*" (complement (seq any-string "*/" any-string)) "*/") + [(union + (seq "/*" (complement (seq any-string "*/" any-string)) "*/") + (seq "//" (repetition 1 +inf.0 (char-complement #\newline)) #\newline)) (token 'COMMENT lexeme #:skip? #t)] [(union #\tab #\space #\newline) (get-token input-port)] [(union "CHIP" "IN" "OUT" "PARTS:") lexeme] diff --git a/beautiful-racket/br/demo/hdl/tst/tokenizer.rkt b/beautiful-racket/br/demo/hdl/tst/tokenizer.rkt index 3e78632..6c78f48 100644 --- a/beautiful-racket/br/demo/hdl/tst/tokenizer.rkt +++ b/beautiful-racket/br/demo/hdl/tst/tokenizer.rkt @@ -9,7 +9,9 @@ (define get-token (lexer [(eof) eof] - [(seq "/*" (complement (seq any-string "*/" any-string)) "*/") + [(union + (seq "/*" (complement (seq any-string "*/" any-string)) "*/") + (seq "//" (repetition 1 +inf.0 (char-complement #\newline)) #\newline)) (token 'COMMENT lexeme #:skip? #t)] [(union #\tab #\space #\newline) (get-token input-port)] [(union "load" "output-list" "set" "eval" "output" (char-set ",;")) lexeme]