/usr/share/perl5/Parse/Yapp/Parse.pm is in libparse-yapp-perl 1.05-12.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 | ####################################################################
#
# This file was generated using Parse::Yapp version 1.05.
#
# Don't edit this file, use source file instead.
#
# ANY CHANGE MADE HERE WILL BE LOST !
#
####################################################################
package Parse::Yapp::Parse;
use vars qw ( @ISA );
use strict;
@ISA= qw ( Parse::Yapp::Driver );
use Parse::Yapp::Driver;
#line 1 "YappParse.yp"
# (c) Copyright Francois Desarmenien 1998-2001, all rights reserved.
# (see COPYRIGHT in Parse::Yapp.pm pod section for use and distribution rights)
#
# Parse/Yapp/Parser.yp: Parse::Yapp::Parser.pm source file
#
# Use: yapp -m 'Parse::Yapp::Parse' -o Parse/Yapp/Parse.pm YappParse.yp
#
# to generate the Parser module.
#
#line 12 "YappParse.yp"
require 5.004;
use Carp;
my($input,$lexlevel,@lineno,$nberr,$prec,$labelno);
my($syms,$head,$tail,$token,$term,$nterm,$rules,$precterm,$start,$nullable);
my($expect);
sub new {
my($class)=shift;
ref($class)
and $class=ref($class);
my($self)=$class->SUPER::new( yyversion => '1.05',
yystates =>
[
{#State 0
ACTIONS => {
"%%" => -6,
'HEADCODE' => 3,
'UNION' => 2,
'TOKEN' => 5,
'ASSOC' => 7,
'START' => 6,
'error' => 9,
'TYPE' => 10,
"\n" => 11,
'EXPECT' => 13
},
GOTOS => {
'head' => 1,
'decls' => 12,
'yapp' => 4,
'decl' => 14,
'headsec' => 8
}
},
{#State 1
ACTIONS => {
'error' => 19,
"%%" => 16,
'IDENT' => 18
},
GOTOS => {
'rules' => 15,
'rulesec' => 20,
'body' => 17
}
},
{#State 2
ACTIONS => {
'CODE' => 21
}
},
{#State 3
ACTIONS => {
"\n" => 22
}
},
{#State 4
ACTIONS => {
'' => 23
}
},
{#State 5
ACTIONS => {
"<" => 25
},
DEFAULT => -19,
GOTOS => {
'typedecl' => 24
}
},
{#State 6
ACTIONS => {
'IDENT' => 26
},
GOTOS => {
'ident' => 27
}
},
{#State 7
ACTIONS => {
"<" => 25
},
DEFAULT => -19,
GOTOS => {
'typedecl' => 28
}
},
{#State 8
ACTIONS => {
"%%" => 29
}
},
{#State 9
ACTIONS => {
"\n" => 30
}
},
{#State 10
ACTIONS => {
"<" => 25
},
DEFAULT => -19,
GOTOS => {
'typedecl' => 31
}
},
{#State 11
DEFAULT => -10
},
{#State 12
ACTIONS => {
"%%" => -7,
'HEADCODE' => 3,
'UNION' => 2,
'TOKEN' => 5,
'ASSOC' => 7,
'START' => 6,
'error' => 9,
'TYPE' => 10,
"\n" => 11,
'EXPECT' => 13
},
GOTOS => {
'decl' => 32
}
},
{#State 13
ACTIONS => {
'NUMBER' => 33
}
},
{#State 14
DEFAULT => -9
},
{#State 15
DEFAULT => -28
},
{#State 16
DEFAULT => -26
},
{#State 17
ACTIONS => {
'TAILCODE' => 34
},
DEFAULT => -45,
GOTOS => {
'tail' => 35
}
},
{#State 18
ACTIONS => {
":" => 36
}
},
{#State 19
ACTIONS => {
";" => 37
}
},
{#State 20
ACTIONS => {
'error' => 19,
"%%" => 39,
'IDENT' => 18
},
GOTOS => {
'rules' => 38
}
},
{#State 21
ACTIONS => {
"\n" => 40
}
},
{#State 22
DEFAULT => -14
},
{#State 23
DEFAULT => -0
},
{#State 24
ACTIONS => {
'LITERAL' => 41,
'IDENT' => 26
},
GOTOS => {
'symlist' => 43,
'ident' => 44,
'symbol' => 42
}
},
{#State 25
ACTIONS => {
'IDENT' => 45
}
},
{#State 26
DEFAULT => -4
},
{#State 27
ACTIONS => {
"\n" => 46
}
},
{#State 28
ACTIONS => {
'LITERAL' => 41,
'IDENT' => 26
},
GOTOS => {
'symlist' => 47,
'ident' => 44,
'symbol' => 42
}
},
{#State 29
DEFAULT => -5
},
{#State 30
DEFAULT => -18
},
{#State 31
ACTIONS => {
'IDENT' => 26
},
GOTOS => {
'ident' => 48,
'identlist' => 49
}
},
{#State 32
DEFAULT => -8
},
{#State 33
ACTIONS => {
"\n" => 50
}
},
{#State 34
DEFAULT => -46
},
{#State 35
DEFAULT => -1
},
{#State 36
ACTIONS => {
'CODE' => 57,
'LITERAL' => 41,
'IDENT' => 26
},
DEFAULT => -35,
GOTOS => {
'rhselts' => 56,
'rule' => 51,
'code' => 52,
'rhs' => 53,
'ident' => 44,
'rhselt' => 58,
'rhss' => 55,
'symbol' => 54
}
},
{#State 37
DEFAULT => -30
},
{#State 38
DEFAULT => -27
},
{#State 39
DEFAULT => -25
},
{#State 40
DEFAULT => -15
},
{#State 41
DEFAULT => -2
},
{#State 42
DEFAULT => -22
},
{#State 43
ACTIONS => {
"\n" => 60,
'LITERAL' => 41,
'IDENT' => 26
},
GOTOS => {
'ident' => 44,
'symbol' => 59
}
},
{#State 44
DEFAULT => -3
},
{#State 45
ACTIONS => {
">" => 61
}
},
{#State 46
DEFAULT => -13
},
{#State 47
ACTIONS => {
"\n" => 62,
'LITERAL' => 41,
'IDENT' => 26
},
GOTOS => {
'ident' => 44,
'symbol' => 59
}
},
{#State 48
DEFAULT => -24
},
{#State 49
ACTIONS => {
"\n" => 63,
'IDENT' => 26
},
GOTOS => {
'ident' => 64
}
},
{#State 50
DEFAULT => -17
},
{#State 51
DEFAULT => -32
},
{#State 52
DEFAULT => -40
},
{#State 53
ACTIONS => {
'PREC' => 66
},
DEFAULT => -34,
GOTOS => {
'prec' => 65
}
},
{#State 54
DEFAULT => -39
},
{#State 55
ACTIONS => {
"|" => 68,
";" => 67
}
},
{#State 56
ACTIONS => {
'CODE' => 57,
'LITERAL' => 41,
'IDENT' => 26
},
DEFAULT => -36,
GOTOS => {
'code' => 52,
'ident' => 44,
'rhselt' => 69,
'symbol' => 54
}
},
{#State 57
DEFAULT => -44
},
{#State 58
DEFAULT => -38
},
{#State 59
DEFAULT => -21
},
{#State 60
DEFAULT => -11
},
{#State 61
DEFAULT => -20
},
{#State 62
DEFAULT => -12
},
{#State 63
DEFAULT => -16
},
{#State 64
DEFAULT => -23
},
{#State 65
ACTIONS => {
'CODE' => 57
},
DEFAULT => -42,
GOTOS => {
'code' => 70,
'epscode' => 71
}
},
{#State 66
ACTIONS => {
'LITERAL' => 41,
'IDENT' => 26
},
GOTOS => {
'ident' => 44,
'symbol' => 72
}
},
{#State 67
DEFAULT => -29
},
{#State 68
ACTIONS => {
'CODE' => 57,
'LITERAL' => 41,
'IDENT' => 26
},
DEFAULT => -35,
GOTOS => {
'rhselts' => 56,
'rule' => 73,
'code' => 52,
'rhs' => 53,
'ident' => 44,
'rhselt' => 58,
'symbol' => 54
}
},
{#State 69
DEFAULT => -37
},
{#State 70
DEFAULT => -43
},
{#State 71
DEFAULT => -33
},
{#State 72
DEFAULT => -41
},
{#State 73
DEFAULT => -31
}
],
yyrules =>
[
[#Rule 0
'$start', 2, undef
],
[#Rule 1
'yapp', 3, undef
],
[#Rule 2
'symbol', 1,
sub
#line 30 "YappParse.yp"
{
exists($$syms{$_[1][0]})
or do {
$$syms{$_[1][0]} = $_[1][1];
$$term{$_[1][0]} = undef;
};
$_[1]
}
],
[#Rule 3
'symbol', 1, undef
],
[#Rule 4
'ident', 1,
sub
#line 41 "YappParse.yp"
{
exists($$syms{$_[1][0]})
or do {
$$syms{$_[1][0]} = $_[1][1];
$$term{$_[1][0]} = undef;
};
$_[1]
}
],
[#Rule 5
'head', 2, undef
],
[#Rule 6
'headsec', 0, undef
],
[#Rule 7
'headsec', 1, undef
],
[#Rule 8
'decls', 2, undef
],
[#Rule 9
'decls', 1, undef
],
[#Rule 10
'decl', 1, undef
],
[#Rule 11
'decl', 4,
sub
#line 66 "YappParse.yp"
{
for (@{$_[3]}) {
my($symbol,$lineno)=@$_;
exists($$token{$symbol})
and do {
_SyntaxError(0,
"Token $symbol redefined: ".
"Previously defined line $$syms{$symbol}",
$lineno);
next;
};
$$token{$symbol}=$lineno;
$$term{$symbol} = [ ];
}
undef
}
],
[#Rule 12
'decl', 4,
sub
#line 84 "YappParse.yp"
{
for (@{$_[3]}) {
my($symbol,$lineno)=@$_;
defined($$term{$symbol}[0])
and do {
_SyntaxError(1,
"Precedence for symbol $symbol redefined: ".
"Previously defined line $$syms{$symbol}",
$lineno);
next;
};
$$token{$symbol}=$lineno;
$$term{$symbol} = [ $_[1][0], $prec ];
}
++$prec;
undef
}
],
[#Rule 13
'decl', 3,
sub
#line 102 "YappParse.yp"
{ $start=$_[2][0]; undef }
],
[#Rule 14
'decl', 2,
sub
#line 103 "YappParse.yp"
{ push(@$head,$_[1]); undef }
],
[#Rule 15
'decl', 3,
sub
#line 104 "YappParse.yp"
{ undef }
],
[#Rule 16
'decl', 4,
sub
#line 106 "YappParse.yp"
{
for ( @{$_[3]} ) {
my($symbol,$lineno)=@$_;
exists($$nterm{$symbol})
and do {
_SyntaxError(0,
"Non-terminal $symbol redefined: ".
"Previously defined line $$syms{$symbol}",
$lineno);
next;
};
delete($$term{$symbol}); #not a terminal
$$nterm{$symbol}=undef; #is a non-terminal
}
}
],
[#Rule 17
'decl', 3,
sub
#line 122 "YappParse.yp"
{ $expect=$_[2][0]; undef }
],
[#Rule 18
'decl', 2,
sub
#line 123 "YappParse.yp"
{ $_[0]->YYErrok }
],
[#Rule 19
'typedecl', 0, undef
],
[#Rule 20
'typedecl', 3, undef
],
[#Rule 21
'symlist', 2,
sub
#line 130 "YappParse.yp"
{ push(@{$_[1]},$_[2]); $_[1] }
],
[#Rule 22
'symlist', 1,
sub
#line 131 "YappParse.yp"
{ [ $_[1] ] }
],
[#Rule 23
'identlist', 2,
sub
#line 134 "YappParse.yp"
{ push(@{$_[1]},$_[2]); $_[1] }
],
[#Rule 24
'identlist', 1,
sub
#line 135 "YappParse.yp"
{ [ $_[1] ] }
],
[#Rule 25
'body', 2,
sub
#line 140 "YappParse.yp"
{
$start
or $start=$$rules[1][0];
ref($$nterm{$start})
or _SyntaxError(2,"Start symbol $start not found ".
"in rules section",$_[2][1]);
$$rules[0]=[ '$start', [ $start, chr(0) ], undef, undef ];
}
],
[#Rule 26
'body', 1,
sub
#line 150 "YappParse.yp"
{ _SyntaxError(2,"No rules in input grammar",$_[1][1]); }
],
[#Rule 27
'rulesec', 2, undef
],
[#Rule 28
'rulesec', 1, undef
],
[#Rule 29
'rules', 4,
sub
#line 157 "YappParse.yp"
{ _AddRules($_[1],$_[3]); undef }
],
[#Rule 30
'rules', 2,
sub
#line 158 "YappParse.yp"
{ $_[0]->YYErrok }
],
[#Rule 31
'rhss', 3,
sub
#line 161 "YappParse.yp"
{ push(@{$_[1]},$_[3]); $_[1] }
],
[#Rule 32
'rhss', 1,
sub
#line 162 "YappParse.yp"
{ [ $_[1] ] }
],
[#Rule 33
'rule', 3,
sub
#line 165 "YappParse.yp"
{ push(@{$_[1]}, $_[2], $_[3]); $_[1] }
],
[#Rule 34
'rule', 1,
sub
#line 166 "YappParse.yp"
{
my($code)=undef;
defined($_[1])
and $_[1][-1][0] eq 'CODE'
and $code = ${pop(@{$_[1]})}[1];
push(@{$_[1]}, undef, $code);
$_[1]
}
],
[#Rule 35
'rhs', 0, undef
],
[#Rule 36
'rhs', 1, undef
],
[#Rule 37
'rhselts', 2,
sub
#line 183 "YappParse.yp"
{ push(@{$_[1]},$_[2]); $_[1] }
],
[#Rule 38
'rhselts', 1,
sub
#line 184 "YappParse.yp"
{ [ $_[1] ] }
],
[#Rule 39
'rhselt', 1,
sub
#line 187 "YappParse.yp"
{ [ 'SYMB', $_[1] ] }
],
[#Rule 40
'rhselt', 1,
sub
#line 188 "YappParse.yp"
{ [ 'CODE', $_[1] ] }
],
[#Rule 41
'prec', 2,
sub
#line 192 "YappParse.yp"
{
defined($$term{$_[2][0]})
or do {
_SyntaxError(1,"No precedence for symbol $_[2][0]",
$_[2][1]);
return undef;
};
++$$precterm{$_[2][0]};
$$term{$_[2][0]}[1];
}
],
[#Rule 42
'epscode', 0,
sub
#line 205 "YappParse.yp"
{ undef }
],
[#Rule 43
'epscode', 1,
sub
#line 206 "YappParse.yp"
{ $_[1] }
],
[#Rule 44
'code', 1,
sub
#line 209 "YappParse.yp"
{ $_[1] }
],
[#Rule 45
'tail', 0, undef
],
[#Rule 46
'tail', 1,
sub
#line 215 "YappParse.yp"
{ $tail=$_[1] }
]
],
@_);
bless($self,$class);
}
#line 218 "YappParse.yp"
sub _Error {
my($value)=$_[0]->YYCurval;
my($what)= $token ? "input: '$$value[0]'" : "end of input";
_SyntaxError(1,"Unexpected $what",$$value[1]);
}
sub _Lexer {
#At EOF
pos($$input) >= length($$input)
and return('',[ undef, -1 ]);
#In TAIL section
$lexlevel > 1
and do {
my($pos)=pos($$input);
$lineno[0]=$lineno[1];
$lineno[1]=-1;
pos($$input)=length($$input);
return('TAILCODE',[ substr($$input,$pos), $lineno[0] ]);
};
#Skip blanks
$lexlevel == 0
? $$input=~m{\G((?:
[\t\ ]+ # Any white space char but \n
| \#[^\n]* # Perl like comments
| /\*.*?\*/ # C like comments
)+)}xsgc
: $$input=~m{\G((?:
\s+ # any white space char
| \#[^\n]* # Perl like comments
| /\*.*?\*/ # C like comments
)+)}xsgc
and do {
my($blanks)=$1;
#Maybe At EOF
pos($$input) >= length($$input)
and return('',[ undef, -1 ]);
$lineno[1]+= $blanks=~tr/\n//;
};
$lineno[0]=$lineno[1];
$$input=~/\G([A-Za-z_][A-Za-z0-9_]*)/gc
and return('IDENT',[ $1, $lineno[0] ]);
$$input=~/\G('(?:[^'\\]|\\\\|\\'|\\)+?')/gc
and do {
$1 eq "'error'"
and do {
_SyntaxError(0,"Literal 'error' ".
"will be treated as error token",$lineno[0]);
return('IDENT',[ 'error', $lineno[0] ]);
};
return('LITERAL',[ $1, $lineno[0] ]);
};
$$input=~/\G(%%)/gc
and do {
++$lexlevel;
return($1, [ $1, $lineno[0] ]);
};
$$input=~/\G{/gc
and do {
my($level,$from,$code);
$from=pos($$input);
$level=1;
while($$input=~/([{}])/gc) {
substr($$input,pos($$input)-1,1) eq '\\' #Quoted
and next;
$level += ($1 eq '{' ? 1 : -1)
or last;
}
$level
and _SyntaxError(2,"Unmatched { opened line $lineno[0]",-1);
$code = substr($$input,$from,pos($$input)-$from-1);
$lineno[1]+= $code=~tr/\n//;
return('CODE',[ $code, $lineno[0] ]);
};
if($lexlevel == 0) {# In head section
$$input=~/\G%(left|right|nonassoc)/gc
and return('ASSOC',[ uc($1), $lineno[0] ]);
$$input=~/\G%(start)/gc
and return('START',[ undef, $lineno[0] ]);
$$input=~/\G%(expect)/gc
and return('EXPECT',[ undef, $lineno[0] ]);
$$input=~/\G%{/gc
and do {
my($code);
$$input=~/\G(.*?)%}/sgc
or _SyntaxError(2,"Unmatched %{ opened line $lineno[0]",-1);
$code=$1;
$lineno[1]+= $code=~tr/\n//;
return('HEADCODE',[ $code, $lineno[0] ]);
};
$$input=~/\G%(token)/gc
and return('TOKEN',[ undef, $lineno[0] ]);
$$input=~/\G%(type)/gc
and return('TYPE',[ undef, $lineno[0] ]);
$$input=~/\G%(union)/gc
and return('UNION',[ undef, $lineno[0] ]);
$$input=~/\G([0-9]+)/gc
and return('NUMBER',[ $1, $lineno[0] ]);
}
else {# In rule section
$$input=~/\G%(prec)/gc
and return('PREC',[ undef, $lineno[0] ]);
}
#Always return something
$$input=~/\G(.)/sg
or die "Parse::Yapp::Grammar::Parse: Match (.) failed: report as a BUG";
$1 eq "\n"
and ++$lineno[1];
( $1 ,[ $1, $lineno[0] ]);
}
sub _SyntaxError {
my($level,$message,$lineno)=@_;
$message= "*".
[ 'Warning', 'Error', 'Fatal' ]->[$level].
"* $message, at ".
($lineno < 0 ? "eof" : "line $lineno").
".\n";
$level > 1
and die $message;
warn $message;
$level > 0
and ++$nberr;
$nberr == 20
and die "*Fatal* Too many errors detected.\n"
}
sub _AddRules {
my($lhs,$lineno)=@{$_[0]};
my($rhss)=$_[1];
ref($$nterm{$lhs})
and do {
_SyntaxError(1,"Non-terminal $lhs redefined: ".
"Previously declared line $$syms{$lhs}",$lineno);
return;
};
ref($$term{$lhs})
and do {
my($where) = exists($$token{$lhs}) ? $$token{$lhs} : $$syms{$lhs};
_SyntaxError(1,"Non-terminal $lhs previously ".
"declared as token line $where",$lineno);
return;
};
ref($$nterm{$lhs}) #declared through %type
or do {
$$syms{$lhs}=$lineno; #Say it's declared here
delete($$term{$lhs}); #No more a terminal
};
$$nterm{$lhs}=[]; #It's a non-terminal now
my($epsrules)=0; #To issue a warning if more than one epsilon rule
for my $rhs (@$rhss) {
my($tmprule)=[ $lhs, [ ], splice(@$rhs,-2) ]; #Init rule
@$rhs
or do {
++$$nullable{$lhs};
++$epsrules;
};
for (0..$#$rhs) {
my($what,$value)=@{$$rhs[$_]};
$what eq 'CODE'
and do {
my($name)='@'.++$labelno."-$_";
push(@$rules,[ $name, [], undef, $value ]);
push(@{$$tmprule[1]},$name);
next;
};
push(@{$$tmprule[1]},$$value[0]);
}
push(@$rules,$tmprule);
push(@{$$nterm{$lhs}},$#$rules);
}
$epsrules > 1
and _SyntaxError(0,"More than one empty rule for symbol $lhs",$lineno);
}
sub Parse {
my($self)=shift;
@_ > 0
or croak("No input grammar\n");
my($parsed)={};
$input=\$_[0];
$lexlevel=0;
@lineno=(1,1);
$nberr=0;
$prec=0;
$labelno=0;
$head=();
$tail="";
$syms={};
$token={};
$term={};
$nterm={};
$rules=[ undef ]; #reserve slot 0 for start rule
$precterm={};
$start="";
$nullable={};
$expect=0;
pos($$input)=0;
$self->YYParse(yylex => \&_Lexer, yyerror => \&_Error);
$nberr
and _SyntaxError(2,"Errors detected: No output",-1);
@$parsed{ 'HEAD', 'TAIL', 'RULES', 'NTERM', 'TERM',
'NULL', 'PREC', 'SYMS', 'START', 'EXPECT' }
= ( $head, $tail, $rules, $nterm, $term,
$nullable, $precterm, $syms, $start, $expect);
undef($input);
undef($lexlevel);
undef(@lineno);
undef($nberr);
undef($prec);
undef($labelno);
undef($head);
undef($tail);
undef($syms);
undef($token);
undef($term);
undef($nterm);
undef($rules);
undef($precterm);
undef($start);
undef($nullable);
undef($expect);
$parsed
}
1;
|