Live data from Hacker News

Parsers don't have to be complicated

bkaradzic.github.io

51–60 of 77 posts

Re: Parsers don't have to be complicated

#51
A parser/compiler could obviously be improved with an LLM (AI!) to suggest improvements to invalid input. That is actually a super good use case of LLM/AI.

Having clang/gcc, or any other parser, implement that is of course impossible, they are too conservative and would rather die than to implement modern helpful tools.

Re: Parsers don't have to be complicated

#52
post #32

Earlier quoted context omitted.

Not for C++ code generated by whole program optimizing compilers. Your "human entered" is doing the heavy lifting. Now that AI is writing code your assertion might be on shaky ground.

> Not for C++ code generated by whole program optimizing compilers. I'd be quite surprised if an optimizing compiler generated C++ code somewhere in its pipeline!

C++26 reflection?

Re: Parsers don't have to be complicated

#53
post #52

Earlier quoted context omitted.

> Not for C++ code generated by whole program optimizing compilers. I'd be quite surprised if an optimizing compiler generated C++ code somewhere in its pipeline!

C++26 reflection?

Oh, true! That's on me for not being specific enough. I was thinking about the optimization pipeline.

Re: Parsers don't have to be complicated

#54
post #32

Earlier quoted context omitted.

Not for C++ code generated by whole program optimizing compilers. Your "human entered" is doing the heavy lifting. Now that AI is writing code your assertion might be on shaky ground.

> Not for C++ code generated by whole program optimizing compilers. I'd be quite surprised if an optimizing compiler generated C++ code somewhere in its pipeline!

Take a look at Felix.

https://felix-lang.github.io/felix/

Ignore the 'scripting' language claim.

Re: Parsers don't have to be complicated

#56
post #54

Earlier quoted context omitted.

> Not for C++ code generated by whole program optimizing compilers. I'd be quite surprised if an optimizing compiler generated C++ code somewhere in its pipeline!

Take a look at Felix. https://felix-lang.github.io/felix/ Ignore the 'scripting' language claim.

Oh, that is certainly not what I was expecting at all. I stand corrected!

I do have to wonder though - do you know what proportion of the C++ compiler time is spent parsing your generated C++ code vs. optimizing it?

Re: Parsers don't have to be complicated

#57

> if (!line.accept('[').isEmpty() ) // [section] header. Is this really ergonomic?

It's not, and the article's attempt at putting lipstick on this pig is nonsensical:

> StringView has no operator bool, so a successful match reads as !scanner.accept('=').isEmpty(). Noisier than returning a bool, but the matched text comes back with the answer instead of requiring a second call to go get it.

Clearly there is a second call, it's the call to isEmpty. Plus, the actual text is lost in this particual example (though we know what it was).

An actual ergonomic way of using this would set things up so that the INI parser's inner code could be written something like this:

    bool success =
        (name = trim(acceptUntil('='))) &&
        accept('=') &&
        accept(Space) &&
        (property = acceptAll());

Re: Parsers don't have to be complicated

#58
post #26

Earlier quoted context omitted.

I think the second-hardest thing is to accept that CS spent decades optimizing parsing algorithms and grammars, and this is still a significant part of CS curricula in many places. But the practical reality is that parsing is almost never a bottleneck. If what you're parsing is within the capacity of humans to interact with (so in the range of tens of kilobytes), a grammar that requires an O(N^2) parser is totally fi…

I don't think it is difficult to accept that fundamentals should be taught. We spend years learning basic arithmetic like the addition of integers. You could very well argue that there is no need for that either because everyone has a calculator app on their phone. This is how dark ages begin.

It drives me crazy how so many people (of all ages) can't do basic math in their head, at least approximately. You need it constantly and it's so much faster than picking up your phone, starting the app, and typing in the operation. I'm so glad my teachers back in the 80s and 90s told me "you won't always have a calculator in your pocket". They were wrong (I do have one) but they were right (it's not always convenient to rely on a calculator).

Re: Parsers don't have to be complicated

#59
post #51

A parser/compiler could obviously be improved with an LLM (AI!) to suggest improvements to invalid input. That is actually a super good use case of LLM/AI. Having clang/gcc, or any other parser, implement that is of course impossible, they are too conservative and would rather die than to implement modern helpful tools.

You're presumably using an LLM to drive the compiler, and your LLM should be just as capable of reading the compiler's error message and fixing the problem. So why double the work?

Re: Parsers don't have to be complicated

#60
post #50

FORTH parsers are ultra simple - get the next space-separated token, if it is a number, push it on the stack, otherwise it's a word - look it up in the dictionary and (if it exists there) execute it.

Even simpler is you go the colorforth route, part of the source code is "pre parsed" by the editor, a prefix byte is added to each word (which is shown as different colors), then a simple dispatch loop with that prefix as a sort of opcode.
Post reply on HN