Liste des Groupes | Revenir à cl c |
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:I'm sure a language could have syntax and parsing rules that interpreted the minus sign as binary minus in "x-y", unary minus in "-x", and part of the literal in "-5" if it is not preceded by an operand that has a suitable subtraction operation. But I think the rules would get fairly complicated - much more so than the rules of C syntax and parsing.On 26.03.2025 20:38, Keith Thompson wrote:[...]I suppose it would be possible to define a language syntax that makesIf -5 were a single token (an integer constant), then 6-5 would be an>
integer constant 6 followed by an integer constant -5, a syntax error.
This is generally not true; that depends on the syntax rules. It is
perfectly fine to have rules for 2-ary addition and subtraction and
have also negative (and positive) literals or expressions with unary
plus and minus operators.
>
Disclaimer: As usual I'm not speaking about any peculiarity that "C"
may (or may not) have defined in its standard, but generally.
-5 a single token and still parses 6-5 as (literal 6, binary-minus,
literal-5).
I don't know of any language that uses "-" for both negation (prefix,For the most part, the important part of the grammar is the "constant expression" or "integer constant expression" - and you get that whether "-5" is parsed as one token (in a hypothetical C variant) or two tokens.
one operand) and subtraction (infix, two operands) and treats -5
as a single token rather than a unary minus operator applied to the
constant/literal "5".
Les messages affichés proviennent d'usenet.