Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partition NonterminalLiteral #37

Open
h2oche opened this issue Feb 8, 2022 · 0 comments
Open

Partition NonterminalLiteral #37

h2oche opened this issue Feb 8, 2022 · 0 comments
Labels
area:cfg Related to control-flow graphs (CFGs) area:lang Related to metalanguage area:spec Related to specifications enhancement Enhance the quality of a feature report Create issues/pull requests to other projects

Comments

@h2oche
Copy link
Contributor

h2oche commented Feb 8, 2022

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.
@h2oche h2oche added enhancement Enhance the quality of a feature report Create issues/pull requests to other projects area:spec Related to specifications area:lang Related to metalanguage area:cfg Related to control-flow graphs (CFGs) labels Feb 8, 2022
@h2oche h2oche assigned h2oche and unassigned h2oche Feb 22, 2022
@h2oche h2oche removed their assignment Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:cfg Related to control-flow graphs (CFGs) area:lang Related to metalanguage area:spec Related to specifications enhancement Enhance the quality of a feature report Create issues/pull requests to other projects
Projects
None yet
Development

No branches or pull requests

1 participant