You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ECMAScript 2017第5章符号约定:产生式、终结符与非终结符是什么?

Understanding Productions, Nonterminals, and Terminals in the ECMAScript 2017 Spec

Great question—these core grammar concepts are the backbone of how the ES2017 spec defines valid JavaScript syntax, so mastering them is key to parsing the rest of the document. Let’s unpack each term using the Chapter 5.1.1 definitions as a guide:

What is a Production?

First, the spec lays it out clearly:

上下文无关文法由若干产生式构成,每个产生式的左部是一个称为非终结符的抽象符号,右部是一个由零个或多个符号组成的序列……

In plain terms, a production is a rule that defines how a syntax element can be structured. Think of it as a recipe: the left side names a syntax category, and the right side lists the possible combinations of symbols that fit that category.

For example, the ES2017 spec has a production for IfStatement that looks roughly like this (simplified):

IfStatement :
    if ( Expression ) Statement
    if ( Expression ) Statement else Statement

This production tells us exactly what a valid if statement can look like—two possible valid structures.

What is a Nonterminal?

A nonterminal is the abstract symbol on the left side of a production. It represents a category of syntax, not a concrete piece of code you’d write. Nonterminals can be broken down further by other productions—they’re like building blocks that get refined until they become actual code.

Using the IfStatement example above: IfStatement, Expression, and Statement are all nonterminals. Each of these has its own set of productions that define what they can be (e.g., Expression might include arithmetic expressions, function calls, etc.).

What is a Terminal?

Terminals are the concrete, atomic symbols that make up actual JavaScript code. They’re the end result of expanding nonterminals—you can’t break them down further with more productions.

Examples of terminals in ES2017 include:

  • Keyword tokens like if, else, const
  • Operators like =, +, *
  • Literals like 42, "hello", true
  • Identifiers like myVariable, calculateTotal

In the simplified IfStatement production, the terminals are the if keyword, parentheses (), and the else keyword.


内容的提问来源于stack exchange,提问作者Magnus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:58:12