Skip to content

Commit

Permalink
better demo
Browse files Browse the repository at this point in the history
  • Loading branch information
wass88 committed Nov 25, 2016
1 parent 77f8cba commit ded4656
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
*.o
*.jsmod
.stack-work
*.cmi
*.cmx
a.out
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,32 @@ OCamlの構文です。

# Interpreter

(TO DO)
```
$ less demo/demo.ml
定曰為print_string。
定名為string_of_int。
定加為(+)。
定減為(-)。
定等為(==)。
定零為0。
定一為1。
定改-行為print_newline。
定読為read_line。
定読-数為read_int。
曰「にーはお、世界」。呼改-行。
定再 階-加 数 為
若 等数零
寧 零
無 加数 所 減数一、階-加 也。
呼読-数、階-加、名、曰。呼改-行。
$ ocamlopt -pp "stack exec cocaml" demo/demo.ml
$ ./a.out
にーはお、世界
10
55
```

# Syntax

Expand Down
8 changes: 7 additions & 1 deletion app/CLI.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import System.Environment
import System.IO

import Parser (parse)
import Transpiler (transpile)

main :: IO ()
main = do
cont <- getContents
args <- getArgs
cont <- case args of
(h:_) -> readFile h
[] -> getContents
putStrLn $ case (parse cont) of
Right ast -> transpile ast
Left error -> show error
4 changes: 2 additions & 2 deletions build/Main.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions demo/demo.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
定曰為print_string。
定名為string_of_int。
定加為(+)。
定減為(-)。
定等為(==)。
定零為0
定一為1
定改-行為print_newline。
定読為read_line。
定読-数為read_int。

曰「にーはお、世界」。呼改-行。
定再 階-加 数 為
若 等数零
寧 零
無 加数 所 減数一、階-加 也。
呼読-数、階-加、名、曰。呼改-行。
30 changes: 19 additions & 11 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
.virt {
white-space: pre;
word-break: break-all;
}
.container {
display: flex;
Expand All @@ -29,6 +30,10 @@
.split {
flex-direction: column;
}
.half {
width: 50vw;
min-width: 400px;
}
.grow {
flex-grow: 1;
}
Expand All @@ -47,7 +52,7 @@
</head>
<body>
<div class="container">
<div class="split grow">
<div class="split half">
<a href=".."><h1 class="mouhitu">孔Caml</h1></a>
<h2 class="mouhitu">入力</h2>
<textarea id="input" contenteditable="true" class="grow fit"
Expand All @@ -57,22 +62,25 @@ <h2 class="mouhitu">入力</h2>
定加為(+)。
定減為(-)。
定等為(==)。
定改為print_newline。
定零為0。
定一為1。
定改-行為print_newline。
定読為read_line。
定見為read_int
定読-数為read_int

曰「にーはお」。呼改。
定再 階数 為
若 等数0
寧 0
無 加数 何 減数1、階 也。亜。
曰「にーはお、世界」。呼改-行。
定再 階-加 数 為
若 等数零
寧 零
無 加数 所 減数一、階-加 也。
呼読-数、階-加、名、曰。呼改-行。
</textarea>
<h2>OCamlコード</h2>
<div id="output" class="grow virt"></div>
<p id="output" class="grow virt"></p>
<h2>抽象構文木</h2>
<div id="ast" class=""></div>
<p id="ast" class=""></p>
</div>
<div id="preview" class="vert grow virt mouhitu"></div>
<p id="preview" class="vert grow virt mouhitu"></p>
</div>
<style>
@font-face{
Expand Down
2 changes: 1 addition & 1 deletion src/Ast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data Expr
data Idt = Idt String deriving (Show, Eq)

alphas :: [Char]
alphas = ['0'..'9'] ++ ['a'..'z'] ++ ['A'..'Z'] ++ "'_()+-="
alphas = ['0'..'9'] ++ ['a'..'z'] ++ ['A'..'Z'] ++ "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"

regchars :: [Char]
regchars = "  、。也為如若寧無呼取所也以定「」"
Expand Down
2 changes: 1 addition & 1 deletion src/Transpiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ expr (Pipe a b) = "(" ++ expr a ++ " |> " ++ expr b ++ ")"
expr (Let r a b c d) =
"(let" ++ rec r ++ " " ++ idt a ++ " " ++ args b ++ " = "
++ expr c ++ " in " ++ expr d ++ ")"
expr (If c t f) = "(if " ++ expr c ++ " then " ++ expr t ++ " else " ++ expr f ++ " end)"
expr (If c t f) = "(if " ++ expr c ++ " then " ++ expr t ++ " else " ++ expr f ++ ")"
expr (Call f) = "(" ++ expr f ++ "())"

sent :: Sent -> String
Expand Down
2 changes: 1 addition & 1 deletion test/TranspilerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ spec = do
(Let Rec (Idt "a") [Idt "b", Idt "c"]
(Apply (i "c") (i "d")) (Pipe (i "e") (i "f")))
describe "lif" $ do
testExpr "(if a then (b |> c) else d end)"
testExpr "(if a then (b |> c) else d)"
(If (i "a") (Pipe (i "b") (i "c")) (i "d"))
describe "call" $ do
testExpr "(a())" (Call (i "a"))
Expand Down

0 comments on commit ded4656

Please sign in to comment.