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.
The tree as shown is not covered by the grammar, because that does not provide a derivation from
IdentifierNametoReservedWord, and it does not provide for derivingReservedWordtoLiteraleither.The
ReservedWordproduction 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: