use strict; use Parse::RecDescent; my $grammar = ' start: a_oder_b a_oder_b(?) a_oder_b(?) eos a_oder_b: "a" | "b" eos: "?" '; my $parser = Parse::RecDescent->new ($grammar); my $re = qr/^[ab]{1,3}$/; my $input = ""; my $switch = "regexp"; my $res = 0; print "exit beendet, switch schaltet um\n\n"; while ($input ne "exit") { printf "%-7s: gib irgendwas ein: ", $switch; chomp ($input = ); if ($input eq "switch") { $switch eq "regexp" and $switch = "grammar" or $switch = "regexp"; next; } elsif ($input eq "exit") { next; } elsif ($switch eq "regexp") { $res = "$input" =~ $re ? 1 : 0; } else { $res = $parser->start ("$input?") ? 1 : 0; } print "[$switch] [$input] wird", $res ? "" : " nicht", " erkannt\n"; }