Context free grammar compilers
A few year back I created a relational calculator, that is, a algebraic calculator working on
sets rather than numbers, called "Rel". You could do A = {1,2}; B={2,3}; C = AUB (A union B) and it happily answered C={1,2,3}. A*B (intersection of A and B) A in B (inclusion) => false, transitions, etc... It could even output a tree graph (coded by hand, no
Graphviz at this time)
I wrote it in C++ with a context-free grammar parser called St-Jean developed by my
CRIM teacher Claude Del Vigna.
I never found another so simple to use parser. I mean, look at
ANTLR. So powerful. But so complicated. And now my main language of choice is Ruby. ANTLR can compile and generate Ruby, but i is painful. Then Ruby has
Treetop. But I never got to use it due to its very light documentation. Well, the search is over, meet
Parslet !
Parslet is so cool
OK, I don't want to write another article about it. Just read
that:
Parslet is a new "simple parser framework" for Ruby built by Kaspar Schiess. It follows the PEG (parsing expression grammar) style of parsing and its primary goals are to be simple, testable, and to have extensive and powerful error reporting features (something that Kaspar states Treetop sorely lacks).
Calculette
So I wrote
Calculette. For now it does almost nothing. With this
grammar, you can write:
# Arithmetic
a = 1
b = a+2
c = a/b # a is casted to floated first
# Functions
def cube(a)
a*a*a
endf
# call the defined function
a = cube(5) + 2 # => 127
Developing Calculette is so fun ! But now what ?
Ideas ?
I don't know what to do from there :)
Maybe I will use it to write a programming language that ease the development of artificial intelligences ? Or a Ant game with scripting ? I don't know yet, any idea welcome :)