lsym_binary_op.c revision 1.5 1 /* $NetBSD: lsym_binary_op.c,v 1.5 2022/04/24 09:04:12 rillig Exp $ */
2
3 /*
4 * Tests for the token lsym_binary_op, which represents a binary operator in
5 * an expression. Examples for binary operators are '>>', '=', '+', '&&'.
6 *
7 * Binary operators are surrounded by blanks.
8 *
9 * Some tokens like '+', '*' or '&' can be either binary or unary operators,
10 * with an entirely different meaning.
11 *
12 * The token '*' is not only a binary or a unary operator, it is used in types
13 * as well, to derive a pointer type.
14 *
15 * See also:
16 * lsym_postfix_op.c for postfix unary operators
17 * lsym_unary_op.c for prefix unary operators
18 * lsym_colon.c for ':'
19 * lsym_question.c for '?'
20 * lsym_comma.c for ','
21 * C99 6.4.6 "Punctuators"
22 */
23
24 //indent input
25 void
26 binary_operators(void)
27 {
28 /* In the order of appearance in C11 6.5. */
29 a = a * a;
30 a = a / a;
31 a = a % a;
32 a = a + a;
33 a = a - a;
34 a = a << a;
35 a = a >> a;
36 a = a < a;
37 a = a > a;
38 a = a <= a;
39 a = a >= a;
40 a = a == a;
41 a = a != a;
42 a = a & a;
43 a = a ^ a;
44 a = a | a;
45 a = a && a;
46 a = a || a;
47 a = a ? a : a;
48 a = a;
49 a *= a;
50 a /= a;
51 a %= a;
52 a += a;
53 a -= a;
54 a <<= a;
55 a >>= a;
56 a &= a;
57 a ^= a;
58 a |= a;
59 a = a, a;
60 }
61 //indent end
62
63 //indent run-equals-input
64
65
66 /*
67 * If a '*' is immediately followed by another '*', they still form separate
68 * operators. The first is a binary operator, the second is unary.
69 */
70 //indent input
71 int var = expr**ptr;
72 //indent end
73
74 //indent run -di0
75 int var = expr * *ptr;
76 //indent end
77