“目标符号”与上下文无关语法中的“开始符号”是否相同

Is `goal symbol` the same thing as `start symbol` in context-free-grammar

Context free grammar定义四个组成部分:

  • A set of non-terminals (V)...

  • A set of tokens, known as terminal symbols (Σ)...

  • A set of productions (P)...

  • One of the non-terminals is designated as the start symbol (S); from where the production begins.

The EcmaScript specification 没有提到 起始符号 ,而是提到了 目标符号 :

Starting from a sentence consisting of a single distinguished nonterminal, called the goal symbol, a given context-free grammar specifies a language, namely, the (perhaps infinite) set of possible sequences of terminal symbols that can result from repeatedly replacing any nonterminal in the sequence with a right-hand side of a production for which the nonterminal is the left-hand side.

根据这个定义我大概可以得出结论目标符号实际上只是开始符号的另一个名称,但是使用goal symbol名称是因为有不同的开始符号 "categories":

There are several situations where the identification of lexical input elements is sensitive to the syntactic grammar context that is consuming the input elements. This requires multiple goal symbols for the lexical grammar.

那么目标符号是CFG上下文中起始符号的别称吗?

您引用的只是 CFG 的一个定义 - 还有其他定义。例如来自 here:

A grammar is the 4-tuple:

  1. A set of terminal symbols (i.e. the valid "words" of the language).
  2. A set of non-terminal symbols (i.e. the "parts-of-speech" of the language).
  3. A set of rules known as productions which can transform each non-terminal into a sequence of terminals.
  4. A start symbol or goal symbol, the non-terminal to generate (e.g., in English: the "sentence").

根据我粗略的网络搜索,似乎在讨论解析器时更常使用术语 "goal symbol"。我想这是因为存在自下而上的解析器,例如 LR-parsers,其中算法不 start 带有目标符号。

顺便说一句,ECMAScript 规范中的特定段落似乎是从 Java Language Specification 中逐字复制的 - 因此您可以将任何事情归咎于它们:-)