Specification
The ECMAScript® Language Specification (a living standard) details everything about the JavaScript language, so anyone can implement their own JavaScript engine.
The following chapters need to be studied for our parser:
- Chapter 5: Notational Conventions
- Chapter 11: ECMAScript Language: Source Text
- Chapter 12: ECMAScript Language: Lexical Grammar
- Chapter 13 - 16: Expressions, Statements, Functions, Classes, Scripts and Modules
- Annex B: Additional ECMAScript Features for Web Browsers
- Annex C: The Strict Mode of ECMAScript
For navigation inside the specification:
- Anything clickable has a permanent link, they are shown on the URL as anchors, for example
#sec-identifiers - Hovering over things may show a tooltip, clicking on
Referencesshows all its references
Notational Conventions
Chapter 5.1.5 Grammar Notation is the section we need to read.
The things to note here are:
Recursion
This is how lists are presented in the grammar.
ArgumentList :
AssignmentExpression
ArgumentList , AssignmentExpression
``````javascript
a, b = 1, c = 2
^_____________^ ArgumentList
^__________^ ArgumentList, AssignmentExpression,
^___^ AssignmentExpressionVariableDeclaration : BindingIdentifier Initializer_opt
javascript
var binding_identifier;
var binding_identifier = Initializer;
______________ Initializer_optScriptBody : StatementList[~Yield, ~Await, ~Return]
ModuleItem :
ImportDeclaration
ExportDeclaration
StatementListItem[~Yield, +Await, ~Return]
```<script src="javascript.js"></script><script type="module" src="main.mjs"></script>