Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Perl and Context Free Grammar

by dref (Novice)
on Nov 20, 2003 at 21:05 UTC ( [id://308707]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @strings = qw(aaabbbccc abc aaaaabbbbbccccc abbccc);
    print "\nAttempt 1\n";
    ...
      while (s/^a(a*)b(b*)c(c*)$/$1$2$3/g) {};
      print ($_ ? "Rejected" : "Accepted","\n");
    }
    
  2. or download this
    print "\nAttempt 2\n";
    my $count;
    ...
      print "$str: ";
      print ($str =~ m/$re2/ ? "Accepted" : "Rejected","\n");
    }
    
  3. or download this
     $rule_i = qr/ (??{$alpha_v1}) (??{$alpha_v2}) ... (??{$alpha_vn}) /x;
    
  4. or download this
     $alpha_N = qr/ (??{$rule_1}) | (??{$rule_2}) | ... | (??{$rule_n}) /x
    +;
    
  5. or download this
    $START = $alpha_N;
    
  6. or download this
    $alpha_Jim    = qr/ Jim \s* /x;
    $alpha_big    = qr/ big \s* /x;
    $alpha_green  = qr/ green \s* /x;
    $alpha_cheese = qr/ cheese \s* /x;
    $alpha_ate    = qr/ ate \s* /x;
    
  7. or download this
    $rule_1       = qr/ (??{$alpha_N}) /x;
    $rule_2       = qr/ (??{$alpha_A}) (??{$alpha_P})/x;
    ...
    $rule_6       = qr/ (??{$alpha_cheese}) /x;
    $rule_7       = qr/ (??{$alpha_Jim}) /x;
    $rule_8       = qr/ (??{$alpha_ate}) /x;
    
  8. or download this
    $alpha_P      = qr/ (??{$rule_1}) | (??{$rule_2}) /x;
    $alpha_S      = qr/ (??{$rule_3}) /x;
    $alpha_A      = qr/ (??{$rule_4}) | (??{$rule_5}) /x;
    $alpha_N      = qr/ (??{$rule_6}) | (??{$rule_7}) /x;
    $alpha_V      = qr/ (??{$rule_8}) /x;
    
  9. or download this
    $START = $alpha_S;
    $G = qr/ ^ (??{$START}) $ /x;
    
  10. or download this
    @strings = ('Jim ate cheese','big Jim ate green cheese',
                'big cheese ate Jim',
    ...
    foreach (@strings) {
      print "Try: $_ -- ", /$G/ ? "Accepted" : "Rejected", "\n";
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://308707]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-03-19 04:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found