nil
nil is a brain**** language macro language and interpreter.
Macro language
nil supports a few macros that get expanded to vanilla brain**** code.
Numbered commands
The commands >, <, +, and - can be given a number to repeat that
command. For example:
+5 will be expanded into ++++++
Macros
Macros can be defined and referenced. However, since they are only expanded, they cannot recurse.
Macros are defined in the form of :sub_name{code} and are called in the form
of sub_name:
Example:
:add_two{++}add_two:
will be expanded to:
++
Including other files
Other files can be included in the current one. Files are included in the format
of: .include(file.nil)
Comments
Unlike regular brain**** where everything is treated as a comment, only lines looking like such are comments:
;this is a comment;
Comments must include both semicolons.
Modes
The original brain**** specification calls for buffers to be output as ASCII text. However, sometimes outputting numbers is more useful. Nil allows modes to be set. In the nil code, the line:
.mode(mode)
Will be used to set the mode. The mode can either be num or ascii. The
default mode is ascii.
Interpreter
nil is also a brain**** interpreter. It does the interpreting in its own special way, though:
- It uses the MacroCompiler to compile the code
- It translates the brain**** to Ruby code
- It then runs the Ruby code it generated.
The interpreter tries to be smart about the way it translates the code, for instance:
+++++ will be translated to:
sp += 5
instead of
sp += 1
sp += 1
sp += 1
sp += 1
sp += 1
Installing
Add this line to your application's Gemfile:
gem 'nil'
And then execute:
$ bundle
Or install it yourself as:
$ gem install nil
Usage
require 'nil'
code = "+4."
mp = Nil::MacroParser.new
code = mp.parse code
interpreter = Nil::Interpreter.new
interpreter.compile code
interpreter.run
Run nil -h for command line tool usage.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request