diff options
| -rw-r--r-- | README.md | 13 | ||||
| -rw-r--r-- | examples/parser_tests.nom (renamed from parser_tests.nom) | 0 | ||||
| -rwxr-xr-x | examples/sample_code.nom | 134 | ||||
| -rw-r--r-- | examples/sample_game.nom (renamed from sample_game.nom) | 0 | ||||
| -rw-r--r-- | examples/tutorial.nom (renamed from tutorial.nom) | 0 |
5 files changed, 147 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..b40b2a9 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +This is a programming language designed to be used for playing games of Nomic, or engaging +in other similar activities revolving around natural language rule-making and self modification. + +The language compiler was written in [moonscript](http://moonscript.org/), using the +[lpeg library](http://www.inf.puc-rio.br/~roberto/lpeg/) for parsing. All of the moon files +have been compiled into lua for convenience. + +In order to run a .nom file, run `lua nomic.lua your_file.nom`. Code can also be compiled +into lua code directly, which still requires nomic.lua as a dependency, but bypasses the +compilation phase when it runs. To compile, run `lua nomic.lua your_file.nom output_file.lua` +which produces an output file which can be run with the command `lua output_file.lua`. + +Example code can be found in the examples folder. diff --git a/parser_tests.nom b/examples/parser_tests.nom index 4f8af85..4f8af85 100644 --- a/parser_tests.nom +++ b/examples/parser_tests.nom diff --git a/examples/sample_code.nom b/examples/sample_code.nom new file mode 100755 index 0000000..c8b48f7 --- /dev/null +++ b/examples/sample_code.nom @@ -0,0 +1,134 @@ +(# This is just a comment #) +(# Nested comments (# like this #) work fine #) +run file "core.nom" + +say "foo" + +say (4) + +(# "rule" is just a function that takes a function call spec and a block of code to run, + and stores the function definition #) +rule "fart": say "poot" + +fart + +(# multi-line strings: #) +say ".." + | Once upon a time + |there was a very + + + |long string + | + | with + | rather + | silly + | indentation + + | and "quotes" + |.." (even fakeouts like that) " + |(done) + | + +rule "doublefart": (# this farts twice #) + say "poot" + say "poot" + +doublefart + +rule "subex work": return "subexpressions work" + +say (subex work) + +say (..) + subex work + +say ["lists", "work"] + +say [] + +say [..] + 1, 2 + 3 + +rule "say both %one and %two": + say %one + say %two + +say both [..] + 1,2 +..and [..] + 3,4 + + +say both.. + "hello" + and "world" + +rule "three": return 3 +say both .. + "a list:" + and [..] + 1,2,(three),(4) + +if 1: yes +..else: no + +if 1: yes ..else: no + +say (do: return 5) + +rule "do %one also %two": + do %one + do %two + +do: say "one liner" +..also: say "another one liner" + +say (do: return "wow") + +say (1 + (-(2 * 3))) + +say (2 + (..) + 3 * 4 +..) + +if %x: + say "one" +..else: if %y: + say "two" +..else: + say "three" + + +printf [..] + ".." + |this is a longstring + | + .., "with", ".." + | multiple lines + +rule "%n bottles": + lua block [..] + ".." + |do + | print("running raw lua code...") + | local n = + .., %n, ".." + | + | for i=n,1,-1 do + | print(tostring(i).." bottles of beer on the wall. Take one down, pass it around,") + | end + | print("no more bottles of beer on the wall.") + |end + nil +9 bottles + +rule "dumsum %nums": + let "sum" = 0 + for "n" in %nums: + let "sum" = (%sum + %n) + return %sum + +say (dumsum [1,2,3]) + diff --git a/sample_game.nom b/examples/sample_game.nom index 010e610..010e610 100644 --- a/sample_game.nom +++ b/examples/sample_game.nom diff --git a/tutorial.nom b/examples/tutorial.nom index 1b25f69..1b25f69 100644 --- a/tutorial.nom +++ b/examples/tutorial.nom |
