p4-spec icon indicating copy to clipboard operation
p4-spec copied to clipboard

Add definition for compound assignment operators

Open rst0git opened this issue 3 years ago • 7 comments

This pull request adds definition for compound-assignment operators to the P4 language specification. These operators provide a shorter syntax for assigning the result of an arithmetic or bitwise operator. The proposed definition of compound assignment operators is similar the C99 specification.

rst0git avatar Sep 09 '22 13:09 rst0git

Did we intentionally forget about |+| and |-| operations? :)

vgurevich avatar Sep 10 '22 21:09 vgurevich

Did we intentionally forget about |+| and |-| operations? :)

Thank you Vladimir for pointing this out! I have revised the pull request to include saturating arithmetic operations.

rst0git avatar Sep 10 '22 23:09 rst0git

Are the "+=" operators two tokens or just one? That is can you do: a + = b; or does it need to be without whitespaces? a += b;

The earlier version only needs parser changes while the later needs both lexer and parser changes. Also it would nice to update the grammar in the Appendix for these too.

apinski-cavium avatar Sep 12 '22 18:09 apinski-cavium

Not only in the appendix. We should also make sure that this won't introduce conflicts in the bison parser (mostly likely not). The implementation has some subtle points - do we want to eliminate these early, in a midend pass, or not at all? If we eliminate them early in the frontend most passes won't need to learn about them. Otherwise we have to add code for handling them in many other places.

mihaibudiu avatar Sep 12 '22 19:09 mihaibudiu

We should also make sure that this won't introduce conflicts in the bison parser (mostly likely not).

It won't because statements are defined as: lvalue = expression lvalue ( ...

And lvalue does not have any of those tokens in it. If it was a single token it would make my parser easier though because I actually handle expression = expression as a way to handle things better for error reasons.

apinski-cavium avatar Sep 12 '22 19:09 apinski-cavium

In the interest of tidying up the set of active issues on the P4 specification repository, I'm marking this as "stalled" and closing it. Of course, we can always re-open it in the future if there is interest in resurrecting it.

jnfoster avatar Nov 11 '23 13:11 jnfoster