I've been researching different ways of constructing the Forge Architect DSL. There are tons of different tools and different algorithms used to lex, tokenise, and evaluate context free languages:
OMeta is based on Parsing Expression Grammars (PEG) that has been extended to handle some of the limitations that the original specification of PEGs had. For example it supports left recursion easily through a simple seed parsing and memoization trick that I don't yet fully grok. (It's all in the PHD paper)
My plan now is to create an OMeta hosted on Elixir in order to allow Elixir to interpret the Architect as an external DSL.
But before I can start, I need to practice my understand on OMeta. I found a blog post by Jeff Moser who worked on the OMeta# on C# 6 years ago. He published a small compiler for a toy Fizzbuzz language that compiled the language into C# and executed.
So here's our mission. We have a new language that looks like this:
for every number from 1 to 100 if the number is a multiple of 3 and it is a multiple of 5 then print "FizzBuzz" else if it is a multiple of 3 then print "Fizz" else if it is a multiple of 5 then print "Buzz" else print the number
Here is my solution (gist):
For the purpose of brevity, this code directly executes the Fizzbuzz language, it doesn't create an intermediate abstract syntax tree. Notice how to it essentially converts all the expressions into functions to be executed at the top level rule.
Hit the run, and you get this inside your console:
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz
Later I created a simple Markdown compiler written in OMetaJS: https://gist.github.com/CMCDragonkai/4bebe4156fcc5fdd76b0 Which was derived from the original here: http://joshondesign.com/2013/03/05/ometa1
Discovered some interesting OMetaJS idiosyncrasies when it comes to string matching: https://gist.github.com/CMCDragonkai/963bf8066ade0253bb78
Now OMetaJS is no longer being maintained. But there are 3 active forks that I am going to investigate:
Now for more OMeta research...