Live data from Hacker News

Parsing C++ is literally undecidable (2013)

blog.reverberate.org

1–10 of 146 posts

Re: Parsing C++ is literally undecidable (2013)

#3

This is why the tools situation in c++ had been so far behind other languages like Java. You have to build a full frontend to even parse the language. They're slowly becoming available via clang now, which is nice.

I wonder if it's possible to craft a non-gigantic C++ file which causes a clang frontend to crash.

Re: Parsing C++ is literally undecidable (2013)

#4
post #3

This is why the tools situation in c++ had been so far behind other languages like Java. You have to build a full frontend to even parse the language. They're slowly becoming available via clang now, which is nice.

I wonder if it's possible to craft a non-gigantic C++ file which causes a clang frontend to crash.

For sure. Generally it boils down to a non-gigantic number of template instantiations or macro expansions that end up generating a huge parse tree.

Re: Parsing C++ is literally undecidable (2013)

#5
post #3

This is why the tools situation in c++ had been so far behind other languages like Java. You have to build a full frontend to even parse the language. They're slowly becoming available via clang now, which is nice.

I wonder if it's possible to craft a non-gigantic C++ file which causes a clang frontend to crash.

This is possible in almost all language, even Python (!!!) - see the Stack Overflow question https://codegolf.stackexchange.com/questions/69189/build-a-c...

Re: Parsing C++ is literally undecidable (2013)

#7

This is why the tools situation in c++ had been so far behind other languages like Java. You have to build a full frontend to even parse the language. They're slowly becoming available via clang now, which is nice.

Java has generics and overloading; how far can you realistically get before building a full frontend? Honest question.

Re: Parsing C++ is literally undecidable (2013)

#8

Why shouldn't C++ templates be Turing-complete? Template metaprogramming is a great strength of C++. The language is gross but the result is quite powerful.

I don't feel as though the article is making value judgements based on the conclusions. At least I didn’t see anything. The implicit conclusion may be “wow, C++ is ridiculous,” but to be honest I didn’t feel that kind of tone when reading this article.

That doesn’t mean it doesn’t matter though. The decidability of C++ grammar certainly matters to folks that are parsing C++ code.

Re: Parsing C++ is literally undecidable (2013)

#9

Why shouldn't C++ templates be Turing-complete? Template metaprogramming is a great strength of C++. The language is gross but the result is quite powerful.

The problem isn't that C++ templates are Turing complete. In fact, many similar macro systems are. The problem is that the result of template/macro expansion may affect the parsing of other places, so you can't parse the non-template parts separately from the Turing-complete parts.

Re: Parsing C++ is literally undecidable (2013)

#10
Can we design a language (cpp-prime?) that is basically c++ but makes parsing easier? I'm thinking reduce the keyword reuse, use different symbols for multiplication and pointers etc. The code would be easy for c++ developers to read and converting between the two could be automatic. However, we would be able to build tooling for this new language much more easily. It would also compile quicker.
Post reply on HN