# # Reduction rules for bool.pl # Perl source code automatically generated at Thu Apr 16 19:16:10 1998 by # py v.0.1 25 Aug 1995 # Source code copyright 1995 M-J. Dominus (mjd@pobox.com) # # rule 1 # bool -> '(' bool ')' sub rule_1 { return $_[1]; } # rule 2 # bool -> bool '|' bool sub rule_2 { if (true($_[0]) || true($_[2])) { return 'T'; } elsif (false($_[0])) { return $_[2]; } elsif (false($_[2])) { return $_[0]; } elsif ($_[0] eq $_[2]) { return $_[0]; } return [ $_[0], '|', $_[2]]; } # rule 3 # bool -> bool '^' bool sub rule_3 { if (constant($_[0]) && constant($_[2])) { return $_[0] ^ $_[2]; } elsif ($_[0] eq $_[2]) { return $_[0]; } return [$_[0], '^', $_[2]]; } # rule 4 # bool -> bool '&' bool sub rule_4 { if (false($_[0]) || false($_[2])) { return 'F'; } elsif (true($_[0])) { return $_[2]; } elsif (true($_[2])) { return $_[0]; } elsif ($_[0] eq $_[2]) { return $_[0]; } return [$_[0], '&', $_[2]]; } # rule 5 # bool -> ATOM sub rule_5 { return $_[0]; } # rule 6 # bool -> CONSTANT sub rule_6 { return $_[0]; } # The lexer converts sequences of characters into # tokens. A token may have a value, which is stored # in the variable $yylval. The return value from yylex # says what the type of token is. { my @tokens = (); sub yylex { my $token; until ($token =~ /\S/) { $token = shift @tokens; return End_of_Input unless defined $token; } if ($token =~ /^[TFtf10]$/ ) { $yylval = ($token =~ /^[Tt1]$/) ? 1 : 0; return CONSTANT; } elsif ($token =~ /^[()&|^]$/) { return $token; } elsif ($token =~ /[^A-Za-z_]/) { warn "Bad token `$token' in input; aborting parse.\n"; @tokens = (); return End_of_Input; } else { $yylval = $token; return ATOM; } } sub set_input { my $instr = join '', @_; $instr =~ tr/\n/ /; @tokens = split(/\b|(?=\W)/, $instr); local $" = ']['; # print STDERR "TOKENS: [@tokens]\n"; } } 1;