143
|
1 /* parse.y -*- text -*- |
1
|
2 |
|
3 Copyright (C) 1992, 1993 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 // Parser for Octave. |
|
24 |
|
25 /* |
|
26 * C decarations. |
|
27 */ |
|
28 %{ |
|
29 #define YYDEBUG 1 |
|
30 |
|
31 #include "SLStack.h" |
|
32 |
|
33 #include "Matrix.h" |
|
34 |
|
35 #include "error.h" |
|
36 #include "variables.h" |
168
|
37 #include "octave-hist.h" |
1
|
38 #include "user-prefs.h" |
|
39 #include "input.h" |
|
40 #include "utils.h" |
|
41 #include "tree.h" |
|
42 #include "symtab.h" |
|
43 #include "builtins.h" |
|
44 #include "octave.h" |
|
45 #include "parse.h" |
|
46 #include "lex.h" |
143
|
47 #include "token.h" |
1
|
48 |
|
49 // Nonzero means we're in the middle of defining a function. |
|
50 int defining_func = 0; |
|
51 |
|
52 // Nonzero means we're in the middle of defining a loop. |
|
53 int looping = 0; |
|
54 |
|
55 // Nonzero means we're in the middle of defining a conditional expression. |
|
56 int iffing = 0; |
|
57 |
|
58 // Nonzero means we need to do some extra lookahead to avoid being |
|
59 // screwed by bogus function syntax. |
|
60 int maybe_screwed = 0; |
|
61 |
|
62 // Nonzero means we need to do some extra lookahead to avoid being |
|
63 // screwed by bogus function syntax. |
|
64 int maybe_screwed_again = 0; |
|
65 |
|
66 // Temporary symbol table pointer used to cope with bogus function syntax. |
|
67 symbol_table *tmp_local_sym_tab = (symbol_table *) NULL; |
|
68 |
|
69 // Stack to hold list of literal matrices. |
|
70 SLStack <tree_matrix *> ml; |
|
71 |
|
72 // A nonzero element corresponding to an element of ml means we just |
|
73 // started reading a new matrix. This should probably be part of a |
|
74 // new struct for matrix lists... |
|
75 SLStack <int> mlnm; |
|
76 |
|
77 // The current input line number. |
|
78 int input_line_number = 0; |
|
79 |
|
80 // The column of the current token. |
143
|
81 int current_input_column = 1; |
1
|
82 |
|
83 // Buffer for help text snagged from M-files. |
|
84 // Probably shouldn't be a fixed size... |
|
85 char help_buf [HELP_BUF_LENGTH]; |
|
86 |
|
87 // Nonzero means we're working on a plot command. |
|
88 int plotting = 0; |
|
89 |
113
|
90 // Nonzero means we've seen something that means we must be past the |
|
91 // range part of a plot command. |
|
92 int past_plot_range = 0; |
|
93 |
1
|
94 // Nonzero means we're looking at the range part of a plot command. |
|
95 int in_plot_range = 0; |
|
96 |
|
97 // Nonzero means we're looking at the using part of a plot command. |
|
98 int in_plot_using = 0; |
|
99 |
|
100 // Nonzero means we're looking at the style part of a plot command. |
|
101 int in_plot_style = 0; |
|
102 |
143
|
103 // Check to see that end statements are properly matched. |
|
104 static int check_end (token *tok, token::end_tok_type expected); |
1
|
105 |
|
106 // Error mesages for mismatched end statements. |
143
|
107 static void end_error (char *type, token::end_tok_type ettype, int l, int c); |
1
|
108 |
|
109 // Generic error messages. |
|
110 static void yyerror (char *s); |
|
111 |
|
112 static tree *maybe_convert_to_ans_assign (tree *expr); |
|
113 static void maybe_warn_assign_as_truth_value (tree *expr); |
|
114 |
|
115 #define ABORT_PARSE \ |
|
116 do \ |
|
117 { \ |
|
118 global_command = NULL_TREE; \ |
|
119 reset_parser (); \ |
|
120 yyerrok; \ |
|
121 if (interactive) \ |
|
122 YYACCEPT; \ |
|
123 else \ |
|
124 YYABORT; \ |
|
125 } \ |
|
126 while (0) |
|
127 |
|
128 %} |
|
129 |
|
130 /* |
|
131 * Bison declarations. |
|
132 */ |
|
133 %union |
|
134 { |
143
|
135 // The type of the basic tokens returned by the lexer. |
|
136 token *tok_val; |
|
137 |
|
138 // Types for the nonterminals we generate. |
1
|
139 tree *tree_type; |
|
140 tree_constant *tree_constant_type; |
|
141 tree_matrix *tree_matrix_type; |
|
142 tree_identifier *tree_identifier_type; |
|
143 tree_function *tree_function_type; |
|
144 tree_index_expression *tree_index_expression_type; |
|
145 tree_colon_expression *tree_colon_expression_type; |
|
146 tree_argument_list *tree_argument_list_type; |
|
147 tree_parameter_list *tree_parameter_list_type; |
|
148 tree_word_list *tree_word_list_type; |
|
149 tree_command *tree_command_type; |
|
150 tree_if_command *tree_if_command_type; |
195
|
151 tree_global_command *tree_global_command_type; |
1
|
152 tree_command_list *tree_command_list_type; |
|
153 tree_word_list_command *tree_word_list_command_type; |
|
154 tree_plot_command *tree_plot_command_type; |
|
155 tree_subplot_list *tree_subplot_list_type; |
|
156 tree_plot_limits *tree_plot_limits_type; |
|
157 tree_plot_range *tree_plot_range_type; |
|
158 tree_subplot_using *tree_subplot_using_type; |
|
159 tree_subplot_style *tree_subplot_style_type; |
|
160 } |
|
161 |
143
|
162 // Tokens with line and column information. |
|
163 %token <tok_val> '=' ':' '-' '+' '*' '/' |
|
164 %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT |
|
165 %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT |
|
166 %token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV QUOTE TRANSPOSE |
|
167 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW |
|
168 %token <tok_val> NUM IMAG_NUM |
169
|
169 %token <tok_val> NAME SCREW |
143
|
170 %token <tok_val> END |
|
171 %token <tok_val> PLOT |
|
172 %token <tok_val> TEXT STYLE |
191
|
173 %token <tok_val> FOR WHILE IF ELSEIF ELSE BREAK CONTINUE FUNC_RET |
1
|
174 |
143
|
175 // Other tokens. |
191
|
176 %token FCN SCREW_TWO |
143
|
177 %token END_OF_INPUT GLOBAL |
1
|
178 %token USING TITLE WITH COLON OPEN_BRACE CLOSE_BRACE |
|
179 |
143
|
180 // Nonterminals we construct. |
1
|
181 %type <tree_type> input command |
|
182 %type <tree_type> ans_expression expression simple_expr simple_expr1 |
|
183 %type <tree_type> title |
|
184 %type <tree_matrix_type> matrix |
|
185 %type <tree_identifier_type> identifier |
|
186 %type <tree_function_type> func_def func_def1 func_def2 func_def3 |
|
187 %type <tree_index_expression_type> variable |
|
188 %type <tree_colon_expression_type> colon_expr |
|
189 %type <tree_argument_list_type> arg_list arg_list1 |
|
190 %type <tree_parameter_list_type> param_list param_list1 func_def1a |
|
191 %type <tree_word_list_type> word_list word_list1 |
|
192 %type <tree_command_type> statement |
|
193 %type <tree_if_command_type> elseif |
195
|
194 %type <tree_global_command_type> global_decl global_decl1 |
1
|
195 %type <tree_command_list_type> simple_list simple_list1 list list1 opt_list |
|
196 %type <tree_word_list_command_type> word_list_cmd |
|
197 %type <tree_plot_command_type> plot_command |
|
198 %type <tree_subplot_list_type> plot_command1 plot_command2 plot_options |
|
199 %type <tree_plot_limits_type> ranges |
|
200 %type <tree_plot_range_type> ranges1 |
|
201 %type <tree_subplot_using_type> using using1 |
|
202 %type <tree_subplot_style_type> style |
|
203 |
143
|
204 // Precedence and associativity. |
1
|
205 %left ';' ',' '\n' |
|
206 %right '=' |
|
207 %left EXPR_AND EXPR_OR |
|
208 %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT |
|
209 %left ':' |
|
210 %left '-' '+' |
|
211 %left '*' '/' LEFTDIV EMUL EDIV ELEFTDIV |
|
212 %left QUOTE TRANSPOSE |
|
213 %left UNARY PLUS_PLUS MINUS_MINUS EXPR_NOT |
|
214 %right POW EPOW |
|
215 |
169
|
216 // There are 19 shift/reduce conflicts, ok? |
|
217 %expect 19 |
143
|
218 |
|
219 // Where to start. |
1
|
220 %start input |
|
221 |
|
222 /* |
|
223 * Grammar rules. |
|
224 */ |
|
225 %% |
|
226 |
|
227 input : '\n' |
|
228 { |
|
229 global_command = NULL_TREE; |
|
230 promptflag = 1; |
|
231 YYACCEPT; |
|
232 } |
|
233 | END_OF_INPUT |
|
234 { |
|
235 global_command = NULL_TREE; |
|
236 promptflag = 1; |
|
237 YYABORT; |
|
238 } |
|
239 | simple_list '\n' |
|
240 { |
|
241 global_command = $1; |
|
242 promptflag = 1; |
|
243 YYACCEPT; |
|
244 } |
|
245 | simple_list END_OF_INPUT |
|
246 { |
|
247 global_command = $1; |
|
248 promptflag = 1; |
|
249 YYACCEPT; |
|
250 } |
|
251 | error |
|
252 { ABORT_PARSE; } |
|
253 | error '\n' |
|
254 { ABORT_PARSE; } |
|
255 | error END_OF_INPUT |
|
256 { ABORT_PARSE; } |
|
257 | simple_list error |
|
258 { ABORT_PARSE; } |
|
259 | simple_list error END_OF_INPUT |
|
260 { ABORT_PARSE; } |
|
261 ; |
|
262 |
|
263 simple_list : semi_comma |
|
264 { $$ = (tree_command_list *) NULL; } |
|
265 | comma_semi |
|
266 { $$ = (tree_command_list *) NULL; } |
|
267 | simple_list1 |
|
268 { $$ = $1->reverse (); } |
|
269 | simple_list1 semi_comma |
|
270 { |
|
271 $1->set_print_flag (0); |
|
272 $$ = $1->reverse (); |
|
273 } |
|
274 | simple_list1 comma_semi |
|
275 { $$ = $1->reverse (); } |
|
276 ; |
|
277 |
|
278 simple_list1 : command |
|
279 { $$ = new tree_command_list ($1); } |
|
280 | semi_comma command |
|
281 { $$ = new tree_command_list ($2); } |
|
282 | comma_semi command |
|
283 { $$ = new tree_command_list ($2); } |
|
284 | simple_list1 semi_comma command |
|
285 { |
|
286 $1->set_print_flag (0); |
|
287 $$ = $1->chain ($3); |
|
288 } |
|
289 | simple_list1 comma_semi command |
|
290 { $$ = $1->chain ($3); } |
|
291 ; |
|
292 |
|
293 semi_comma : ';' |
|
294 | semi_comma ',' |
|
295 | semi_comma ';' |
|
296 ; |
|
297 |
|
298 comma_semi : ',' |
|
299 | comma_semi ';' |
|
300 | comma_semi ',' |
|
301 ; |
|
302 |
|
303 comma_nl_sep : ',' |
|
304 | '\n' |
|
305 | comma_nl_sep sep |
|
306 ; |
|
307 |
|
308 semi_sep : ';' |
|
309 | semi_sep sep |
|
310 ; |
|
311 |
|
312 opt_list : // empty |
|
313 { $$ = new tree_command_list (); } |
|
314 | list |
|
315 { $$ = $1; } |
|
316 |
|
317 list : list1 |
|
318 { $$ = $1->reverse (); } |
|
319 | list1 comma_nl_sep |
|
320 { $$ = $1->reverse (); } |
|
321 | list1 semi_sep |
|
322 { |
|
323 $1->set_print_flag (0); |
|
324 $$ = $1->reverse (); |
|
325 } |
|
326 ; |
|
327 |
|
328 list1 : command |
|
329 { $$ = new tree_command_list ($1); } |
|
330 | list1 comma_nl_sep command |
|
331 { $$ = $1->chain ($3); } |
|
332 | list1 semi_sep command |
|
333 { |
|
334 $1->set_print_flag (0); |
|
335 $$ = $1->chain ($3); |
|
336 } |
|
337 ; |
|
338 |
|
339 command : plot_command |
|
340 { $$ = $1; } |
|
341 | statement |
|
342 { $$ = $1; } |
|
343 | ans_expression |
|
344 { $$ = $1; } |
|
345 | func_def |
|
346 { $$ = $1; } |
|
347 | global_decl |
191
|
348 { $$ = $1; } |
1
|
349 ; |
|
350 |
|
351 plot_command : PLOT plot_command1 |
|
352 { |
|
353 tree_subplot_list *tmp = $2->reverse (); |
143
|
354 $$ = new tree_plot_command (tmp, $1->pttype ()); |
1
|
355 plotting = 0; |
113
|
356 past_plot_range = 0; |
1
|
357 in_plot_range = 0; |
|
358 in_plot_using = 0; |
|
359 in_plot_style = 0; |
|
360 } |
|
361 | PLOT ranges plot_command1 |
|
362 { |
|
363 tree_subplot_list *tmp = $3->reverse (); |
143
|
364 $$ = new tree_plot_command (tmp, $2, $1->pttype ()); |
1
|
365 plotting = 0; |
113
|
366 past_plot_range = 0; |
1
|
367 in_plot_range = 0; |
|
368 in_plot_using = 0; |
|
369 in_plot_style = 0; |
|
370 } |
|
371 ; |
|
372 |
|
373 ranges : ranges1 |
|
374 { $$ = new tree_plot_limits ($1); } |
|
375 | ranges1 ranges1 |
|
376 { $$ = new tree_plot_limits ($1, $2); } |
|
377 | ranges1 ranges1 ranges1 |
|
378 { $$ = new tree_plot_limits ($1, $2, $3); } |
|
379 ; |
|
380 |
|
381 ranges1 : OPEN_BRACE expression COLON expression CLOSE_BRACE |
|
382 { $$ = new tree_plot_range ($2, $4); } |
|
383 | OPEN_BRACE COLON expression CLOSE_BRACE |
|
384 { $$ = new tree_plot_range (NULL, $3); } |
|
385 | OPEN_BRACE expression COLON CLOSE_BRACE |
|
386 { $$ = new tree_plot_range ($2, NULL); } |
|
387 | OPEN_BRACE COLON CLOSE_BRACE |
|
388 { $$ = new tree_plot_range (); } |
|
389 | OPEN_BRACE CLOSE_BRACE |
|
390 { $$ = new tree_plot_range (); } |
|
391 ; |
|
392 |
|
393 plot_command1 : plot_command2 |
|
394 { $$ = $1; } |
|
395 | plot_command1 ',' plot_command2 |
|
396 { $$ = $1->chain ($3); } |
|
397 ; |
|
398 |
|
399 plot_command2 : expression |
|
400 { $$ = new tree_subplot_list ($1); } |
|
401 | expression plot_options |
|
402 { $$ = $2->set_data ($1); } |
|
403 ; |
|
404 |
|
405 plot_options : using |
|
406 { $$ = new tree_subplot_list ($1, NULL, NULL); } |
|
407 | title |
|
408 { $$ = new tree_subplot_list (NULL, $1, NULL); } |
|
409 | style |
|
410 { $$ = new tree_subplot_list (NULL, NULL, $1); } |
|
411 | using title |
|
412 { $$ = new tree_subplot_list ($1, $2, NULL); } |
|
413 | title using |
|
414 { $$ = new tree_subplot_list ($2, $1, NULL); } |
|
415 | using style |
|
416 { $$ = new tree_subplot_list ($1, NULL, $2); } |
|
417 | style using |
|
418 { $$ = new tree_subplot_list ($2, NULL, $1); } |
|
419 | title style |
|
420 { $$ = new tree_subplot_list (NULL, $1, $2); } |
|
421 | style title |
|
422 { $$ = new tree_subplot_list (NULL, $2, $1); } |
|
423 | using title style |
|
424 { $$ = new tree_subplot_list ($1, $2, $3); } |
|
425 | using style title |
|
426 { $$ = new tree_subplot_list ($1, $3, $2); } |
|
427 | title using style |
|
428 { $$ = new tree_subplot_list ($2, $1, $3); } |
|
429 | title style using |
|
430 { $$ = new tree_subplot_list ($3, $1, $2); } |
|
431 | style using title |
|
432 { $$ = new tree_subplot_list ($2, $3, $1); } |
|
433 | style title using |
|
434 { $$ = new tree_subplot_list ($3, $2, $1); } |
|
435 ; |
|
436 |
|
437 using : using1 |
|
438 { |
|
439 $$ = $1; |
|
440 in_plot_using = 0; |
|
441 } |
|
442 | using1 expression |
|
443 { |
|
444 $$ = $1->set_format ($2); |
|
445 in_plot_using = 0; |
|
446 } |
|
447 ; |
|
448 |
|
449 using1 : USING expression |
|
450 { |
|
451 tree_subplot_using *tmp = new tree_subplot_using (); |
|
452 $$ = tmp->add_qualifier ($2); |
|
453 } |
|
454 | using1 COLON expression |
|
455 { $$ = $1->add_qualifier ($3); } |
|
456 ; |
|
457 |
|
458 title : TITLE expression |
|
459 { $$ = $2; } |
|
460 ; |
|
461 |
|
462 style : WITH STYLE |
143
|
463 { $$ = new tree_subplot_style ($2->string ()); } |
1
|
464 | WITH STYLE expression |
143
|
465 { $$ = new tree_subplot_style ($2->string (), $3); } |
1
|
466 | WITH STYLE expression bogus_syntax expression |
143
|
467 { $$ = new tree_subplot_style ($2->string (), $3, $5); } |
1
|
468 ; |
|
469 |
|
470 bogus_syntax : // empty |
|
471 ; |
|
472 |
|
473 ans_expression : expression |
|
474 { $$ = maybe_convert_to_ans_assign ($1); } |
|
475 ; |
|
476 |
|
477 global_decl : GLOBAL global_decl1 |
191
|
478 { $$ = $2->reverse (); } |
195
|
479 | GLOBAL global_decl1 ',' |
|
480 { $$ = $2->reverse (); } |
1
|
481 ; |
|
482 |
|
483 global_decl1 : NAME |
191
|
484 { |
195
|
485 $$ = new tree_global_command |
|
486 ($1->sym_rec (), $1->line (), $1->column ()); |
191
|
487 } |
1
|
488 | NAME '=' expression |
|
489 { |
195
|
490 $$ = new tree_global_command |
|
491 ($1->sym_rec (), $3, $1->line (), $1->column ()); |
1
|
492 } |
|
493 | global_decl1 optcomma NAME |
191
|
494 { |
195
|
495 $$ = $1->chain ($3->sym_rec (), $3->line (), |
|
496 $3->column ()); |
191
|
497 } |
1
|
498 | global_decl1 optcomma NAME '=' expression |
|
499 { |
195
|
500 $$ = $1->chain ($3->sym_rec (), $5, $3->line (), |
|
501 $3->column ()); |
1
|
502 } |
|
503 ; |
|
504 |
|
505 optcomma : // empty |
|
506 | ',' |
|
507 { |
|
508 if (user_pref.warn_comma_in_global_decl) |
|
509 warning ("comma in global declaration not\ |
|
510 interpreted as a command separator"); |
|
511 } |
|
512 ; |
|
513 |
|
514 statement : WHILE expression optsep opt_list END |
|
515 { |
|
516 maybe_warn_assign_as_truth_value ($2); |
143
|
517 if (check_end ($5, token::while_end)) |
|
518 ABORT_PARSE; |
1
|
519 looping--; |
191
|
520 $$ = new tree_while_command ($2, $4, $1->line (), |
|
521 $1->column ()); |
1
|
522 } |
118
|
523 | FOR variable '=' expression optsep opt_list END |
1
|
524 { |
143
|
525 if (check_end ($7, token::for_end)) |
|
526 ABORT_PARSE; |
1
|
527 looping--; |
191
|
528 $$ = new tree_for_command ($2, $4, $6, |
|
529 $1->line (), $1->column ()); |
1
|
530 } |
|
531 | IF expression optsep opt_list END |
|
532 { |
|
533 maybe_warn_assign_as_truth_value ($2); |
143
|
534 if (check_end ($5, token::if_end)) |
|
535 ABORT_PARSE; |
1
|
536 iffing--; |
191
|
537 $$ = new tree_if_command ($2, $4, |
|
538 $1->line (), $1->column ()); |
1
|
539 } |
|
540 | IF expression optsep opt_list ELSE optsep opt_list END |
|
541 { |
|
542 maybe_warn_assign_as_truth_value ($2); |
143
|
543 if (check_end ($8, token::if_end)) |
|
544 ABORT_PARSE; |
1
|
545 iffing--; |
191
|
546 tree_if_command *t1 = new tree_if_command |
|
547 ($7, $5->line (), $5->column ()); |
|
548 $$ = t1->chain ($2, $4, $1->line (), $1->column ()); |
1
|
549 } |
|
550 | IF expression optsep opt_list elseif END |
|
551 { |
|
552 maybe_warn_assign_as_truth_value ($2); |
143
|
553 if (check_end ($6, token::if_end)) |
|
554 ABORT_PARSE; |
1
|
555 iffing--; |
|
556 tree_if_command *t1 = $5->reverse (); |
|
557 // Add the if list to the new head of the elseif |
|
558 // list, and return the list. |
191
|
559 $$ = t1->chain ($2, $4, $1->line (), $1->column ()); |
1
|
560 } |
|
561 | IF expression optsep opt_list elseif ELSE optsep opt_list END |
|
562 { |
|
563 maybe_warn_assign_as_truth_value ($2); |
143
|
564 if (check_end ($9, token::if_end)) |
|
565 ABORT_PARSE; |
1
|
566 iffing--; |
|
567 // Add the else list to the head of the elseif list, |
|
568 // then reverse the list. |
191
|
569 tree_if_command *t1 = $5->chain ($8, $6->line (), |
|
570 $6->column ()); |
1
|
571 t1 = t1->reverse (); |
|
572 // Add the if list to the new head of the elseif |
|
573 // list, and return the list. |
191
|
574 $$ = t1->chain ($2, $4, $1->line (), $1->column ()); |
1
|
575 } |
|
576 | BREAK |
|
577 { |
|
578 if (!looping) |
|
579 { |
|
580 yyerror ("parse error"); |
|
581 error ("break: only meaningful within a `for'\ |
|
582 or `while' loop"); |
|
583 ABORT_PARSE; |
|
584 } |
191
|
585 $$ = new tree_break_command ($1->line (), $1->column ()); |
1
|
586 } |
|
587 | CONTINUE |
|
588 { |
|
589 if (!looping) |
|
590 { |
|
591 yyerror ("parse error"); |
|
592 error ("continue: only meaningful within a\ |
|
593 `for' or `while' loop"); |
|
594 ABORT_PARSE; |
|
595 } |
191
|
596 $$ = new tree_continue_command ($1->line (), |
|
597 $1->column ()); |
1
|
598 } |
|
599 | FUNC_RET |
|
600 { |
|
601 if (!defining_func) |
|
602 { |
|
603 yyerror ("parse error"); |
|
604 error ("return: only meaningful within a function"); |
|
605 ABORT_PARSE; |
|
606 } |
191
|
607 $$ = new tree_return_command ($1->line (), $1->column ()); |
1
|
608 } |
|
609 ; |
|
610 |
|
611 elseif : ELSEIF optsep expression optsep opt_list |
|
612 { |
|
613 maybe_warn_assign_as_truth_value ($3); |
191
|
614 $$ = new tree_if_command ($3, $5, $1->line (), |
|
615 $1->column ()); |
1
|
616 } |
|
617 | elseif ELSEIF optsep expression optsep opt_list |
|
618 { |
|
619 maybe_warn_assign_as_truth_value ($4); |
191
|
620 $$ = $1->chain ($4, $6, $2->line (), $2->column ()); |
1
|
621 } |
|
622 ; |
|
623 |
|
624 optsep : // empty |
|
625 | sep |
|
626 ; |
|
627 |
|
628 sep : ',' |
|
629 | ';' |
|
630 | '\n' |
|
631 | sep ',' |
|
632 | sep ';' |
|
633 | sep '\n' |
|
634 ; |
|
635 |
|
636 screwed_again : // empty |
|
637 { maybe_screwed_again++; } |
|
638 ; |
|
639 |
|
640 expression : variable '=' expression |
143
|
641 { $$ = new tree_simple_assignment_expression |
|
642 ($1, $3, $2->line (), $2->column ()); } |
1
|
643 | '[' screwed_again matrix_row SCREW_TWO '=' expression |
|
644 { |
|
645 |
|
646 // Will need a way to convert the matrix list to a list of |
143
|
647 // identifiers. If that fails, we can abort here, without losing |
1
|
648 // anything -- no other possible syntax is valid if we've seen the |
|
649 // equals sign as the next token after the `]'. |
|
650 |
|
651 $$ = (tree_multi_assignment_expression *) NULL; |
|
652 maybe_screwed_again--; |
|
653 tree_matrix *tmp = ml.pop (); |
|
654 tmp = tmp->reverse (); |
|
655 tree_return_list *id_list = tmp->to_return_list (); |
|
656 if (id_list == NULL_TREE) |
|
657 { |
|
658 yyerror ("parse error"); |
143
|
659 error ("invalid identifier list for assignment"); |
1
|
660 $$ = (tree_multi_assignment_expression *) NULL; |
|
661 ABORT_PARSE; |
|
662 } |
|
663 else |
143
|
664 $$ = new tree_multi_assignment_expression |
|
665 (id_list, $6, $5->line (), $5->column ()); |
1
|
666 } |
|
667 | NUM '=' expression |
|
668 { |
|
669 yyerror ("parse error"); |
|
670 error ("invalid assignment to a number"); |
|
671 $$ = (tree_simple_assignment_expression *) NULL; |
|
672 ABORT_PARSE; |
|
673 } |
|
674 | simple_expr |
|
675 { $$ = $1; } |
|
676 ; |
|
677 |
|
678 simple_expr : simple_expr1 |
|
679 { $$ = $1; } |
|
680 | identifier PLUS_PLUS |
143
|
681 { $$ = new tree_postfix_expression |
|
682 ($1, tree::increment, $2->line (), $2->column ()); } |
1
|
683 | identifier MINUS_MINUS |
143
|
684 { $$ = new tree_postfix_expression |
|
685 ($1, tree::decrement, $2->line (), $2->column ()); } |
1
|
686 | simple_expr QUOTE |
143
|
687 { $$ = new tree_unary_expression |
|
688 ($1, tree::hermitian, $2->line (), $2->column ()); } |
1
|
689 | simple_expr TRANSPOSE |
143
|
690 { $$ = new tree_unary_expression |
|
691 ($1, tree::transpose, $2->line (), $2->column ()); } |
1
|
692 | simple_expr POW simple_expr |
143
|
693 { $$ = new tree_binary_expression |
|
694 ($1, $3, tree::power, $2->line (), $2->column ()); } |
1
|
695 | simple_expr EPOW simple_expr |
143
|
696 { $$ = new tree_binary_expression |
|
697 ($1, $3, tree::elem_pow, $2->line (), $2->column ()); } |
1
|
698 | simple_expr '+' simple_expr |
143
|
699 { $$ = new tree_binary_expression |
|
700 ($1, $3, tree::add, $2->line (), $2->column ()); } |
1
|
701 | simple_expr '-' simple_expr |
143
|
702 { $$ = new tree_binary_expression |
|
703 ($1, $3, tree::subtract, $2->line (), $2->column ()); } |
1
|
704 | simple_expr '*' simple_expr |
143
|
705 { $$ = new tree_binary_expression |
|
706 ($1, $3, tree::multiply, $2->line (), $2->column ()); } |
1
|
707 | simple_expr '/' simple_expr |
143
|
708 { $$ = new tree_binary_expression |
|
709 ($1, $3, tree::divide, $2->line (), $2->column ()); } |
1
|
710 | simple_expr EMUL simple_expr |
143
|
711 { $$ = new tree_binary_expression |
|
712 ($1, $3, tree::el_mul, $2->line (), $2->column ()); } |
1
|
713 | simple_expr EDIV simple_expr |
143
|
714 { $$ = new tree_binary_expression |
|
715 ($1, $3, tree::el_div, $2->line (), $2->column ()); } |
1
|
716 | simple_expr LEFTDIV simple_expr |
143
|
717 { $$ = new tree_binary_expression |
|
718 ($1, $3, tree::leftdiv, $2->line (), $2->column ()); } |
1
|
719 | simple_expr ELEFTDIV simple_expr |
143
|
720 { $$ = new tree_binary_expression |
|
721 ($1, $3, tree::el_leftdiv, $2->line (), $2->column ()); } |
1
|
722 | simple_expr EXPR_LT simple_expr |
143
|
723 { $$ = new tree_binary_expression |
|
724 ($1, $3, tree::cmp_lt, $2->line (), $2->column ()); } |
1
|
725 | simple_expr EXPR_LE simple_expr |
143
|
726 { $$ = new tree_binary_expression |
|
727 ($1, $3, tree::cmp_le, $2->line (), $2->column ()); } |
1
|
728 | simple_expr EXPR_EQ simple_expr |
143
|
729 { $$ = new tree_binary_expression |
|
730 ($1, $3, tree::cmp_eq, $2->line (), $2->column ()); } |
1
|
731 | simple_expr EXPR_GE simple_expr |
143
|
732 { $$ = new tree_binary_expression |
|
733 ($1, $3, tree::cmp_ge, $2->line (), $2->column ()); } |
1
|
734 | simple_expr EXPR_GT simple_expr |
143
|
735 { $$ = new tree_binary_expression |
|
736 ($1, $3, tree::cmp_gt, $2->line (), $2->column ()); } |
1
|
737 | simple_expr EXPR_NE simple_expr |
143
|
738 { $$ = new tree_binary_expression |
|
739 ($1, $3, tree::cmp_ne, $2->line (), $2->column ()); } |
1
|
740 | simple_expr EXPR_AND simple_expr |
143
|
741 { $$ = new tree_binary_expression |
|
742 ($1, $3, tree::and, $2->line (), $2->column ()); } |
1
|
743 | simple_expr EXPR_OR simple_expr |
143
|
744 { $$ = new tree_binary_expression |
|
745 ($1, $3, tree::or, $2->line (), $2->column ()); } |
1
|
746 ; |
|
747 |
|
748 simple_expr1 : NUM |
143
|
749 { $$ = new tree_constant ($1->number ()); } |
1
|
750 | IMAG_NUM |
143
|
751 { $$ = new tree_constant (Complex (0.0, $1->number ())); } |
1
|
752 | TEXT |
143
|
753 { $$ = new tree_constant ($1->string ()); } |
1
|
754 | word_list_cmd |
|
755 { $$ = $1; } |
|
756 | '(' expression ')' |
|
757 { |
|
758 if ($2->is_assignment_expression ()) |
|
759 ((tree_assignment_expression *) $2) -> in_parens++; |
|
760 $$ = $2; |
|
761 } |
|
762 | variable |
|
763 { $$ = $1; } |
|
764 | matrix |
|
765 { $$ = $1; } |
|
766 | colon_expr |
|
767 { $$ = $1; } |
|
768 | PLUS_PLUS identifier %prec UNARY |
143
|
769 { $$ = new tree_prefix_expression |
|
770 ($2, tree::increment, $1->line (), $1->column ()); } |
1
|
771 | MINUS_MINUS identifier %prec UNARY |
143
|
772 { $$ = new tree_prefix_expression |
|
773 ($2, tree::decrement, $1->line (), $1->column ()); } |
1
|
774 | EXPR_NOT simple_expr |
143
|
775 { $$ = new tree_unary_expression |
|
776 ($2, tree::not, $1->line (), $1->column ()); } |
1
|
777 | '+' simple_expr %prec UNARY |
|
778 { $$ = $2; } |
|
779 | '-' simple_expr %prec UNARY |
143
|
780 { $$ = new tree_unary_expression |
|
781 ($2, tree::uminus, $1->line (), $1->column ()); } |
1
|
782 ; |
|
783 |
|
784 colon_expr : simple_expr ':' simple_expr |
143
|
785 { $$ = new tree_colon_expression |
|
786 ($1, $3, $2->line (), $2->column ()); } |
1
|
787 | colon_expr ':' simple_expr |
|
788 { |
|
789 $$ = $1->chain ($3); |
|
790 if ($$ == (tree_colon_expression *) NULL) |
|
791 { |
|
792 yyerror ("parse error"); |
|
793 ABORT_PARSE; |
|
794 } |
|
795 } |
|
796 ; |
|
797 |
|
798 word_list_cmd : identifier word_list |
|
799 { $$ = new tree_word_list_command ($1, $2); } |
|
800 ; |
|
801 |
|
802 word_list : word_list1 |
|
803 { $$ = $1->reverse (); } |
|
804 ; |
|
805 |
|
806 word_list1 : TEXT |
143
|
807 { $$ = new tree_word_list ($1->string ()); } |
1
|
808 | word_list1 TEXT |
143
|
809 { $$ = $1->chain ($2->string ()); } |
1
|
810 ; |
|
811 |
|
812 // This is truly disgusting. |
|
813 |
|
814 g_symtab : // empty |
|
815 { curr_sym_tab = global_sym_tab; } |
|
816 ; |
|
817 |
|
818 local_symtab : // empty |
|
819 { curr_sym_tab = tmp_local_sym_tab; } |
|
820 ; |
|
821 |
|
822 safe : // empty |
|
823 { maybe_screwed = 0; } |
|
824 ; |
|
825 |
|
826 are_we_screwed : // empty |
|
827 { maybe_screwed = 1; } |
|
828 ; |
|
829 |
|
830 func_def : FCN g_symtab are_we_screwed func_def1 |
|
831 { |
|
832 curr_sym_tab = top_level_sym_tab; |
|
833 defining_func = 0; |
|
834 $$ = (tree_function *) NULL; |
|
835 } |
|
836 | FCN g_symtab are_we_screwed func_def2 |
|
837 { |
|
838 curr_sym_tab = top_level_sym_tab; |
|
839 defining_func = 0; |
|
840 $$ = (tree_function *) NULL; |
|
841 } |
|
842 ; |
|
843 |
|
844 func_def1 : SCREW safe g_symtab '=' func_def2 |
|
845 { |
143
|
846 tree_identifier *tmp = new tree_identifier |
|
847 ($1->sym_rec (), $1->line (), $1->column ()); |
1
|
848 tree_parameter_list *tpl = new tree_parameter_list (tmp); |
|
849 tpl = tpl->reverse (); |
|
850 tpl->mark_as_formal_parameters (); |
|
851 $$ = $5->define_ret_list (tpl); |
|
852 } |
|
853 | func_def1a ']' g_symtab '=' func_def2 |
|
854 { |
|
855 tree_parameter_list *tpl = $1->reverse (); |
|
856 tpl->mark_as_formal_parameters (); |
|
857 $$ = $5->define_ret_list (tpl); |
|
858 } |
|
859 ; |
|
860 |
|
861 func_def1a : '[' safe local_symtab identifier |
|
862 { $$ = new tree_parameter_list ($4); } |
|
863 | func_def1a ',' identifier |
|
864 { $$ = $1->chain ($3); } |
|
865 ; |
|
866 |
|
867 func_def2 : identifier safe local_symtab func_def3 |
|
868 { |
|
869 char *id_name = $1->name (); |
|
870 // if (is_text_function_name (id_name)) |
|
871 // { |
|
872 // yyerror ("parse error"); |
|
873 // error ("invalid use of reserved word %s", id_name); |
|
874 // ABORT_PARSE; |
|
875 // } |
|
876 |
|
877 // If input is coming from a file, issue a warning if the name of the |
|
878 // file does not match the name of the function stated in the file. |
|
879 // Matlab doesn't provide a diagnostic (it ignores the stated name). |
|
880 |
|
881 if (reading_m_file) |
|
882 { |
|
883 if (strcmp (curr_m_file_name, id_name) != 0) |
195
|
884 { |
|
885 warning ("function name `%s' does not agree\ |
1
|
886 with M-file name `%s.m'", id_name, curr_m_file_name); |
|
887 |
195
|
888 $1->rename (curr_m_file_name); |
|
889 } |
|
890 |
|
891 $4->stash_m_file_name (curr_m_file_name); |
|
892 $4->stash_m_file_time (time ((time_t *) NULL)); |
|
893 $4->mark_as_system_m_file (); |
1
|
894 } |
195
|
895 else if (! input_from_tmp_history_file |
|
896 && reading_script_file |
|
897 && strcmp (curr_m_file_name, id_name) == 0) |
1
|
898 { |
195
|
899 warning ("function `%s' defined within\ |
1
|
900 script file `%s.m'", id_name, curr_m_file_name); |
|
901 } |
|
902 |
143
|
903 $4->stash_function_name (id_name); |
195
|
904 |
|
905 $1->define ($4); |
|
906 $1->document (help_buf); |
|
907 |
1
|
908 $$ = $4; |
|
909 } |
|
910 ; |
|
911 |
|
912 func_def3 : param_list optsep opt_list fcn_end_or_eof |
|
913 { |
|
914 tree_function *fcn = new tree_function ($3, curr_sym_tab); |
|
915 $$ = fcn->define_param_list ($1); |
|
916 } |
|
917 | '(' ')' optsep opt_list fcn_end_or_eof |
|
918 { $$ = new tree_function ($4, curr_sym_tab); } |
|
919 | optsep opt_list fcn_end_or_eof |
|
920 { $$ = new tree_function ($2, curr_sym_tab); } |
|
921 ; |
|
922 |
|
923 fcn_end_or_eof : END |
|
924 { |
143
|
925 if (check_end ($1, token::function_end)) |
1
|
926 ABORT_PARSE; |
|
927 |
|
928 if (reading_m_file) |
|
929 check_for_garbage_after_fcn_def (); |
|
930 } |
|
931 | END_OF_INPUT |
|
932 { |
|
933 if (! (reading_m_file || reading_script_file)) |
|
934 YYABORT; |
|
935 } |
|
936 ; |
|
937 |
|
938 variable : identifier |
191
|
939 { |
|
940 $$ = new tree_index_expression |
|
941 ($1, $1->line (), $1->column ()); |
|
942 } |
1
|
943 | identifier '(' arg_list ')' |
191
|
944 { |
|
945 $$ = new tree_index_expression |
|
946 ($1, $3, $1->line (), $1->column ()); |
|
947 } |
1
|
948 | identifier '(' ')' |
|
949 { |
|
950 $$ = new tree_index_expression |
191
|
951 ($1, (tree_argument_list *) NULL, |
|
952 $1->line (), $1->column ()); |
1
|
953 } |
|
954 | identifier '[' |
|
955 { |
|
956 yyerror ("parse error"); |
|
957 error ("use `(\' and `)\' as index operators, not\ |
|
958 `[\' and `]\'"); |
|
959 $$ = (tree_index_expression *) NULL; |
|
960 ABORT_PARSE; |
|
961 } |
|
962 ; |
|
963 |
|
964 param_list : param_list1 ')' |
|
965 { |
|
966 tree_parameter_list *tmp = $1->reverse (); |
|
967 tmp->mark_as_formal_parameters (); |
|
968 $$ = tmp; |
|
969 } |
|
970 |
|
971 param_list1 : '(' identifier |
|
972 { $$ = new tree_parameter_list ($2); } |
|
973 | param_list1 ',' identifier |
|
974 { $$ = $1->chain ($3); } |
|
975 | '(' error |
|
976 { |
|
977 error ("parameter lists may only contain identifiers"); |
|
978 $$ = (tree_parameter_list *) NULL; |
|
979 } |
|
980 | param_list1 ',' error |
|
981 { |
|
982 error ("parameter lists may only contain identifiers"); |
|
983 $$ = (tree_parameter_list *) NULL; |
|
984 } |
|
985 ; |
|
986 |
|
987 identifier : NAME |
143
|
988 { $$ = new tree_identifier |
|
989 ($1->sym_rec (), $1->line (), $1->column ()); } |
1
|
990 |
|
991 arg_list : arg_list1 |
|
992 { $$ = $1->reverse (); } |
|
993 ; |
|
994 |
|
995 arg_list1 : ':' |
|
996 { |
|
997 tree_constant *colon; |
|
998 colon = new tree_constant (tree_constant_rep::magic_colon); |
|
999 $$ = new tree_argument_list (colon); |
|
1000 } |
|
1001 | arg_list1 ',' ':' |
|
1002 { |
|
1003 tree_constant *colon; |
|
1004 colon = new tree_constant (tree_constant_rep::magic_colon); |
|
1005 $$ = $1->chain (colon); |
|
1006 if ($$ == NULL_TREE) |
|
1007 { |
|
1008 yyerror ("parse error"); |
|
1009 ABORT_PARSE; |
|
1010 } |
|
1011 } |
|
1012 | expression |
|
1013 { $$ = new tree_argument_list ($1); } |
|
1014 | arg_list1 ',' expression |
|
1015 { |
|
1016 $$ = $1->chain ($3); |
|
1017 if ($$ == NULL_TREE) |
|
1018 { |
|
1019 yyerror ("parse error"); |
|
1020 ABORT_PARSE; |
|
1021 } |
|
1022 } |
|
1023 ; |
|
1024 |
|
1025 matrix : '[' ']' |
|
1026 { |
|
1027 mlnm.pop (); |
|
1028 $$ = new tree_matrix (); |
|
1029 } |
|
1030 | '[' ';' ']' |
|
1031 { |
|
1032 mlnm.pop (); |
|
1033 $$ = new tree_matrix (); |
|
1034 } |
|
1035 | '[' screwed_again rows ']' |
|
1036 { |
|
1037 mlnm.pop (); |
|
1038 maybe_screwed_again--; |
|
1039 tree_matrix *tmp = ml.pop (); |
|
1040 $$ = tmp->reverse (); |
|
1041 } |
|
1042 ; |
|
1043 |
|
1044 rows : matrix_row |
|
1045 | rows ';' // Ignore trailing semicolon. |
|
1046 | rows ';' matrix_row |
|
1047 ; |
|
1048 |
|
1049 matrix_row : expression // First element on row. |
|
1050 { |
|
1051 if (mlnm.top ()) |
|
1052 { |
|
1053 mlnm.pop (); |
|
1054 mlnm.push (0); |
143
|
1055 tree_matrix *tmp = new tree_matrix ($1, tree::md_none); |
1
|
1056 ml.push (tmp); |
|
1057 } |
|
1058 else |
|
1059 { |
|
1060 tree_matrix *tmp = ml.pop (); |
|
1061 tmp = tmp->chain ($1, tree::md_down); |
|
1062 ml.push (tmp); |
|
1063 } |
|
1064 } |
|
1065 | matrix_row ',' // Ignore trailing comma. |
|
1066 | matrix_row ',' expression |
|
1067 { |
|
1068 tree_matrix *tmp = ml.pop (); |
|
1069 tmp = tmp->chain ($3, tree::md_right); |
|
1070 ml.push (tmp); |
|
1071 } |
|
1072 ; |
|
1073 |
|
1074 %% |
|
1075 |
|
1076 static void |
|
1077 yyerror (char *s) |
|
1078 { |
|
1079 char *line = current_input_line; |
143
|
1080 int err_col = current_input_column - 1; |
1
|
1081 if (err_col == 0) |
|
1082 err_col = strlen (current_input_line) + 1; |
|
1083 |
|
1084 // Print a message like `parse error'. |
|
1085 fprintf (stderr, "\n%s", s); |
|
1086 |
|
1087 // Maybe print the line number and file name. |
|
1088 if (reading_m_file || reading_script_file) |
|
1089 fprintf (stderr, " near line %d of file %s.m", input_line_number, |
|
1090 curr_m_file_name); |
|
1091 |
|
1092 int len = strlen (line); |
|
1093 if (line[len-1] == '\n') |
|
1094 { |
|
1095 len--; |
|
1096 line[len] = '\0'; |
|
1097 } |
|
1098 |
|
1099 // Print the line, maybe with a pointer near the error token. |
|
1100 if (err_col > len) |
|
1101 fprintf (stderr, ":\n\n %s\n\n", line); |
|
1102 else |
|
1103 fprintf (stderr, ":\n\n %s\n %*s\n\n", line, err_col, "^"); |
|
1104 } |
|
1105 |
143
|
1106 static int |
|
1107 check_end (token *tok, token::end_tok_type expected) |
|
1108 { |
|
1109 token::end_tok_type ettype = tok->ettype (); |
|
1110 if (ettype != expected && ettype != token::simple_end) |
|
1111 { |
|
1112 yyerror ("parse error"); |
|
1113 |
|
1114 int l = tok->line (); |
|
1115 int c = tok->column (); |
|
1116 |
|
1117 switch (expected) |
|
1118 { |
|
1119 case token::for_end: |
|
1120 end_error ("for", ettype, l, c); |
|
1121 break; |
|
1122 case token::function_end: |
|
1123 end_error ("function", ettype, l, c); |
|
1124 break; |
|
1125 case token::if_end: |
|
1126 end_error ("if", ettype, l, c); |
|
1127 break; |
|
1128 case token::while_end: |
|
1129 end_error ("while", ettype, l, c); |
|
1130 break; |
|
1131 default: |
|
1132 panic_impossible (); |
|
1133 break; |
|
1134 } |
|
1135 return 1; |
|
1136 } |
|
1137 else |
|
1138 return 0; |
|
1139 } |
|
1140 |
1
|
1141 static void |
143
|
1142 end_error (char *type, token::end_tok_type ettype, int l, int c) |
1
|
1143 { |
143
|
1144 static char *fmt = "%s command matched by `%s' near line %d column %d"; |
|
1145 |
1
|
1146 switch (ettype) |
|
1147 { |
143
|
1148 case token::simple_end: |
|
1149 error (fmt, type, "end", l, c); |
1
|
1150 break; |
143
|
1151 case token::for_end: |
|
1152 error (fmt, type, "endfor", l, c); |
1
|
1153 break; |
143
|
1154 case token::function_end: |
|
1155 error (fmt, type, "endfunction", l, c); |
1
|
1156 break; |
143
|
1157 case token::if_end: |
|
1158 error (fmt, type, "endif", l, c); |
1
|
1159 break; |
143
|
1160 case token::while_end: |
|
1161 error (fmt, type, "endwhile", l, c); |
1
|
1162 break; |
|
1163 default: |
|
1164 panic_impossible (); |
|
1165 break; |
|
1166 } |
|
1167 } |
|
1168 |
|
1169 /* |
|
1170 * Need to make sure that the expression isn't already an identifier |
|
1171 * that has a name, or an assignment expression. |
|
1172 * |
|
1173 * Note that an expression can't be just an identifier anymore -- it |
|
1174 * must at least be an index expression (see the definition of the |
|
1175 * non-terminal `variable' above). |
183
|
1176 * |
|
1177 * XXX FIXME XXX. This isn't quite sufficient. For example, try the |
|
1178 * command `x = 4, x' for `x' previously undefined. |
195
|
1179 * |
|
1180 * XXX FIXME XXX -- we should probably delay doing this until eval-time. |
1
|
1181 */ |
|
1182 tree * |
|
1183 maybe_convert_to_ans_assign (tree *expr) |
|
1184 { |
|
1185 if (expr->is_index_expression ()) |
|
1186 { |
195
|
1187 expr->mark_for_possible_ans_assign (); |
|
1188 return expr; |
|
1189 } |
|
1190 else if (expr->is_assignment_expression () |
|
1191 || expr->is_prefix_expression ()) |
|
1192 { |
|
1193 return expr; |
|
1194 } |
|
1195 else |
|
1196 { |
|
1197 symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0); |
1
|
1198 |
195
|
1199 assert (sr != (symbol_record *) NULL); |
|
1200 |
|
1201 tree_identifier *ans = new tree_identifier (sr); |
|
1202 |
|
1203 return new tree_simple_assignment_expression (ans, expr); |
1
|
1204 } |
|
1205 } |
|
1206 |
|
1207 void |
|
1208 maybe_warn_assign_as_truth_value (tree *expr) |
|
1209 { |
|
1210 if (user_pref.warn_assign_as_truth_value |
|
1211 && expr->is_assignment_expression () |
|
1212 && ((tree_assignment_expression *) expr) -> in_parens < 2) |
|
1213 { |
|
1214 warning ("suggest parenthesis around assignment used as truth value"); |
|
1215 } |
|
1216 } |