Liste des Groupes | Revenir à cl c |
On 2024-08-31, Bart <bc@freeuk.com> wrote:[...]
I can also say that the C grammar is buggy:>
>
assignment-expression:
conditional-expression
unary-expression asssignment-operator assignment-expression
I second that. If I had energy and motivation for that sort of
thing, I would submit a defect report.
>
There is no value (no pun intended) in constraining the left side
of an assignment to just that class of expression that might
produce a modifiable lvalue, since that constraint must be checked
regardless.
>
It creates an gratuitous inconsistency between the formal ISO C
grammar and the intuitive precedence model for expressions that
everyone understands. Even the K&R2 book has a precedence table
(P. p53?).
>When attempting to parse an assignment-expression, do you go for>
a conditional-expression or unary-expression?
If using a parser generator tool, like one of the Yacc
derivatives, I would just make it:
>
expr : ... /* numerous rules */
| expr '=' expr { ... }
| ... /* numerous rules */
;
>
using %left and %right declarations to set up the operator
precedences and associativities.
>
Anything you do differently from a specification, though, creates
risk. It takes extra work to show that what you have is
equivalent.
Les messages affichés proviennent d'usenet.