A programming language design prototyping tool
plt.js is an environment for writing and testing programming language grammars. You write your language's grammar and example code in an HTMLish syntax, and plt.js will parse your code against your grammar and display the result. It will also provide you with a REPL interface into your language, so you can get a feel for it right away.
It looks like this:
<grammar>
start = '(' '+' space a:number ' ' b:number space ')' { return a + b }
number = d:digit+ { return parseInt( d.join('') ) }
digit = [0123456789]
space = ' '*
</grammar>
<h3>Addition</h3>
<code>(+ 5 10)</code>
<code>(+7 13)</code>
<code>(+ 7 13)</code>
Which would output
Addition
(+ 5 10)
↳ 15
(+7 13)
↳ 20
(+ 7 13)
↳ 20
And if you type (+ 12 89)
and hit enter, you should see
> (+ 12 89)
101
Try it. It's great fun.
- Download and extract plt.js
- Copy
example.html
toyour-language.html
- Open
your-language.html
in a browser - Replace the
<title>
tag with the name of your language - Replace the
<grammar>
tag with the PEG grammar of your language - Write examples of correct syntax in
<code>
tags. plt.js will parse them and display the result - Write examples of incorrect syntax in
<code bad>
tags. plt.js will parse them and display the result - Write any other HTML to annotate your examples
- Open
your-language.html
file in a browser
plt.js
is designed to work offline. The only constraint is that your your-language.html
file must be in the same folder as the js/
folder where plt.js keeps its files.
To test your language, add the expect
tag to your code examples:
<code expect="15">(+ 5 10)</code>
<code expect="20">(+7 13)</code>
<code expect="20">(+ 7 13)</code>
Errors will appear inline:
PLT is short for Programming Language Theory, the branch of computer science that deals with the design and implementation of programming languages.
plt.js comes out of my time as an Eyebeam Fellow exploring code as a medium of self expression. It was further developed as a teaching tool for my programming language design class at NYU ITP.
Copyright © 2014 Ramsey Nasser. Released under the MIT License.
PEG.js Copyright © 2010–2013 David Majda
Sugar.js Copyright © 2011 Andrew Plummer