CppCon 2018: Timur Doumler & Dmitry Kozhevnikov “Parsing C++”

preview_player
Показать описание


C++ is a notoriously hard language to parse. Its grammar is highly context-dependent and ambiguous, and cannot be parsed without semantic analysis and arbitrarily long lookahead. Not only programmers, but also compilers (and their authors) often struggle with interpreting certain C++ constructs correctly.

This talk sheds some light on the grammar of C++ and why parsing it is hard. We will discuss which of these problems are inherited from C, and which arise due to features unique to C++. We will also look at a reasonably easy-to-parse subset of C++ (and whether it ever occurs in real life). Most importantly, we will talk about why all this matters for the practical C++ developer, and not just for compiler writers. And of course, we will also show plenty of surprising, brain-twisting code snippets.

This talk is aimed at general C++ programmers and does not require any expert knowledge about parsing and semantic analysis.

Timur Doumler, JetBrains

Dmitry Kozhevnikov
Software Developer, JetBrains
Dmitry works on C++ support in the CLion IDE by JetBrains, covering various aspects like the in-house C++ engine, inspections and refactoring engine, and clang integration.


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

@46:30 libClang should be in charge of all this. Its too complex for regular guys like this. They jump through hoops and go into undefined territory just to Parse. What this taught me was to NOT attempt to parse a 25 year old language with all this hidden cruft to trip you up.

mrlithium
Автор

@7:51 Completely forgot to mention unions here, but I guess that's a minor oversight because unions resemble structs in many ways when it comes to typing.

JuusoAlasuutari
Автор

They did not mention some ambiguities that are more common like:
Type V(A* B);
This can be a function declaration (if A is a type) or a variable declaration (if A and B are variables).

satyadas
Автор

After watching this I feel like getting rid of macros shouldn't be the foremost priority in the development of C++.

Raattis
Автор

C++ needs to make a breaking change and provide automatic conversion tool from C++ to CPrime... this is getting ridiculous, guys did not even mention structured bindings when it comes to [

Voy
Автор

Can we just stop using text for source code? All ambiguities should be resolved during input in an editor, leaving meta-programs to operate on proper structures.