Skip to content

Instantly share code, notes, and snippets.

@arodland
Created September 10, 2011 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arodland/1207865 to your computer and use it in GitHub Desktop.
Save arodland/1207865 to your computer and use it in GitHub Desktop.
#!perl
#
use strict;
use warnings;
use Regexp::Grammars;
my $parser = qr/
<nocontext:>
^<Statement>$
<rule: Statement> <Implication>
<rule: Implication> <L=Disjunction> -> <R=Implication> | <Disjunction>
<rule: Disjunction> <L=Conjunction> \|\| <R=Disjunction> | <Conjunction>
<rule: Conjunction> <L=Term> && <R=Conjunction> | <Term>
<rule: Term> <Variable> | \( <Statement> \)
<token: Variable> \w+
/xms;
my $text = '(P || Q || R) && ((P -> R) -> Q)';
use Data::Dumper;
print Dumper($/{Statement}) if $text =~ $parser;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment