Commits

Cat's Eye Technologies committed f11cd21

'run' and 'parse' verbs on bin/granolam. More tests. Fix one.

  • Participants
  • Parent commits 38a2cf6

Comments (0)

Files changed (8)

File README.markdown

 After the module is built, run the script `granolam_shell` in the `bin`
 directory to start a GraNoLa/M shell.
 
-Or you can run `bin/granolam` _filename_ to run a GraNoLa/M program
+Or you can run `bin/granolam run` _filename_ to run a GraNoLa/M program
 written in a text file on the filesystem.  This uses `escript`, so you
 don't have to build the module first.  But you need `realpath`.
 

File doc/GraNoLa-M.markdown

 The following EBNF exemplifies the simplicity of the grammar for this
 data type:
 
-    Graph ::= "^" ExtantName | NewName ["=" Graph] "(" {Graph} ")".
+    Graph ::= "^" ExtantName
+            | NewName ["=" Graph] "(" {Graph} ")".
 
 That is, the syntactic representation of a graph starts with either a
 caret followed by an existing label in the graph, or it starts with a
 Tests
 -----
 
+    -> Functionality "Parse GraNoLa/M Program" is implemented by
+    -> shell command "bin/granolam parse %(test-body-file)"
+
     -> Functionality "Interpret GraNoLa/M Program" is implemented by
-    -> shell command "bin/granolam %(test-body-file) | head --bytes=60"
+    -> shell command "bin/granolam run %(test-body-file)"
 
-    -> Tests for functionality "Interpret GraNoLa/M Program"
+    -> Functionality "Interpret Endless GraNoLa/M Program" is implemented by
+    -> shell command "bin/granolam run %(test-body-file) | head --bytes=60"
 
-Here are some tests.  They all loop infinitely, so we only look at the
+    -> Tests for functionality "Parse GraNoLa/M Program"
+
+Just getting the syntax right.
+
+    | a(b(^a)c(^a)d(^a)e(^a))
+    = {a,nil,[{b,nil,[a]},{c,nil,[a]},{d,nil,[a]},{e,nil,[a]}]}
+
+    | a(b(c(d(e(^a)))))
+    = {a,nil,[{b,nil,[{c,nil,[{d,nil,[{e,nil,[a]}]}]}]}]}
+
+    | a=a()(b=a(b())(^a))
+    = {a,{a,nil,[]},[{b,{a,nil,[{b,nil,[]}]},[a]}]}
+
+    | a=b=c=d=e()()()()(^a)
+    = {a,{b,{c,{d,{e,nil,[]},[]},[]},[]},[a]}
+
+    | ^potrzebie
+    = potrzebie
+
+    | ^potrzebie()
+    = potrzebie
+
+    | a=^#potrzebie(b=^uwaming(^a))
+    = {a,'#potrzebie',[{b,uwaming,[a]}]}
+
+    | a=^#cthulhu(b=^uwaming(^a))
+    = {a,'#cthulhu',[{b,uwaming,[a]}]}
+
+    | a=^whebong(b=^uwaming(^a))
+    = {a,whebong,[{b,uwaming,[a]}]}
+
+    | a=^0hello(b=^@hello(c=^taug(d=^uwaming(^a))))
+    = {a,'0hello',[{b,'@hello',[{c,taug,[{d,uwaming,[a]}]}]}]}
+
+    | a=^1hello(b=^uwaming(end() hello(world())))
+    = {a,'1hello',[{b,uwaming,[{'end',nil,[]},{hello,nil,[{world,nil,[]}]}]}]}
+
+Doesn't parse.  Why not?  Must find out someday.
+
+    | a=^sajalom(b=^#d(c=^bimodang(^a))
+    |   d(e=^#sakura(f=^uwaming(g=^ubewic()))))
+    = ???
+
+    | a=^sajalom(b=^bejadoz(c=^soduv(^a d())))
+    = {a,sajalom,[{b,bejadoz,[{c,soduv,[a,{d,nil,[]}]}]}]}
+
+    -> Tests for functionality "Interpret Endless GraNoLa/M Program"
+
+Here are some tests.  These all loop infinitely, so we only look at the
 first 60 bytes of output.
 
     | a=^#cthulhu(b=^uwaming(^a))
     | a=^0hello(b=^@hello(c=^taug(d=^uwaming(^a))))
     = embed=stack(hello())() embed=hello(hello())() embed=hello(he
 
+    -> Tests for functionality "Interpret GraNoLa/M Program"
+
+This one doesn't loop infinitely.  Note, there is a space after `world())`.
+
+    | a=^1hello(b=^uwaming(end() hello(world())))
+    = hello(world()) 
+
 The other tests in the suite in the code don't seem to work.  Pity.
+
+The last test in the suite may need user input.

File eg/example4.granolam

-a=^1hello(b=^uwaming(end=() hello=(world())))
+a=^1hello(b=^uwaming(end() hello(world())))

File eg/example6.granolam

+a=^sajalom(b=^#d(c=^bimodang(^a))
+  d(e=^#sakura(f=^uwaming(g=^ubewic()))))
+

File eg/hello-world.granolam

+a=^1hello(b=^uwaming(end() hello(world())))
+
 #!/bin/sh
 
-if [ ! -d ebin ]; then
-  mkdir ebin
-fi
+mkdir -p ebin
 for FILE in src/*.erl; do
   erlc -o ebin $FILE
 done

File src/granolam.erl

 test(1)->run("a=^#cthulhu(b=^uwaming(^a))");
 test(2)->run("a=^whebong(b=^uwaming(^a))");
 test(4)->run("a=^0hello(b=^@hello(c=^taug(d=^uwaming(^a))))");
-test(5)->run("a=^1hello(b=^uwaming(end=() hello=(world())))");
+test(5)->run("a=^1hello(b=^uwaming(end() hello(world())))");
 test(6)->run("a=^sajalom(b=^#d(c=^bimodang(^a))"
              "d(e=^#sakura(f=^uwaming(g=^ubewic()))))");
 test(7)->run("a=^sajalom(b=^bejadoz(c=^soduv(^a d())))");
 
 %% Script Interface ------------------------------------------------------
 
-main([N]) ->
-  {ok,B} = file:read_file(N),run(binary_to_list(B)).
+main(["run",N]) ->
+  {ok,B} = file:read_file(N),run(binary_to_list(B)),io:fwrite("\n");
+main(["parse",N]) ->
+  {ok,B} = file:read_file(N),io:fwrite("~w\n",[parse(binary_to_list(B))]).
 #!/bin/sh
 
-./make.sh
 falderal doc/GraNoLa-M.markdown