Add definition for compound assignment operators
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.
Did we intentionally forget about |+| and |-| operations? :)
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.
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.
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.
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.
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.