TinyPG Function Implementation

108 views Asked by At

Recently I've been very interested in parser generators and compiler compilers. To play around, I downloaded TinyPG and now have a simple language to parse strings and floats. Now, I'm curious about implementing simple functions with parameters. I have managed to make parameterless functions by evaluating the one-expression body and storing that in a table, and the value then gets retrieved when the function is called. How would I go about implementing simple, one expression functions with parameters in TinyPG (or any other parser generator)?

1

There are 1 answers

0
Blue0500 On BEST ANSWER

Ok, I actually found the answer to this by accident. I stumbled upon the Tiny Expression Evaluator, which was written with TinyPG. To test the function capabilities, I put in the Fibonacci sequence, fib(x) := x=0 ? 0 : (x=1 ? 1 : fib(x - 2) + fib(x - 1)), and it worked as expected. Now I'll have to figure out how they did it.