4 ms·
Another fun way to write a recursive descent parser is to abstract and parametrize the recursive descent algorithm. Best done in dynamic languages. I wrote an
by megous 10y ago
Another fun way to write a recursive descent parser is to abstract and parametrize the recursive descent algorithm.
Best done in dynamic languages. I wrote an abstract recursive descent parser in JS which accepts an array of terminal (regexp) and non-terminal definitions (array of terminal/non-terminal names + action callback), and returns the function that will parse the text.
The parser "generator" has 125 lines of code and doesn't really generate anything. It's an extremely lightweight solution to quickly produce purpose made languages in the browser without need for any tooling.
Together with `` template strings to write your custom made language code in, it makes for a lot of fun in JS. :D
- Stratoscope 10y agoIt would be really interesting to see that code if you ever want to publish it. Thanks!
- megous 10y agoI guess why not. :) https://megous.com/dl/parser/tests/index.html https://megous.com/dl/parser/tests/index.html See the code. AGPL.