Live data from Hacker News

Parsing C++ is literally undecidable (2013)

blog.reverberate.org

11–20 of 146 posts

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

#11
post #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.

C?

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

#12

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 think it was designed to be Turing-complete, so it’s a lot more annoying than it could be when you try to use it this way.

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

#13
post #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.

In theory that's D. D was designed to be easier to parse than C++, for example, it uses Foo!Bar and Foo!(Bar, 4) template syntax rather than Foo and Foo. On the other hand, it still uses templates and supports mixins (basically #define on steroids), so while it's easy to parse, large chunks of code don't exist until compile time so can't be indexed by IDEs perfectly.

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

#14

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.

Anecdotal, but I’ve found it difficult to find a Java autocomplete plug-in that doesn’t run Eclipse in the background to work.

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

#16
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.

There is this funny competition: https://tgceec.tumblr.com/

You could pick the winning entries and use them as a corpus for a fuzzer and you might find compiler crashes.

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

#17
post #15

> If it is not SomeType, then ::name is a typedef for int and the parse tree is declaring a pointer-to-int named x. Doesn't this require "typename" at the beginning of the line?

No, not in this instance. typename is needed to mark dependent names as types, but you can only have dependent (i.e. on a template parameter) names within templates.

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

#18
post #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.

It is called Ada.

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

#19
post #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.

In theory that's D. D was designed to be easier to parse than C++, for example, it uses Foo!Bar and Foo!(Bar, 4) template syntax rather than Foo and Foo . On the other hand, it still uses templates and supports mixins (basically #define on steroids), so while it's easy to parse, large chunks of code don't exist until compile time so can't be indexed by IDEs perfectly.

And as much as I like their community, I feel it already lost its spotlight opportunity, due to their lack of manpower vs other languages offerings and continuous improvements.

Even if C++ is a little baroque, C++17 and now C++20 provide many of the D's benefits, while keeping all the libraries, and finally we are getting Java like C++'s tooling to just throw it away.

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

#20
post #19

Earlier quoted context omitted.

In theory that's D. D was designed to be easier to parse than C++, for example, it uses Foo!Bar and Foo!(Bar, 4) template syntax rather than Foo and Foo . On the other hand, it still uses templates and supports mixins (basically #define on steroids), so while it's easy to parse, large chunks of code don't exist until compile time so can't be indexed by IDEs perfectly.

And as much as I like their community, I feel it already lost its spotlight opportunity, due to their lack of manpower vs other languages offerings and continuous improvements. Even if C++ is a little baroque, C++17 and now C++20 provide many of the D's benefits, while keeping all the libraries, and finally we are getting Java like C++'s tooling to just throw it away.

> due to their lack of manpower vs other languages offerings and continuous improvements

No. D failed due to a mandatory GC and the 'two standard libraries' idiocy.

Post reply on HN