5 ms·
Okay, but I have no problem with the parsers of any C or C++ compiler. I don't care to make it easier for the machine.
by stefan_ 8y ago
Okay, but I have no problem with the parsers of any C or C++ compiler. I don't care to make it easier for the machine.
- diroussel 8y agoIn type to the right Language’s it’s also easier to grep for assignment or function declaration. And for me, easier to read.
- mehrdadn 8y agoEasier for the machine means easier for people to write tooling for the language. Imagine if you could ast.parse() C++ code the same way you could for Python code.
- tigershark 8y agoYou can easily parse c# or f# that are probably more complex than C++, so maybe it’s not so impossible?
- Gladdyu 8y agoI doubt those are more complex to parse than C++, as C++ parsing is undecidable. http://blog.reverberate.org/2013/08/parsing-c-is-literally-undecidable.html http://blog.reverberate.org/2013/08/parsing-c-is-literally-u...
- tigershark 8y agoC# compiler can generate a huge amount of code from simple and small programs: https://mattwarren.org/2017/11/08/A-DoS-Attack-against-the-C-Compiler/ https://mattwarren.org/2017/11/08/A-DoS-Attack-against-the-C... But you can very easily get the AST. Obviously it may happen that you have to wait until the hell is frozen to get a result, but generally it doesn’t happen in code that you see day to day..
- mehrdadn 8y agoThere's something that's unsatisfying about most of these examples which is that a sane person wouldn't write code that multiplies two objects and throws away the result, so people might think that if you added extra constraints to prevent depending on silly side effects, the issue would go away. This is definitely false, but it's not exactly obvious if you don't think about it too hard... I wish people actually paid attention to it when constructing counterexamples. So, for anyone else feeling similarly unsatisfied, here's another example that might be more satisfying in that respect: y = f(g<T, U>(x)); In conjunction with the fact that templates are already Turing-complete, we can see that detecting whether this is a call to a templated g or two comparisons is a Turing-complete question. Also notice a similar parsing issue arises in C# as well, but I don't think generics there can be used to perform Turing-complete computation... though not sure.
- mehrdadn 8y agoI didn't say it was impossible.
- tigershark 8y agoSorry, also I didn’t mean impossible, the right word is probably unpractical...
- mehrdadn 8y agoWell I don't think C++ parsing is easier than C# parsing either.
- jcelerier 8y agoast.parse() in c++ is just a matter of including libclang.h
- saagarjha 8y agoOh, but you do, because the parser will invariably leak into the way you write code. If your code takes twelve times longer to compile [1], or you need to add a space because the parser thinks that ">>" at the end of a nested template is ambiguous [2], or any number of "hacks" we have internalized as idioms because they make the parser happy, it's not really a problem with your machine anymore. [1]: https://stackoverflow.com/questions/29707622/swift-compiler-error-expression-too-complex-on-a-string-concatenation https://stackoverflow.com/questions/29707622/swift-compiler-... [2]: https://en.wikipedia.org/wiki/C%2B%2B11#Right_angle_bracket https://en.wikipedia.org/wiki/C%2B%2B11#Right_angle_bracket
- colanderman 8y ago[1] doesn't have anything to do with parsing (the problem would exist even if the compiler were fed the AST directly; the parser does not perform type inference). [2] hasn't been an issue since 2011.