Comment

Comment by derefr

My 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 parser-generator utility that emits JavaScript, though, I’d be led to wonder whether it wouldn’t still be a more efficient use of my time (compared to hand-rolling a parser, usually a pretty finicky task) to just use yacc itself to emit C, and then use Emscripten to get WASM, and then call that from JavaScript. I’d probably do that first—it’d take about an hour—and then profile the resulting parser (including the JS-WASM overhead.) Hopefully, it’d fall within the tolerances for parsing time. Only if it didn’t would I sigh and begin to hand-roll a parser.

parent derefr 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton