MiniScript port of Bantam, a Pratt parser demo by Bob Nystrom
Bantam is a toy language created by Bob Nystrom to demonstrate Pratt parsing — an approach to parsing (computer) languages in which little mini-parsers (or "parselets" as he calls them) are each responsible for one type of statement or sub-expression.
Read more about it in my blog post, Pratt Parsing in MiniScript. And for more background and explanation, certainly read Bob's blog post.
You can run the code in Mini Micro.
- Clone or download the code from this repo to your local hard drive.
- Download Mini Micro, if you don't have it already. Launch it.
- Click the top disk slot (bottom-left corner of the window), choose "Mount Folder", and mount the "src" folder from this repo.
- Type
run "main"
and press return/enter.
The code should show "Passed all 24 tests." That means it worked!
If you like, you can now type interact
to enter a sort of interactive REPL mode. Type an expression at the $
prompt, and it will show you how it is parsed. For example, enter "a+b*c", and it will print (a + (b * c))
.
You can also get it to run in command-line MiniScript, but it will take a bit more work: (1) add importUtil.ms to your lib
folder, if you don't have it already; and (2) either ensure that .
(the current directory) is in your MS_IMPORT_PATH
, or move all the files except main.ms
into a lib
subfolder.