如何阅读抽象编程信息

时间:2022-12-17 15:03:35

I had a test yesterday and I found myself having to understand something I had no knowledge about.

我昨天接受了测试,发现自己必须了解一些我不了解的事情。

Please see the following page:

请参阅以下页面:

declaration-list:
  declaration
  declaration-list declaration 
declaration-specifiers:
  storage-class-specifier declaration-specifiersopt
  type-specifier declaration-specifiersopt
  type-qualifier declaration-specifiersopt 
storage-class specifier: one of
  auto register static extern typedef 
type specifier: one of
  void char short int long float double signed
  unsigned struct-or-union-specifier enum-specifier typedef-name 
type-qualifier: one of
  const volatile 
struct-or-union-specifier:
  struct-or-union identifieropt { struct-declaration-list }
  struct-or-union identifier 
struct-or-union: one of
  struct union 
struct-declaration-list:
  struct declaration
  struct-declaration-list struct declaration 
init-declarator-list:
  init-declarator
  init-declarator-list, init-declarator 
init-declarator:
  declarator
  declarator = initializer 
struct-declaration:
  specifier-qualifier-list struct-declarator-list; 
specifier-qualifier-list:
  type-specifier specifier-qualifier-listopt
  type-qualifier specifier-qualifier-listopt 
struct-declarator-list:
  struct-declarator
  struct-declarator-list , struct-declarator 
struct-declarator:
  declarator
  declaratoropt : constant-expression 
enum-specifier:
  enum identifieropt { enumerator-list }
  enum identifier 

This is from the book "The C Programming Language" by Brian W. Kernighan Dennis M. Ritchie but I saw it on the internet and on many other books.

这是由Brian W. Kernighan Dennis M. Ritchie撰写的“The C Programming Language”一书,但我在网上和许多其他书籍上看过它。

I tried googling it but frankly, I have no Idea how is it called so I couldn't find any relevant information. Our professors have never tought us to read it and I now believe it's extremely important to know how to read it.

我试着谷歌搜索它,但坦率地说,我不知道如何调用它,所以我找不到任何相关信息。我们的教授从来没有想过我们阅读它,我现在相信知道如何阅读它是非常重要的。

I'm looking for reference to guides or a short explanation on how to approach it.

我正在寻找指南的参考或如何处理它的简短说明。

I apologize if that's a repost but I couldn't find any related post.

如果这是一个转发,我道歉,但我找不到任何相关的帖子。

2 个解决方案

#1


1  

It is called the syntax notation. It is described in C11 6.1:

它被称为语法表示法。它在C11 6.1中描述:

  1. In the syntax notation used in this clause, syntactic categories (nonterminals) are indicated by italic type, and literal words and character set members (terminals) by bold type. A colon (:) following a nonterminal introduces its definition. Alternative definitions are listed on separate lines, except when prefaced by the words ''one of''. An optional symbol is indicated by the subscript opt, so that

    在本节中使用的语法表示法中,语法类别(非终结符号)由斜体类型表示,文字单词和字符集成员(终端)以粗体表示。非终结符后面的冒号(:)引入了它的定义。替代定义列在单独的行中,除非以“其中一个”开头。可选符号由下标opt表示,因此

                        { expressionopt}

    {expressionsopt}

    indicates an optional expression enclosed in braces.

    表示括在大括号中的可选表达式。

So, to take the first non-terminal as an example:

所以,以第一个非终端为例:

declaration-list:
      declaration
      declaration-list declaration

声明列表:声明声明列表声明

means that a declaration-list is a single declaration, or alternatively a declaration-list followed by a single declaration (i.e. it would define itself recursively).

表示声明列表是单个声明,或者声明列表后跟单个声明(即它将递归地定义自身)。

By the way, these declaration-lists are the old and long obsolete way how function parameters were typed in C:

顺便说一句,这些声明列表是在C中输入函数参数的旧的和过时的过时方式:

some_function(a, b)
    int a;
    double b;
{
    printf("a = %d, b = %f\n", a, b);
}

The int a; double b; part is the optional declaration-list, and double b; is a single declaration. So the declaration-list is defined recursively as being a declaration list that is of one declaration, or a declaration list that is followed by a declaration.

