Sitelet https://github.com/gpuweb/gpuweb/issues/1063
Skip to content

[WGSL] Validate the grammar is unambiguous #1063

Description

@litherum

I've done some initial work porting WGSL's grammar to Bison so we can determine whether its ambiguous or not. Here's the work-in-progress, as of 3c633ea:

wgsl.y.zip

A few observations:

  1. The grammar is ambiguous today because of type_decl argument_expression_list casts. See the discussion about this in Rename 'as' to bitcast; remove 'cast' #1047 and https://docs.google.com/document/d/1LN-L9UEtLPFKfou7jrpiSLH42xGp5ybvKaBHFTc4VKg/edit#heading=h.hp3f2zbslxr9
  2. The grammar isn't LALR(1) today because of func_call_statement. For example, in foo(...) = 5; vs foo(...);, the differentiator (= vs ;) is many tokens after the point where we have to pick a path. I think this is fixable by rejiggering the grammar because foo(...) = 5; is illegal in WGSL (for now) anyway.
  3. Bison doesn't support the * and + and ? operators that are in the spec's grammar, so I had to replace them with additional helper rules. (Which is fine.)

In https://docs.google.com/document/d/1LN-L9UEtLPFKfou7jrpiSLH42xGp5ybvKaBHFTc4VKg/edit#heading=h.hp3f2zbslxr9 we decided to try to rejigger the grammar to be LALR(1) and see if it's possible without too much trouble, so we'll investigate doing that.

I don't think there was a resolution about what to do about casts. I expect we'll discuss this in the coming meeting.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgslWebGPU Shading Language Issueswgsl:tokensWGSL tokenization and literals

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions