Every repository with this icon (
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Thu Sep 17 16:07:47 -0700 2009 | |
| |
README.md | Fri Oct 23 13:54:30 -0700 2009 | |
| |
bin/ | Fri Dec 04 00:51:34 -0800 2009 | |
| |
brat | Fri Dec 18 17:26:30 -0800 2009 | |
| |
build.sh | Tue Dec 08 16:11:40 -0800 2009 | |
| |
core/ | Sat Dec 12 17:22:41 -0800 2009 | |
| |
examples/ | Fri Nov 06 12:59:20 -0800 2009 | |
| |
lib/ | Sun Dec 13 13:52:17 -0800 2009 | |
| |
parser/ | Sun Dec 13 13:49:37 -0800 2009 | |
| |
src/ | Sun Dec 13 13:52:17 -0800 2009 | |
| |
stdlib/ | Tue Dec 08 16:14:19 -0800 2009 | |
| |
test/ | Tue Dec 08 01:44:32 -0800 2009 |
Brat
Brat is a little toy language that doesn't care what you think of it.
It won't admit it, but it is not even out of infancy. Not even a toddler yet. But it can already run methods and create objects and has arrays and hashes and numbers and that sort of stuff, so it thinks quite highly of itself.
Brat uses a PEG parser written using TreeTop, a Ruby parser generator. The Brat code is then converted into Neko, compiled to Neko bytecode, and then run on the Neko VM.
Brat is flexible enough that you can get by with a very small core and write any functionality that most languages use keywords for. For example, you can write and use a while loop like so:
#Loops until the block returns false
while = { block |
true? block, { while ->block }
}
n = 1
while {
p n
n = n + 1
n < 10
}
If you would rather have your conditions be separated out, you could define it this way instead:
#Loops until condition is false
while = { condition, block |
true? condition, { block; while ->condition, ->block }
}
n = 1
while { n < 10 } { p n; n = n + 1 }
Features
- Compiles to the Neko VM the way Python compiles to its bytecode
- Parser is in Ruby
- Typeless, and pretty much classless
- Everything is object, except functions
- And functions are closures, which can be attached to objects to make methods
- Objects use a prototyping system and are completely open (plus, you can clone or inherit, your choice)
- Tail calls are optimized to make infinite loops faster (and more inifinite)
- Interactive shell just like the big boys
- Built in hash tables and dynamic arrays
- Arbitrary precision numbers
- Very flexible unary and binary operators
Requirements
Please have on hand:
- Linux (for now)
- A relatively modern Ruby (let's say 1.8.6 and up)
- You will need Ruby to be compiled with readline to use the interactive mode
- RubyGems so you may get the next requirement
- Treetop -
gem install treetop - Git if you want to check it out of the repository directly -
sudo urpmi git(or the equivalent for your platform)
Installation
Please follow the following steps, in the order in which they are ordered:
- Clone or download the latest Brat version.
There are Linux x86 binaries included. These may work for you.
If not, to compile from the source:
- Install libgc -
sudo urpmi libgc1 libgc-devel(or the equivalent for your platform) - Install GMP -
sudo urpmi libgmp libgmp-devel - Run
sh ./build.shto compile Neko and Brat (it is fine to skip any libraries it may ask about)
Testing
Try out your newly discovered power thusly:
- Type
cd brat(or wherever you tucked it away) - Create a new file, perhaps called
test.brat - In that file, type something like:
p "OK COMPUTER" - Save and close it
- Return to the comfort of your command line
- Type
./brat test.brat - Cross fingers
- Press enter
- Marvel or weep, as appropriate
For Convenience
If you want to be able to run Brat from anywhere, you can add it to your path. For example, if you had put Brat in your home directory under brat/ you would do export PATH=$PATH:$HOME/brat/
More Testing
Run ruby test/test.rb to run the test suite. SWEET.
More Fun
Try using Brat interactively by starting it without passing in a file name: ./brat
Even more fun
Take a look at some examples of Brat code.
Problems
Sometimes there are problems. Everyone has issues. Report Brat issues here.
License
The MIT License
Copyright (c) 2009, Justin Collins
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.







