Commit | Line | Data |
---|---|---|
4514e9cd ML |
1 | %{ |
2 | ||
3 | /* Copyright (c) 1982 Regents of the University of California */ | |
4 | ||
3f80f200 | 5 | static char sccsid[] = "@(#)commands.y 1.3 %G%"; |
4514e9cd ML |
6 | |
7 | /* | |
8 | * Yacc grammar for debugger commands. | |
9 | */ | |
10 | ||
11 | #include "defs.h" | |
12 | #include "symbols.h" | |
13 | #include "operators.h" | |
14 | #include "tree.h" | |
15 | #include "process.h" | |
16 | #include "source.h" | |
17 | #include "scanner.h" | |
18 | #include "names.h" | |
19 | ||
20 | private String curformat = "X"; | |
21 | ||
22 | %} | |
23 | ||
24 | %term | |
25 | ALIAS AND ASSIGN AT CALL CATCH CONT DELETE DIV DUMP | |
26 | EDIT FILE FUNC GRIPE HELP IF IGNORE IN LIST MOD NEXT NEXTI NIL NOT OR | |
27 | PRINT PSYM QUIT RUN SH SKIP SOURCE STATUS STEP STEPI | |
28 | STOP STOPI TRACE TRACEI | |
29 | USE WHATIS WHEN WHERE WHEREIS WHICH | |
30 | ||
31 | %term INT REAL NAME STRING | |
32 | %term LFORMER RFORMER ABSTRACTION ARROW | |
33 | ||
34 | %right INT | |
35 | %binary REDIRECT | |
36 | %binary '<' '=' '>' '!' IN | |
37 | %left '+' '-' OR | |
38 | %left UNARYSIGN | |
39 | %left '*' '/' DIV MOD AND | |
40 | %left NOT '(' '[' '.' '^' ARROW | |
3f80f200 | 41 | %left '\\' |
4514e9cd ML |
42 | |
43 | %union { | |
44 | Name y_name; | |
45 | Symbol y_sym; | |
46 | Node y_node; | |
47 | Integer y_int; | |
48 | Operator y_op; | |
49 | long y_long; | |
50 | double y_real; | |
51 | String y_string; | |
52 | Boolean y_bool; | |
53 | Cmdlist y_cmdlist; | |
54 | }; | |
55 | ||
56 | %type <y_op> trace stop | |
57 | %type <y_long> INT count | |
58 | %type <y_real> REAL | |
59 | %type <y_string> STRING redirectout filename opt_filename mode | |
60 | %type <y_name> ALIAS AND ASSIGN AT CALL CATCH CONT DELETE DIV DUMP | |
61 | %type <y_name> EDIT FILE FUNC GRIPE HELP IF IGNORE IN LIST MOD | |
62 | %type <y_name> NEXT NEXTI NIL NOT OR | |
63 | %type <y_name> PRINT PSYM QUIT RUN SH SKIP SOURCE STATUS STEP STEPI | |
64 | %type <y_name> STOP STOPI TRACE TRACEI | |
65 | %type <y_name> USE WHATIS WHEN WHERE WHEREIS WHICH | |
66 | %type <y_name> name NAME keyword | |
67 | %type <y_node> symbol | |
68 | %type <y_node> command rcommand cmd step what where examine | |
69 | %type <y_node> event opt_arglist opt_cond | |
70 | %type <y_node> exp_list exp term boolean_exp constant address | |
71 | %type <y_node> alias_command list_command line_number | |
72 | %type <y_cmdlist> actions | |
73 | ||
74 | %% | |
75 | ||
76 | input: | |
77 | input command_nl | |
78 | | | |
79 | /* empty */ | |
80 | ; | |
81 | command_nl: | |
82 | command_line '\n' | |
83 | | | |
84 | command_line ';' | |
85 | | | |
86 | '\n' | |
87 | ; | |
88 | ||
89 | command_line: | |
90 | command | |
91 | { | |
92 | if ($1 != nil) { | |
93 | eval($1); | |
94 | } | |
95 | } | |
96 | | | |
97 | rcommand redirectout | |
98 | { | |
99 | if ($1 != nil) { | |
100 | if ($2 != nil) { | |
101 | setout($2); | |
102 | eval($1); | |
103 | unsetout(); | |
104 | } else { | |
105 | eval($1); | |
106 | } | |
107 | } | |
108 | } | |
109 | ; | |
110 | redirectout: | |
111 | '>' shellmode NAME | |
112 | { | |
113 | $$ = ident($3); | |
114 | } | |
115 | | | |
116 | /* empty */ | |
117 | { | |
118 | $$ = nil; | |
119 | } | |
120 | ; | |
121 | ||
122 | /* | |
123 | * Non-redirectable commands. | |
124 | */ | |
125 | command: | |
126 | alias_command | |
127 | { | |
128 | $$ = $1; | |
129 | } | |
130 | | | |
131 | ASSIGN term '=' exp | |
132 | { | |
133 | $$ = build(O_ASSIGN, $2, $4); | |
134 | } | |
135 | | | |
136 | CATCH INT | |
137 | { | |
138 | $$ = build(O_CATCH, $2); | |
139 | } | |
140 | | | |
141 | CONT | |
142 | { | |
143 | $$ = build(O_CONT); | |
144 | } | |
145 | | | |
146 | DELETE INT | |
147 | { | |
148 | $$ = build(O_DELETE, $2); | |
149 | } | |
150 | | | |
151 | EDIT shellmode opt_filename | |
152 | { | |
153 | $$ = build(O_EDIT, $3); | |
154 | } | |
155 | | | |
156 | FILE shellmode opt_filename | |
157 | { | |
158 | $$ = build(O_CHFILE, $3); | |
159 | } | |
160 | | | |
161 | FUNC | |
162 | { | |
163 | $$ = build(O_FUNC, nil); | |
164 | } | |
165 | | | |
166 | FUNC symbol | |
167 | { | |
168 | $$ = build(O_FUNC, $2); | |
169 | } | |
170 | | | |
171 | GRIPE | |
172 | { | |
173 | $$ = build(O_GRIPE); | |
174 | } | |
175 | | | |
176 | HELP | |
177 | { | |
178 | $$ = build(O_HELP); | |
179 | } | |
180 | | | |
181 | IGNORE INT | |
182 | { | |
183 | $$ = build(O_IGNORE, $2); | |
184 | } | |
185 | | | |
186 | list_command | |
187 | { | |
188 | $$ = $1; | |
189 | } | |
190 | | | |
191 | PSYM term | |
192 | { | |
193 | $$ = build(O_PSYM, $2); | |
194 | } | |
195 | | | |
196 | QUIT | |
197 | { | |
198 | if (not popinput()) { | |
199 | quit(0); | |
200 | } else { | |
201 | $$ = nil; | |
202 | } | |
203 | } | |
204 | | | |
205 | runcommand | |
206 | { | |
207 | run(); | |
208 | /* NOTREACHED */ | |
209 | } | |
210 | | | |
211 | SH | |
212 | { | |
213 | shellline(); | |
214 | $$ = nil; | |
215 | } | |
216 | | | |
217 | SOURCE shellmode filename | |
218 | { | |
219 | $$ = build(O_SOURCE, $3); | |
220 | } | |
221 | | | |
222 | step | |
223 | { | |
224 | $$ = $1; | |
225 | } | |
226 | | | |
227 | stop where opt_cond | |
228 | { | |
229 | $$ = build($1, nil, $2, $3); | |
230 | } | |
231 | | | |
232 | stop what opt_cond | |
233 | { | |
234 | $$ = build($1, $2, nil, $3); | |
235 | } | |
236 | | | |
237 | stop IF boolean_exp | |
238 | { | |
239 | $$ = build($1, nil, nil, $3); | |
240 | } | |
241 | | | |
242 | trace what where opt_cond | |
243 | { | |
244 | $$ = build($1, $2, $3, $4); | |
245 | } | |
246 | | | |
247 | trace where opt_cond | |
248 | { | |
249 | $$ = build($1, nil, $2, $3); | |
250 | } | |
251 | | | |
252 | trace what opt_cond | |
253 | { | |
254 | $$ = build($1, $2, nil, $3); | |
255 | } | |
256 | | | |
257 | trace opt_cond | |
258 | { | |
259 | $$ = build($1, nil, nil, $2); | |
260 | } | |
261 | | | |
262 | WHATIS term | |
263 | { | |
264 | $$ = build(O_WHATIS, $2); | |
265 | } | |
266 | | | |
267 | WHEN event '{' actions '}' | |
268 | { | |
269 | $$ = build(O_ADDEVENT, $2, $4); | |
270 | } | |
271 | | | |
272 | WHEREIS symbol | |
273 | { | |
274 | $$ = build(O_WHEREIS, $2); | |
275 | } | |
276 | | | |
277 | WHICH symbol | |
278 | { | |
279 | $$ = build(O_WHICH, $2); | |
280 | } | |
281 | | | |
282 | USE shellmode sourcepath | |
283 | { | |
284 | $$ = nil; | |
285 | if (list_size(sourcepath) == 0) { | |
286 | list_append(list_item("."), nil, sourcepath); | |
287 | } | |
288 | } | |
289 | ; | |
290 | runcommand: | |
291 | run shellmode arglist | |
292 | ; | |
293 | run: | |
294 | RUN | |
295 | { | |
296 | fflush(stdout); | |
297 | arginit(); | |
298 | } | |
299 | ; | |
300 | arglist: | |
301 | arglist arg | |
302 | | | |
303 | /* empty */ | |
304 | ; | |
305 | arg: | |
306 | NAME | |
307 | { | |
308 | newarg(ident($1)); | |
309 | } | |
310 | | | |
311 | '<' NAME | |
312 | { | |
313 | inarg(ident($2)); | |
314 | } | |
315 | | | |
316 | '>' NAME | |
317 | { | |
318 | outarg(ident($2)); | |
319 | } | |
320 | ; | |
321 | step: | |
322 | STEP | |
323 | { | |
324 | $$ = build(O_STEP, true, false); | |
325 | } | |
326 | | | |
327 | STEPI | |
328 | { | |
329 | $$ = build(O_STEP, false, false); | |
330 | } | |
331 | | | |
332 | NEXT | |
333 | { | |
334 | $$ = build(O_STEP, true, true); | |
335 | } | |
336 | | | |
337 | NEXTI | |
338 | { | |
339 | $$ = build(O_STEP, false, true); | |
340 | } | |
341 | ; | |
342 | shellmode: | |
343 | /* empty */ | |
344 | { | |
345 | beginshellmode(); | |
346 | } | |
347 | ; | |
348 | sourcepath: | |
349 | sourcepath NAME | |
350 | { | |
351 | list_append(list_item(ident($2)), nil, sourcepath); | |
352 | } | |
353 | | | |
354 | /* empty */ | |
355 | { | |
356 | String dir; | |
357 | ||
358 | foreach (String, dir, sourcepath) | |
359 | list_delete(list_curitem(sourcepath), sourcepath); | |
360 | endfor | |
361 | } | |
362 | ; | |
363 | event: | |
364 | where | |
365 | | | |
366 | exp | |
367 | ; | |
368 | actions: | |
369 | actions cmd ';' | |
370 | { | |
371 | $$ = $1; | |
372 | cmdlist_append($2, $$); | |
373 | } | |
374 | | | |
375 | cmd ';' | |
376 | { | |
377 | $$ = list_alloc(); | |
378 | cmdlist_append($1, $$); | |
379 | } | |
380 | ; | |
381 | cmd: | |
382 | command | |
383 | | | |
384 | rcommand | |
385 | ; | |
386 | ||
387 | /* | |
388 | * Redirectable commands. | |
389 | */ | |
390 | rcommand: | |
391 | PRINT exp_list | |
392 | { | |
393 | $$ = build(O_PRINT, $2); | |
394 | } | |
395 | | | |
396 | WHERE | |
397 | { | |
398 | $$ = build(O_WHERE); | |
399 | } | |
400 | | | |
401 | examine | |
402 | { | |
403 | $$ = $1; | |
404 | } | |
405 | | | |
406 | CALL term | |
407 | { | |
408 | $$ = $2; | |
409 | } | |
410 | | | |
411 | DUMP | |
412 | { | |
413 | $$ = build(O_DUMP); | |
414 | } | |
415 | | | |
416 | STATUS | |
417 | { | |
418 | $$ = build(O_STATUS); | |
419 | } | |
420 | ; | |
421 | alias_command: | |
422 | ALIAS name name | |
423 | { | |
424 | $$ = build(O_ALIAS, build(O_NAME, $2), build(O_NAME, $3)); | |
425 | } | |
426 | | | |
427 | ALIAS name | |
428 | { | |
429 | $$ = build(O_ALIAS, build(O_NAME, $2), nil); | |
430 | } | |
431 | | | |
432 | ALIAS | |
433 | { | |
434 | $$ = build(O_ALIAS, nil, nil); | |
435 | } | |
436 | ; | |
437 | trace: | |
438 | TRACE | |
439 | { | |
440 | $$ = O_TRACE; | |
441 | } | |
442 | | | |
443 | TRACEI | |
444 | { | |
445 | $$ = O_TRACEI; | |
446 | } | |
447 | ; | |
448 | stop: | |
449 | STOP | |
450 | { | |
451 | $$ = O_STOP; | |
452 | } | |
453 | | | |
454 | STOPI | |
455 | { | |
456 | $$ = O_STOPI; | |
457 | } | |
458 | ; | |
459 | what: | |
460 | exp | |
461 | { | |
462 | $$ = $1; | |
463 | } | |
464 | | | |
465 | STRING ':' line_number | |
466 | { | |
467 | $$ = build(O_QLINE, build(O_SCON, $1), $3); | |
468 | } | |
469 | ; | |
470 | where: | |
471 | IN term | |
472 | { | |
473 | $$ = $2; | |
474 | } | |
475 | | | |
476 | AT line_number | |
477 | { | |
478 | $$ = build(O_QLINE, build(O_SCON, cursource), $2); | |
479 | } | |
480 | | | |
481 | AT STRING ':' line_number | |
482 | { | |
483 | $$ = build(O_QLINE, build(O_SCON, $2), $4); | |
484 | } | |
485 | ; | |
486 | filename: | |
487 | NAME | |
488 | { | |
489 | $$ = ident($1); | |
490 | } | |
491 | ; | |
492 | opt_filename: | |
493 | /* empty */ | |
494 | { | |
495 | $$ = nil; | |
496 | } | |
497 | | | |
498 | filename | |
499 | { | |
500 | $$ = $1; | |
501 | } | |
502 | ; | |
503 | opt_arglist: | |
504 | /* empty */ | |
505 | { | |
506 | $$ = nil; | |
507 | } | |
508 | | | |
509 | '(' exp_list ')' | |
510 | { | |
511 | $$ = $2; | |
512 | } | |
513 | ; | |
514 | list_command: | |
515 | LIST | |
516 | { | |
517 | $$ = build(O_LIST, | |
518 | build(O_LCON, (long) cursrcline), | |
519 | build(O_LCON, (long) cursrcline + 9) | |
520 | ); | |
521 | } | |
522 | | | |
523 | LIST line_number | |
524 | { | |
525 | $$ = build(O_LIST, $2, $2); | |
526 | } | |
527 | | | |
528 | LIST line_number ',' line_number | |
529 | { | |
530 | $$ = build(O_LIST, $2, $4); | |
531 | } | |
532 | | | |
533 | LIST symbol | |
534 | { | |
535 | $$ = build(O_LIST, $2); | |
536 | } | |
537 | ; | |
538 | line_number: | |
539 | INT | |
540 | { | |
541 | $$ = build(O_LCON, $1); | |
542 | } | |
543 | | | |
544 | '$' | |
545 | { | |
546 | $$ = build(O_LCON, (long) LASTLINE); | |
547 | } | |
548 | ; | |
549 | examine: | |
550 | address '/' count mode | |
551 | { | |
552 | $$ = build(O_EXAMINE, $4, $1, nil, $3); | |
553 | } | |
554 | | | |
555 | address ',' address '/' mode | |
556 | { | |
557 | $$ = build(O_EXAMINE, $5, $1, $3, 0); | |
558 | } | |
559 | | | |
560 | '/' count mode | |
561 | { | |
562 | $$ = build(O_EXAMINE, $3, build(O_LCON, (long) prtaddr), nil, $2); | |
563 | } | |
3f80f200 ML |
564 | | |
565 | address '=' mode | |
566 | { | |
567 | $$ = build(O_EXAMINE, $3, $1, nil, 0); | |
568 | } | |
4514e9cd ML |
569 | ; |
570 | address: | |
571 | INT | |
572 | { | |
573 | $$ = build(O_LCON, $1); | |
574 | } | |
575 | | | |
576 | '&' term | |
577 | { | |
578 | $$ = amper($2); | |
579 | } | |
580 | | | |
581 | address '+' address | |
582 | { | |
583 | $$ = build(O_ADD, $1, $3); | |
584 | } | |
585 | | | |
586 | address '-' address | |
587 | { | |
588 | $$ = build(O_SUB, $1, $3); | |
589 | } | |
590 | | | |
591 | address '*' address | |
592 | { | |
593 | $$ = build(O_MUL, $1, $3); | |
594 | } | |
595 | | | |
596 | '*' address %prec UNARYSIGN | |
597 | { | |
598 | $$ = build(O_INDIR, $2); | |
599 | } | |
600 | | | |
601 | '(' exp ')' | |
602 | { | |
603 | $$ = $2; | |
604 | } | |
605 | ; | |
606 | count: | |
607 | /* empty */ | |
608 | { | |
609 | $$ = 1; | |
610 | } | |
611 | | | |
612 | INT | |
613 | { | |
614 | $$ = $1; | |
615 | } | |
616 | ; | |
617 | mode: | |
618 | name | |
619 | { | |
620 | $$ = ident($1); | |
621 | curformat = $$; | |
622 | } | |
623 | | | |
624 | /* empty */ | |
625 | { | |
626 | $$ = curformat; | |
627 | } | |
628 | ; | |
629 | opt_cond: | |
630 | /* empty */ | |
631 | { | |
632 | $$ = nil; | |
633 | } | |
634 | | | |
635 | IF boolean_exp | |
636 | { | |
637 | $$ = $2; | |
638 | } | |
639 | ; | |
640 | exp_list: | |
641 | exp | |
642 | { | |
643 | $$ = build(O_COMMA, $1, nil); | |
644 | } | |
645 | | | |
646 | exp ',' exp_list | |
647 | { | |
648 | $$ = build(O_COMMA, $1, $3); | |
649 | } | |
650 | ; | |
651 | exp: | |
652 | term | |
653 | { | |
654 | $$ = build(O_RVAL, $1); | |
655 | } | |
656 | | | |
657 | constant | |
658 | { | |
659 | $$ = $1; | |
660 | } | |
3f80f200 ML |
661 | | |
662 | exp '\\' symbol | |
663 | { | |
664 | $$ = build(O_TYPERENAME, $1, $3); | |
665 | } | |
4514e9cd ML |
666 | | |
667 | '+' exp %prec UNARYSIGN | |
668 | { | |
669 | $$ = $2; | |
670 | } | |
671 | | | |
672 | '-' exp %prec UNARYSIGN | |
673 | { | |
674 | $$ = build(O_NEG, $2); | |
675 | } | |
676 | | | |
677 | '&' exp %prec UNARYSIGN | |
678 | { | |
679 | $$ = amper($2); | |
680 | } | |
681 | | | |
682 | exp '+' exp | |
683 | { | |
684 | $$ = build(O_ADD, $1, $3); | |
685 | } | |
686 | | | |
687 | exp '-' exp | |
688 | { | |
689 | $$ = build(O_SUB, $1, $3); | |
690 | } | |
691 | | | |
692 | exp '*' exp | |
693 | { | |
694 | $$ = build(O_MUL, $1, $3); | |
695 | } | |
696 | | | |
697 | exp '/' exp | |
698 | { | |
699 | $$ = build(O_DIVF, $1, $3); | |
700 | } | |
701 | | | |
702 | exp DIV exp | |
703 | { | |
704 | $$ = build(O_DIV, $1, $3); | |
705 | } | |
706 | | | |
707 | exp MOD exp | |
708 | { | |
709 | $$ = build(O_MOD, $1, $3); | |
710 | } | |
711 | | | |
712 | exp AND exp | |
713 | { | |
714 | $$ = build(O_AND, $1, $3); | |
715 | } | |
716 | | | |
717 | exp OR exp | |
718 | { | |
719 | $$ = build(O_OR, $1, $3); | |
720 | } | |
721 | | | |
722 | exp '<' exp | |
723 | { | |
724 | $$ = build(O_LT, $1, $3); | |
725 | } | |
726 | | | |
727 | exp '<' '=' exp | |
728 | { | |
729 | $$ = build(O_LE, $1, $4); | |
730 | } | |
731 | | | |
732 | exp '>' exp | |
733 | { | |
734 | $$ = build(O_GT, $1, $3); | |
735 | } | |
736 | | | |
737 | exp '>' '=' exp | |
738 | { | |
739 | $$ = build(O_GE, $1, $4); | |
740 | } | |
741 | | | |
742 | exp '=' exp | |
743 | { | |
744 | $$ = build(O_EQ, $1, $3); | |
745 | } | |
746 | | | |
747 | exp '=' '=' exp | |
748 | { | |
749 | $$ = build(O_EQ, $1, $4); | |
750 | } | |
751 | | | |
752 | exp '<' '>' exp | |
753 | { | |
754 | $$ = build(O_NE, $1, $4); | |
755 | } | |
756 | | | |
757 | exp '!' '=' exp | |
758 | { | |
759 | $$ = build(O_NE, $1, $4); | |
760 | } | |
761 | | | |
762 | '(' exp ')' | |
763 | { | |
764 | $$ = $2; | |
765 | } | |
766 | ; | |
767 | term: | |
768 | symbol | |
769 | { | |
770 | $$ = $1; | |
771 | } | |
772 | | | |
773 | term '[' exp_list ']' | |
774 | { | |
775 | $$ = subscript($1, $3); | |
776 | } | |
777 | | | |
778 | term '.' name | |
779 | { | |
780 | $$ = dot($1, $3); | |
781 | } | |
782 | | | |
783 | term ARROW name | |
784 | { | |
785 | $$ = dot($1, $3); | |
786 | } | |
787 | | | |
788 | '*' term %prec UNARYSIGN | |
789 | { | |
790 | $$ = build(O_INDIR, $2); | |
791 | } | |
792 | | | |
793 | '*' '(' exp ')' %prec UNARYSIGN | |
794 | { | |
795 | $$ = build(O_INDIR, $3); | |
796 | } | |
797 | | | |
798 | term '^' %prec UNARYSIGN | |
799 | { | |
800 | $$ = build(O_INDIR, $1); | |
801 | } | |
802 | | | |
803 | '#' term %prec UNARYSIGN | |
804 | { | |
805 | $$ = concrete($2); | |
806 | } | |
807 | | | |
808 | term '(' exp_list ')' | |
809 | { | |
810 | $$ = build(O_CALL, $1, $3); | |
811 | } | |
812 | ; | |
813 | boolean_exp: | |
814 | exp | |
815 | { | |
816 | chkboolean($1); | |
817 | $$ = $1; | |
818 | } | |
819 | ; | |
820 | constant: | |
821 | INT | |
822 | { | |
823 | $$ = build(O_LCON, $1); | |
824 | } | |
825 | | | |
826 | REAL | |
827 | { | |
828 | $$ = build(O_FCON, $1); | |
829 | } | |
830 | | | |
831 | STRING | |
832 | { | |
833 | $$ = build(O_SCON, $1); | |
834 | } | |
835 | ; | |
836 | symbol: | |
837 | name | |
838 | { | |
839 | $$ = build(O_SYM, which($1)); | |
840 | } | |
841 | ; | |
842 | name: | |
843 | NAME | |
844 | { | |
845 | $$ = $1; | |
846 | } | |
847 | | | |
848 | keyword | |
849 | { | |
850 | $$ = $1; | |
851 | } | |
852 | keyword: | |
853 | ALIAS | AND | ASSIGN | AT | CALL | CATCH | CONT | DELETE | DIV | DUMP | | |
854 | EDIT | FILE | FUNC | GRIPE | HELP | IGNORE | IN | LIST | MOD | | |
855 | NEXT | NEXTI | NIL | NOT | OR | PRINT | PSYM | QUIT | RUN | | |
856 | SH | SKIP | SOURCE | STATUS | STEP | STEPI | | |
857 | STOP | STOPI | TRACE | TRACEI | | |
858 | USE | WHATIS | WHEN | WHERE | WHICH | |
859 | ; |