C++ Parse Analysis Introduction 2019.02.11 Kei Hasegawa
Ex1:Declaration struct T { T(); /* ... */ }; T::T() { /* ... */ }; T (a); // Declaration of `a’
Ex1:Declaration (continue) T:: T () { /* ... */ } T (a); type-name type-name declarator-id simple-type-specifier Even though parser can recognize ‘(‘ after `T’ , it’s not obvious that which rule should be chosen for `type-name’.
Ex2:Initializer struct T { /* ... */ }; int a; T t(a); // Declaration of variable `t’ typedef int A; T t2(A); // Declaration of function `t2’
Ex2:Initializer (continue) T t ( a ) T t2 ( A ) initializer parameter-declaration-clause declarator-id declarator-id Even though parser can recognize ‘(‘ after `t’ or `t2’, it’s not obvious that it is the start of `initializer’ or ‘(‘ parameter-declaration-clause ‘)’.
Ex3: Template template<class C> class T { /* ... */ }; T<char> tc; At the timing of reading `T<char>’, instantiation starts.
Ex4: member function struct T { }; void f(A a); // Error: `A’ is undeclared. void g() { A a = sizeof(T) + c[5]; /* ... */ } // OK! // ... typedef int A; char c[10]; };