Question about the ambiguity of P4 grammar

I’ve been studying the P4 Language Specification, and noticed that it is said:

The grammar is actually ambiguous, so the lexer and the parser must collaborate for parsing the language. In particular, the lexer must be able to distinguish two kinds of identifiers:

  • Type names previously introduced (TYPE_IDENTIFIER tokens)
  • Regular identifiers (IDENTIFIER token)

I wonder if some examples could be given to illustrate such ambiguities?

In a language tool project I’m currently working on, we would like to modify the P4 grammar a little bit so it doesn’t have to distinguish between TYPE_IDENTIFIER and IDENTIFIER in the parsing phase. For the P4 language experts here, do you think this is achievable? And could you give us some suggestions on what you think is the best way to approach this?

Thanks!

I would recommend asking this question in an issue for the p4-spec, since those who know the answer are likely to see it sooner there than on this forum. If it is answered there, replying here with a link to the answer might be useful to future readers of this question.

Thanks for your suggestion! I’ll ask over there.

An example to show the P4 grammar ambiguity is given here.

1 Like