Guest User

Untitled

a guest
Aug 10th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #!perl
  2. #
  3. use strict;
  4. use warnings;
  5.  
  6. use Regexp::Grammars;
  7.  
  8. my $parser = qr/
  9. <nocontext:>
  10. ^<Statement>$
  11.  
  12. <rule: Statement> <Implication>
  13.  
  14. <rule: Implication> <L=Disjunction> -> <R=Implication> | <Disjunction>
  15.  
  16. <rule: Disjunction> <L=Conjunction> \|\| <R=Disjunction> | <Conjunction>
  17.  
  18. <rule: Conjunction> <L=Term> && <R=Conjunction> | <Term>
  19.  
  20. <rule: Term> <Variable> | \( <Statement> \)
  21.  
  22. <token: Variable> \w+
  23. /xms;
  24.  
  25. my $text = '(P || Q || R) && ((P -> R) -> Q)';
  26. use Data::Dumper;
  27. print Dumper($/{Statement}) if $text =~ $parser;
Add Comment
Please, Sign In to add comment