xref: /PHP-Parser/test/code/parser/expr/math.test (revision 4e27a17c)
1Mathematical operators
2-----
3<?php
4
5// unary ops
6~$a;
7+$a;
8-$a;
9
10// binary ops
11$a & $b;
12$a | $b;
13$a ^ $b;
14$a . $b;
15$a / $b;
16$a - $b;
17$a % $b;
18$a * $b;
19$a + $b;
20$a << $b;
21$a >> $b;
22$a ** $b;
23
24// associativity
25$a * $b * $c;
26$a * ($b * $c);
27
28// precedence
29$a + $b * $c;
30($a + $b) * $c;
31
32// pow is special
33$a ** $b ** $c;
34($a ** $b) ** $c;
35-----
36array(
37    0: Stmt_Expression(
38        expr: Expr_BitwiseNot(
39            expr: Expr_Variable(
40                name: a
41            )
42        )
43        comments: array(
44            0: // unary ops
45        )
46    )
47    1: Stmt_Expression(
48        expr: Expr_UnaryPlus(
49            expr: Expr_Variable(
50                name: a
51            )
52        )
53    )
54    2: Stmt_Expression(
55        expr: Expr_UnaryMinus(
56            expr: Expr_Variable(
57                name: a
58            )
59        )
60    )
61    3: Stmt_Expression(
62        expr: Expr_BinaryOp_BitwiseAnd(
63            left: Expr_Variable(
64                name: a
65            )
66            right: Expr_Variable(
67                name: b
68            )
69        )
70        comments: array(
71            0: // binary ops
72        )
73    )
74    4: Stmt_Expression(
75        expr: Expr_BinaryOp_BitwiseOr(
76            left: Expr_Variable(
77                name: a
78            )
79            right: Expr_Variable(
80                name: b
81            )
82        )
83    )
84    5: Stmt_Expression(
85        expr: Expr_BinaryOp_BitwiseXor(
86            left: Expr_Variable(
87                name: a
88            )
89            right: Expr_Variable(
90                name: b
91            )
92        )
93    )
94    6: Stmt_Expression(
95        expr: Expr_BinaryOp_Concat(
96            left: Expr_Variable(
97                name: a
98            )
99            right: Expr_Variable(
100                name: b
101            )
102        )
103    )
104    7: Stmt_Expression(
105        expr: Expr_BinaryOp_Div(
106            left: Expr_Variable(
107                name: a
108            )
109            right: Expr_Variable(
110                name: b
111            )
112        )
113    )
114    8: Stmt_Expression(
115        expr: Expr_BinaryOp_Minus(
116            left: Expr_Variable(
117                name: a
118            )
119            right: Expr_Variable(
120                name: b
121            )
122        )
123    )
124    9: Stmt_Expression(
125        expr: Expr_BinaryOp_Mod(
126            left: Expr_Variable(
127                name: a
128            )
129            right: Expr_Variable(
130                name: b
131            )
132        )
133    )
134    10: Stmt_Expression(
135        expr: Expr_BinaryOp_Mul(
136            left: Expr_Variable(
137                name: a
138            )
139            right: Expr_Variable(
140                name: b
141            )
142        )
143    )
144    11: Stmt_Expression(
145        expr: Expr_BinaryOp_Plus(
146            left: Expr_Variable(
147                name: a
148            )
149            right: Expr_Variable(
150                name: b
151            )
152        )
153    )
154    12: Stmt_Expression(
155        expr: Expr_BinaryOp_ShiftLeft(
156            left: Expr_Variable(
157                name: a
158            )
159            right: Expr_Variable(
160                name: b
161            )
162        )
163    )
164    13: Stmt_Expression(
165        expr: Expr_BinaryOp_ShiftRight(
166            left: Expr_Variable(
167                name: a
168            )
169            right: Expr_Variable(
170                name: b
171            )
172        )
173    )
174    14: Stmt_Expression(
175        expr: Expr_BinaryOp_Pow(
176            left: Expr_Variable(
177                name: a
178            )
179            right: Expr_Variable(
180                name: b
181            )
182        )
183    )
184    15: Stmt_Expression(
185        expr: Expr_BinaryOp_Mul(
186            left: Expr_BinaryOp_Mul(
187                left: Expr_Variable(
188                    name: a
189                )
190                right: Expr_Variable(
191                    name: b
192                )
193            )
194            right: Expr_Variable(
195                name: c
196            )
197        )
198        comments: array(
199            0: // associativity
200        )
201    )
202    16: Stmt_Expression(
203        expr: Expr_BinaryOp_Mul(
204            left: Expr_Variable(
205                name: a
206            )
207            right: Expr_BinaryOp_Mul(
208                left: Expr_Variable(
209                    name: b
210                )
211                right: Expr_Variable(
212                    name: c
213                )
214            )
215        )
216    )
217    17: Stmt_Expression(
218        expr: Expr_BinaryOp_Plus(
219            left: Expr_Variable(
220                name: a
221            )
222            right: Expr_BinaryOp_Mul(
223                left: Expr_Variable(
224                    name: b
225                )
226                right: Expr_Variable(
227                    name: c
228                )
229            )
230        )
231        comments: array(
232            0: // precedence
233        )
234    )
235    18: Stmt_Expression(
236        expr: Expr_BinaryOp_Mul(
237            left: Expr_BinaryOp_Plus(
238                left: Expr_Variable(
239                    name: a
240                )
241                right: Expr_Variable(
242                    name: b
243                )
244            )
245            right: Expr_Variable(
246                name: c
247            )
248        )
249    )
250    19: Stmt_Expression(
251        expr: Expr_BinaryOp_Pow(
252            left: Expr_Variable(
253                name: a
254            )
255            right: Expr_BinaryOp_Pow(
256                left: Expr_Variable(
257                    name: b
258                )
259                right: Expr_Variable(
260                    name: c
261                )
262            )
263        )
264        comments: array(
265            0: // pow is special
266        )
267    )
268    20: Stmt_Expression(
269        expr: Expr_BinaryOp_Pow(
270            left: Expr_BinaryOp_Pow(
271                left: Expr_Variable(
272                    name: a
273                )
274                right: Expr_Variable(
275                    name: b
276                )
277            )
278            right: Expr_Variable(
279                name: c
280            )
281        )
282    )
283)
284