什么是嵌套名称说明符? [英] What is a nested name specifier?

查看:735
本文介绍了什么是嵌套名称说明符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关



我想知道什么是嵌套的名称说明符?我在草稿中查找,但我可以理解语法,因为我还没有采取任何编译器设计类。

  void S (){} 

struct S {
S(){cout< 1;}
void f(){}
static const int x = 0;
};

int main(){
struct S * p = new struct :: S;
p-> :: S :: f();

S :: x;

:: S(); // Is :: S是一个嵌套的名称说明符吗?
delete p;
}


解决方案

:: S 是一个 qualified-id



qualified-id :: S :: f S :: 是一个嵌套名称说明符



中, id 的一部分




  • qualified-id 开头或在初始范围解析运算符( :: )之后开始 id

  • 的最开始处以 qualified-id 中的最后一个范围解析运算符结束。 b $ b


非常正式 1 id qualified-id unqualified-id 。如果 id qualified-id ,它实际上由两部分组成:嵌套名称说明符后面跟一个 unsqualified-id



给定:

  struct A {
struct B {
void F();
};
};




  • A em>,但没有 nested-name-specifier

  • A :: B > qualified-id 和 A :: 是一个嵌套名称说明符

  • :: A :: B qualified-id A :: a qualified-id ,并且 B :: A :: B :: -name-specifiers 。

  • :: A :: B :: F ,并且 B :: A :: B ::
  • 。这是一个不完整的描述。很难用简单的英语描述语法...


    Related to this

    I want to know what exactly is a nested name specifier? I looked up in the draft but I could understand the grammar as I haven't taken any Compiler Design classes yet.

    void S(){}
    
    struct S{
       S(){cout << 1;}
       void f(){}
       static const int x = 0;
    }; 
    
    int main(){ 
       struct S *p = new struct ::S;  
       p->::S::f();
    
       S::x;  
    
       ::S(); // Is ::S a nested name specifier?
       delete p;
    } 
    

    解决方案

    ::S is a qualified-id.

    In the qualified-id ::S::f, S:: is a nested-name-specifier.

    In informal terms1, a nested-name-specifier is the part of the id that

    • begins either at the very beginning of a qualified-id or after the initial scope resolution operator (::) if one appears at the very beginning of the id and
    • ends with the last scope resolution operator in the qualified-id.

    Very informally1, an id is either a qualified-id or an unqualified-id. If the id is a qualified-id, it is actually composed of two parts: a nested-name specifier followed by an unqualified-id.

    Given:

    struct  A {
        struct B {
            void F();
        };
    };
    

    • A is an unqualified-id.
    • ::A is a qualified-id but has no nested-name-specifier.
    • A::B is a qualified-id and A:: is a nested-name-specifier.
    • ::A::B is a qualified-id and A:: is a nested-name-specifier.
    • A::B::F is a qualified-id and both B:: and A::B:: are nested-name-specifiers.
    • ::A::B::F is a qualified-id and both B:: and A::B:: are nested-name-specifiers.

    [1] This is quite an inexact description. It's hard to describe a grammar in plain English...

    这篇关于什么是嵌套名称说明符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