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