Skip to content

Partition NonterminalLiteral #37

@h2oche

Description

@h2oche

Currently,

  • NonterminalLiteral represents both the grammar symbol(Ex: |A| Contains |B|) and references to child of AST node.

For example,

<emu-grammar>ArrowFunction : ArrowParameters `=>` ConciseBody</emu-grammar>
<emu-alg>
  1. If _symbol_ is not one of |NewTarget|, |SuperProperty|, |SuperCall|, `super` or `this`, return *false*. // SDO, free, grammar symbol
  1. If |ArrowParameters| Contains _symbol_ is *true*, return *true*. // SDO, not free, reference
  1. Return |ConciseBody| Contains _symbol_. // SDO, not free, reference
</emu-alg>
<emu-grammar>ClassTail : ClassHeritage? `{` ClassBody `}`</emu-grammar>
<emu-alg>
  1. If _symbol_ is |ClassBody|, return *true*. // SDO, not free, grammar symbol
  1. If _symbol_ is |ClassHeritage|, then // SDO, not free, grammar symbol
    1. If |ClassHeritage| is present, return *true*; otherwise return *false*. // SDO, not free, reference
  1. If |ClassHeritage| is present, then // SDO, not free, reference
    1. If |ClassHeritage| Contains _symbol_ is *true*, return *true*. // SDO, not free, reference
  1. Return the result of ComputedPropertyContains of |ClassBody| with argument _symbol_. // SDO, not free, reference
</emu-alg>
<emu-grammar>MethodDefinition : ClassElementName `(` UniqueFormalParameters `)` `{` FunctionBody `}`</emu-grammar>
<emu-alg>
  1. If |UniqueFormalParameters| Contains |SuperCall| is *true*, return *true*. // SDO, free, grammar symbol
  1. Return |FunctionBody| Contains |SuperCall|.
</emu-alg>
ParseScript (
  _sourceText_: ECMAScript source text,
  _realm_: unknown,
  _hostDefined_: unknown,
)
<emu-alg>
  1. Let _body_ be ParseText(_sourceText_, |Script|). // not SDO, free, grammar symbol
  1. If _body_ is a List of errors, return _body_.
  1. Return Script Record { [[Realm]]: _realm_, [[ECMAScriptCode]]: _body_, [[HostDefined]]: _hostDefined_ }.
</emu-alg>
CreateDynamicFunction (
  _constructor_: a constructor,
  _newTarget_: a constructor,
  _kind_: ~normal~, ~generator~, ~async~, or ~asyncGenerator~,
  _args_: a List of ECMAScript language values,
)
<emu-alg>
  ...
  1. If _kind_ is ~normal~, then
    1. Let _prefix_ be *"function"*.
    1. Let _exprSym_ be the grammar symbol |FunctionExpression|. // not SDO, free, grammar symbol
    1. Let _bodySym_ be the grammar symbol |FunctionBody[~Yield, ~Await]|. // not SDO, free, grammar symbol
    1. Let _parameterSym_ be the grammar symbol |FormalParameters[~Yield, ~Await]|. // not SDO, free, grammar symbol
    1. Let _fallbackProto_ be *"%Function.prototype%"*.
  ...
</emu-alg>
Static Semantics: IsLabelledFunction (_stmt_: unknown)

<emu-alg>
  1. If _stmt_ is not a |LabelledStatement|, return *false*. // not SDO, free, grammar symbol ??
  1. Let _item_ be the |LabelledItem| of _stmt_.
  1. If _item_ is <emu-grammar>LabelledItem : FunctionDeclaration</emu-grammar> , return *true*.
  1. Let _subStmt_ be the |Statement| of _item_.
  1. Return IsLabelledFunction(_subStmt_).
</emu-alg>

Current compile rule:

  • If non-terminal literal is used in sdo and not free, compile it to the reference of AST node
  • Otherwise, compile it to the grammar expression
  • It works for most of cases, but there are corner cases such as in ClassTail[0,3].Contains.

Desired:

  • Edit ecma262/spec.html to clearly describe the usage of nonterminal literal.
  • Fix parsing rules of meta-language.
  • Fix compilation rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cfgRelated to control-flow graphs (CFGs)area:langRelated to metalanguagearea:specRelated to specificationsenhancementEnhance the quality of a featurereportCreate issues/pull requests to other projects

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions