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

Rework WGSL grammar to make it nicer for recursive descent #3299

Merged
merged 2 commits into from Aug 10, 2022

Conversation

dneto0
Copy link
Contributor

@dneto0 dneto0 commented Aug 9, 2022

Contributes to #3286

Make certain productions amenable for recursive descent

Avoid this kind of pattern:

(x y) * x

When you see a substring that would match 'x', you don't know
if it should match the first or second 'x' in that phrase.

Rewrite it something like this, to put the certain match against 'x'
first.

x (y x) *

In particular, rewrite these rules:

  • struct_body_decl
  • argument_expression_list
  • param_list
  1. Introduce additive_operator, multiplicative_operator

This helps eliminate epsilons in the left-recursive form of the grammar

  1. Create optionally_typed_ident, and use it to replace
    (ident | variable_ident_decl) pattern which became common
    because of type inferencing rules.

Also expand last remaining use of variable_ident_decl, for formal
parameter declaration.

Contributes to gpuweb#3286

1.
Make certain productions amenable for recursive descent

Avoid this kind of pattern:

   (x y) * x

When you see a substring that would match 'x', you don't know
if it should match the first or second 'x' in that phrase.

Rewrite it something like this, to put the certain match against 'x'
first.

   x (y x) *

In particular, rewrite these rules:
- struct_body_decl
- argument_expression_list
- param_list

2. Introduce additive_operator, multiplicative_operator

This helps eliminate epsilons in the left-recursive form of the grammar

3. Create optionally_typed_ident, and use it to replace
(ident | variable_ident_decl) pattern which became common
because of type inferencing rules.

Also expand last remaining use of variable_ident_decl, for formal
parameter declaration.
@dneto0 dneto0 added the wgsl WebGPU Shading Language Issues label Aug 9, 2022
@dneto0 dneto0 added this to the V1.0 milestone Aug 9, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2022

Previews, as seen when this build job started (50aa755):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt

wgsl/index.bs Outdated Show resolved Hide resolved
@dneto0 dneto0 requested a review from alan-baker August 10, 2022 15:08
@github-actions
Copy link
Contributor

Previews, as seen when this build job started (0644866):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt

@dneto0 dneto0 merged commit 0250ffc into gpuweb:main Aug 10, 2022
jdarpinian pushed a commit to jdarpinian/gpuweb that referenced this pull request Aug 12, 2022
* Rework WGSL grammar to make it nicer for recursive descent

Contributes to gpuweb#3286

1.
Make certain productions amenable for recursive descent

Avoid this kind of pattern:

   (x y) * x

When you see a substring that would match 'x', you don't know
if it should match the first or second 'x' in that phrase.

Rewrite it something like this, to put the certain match against 'x'
first.

   x (y x) *

In particular, rewrite these rules:
- struct_body_decl
- argument_expression_list
- param_list

2. Introduce additive_operator, multiplicative_operator

This helps eliminate epsilons in the left-recursive form of the grammar

3. Create optionally_typed_ident, and use it to replace
(ident | variable_ident_decl) pattern which became common
because of type inferencing rules.

Also expand last remaining use of variable_ident_decl, for formal
parameter declaration.

* WGSL structs always have at least one member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wgsl WebGPU Shading Language Issues
Projects
WGSL
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

3 participants