#!/usr/bin/perl
##########################################
# Playing around with parsing 
# context-free and context-sensitive textbook examples
# using Parse::RecDescent.
#
# May 2, 2003 - Jim Mahoney
##############################################
use warnings;
use strict;
use Parse::RecDescent;
use Data::Dumper;
# $::RD_HINT=1;
# $::RD_TRACE=1;
our $DEBUG=0;

# - - - define the grammer for Parse::RecDescent - - - - - 
# see for example http://search.cpan.org/dist/Parse-RecDescent/
# append the line <autotree> to turn the result into a tree that Data::Dumper can print.

my $aNbN_grammar = <<'EOG';
  S   : P end
  P   :   'a' 'b' | 'a' P 'b' 
  end : /$/
EOG

my $ABparser = new Parse::RecDescent($aNbN_grammar);

sub tryAB {
  my ($string) = @_;
  print " Trying '$string' ... ";
  my $result = $ABparser->S($string);
  print defined($result) ? "yes" : "no";
  print ".\n";
  # print Dumper($result) if defined($result);
}

tryAB("ab");
tryAB("abb");
tryAB("aabb");
tryAB("aab");

# ============================================= 


