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
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) |
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
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) |
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
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) | |
-- ----------------------------------------------- |
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
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} | |
-- |
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
% 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}. |
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/d80157733f7c286f8e760bca193e027d | |
-module(i2r). | |
-export([integer2roman/1]). | |
%----------------------------------------------- | |
% integer --> roman numeral |
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/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} |
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
# calc | |
# https://gist.github.com/yamasushi/0eb6dc0e023dcb2fa01102e973868903 | |
class Calc | |
def initialize(lex,var,fn,op) | |
@lex=lex | |
@var=var | |
@fn =fn | |
@op =op | |
end |
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/d250be27cb9115aeb55ec81a9c9b28a8 | |
#----------------------------------------------- | |
# integer --> roman numeral | |
#----------------------------------------------- | |
# N -> N D | D |
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 | |
# 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} |
NewerOlder