int a;双b; part是可选的声明列表,双b;是一个单一的声明。因此,声明列表以递归方式定义为一个声明列表,该声明列表是一个声明,或声明列表后跟一个声明。


To actually internalize meaning to these syntactic constructs, you'd better read the C11 standard draft n1570 online or the PDF version. Note also, that the grammar just gives the syntax of a C program, but the constraints and semantics of the C program are written in text.

为了实际内化这些句法结构的含义,你最好阅读在线的C11标准草案n1570或PDF版本。另请注意,语法只是给出了C程序的语法,但C程序的约束和语义是用文本编写的。

#2


2  

The first definition...

第一个定义......

declaration-list:
    declaration
    declaration-list declaration

...can be read as: "A declaration-list is either a declaration or a declaration-list followed by a declaration."

...可以理解为:“声明列表是声明或声明列表,后跟声明。”

This recursive definition allows for the following as examples of a declaration-list:

此递归定义允许以下作为声明列表的示例:

  • declaration
  • declaration declaration
  • declaration declaration declaration
  • 声明声明

  • etc.

The full grammar definition will contain additional rules describing what makes up a valid declaration, and so on.

完整的语法定义将包含描述构成有效声明的内容的其他规则,依此类推。

#1


1  

It is called the syntax notation. It is described in C11 6.1:

它被称为语法表示法。它在C11 6.1中描述:

  1. In the syntax notation used in this clause, syntactic categories (nonterminals) are indicated by italic type, and literal words and character set members (terminals) by bold type. A colon (:) following a nonterminal introduces its definition. Alternative definitions are listed on separate lines, except when prefaced by the words ''one of''. An optional symbol is indicated by the subscript opt, so that

    在本节中使用的语法表示法中,语法类别(非终结符号)由斜体类型表示,文字单词和字符集成员(终端)以粗体表示。非终结符后面的冒号(:)引入了它的定义。替代定义列在单独的行中,除非以“其中一个”开头。可选符号由下标opt表示,因此

                        { expressionopt}

    {expressionsopt}

    indicates an optional expression enclosed in braces.

    表示括在大括号中的可选表达式。

So, to take the first non-terminal as an example:

所以,以第一个非终端为例:

declaration-list:
      declaration
      declaration-list declaration

声明列表:声明声明列表声明

means that a declaration-list is a single declaration, or alternatively a declaration-list followed by a single declaration (i.e. it would define itself recursively).

表示声明列表是单个声明,或者声明列表后跟单个声明(即它将递归地定义自身)。

By the way, these declaration-lists are the old and long obsolete way how function parameters were typed in C:

顺便说一句,这些声明列表是在C中输入函数参数的旧的和过时的过时方式:

some_function(a, b)
    int a;
    double b;
{
    printf("a = %d, b = %f\n", a, b);
}

The int a; double b; part is the optional declaration-list, and double b; is a single declaration. So the declaration-list is defined recursively as being a declaration list that is of one declaration, or a declaration list that is followed by a declaration.

int a;双b; part是可选的声明列表,双b;是一个单一的声明。因此,声明列表以递归方式定义为一个声明列表,该声明列表是一个声明,或声明列表后跟一个声明。


To actually internalize meaning to these syntactic constructs, you'd better read the C11 standard draft n1570 online or the PDF version. Note also, that the grammar just gives the syntax of a C program, but the constraints and semantics of the C program are written in text.

为了实际内化这些句法结构的含义,你最好阅读在线的C11标准草案n1570或PDF版本。另请注意,语法只是给出了C程序的语法,但C程序的约束和语义是用文本编写的。

#2


2  

The first definition...

第一个定义......

declaration-list:
    declaration
    declaration-list declaration

...can be read as: "A declaration-list is either a declaration or a declaration-list followed by a declaration."

...可以理解为:“声明列表是声明或声明列表,后跟声明。”

This recursive definition allows for the following as examples of a declaration-list:

此递归定义允许以下作为声明列表的示例:

  • declaration
  • declaration declaration
  • declaration declaration declaration
  • 声明声明

  • etc.

The full grammar definition will contain additional rules describing what makes up a valid declaration, and so on.

完整的语法定义将包含描述构成有效声明的内容的其他规则,依此类推。