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