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