Hacker News new | ask | show | jobs
by pnx 2500 days ago
>Consider something as simple as parsing an integer in a text-based format; there may be whitespace to skip, an optional sign character, and then a loop to accumulate digits and convert them (itself a subtraction, multiply, and add), and there's still the questions of all the invalid cases and what they should do.

    ^[ *][-?][0-9][0-9]*[ *]$
You're welcome. Anything that passes that regex is a valid number. Now using that as a basis of a lexer means that you can store any int in whatever precision you feel like.

It's unfortunate that the majority of programmers these days are so computer illiterate that they can't write a parser for matching parens and call you an elitist for pointing out this is something anyone with a year of programming should be able to do in their sleep.

1 comments

Just matching that regex alone is going to take a pretty large number of instructions (at least dozens.) That's not "simple" by any measure.
Probably tens of thousands.

And it will still be a faster operation than fetching the next json file from disk by an order of magnitude, or two.