comparison src/parse.y @ 191:b6b4d8c513fe

[project @ 1993-10-29 23:41:39 by jwe]
author jwe
date Fri, 29 Oct 1993 23:41:39 +0000
parents aa5d189f5f07
children 13c6086c325c
comparison
equal deleted inserted replaced
190:edfb6cafe85d 191:b6b4d8c513fe
170 %token <tok_val> NUM IMAG_NUM 170 %token <tok_val> NUM IMAG_NUM
171 %token <tok_val> NAME SCREW 171 %token <tok_val> NAME SCREW
172 %token <tok_val> END 172 %token <tok_val> END
173 %token <tok_val> PLOT 173 %token <tok_val> PLOT
174 %token <tok_val> TEXT STYLE 174 %token <tok_val> TEXT STYLE
175 %token <tok_val> FOR WHILE IF ELSEIF ELSE BREAK CONTINUE FUNC_RET
175 176
176 // Other tokens. 177 // Other tokens.
177 %token FOR WHILE IF ELSEIF ELSE FCN BREAK CONTINUE FUNC_RET SCREW_TWO 178 %token FCN SCREW_TWO
178 %token END_OF_INPUT GLOBAL 179 %token END_OF_INPUT GLOBAL
179 %token USING TITLE WITH COLON OPEN_BRACE CLOSE_BRACE 180 %token USING TITLE WITH COLON OPEN_BRACE CLOSE_BRACE
180 181
181 // Nonterminals we construct. 182 // Nonterminals we construct.
182 %type <tree_type> input command 183 %type <tree_type> input command
191 %type <tree_parameter_list_type> param_list param_list1 func_def1a 192 %type <tree_parameter_list_type> param_list param_list1 func_def1a
192 %type <tree_word_list_type> word_list word_list1 193 %type <tree_word_list_type> word_list word_list1
193 %type <tree_command_type> statement 194 %type <tree_command_type> statement
194 %type <tree_if_command_type> elseif 195 %type <tree_if_command_type> elseif
195 %type <tree_command_list_type> simple_list simple_list1 list list1 opt_list 196 %type <tree_command_list_type> simple_list simple_list1 list list1 opt_list
197 %type <tree_command_list_type> global_decl global_decl1
196 %type <tree_word_list_command_type> word_list_cmd 198 %type <tree_word_list_command_type> word_list_cmd
197 %type <tree_plot_command_type> plot_command 199 %type <tree_plot_command_type> plot_command
198 %type <tree_subplot_list_type> plot_command1 plot_command2 plot_options 200 %type <tree_subplot_list_type> plot_command1 plot_command2 plot_options
199 %type <tree_plot_limits_type> ranges 201 %type <tree_plot_limits_type> ranges
200 %type <tree_plot_range_type> ranges1 202 %type <tree_plot_range_type> ranges1
343 | ans_expression 345 | ans_expression
344 { $$ = $1; } 346 { $$ = $1; }
345 | func_def 347 | func_def
346 { $$ = $1; } 348 { $$ = $1; }
347 | global_decl 349 | global_decl
348 { $$ = NULL_TREE; } 350 { $$ = $1; }
349 ; 351 ;
350 352
351 plot_command : PLOT plot_command1 353 plot_command : PLOT plot_command1
352 { 354 {
353 tree_subplot_list *tmp = $2->reverse (); 355 tree_subplot_list *tmp = $2->reverse ();
473 ans_expression : expression 475 ans_expression : expression
474 { $$ = maybe_convert_to_ans_assign ($1); } 476 { $$ = maybe_convert_to_ans_assign ($1); }
475 ; 477 ;
476 478
477 global_decl : GLOBAL global_decl1 479 global_decl : GLOBAL global_decl1
478 { } 480 { $$ = $2->reverse (); }
479 ; 481 ;
480 482
481 global_decl1 : NAME 483 global_decl1 : NAME
482 { force_global ($1->sym_rec()->name ()); } 484 {
485 force_global ($1->sym_rec()->name ());
486 $$ = new tree_command_list ();
487 }
483 | NAME '=' expression 488 | NAME '=' expression
484 { 489 {
485 symbol_record *sr = force_global ($1->sym_rec()->name ()); 490 symbol_record *sr = force_global ($1->sym_rec()->name ());
486 tree_identifier *id = new tree_identifier 491 tree_identifier *id = new tree_identifier
487 (sr, $1->line (), $1->column ()); 492 (sr, $1->line (), $1->column ());
488 tree_simple_assignment_expression *expr = 493 tree_simple_assignment_expression *expr =
489 new tree_simple_assignment_expression 494 new tree_simple_assignment_expression
490 (id, $3, $2->line (), $2->column ()); 495 (id, $3, $2->line (), $2->column ());
491 expr->eval (0); 496 $$ = new tree_command_list (expr);
492 } 497 }
493 | global_decl1 optcomma NAME 498 | global_decl1 optcomma NAME
494 { force_global ($3->sym_rec()->name ()); } 499 {
500 force_global ($3->sym_rec()->name ());
501 $$ = $1;
502 }
495 | global_decl1 optcomma NAME '=' expression 503 | global_decl1 optcomma NAME '=' expression
496 { 504 {
497 symbol_record *sr = force_global ($3->sym_rec()->name ()); 505 symbol_record *sr = force_global ($3->sym_rec()->name ());
498 tree_identifier *id = new tree_identifier 506 tree_identifier *id = new tree_identifier
499 (sr, $3->line (), $3->column ()); 507 (sr, $3->line (), $3->column ());
500 tree_simple_assignment_expression *expr = 508 tree_simple_assignment_expression *expr =
501 new tree_simple_assignment_expression 509 new tree_simple_assignment_expression
502 (id, $5, $4->line (), $4->column ()); 510 (id, $5, $4->line (), $4->column ());
503 expr->eval (0); 511 $$ = $1->chain (expr);
504 } 512 }
505 ; 513 ;
506 514
507 optcomma : // empty 515 optcomma : // empty
508 | ',' 516 | ','
517 { 525 {
518 maybe_warn_assign_as_truth_value ($2); 526 maybe_warn_assign_as_truth_value ($2);
519 if (check_end ($5, token::while_end)) 527 if (check_end ($5, token::while_end))
520 ABORT_PARSE; 528 ABORT_PARSE;
521 looping--; 529 looping--;
522 $$ = new tree_while_command ($2, $4); 530 $$ = new tree_while_command ($2, $4, $1->line (),
531 $1->column ());
523 } 532 }
524 | FOR variable '=' expression optsep opt_list END 533 | FOR variable '=' expression optsep opt_list END
525 { 534 {
526 if (check_end ($7, token::for_end)) 535 if (check_end ($7, token::for_end))
527 ABORT_PARSE; 536 ABORT_PARSE;
528 looping--; 537 looping--;
529 $$ = new tree_for_command ($2, $4, $6); 538 $$ = new tree_for_command ($2, $4, $6,
539 $1->line (), $1->column ());
530 } 540 }
531 | IF expression optsep opt_list END 541 | IF expression optsep opt_list END
532 { 542 {
533 maybe_warn_assign_as_truth_value ($2); 543 maybe_warn_assign_as_truth_value ($2);
534 if (check_end ($5, token::if_end)) 544 if (check_end ($5, token::if_end))
535 ABORT_PARSE; 545 ABORT_PARSE;
536 iffing--; 546 iffing--;
537 $$ = new tree_if_command ($2, $4); 547 $$ = new tree_if_command ($2, $4,
548 $1->line (), $1->column ());
538 } 549 }
539 | IF expression optsep opt_list ELSE optsep opt_list END 550 | IF expression optsep opt_list ELSE optsep opt_list END
540 { 551 {
541 maybe_warn_assign_as_truth_value ($2); 552 maybe_warn_assign_as_truth_value ($2);
542 if (check_end ($8, token::if_end)) 553 if (check_end ($8, token::if_end))
543 ABORT_PARSE; 554 ABORT_PARSE;
544 iffing--; 555 iffing--;
545 tree_if_command *t1 = new tree_if_command ($7); 556 tree_if_command *t1 = new tree_if_command
546 $$ = t1->chain ($2, $4); 557 ($7, $5->line (), $5->column ());
558 $$ = t1->chain ($2, $4, $1->line (), $1->column ());
547 } 559 }
548 | IF expression optsep opt_list elseif END 560 | IF expression optsep opt_list elseif END
549 { 561 {
550 maybe_warn_assign_as_truth_value ($2); 562 maybe_warn_assign_as_truth_value ($2);
551 if (check_end ($6, token::if_end)) 563 if (check_end ($6, token::if_end))
552 ABORT_PARSE; 564 ABORT_PARSE;
553 iffing--; 565 iffing--;
554 tree_if_command *t1 = $5->reverse (); 566 tree_if_command *t1 = $5->reverse ();
555 // Add the if list to the new head of the elseif 567 // Add the if list to the new head of the elseif
556 // list, and return the list. 568 // list, and return the list.
557 $$ = t1->chain ($2, $4); 569 $$ = t1->chain ($2, $4, $1->line (), $1->column ());
558 } 570 }
559 | IF expression optsep opt_list elseif ELSE optsep opt_list END 571 | IF expression optsep opt_list elseif ELSE optsep opt_list END
560 { 572 {
561 maybe_warn_assign_as_truth_value ($2); 573 maybe_warn_assign_as_truth_value ($2);
562 if (check_end ($9, token::if_end)) 574 if (check_end ($9, token::if_end))
563 ABORT_PARSE; 575 ABORT_PARSE;
564 iffing--; 576 iffing--;
565 // Add the else list to the head of the elseif list, 577 // Add the else list to the head of the elseif list,
566 // then reverse the list. 578 // then reverse the list.
567 tree_if_command *t1 = $5->chain ($8); 579 tree_if_command *t1 = $5->chain ($8, $6->line (),
580 $6->column ());
568 t1 = t1->reverse (); 581 t1 = t1->reverse ();
569 // Add the if list to the new head of the elseif 582 // Add the if list to the new head of the elseif
570 // list, and return the list. 583 // list, and return the list.
571 $$ = t1->chain ($2, $4); 584 $$ = t1->chain ($2, $4, $1->line (), $1->column ());
572 } 585 }
573 | BREAK 586 | BREAK
574 { 587 {
575 if (!looping) 588 if (!looping)
576 { 589 {
577 yyerror ("parse error"); 590 yyerror ("parse error");
578 error ("break: only meaningful within a `for'\ 591 error ("break: only meaningful within a `for'\
579 or `while' loop"); 592 or `while' loop");
580 ABORT_PARSE; 593 ABORT_PARSE;
581 } 594 }
582 $$ = new tree_break_command (); 595 $$ = new tree_break_command ($1->line (), $1->column ());
583 } 596 }
584 | CONTINUE 597 | CONTINUE
585 { 598 {
586 if (!looping) 599 if (!looping)
587 { 600 {
588 yyerror ("parse error"); 601 yyerror ("parse error");
589 error ("continue: only meaningful within a\ 602 error ("continue: only meaningful within a\
590 `for' or `while' loop"); 603 `for' or `while' loop");
591 ABORT_PARSE; 604 ABORT_PARSE;
592 } 605 }
593 $$ = new tree_break_command (); 606 $$ = new tree_continue_command ($1->line (),
607 $1->column ());
594 } 608 }
595 | FUNC_RET 609 | FUNC_RET
596 { 610 {
597 if (!defining_func) 611 if (!defining_func)
598 { 612 {
599 yyerror ("parse error"); 613 yyerror ("parse error");
600 error ("return: only meaningful within a function"); 614 error ("return: only meaningful within a function");
601 ABORT_PARSE; 615 ABORT_PARSE;
602 } 616 }
603 $$ = new tree_return_command (); 617 $$ = new tree_return_command ($1->line (), $1->column ());
604 } 618 }
605 ; 619 ;
606 620
607 elseif : ELSEIF optsep expression optsep opt_list 621 elseif : ELSEIF optsep expression optsep opt_list
608 { 622 {
609 maybe_warn_assign_as_truth_value ($3); 623 maybe_warn_assign_as_truth_value ($3);
610 $$ = new tree_if_command ($3, $5); 624 $$ = new tree_if_command ($3, $5, $1->line (),
625 $1->column ());
611 } 626 }
612 | elseif ELSEIF optsep expression optsep opt_list 627 | elseif ELSEIF optsep expression optsep opt_list
613 { 628 {
614 maybe_warn_assign_as_truth_value ($4); 629 maybe_warn_assign_as_truth_value ($4);
615 $$ = $1->chain ($4, $6); 630 $$ = $1->chain ($4, $6, $2->line (), $2->column ());
616 } 631 }
617 ; 632 ;
618 633
619 optsep : // empty 634 optsep : // empty
620 | sep 635 | sep
925 YYABORT; 940 YYABORT;
926 } 941 }
927 ; 942 ;
928 943
929 variable : identifier 944 variable : identifier
930 { $$ = new tree_index_expression ($1); } 945 {
946 $$ = new tree_index_expression
947 ($1, $1->line (), $1->column ());
948 }
931 | identifier '(' arg_list ')' 949 | identifier '(' arg_list ')'
932 { $$ = new tree_index_expression ($1, $3); } 950 {
951 $$ = new tree_index_expression
952 ($1, $3, $1->line (), $1->column ());
953 }
933 | identifier '(' ')' 954 | identifier '(' ')'
934 { 955 {
935 $$ = new tree_index_expression 956 $$ = new tree_index_expression
936 ($1, (tree_argument_list *) NULL); 957 ($1, (tree_argument_list *) NULL,
958 $1->line (), $1->column ());
937 } 959 }
938 | identifier '[' 960 | identifier '['
939 { 961 {
940 yyerror ("parse error"); 962 yyerror ("parse error");
941 error ("use `(\' and `)\' as index operators, not\ 963 error ("use `(\' and `)\' as index operators, not\