Write a parser with JavaScript
21–26 of 26 posts
Re: Write a parser with JavaScript
#22My intuition as someone who writes compilers, when handed a BNF grammar, is to reach for a parser-generator like yacc, so that I can keep the BNF grammar as the canonical representation of the grammar, and have everything else derived automatically and kept in sync. (Even though, yes, in this case, JSON is a very static spec that hasn’t changed since it was introduced.) Presuming for a moment that there isn’t a parse…
But there can also be good reasons to use a hand-rolled recursive descent parser. It simplifies the build system, and it can also be easier to produce good error messages.
Re: Write a parser with JavaScript
#23Wait this is a JSON parser, not a JavaScript parser! Still nice work! There is something "raw" about writing parsers by hand (even if they are recursive descent). Teaches one a lot about clean design and modularity etc!
Re: Write a parser with JavaScript
#24Re: Write a parser with JavaScript
#25Anybody interested in parsers is gonna love it:
Re: Write a parser with JavaScript
#26My intuition as someone who writes compilers, when handed a BNF grammar, is to reach for a parser-generator like yacc, so that I can keep the BNF grammar as the canonical representation of the grammar, and have everything else derived automatically and kept in sync. (Even though, yes, in this case, JSON is a very static spec that hasn’t changed since it was introduced.) Presuming for a moment that there isn’t a parse…
I've been looking at the WASM side myself and suspect it's only a matter of time before there's a JS/TS PEG library written mostly in Rust.