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