by gambler · 5y ago · 0 comments
My best stab at representing something like EBNF in JS looked like this:
class ArrayGrammar { //e.g: [1, 2, 3, [4, 5,],]
array =()=> ['[', this.entries, ']'];
entries =()=> many(this.entry);
entry =()=> [either(this.array, this.number, ''), /\s*,\s*/];
number =()=> /\d+/;
}
This is a grammar for "arrays" of positive integers. I tested it out and concluded that this is too awful to be of any practical use. Now I'm seeing something with significantly more involved representation making it to the front page of HN. Hm.---
Edit: Not much to look at, but here is the source code of the toy implementation if anyone is interested:
https://jsfiddle.net/306jrnt9/1/
The only "cool" part about it is that the parser implementation is close to 100 lines of code.
https://tree-sitter.github.io/tree-sitter/creating-parsers#t...
Is it because the papers are hard to understand? All those symbols make no sense to the uninitiated. I definitely struggled to gain an understanding of how it works.