Write a parser with JavaScript
lihautan.com
Write a parser with JavaScript
1–10 of 26 posts
Re: Write a parser with JavaScript
#2Re: Write a parser with JavaScript
#3Re: Write a parser with JavaScript
#4I get the purpose, of course, but geez.
Re: Write a parser with JavaScript
#5A great parser framework is Chevrotain by SAP
Re: Write a parser with JavaScript
#6That's a heck of an interview question. I like what he was tempted to write better. I really don't want engineers toiling for hours over something a language or framework already provides. I get the purpose, of course, but geez.
But an entire JSON parser? That's nuts!
Re: Write a parser with JavaScript
#7Presuming 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.
Re: Write a parser with JavaScript
#8That's a heck of an interview question. I like what he was tempted to write better. I really don't want engineers toiling for hours over something a language or framework already provides. I get the purpose, of course, but geez.
One of my interview questions was to write a toy lisp interpreter (only needs to do addition and multiplication, that kinda thing). Not nearly this crazy, only took like 20 lines of Python, but I could see why it would be helpful. But an entire JSON parser? That's nuts!
Maybe it makes sense if you assume the input has already been tokenized so you are not expected to deal with the minutiae of string literal escape sequences and such and can focus on the high level design/flow...
Re: Write a parser with JavaScript
#9My 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…
Re: Write a parser with JavaScript
#10http://notes.eatonphil.com/writing-a-simple-json-parser.html