Brian Picciano
360857d506
The new gg format is based on a BNF file which can be found in the `gg` directory. The code for decoding `.gg` files has been refactored to mirror that file. The result is more resilient parsing, better errors, and a greater ability to extend the format in the future. The new decoder is notable in that it does not use a lexer. Both lexing and parsing are done in a single step. The format syntax itself has also been modified. Rather than using semi-colons everywhere, commas are used as separators in tuples. Additionally the final comma/semi-colon is no longer required.
25 lines
743 B
Plaintext
25 lines
743 B
Plaintext
* A function which accepts a number N and returns the Nth fibonacci number
|
|
{
|
|
* We are passing a tuple of inputs into a graph here, such that the graph is
|
|
* evaluated as an anonymous function. That anonymous function uses recur
|
|
* internally to compute the result.
|
|
out = {
|
|
|
|
* A little helper function.
|
|
decr = { out = add < (in, -1) };
|
|
|
|
* Deconstruct the input tuple into its individual elements, for clarity.
|
|
* There will be a more ergonomic way of doing this one day.
|
|
n = tupEl < (in, 0);
|
|
a = tupEl < (in, 1);
|
|
b = tupEl < (in, 2);
|
|
|
|
out = if < (
|
|
isZero < n,
|
|
a,
|
|
recur < ( decr<n, b, add<(a,b) ),
|
|
);
|
|
|
|
} < (in, 0, 1);
|
|
}
|