NullLiteral 如何以树形式表示?
根据 ECMAScript 规范 中的 < strong>7.8.1 a NullLiteral
定义如下:
NullLiteral :: null
我试图理解的是,当 NullLiteral
包含在其中时,它如何以树形式表示以下产生式可在 7.6.1 和 7.8 节中找到。
ReservedWord :: Keyword FutureReservedWord NullLiteral BooleanLiteral Literal :: NullLiteral BooleanLiteral NumericLiteral StringLiteral
我对它的外观的最佳猜测是:
InputElementDiv | Token | IdentifierName | ReservedWord | Literal | NullLiteral | null
但这对我来说似乎并不正确。
注意
根据我的研究,似乎很少有编译器真正从语言语法生成 CST。我当然可以理解为什么,但这对我来说是一个学习练习,所以我想在转向更专业的解析方法(例如使用解析器生成器)之前先解决这个问题。
According to the ECMAScript specification in section 7.8.1 a NullLiteral
is defined as follows:
NullLiteral :: null
What I am trying to understand is how this is represented in tree form when a NullLiteral
is included in the following productions found in sections 7.6.1 and 7.8.
ReservedWord :: Keyword FutureReservedWord NullLiteral BooleanLiteral Literal :: NullLiteral BooleanLiteral NumericLiteral StringLiteral
My best guess as to how it would look is this:
InputElementDiv | Token | IdentifierName | ReservedWord | Literal | NullLiteral | null
This just does not seem right to me though.
Note
From my research it seems that very few compilers actually generate CSTs from the language grammar. I can of course understand why but this is a learning exercise for me so I want to get this right before I move to more professional means of parsing such as using a parser generator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
语法未涵盖所示的树,因为它不提供从
IdentifierName
到ReservedWord
的派生,并且不提供派生ReservedWord
code> 到Literal
之一。事实上,
ReservedWord
产生式仅用于限制IdentifierName
的有效值,这应该在词法级别上看到。它不会进入 CST,在 CST 中您只能看到IdentifierName
。Literal 的上下文是 PrimaryExpression,因此真实 CST 的片段可能如下所示:
The tree as shown is not covered by the grammar, because that does not provide a derivation from
IdentifierName
toReservedWord
, and it does not provide for derivingReservedWord
toLiteral
either.The
ReservedWord
production in fact is used only to restrict valid values ofIdentifierName
, and this should be seen on the lexical level. It does not make it into a CST, where you would see just theIdentifierName
.The context of Literal is PrimaryExpression, so a fragment of a real CST could look like this: