Skip to content

Instantly share code, notes, and snippets.

@yamasushi
yamasushi / bindec2.hs
Last active December 31, 2023 01:01
binary number with a decimal point
module Bindec2 where
import Debug.Trace
{-
# binary number with a "decimal" point
Compilers 2nd ed.
Exercise 5.2.4 (p.317)
Exercise 5.2.5 (p.317)
Exercise 5.5.6 (p.352)
Compilers 1st ed.
Exercise 5.8 (p.337)
@yamasushi
yamasushi / bindec1.hs
Last active December 31, 2023 01:02
binary number with a decimal point
module Bindec1 where
import Debug.Trace
{-
# binary number with a "decimal" point
Compilers 2nd ed.
Exercise 5.2.4 (p.317)
Exercise 5.2.5 (p.317)
Exercise 5.5.6 (p.352)
Compilers 1st ed.
Exercise 5.8 (p.337)
@yamasushi
yamasushi / I2r.hs
Last active December 23, 2023 02:44
integer <-----> roman numeral
module I2r ( integer2roman ) where
import Data.Char
-- integer ----> roman numeral
-- https://gist.github.com/yamasushi/2cdcf3e33dd96451870bf1e979c484cc
--- Compilers 1st ed. ex. P2.1 (p. 81)
--- Compilers 2nd ed. ex. 2.3.3 (p. 60)
-- -----------------------------------------------
@yamasushi
yamasushi / binnum.hs
Last active December 17, 2023 22:42
positive binary number
import Text.Printf
import Numeric
import Data.Char
-- positive binary number
-- https://gist.github.com/yamasushi/472c444409e8bd519e76bf0325398715
-- B -> B1 0 { B.syn = 2 * B1.syn }
-- | B1 1 { B.syn = 2 * B1.syn + 1}
-- | 1 {B.syn = 1}
--
@yamasushi
yamasushi / calc.erl
Last active December 16, 2023 06:39
desk calculator
% desk calculator
% parser
% https://gist.github.com/yamasushi/28fb60613726b55b7bea51d867b67fac
-module(calc).
-export([parse/3]).
parse(Env,Emitter,Lexer)->
{{Env,_,Lexer},Syn}=expr({Env,Emitter,Lexer}),
{Env,Lexer,Syn}.
@yamasushi
yamasushi / i2r.erl
Last active December 22, 2023 23:18
integer <----> roman numeral
% 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/d80157733f7c286f8e760bca193e027d
-module(i2r).
-export([integer2roman/1]).
%-----------------------------------------------
% integer --> roman numeral
@yamasushi
yamasushi / binnum.erl
Created December 4, 2023 22:32
positive binary number
% positive binary number
% https://gist.github.com/yamasushi/3c948fd6bdf49ea00058134544425bdd
% Compilers 2nd ed. ex. 5.4.3 (p. 337)
-module(binnum).
-export([test/1]).
% B -> B1 0 { B.syn = 2 * B1.syn }
% | B1 1 { B.syn = 2 * B1.syn + 1}
% | 1 {B.syn = 1}
@yamasushi
yamasushi / calc.rb
Last active December 16, 2023 04:39
desk calculator
# calc
# https://gist.github.com/yamasushi/0eb6dc0e023dcb2fa01102e973868903
class Calc
def initialize(lex,var,fn,op)
@lex=lex
@var=var
@fn =fn
@op =op
end
@yamasushi
yamasushi / i2r.rb
Last active December 2, 2023 06:11
integer <----> roman numeral
# 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/d250be27cb9115aeb55ec81a9c9b28a8
#-----------------------------------------------
# integer --> roman numeral
#-----------------------------------------------
# N -> N D | D
@yamasushi
yamasushi / binnum.rb
Last active November 29, 2023 22:13
positive binary number
# positive binary number
# Compilers 2nd ed. ex. 5.4.3 (p. 337)
# https://gist.github.com/yamasushi/c5b79764bdbf8af995c5782c4bacc105
# 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}