Skip to content

Instantly share code, notes, and snippets.

View jeffreykegler's full-sized avatar

Jeffrey Kegler jeffreykegler

View GitHub Profile
@jeffreykegler
jeffreykegler / balanced.pl
Created November 7, 2011 04:36
Marpa::{XS,PP} vs. Regex::Common::balanced benchmarking script
use 5.010;
use strict;
use warnings;
use Benchmark qw(timeit countit timestr);
use Regexp::Common qw /balanced/;
use Getopt::Long;
my $example;
my $length = 1000;
my $string;
@jeffreykegler
jeffreykegler / sql_insert.pl
Created January 4, 2012 04:10
Example: Subset of SQL-2003 SQL INSERT statement
use strict;
use warnings;
use 5.010;
use Marpa::XS;
use Data::Dumper;
# An SQL INSERT statement for testing
my $text = q{
INSERT INTO `tehtable` ( `field00`, `field01` ) VALUES ( 123, `abcd\'e
+fgh` );
@jeffreykegler
jeffreykegler / minmax_to_BNF.pl
Created April 7, 2012 03:16
Min,max to BNF rewriter
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use Scalar::Util;
use English qw( -no_match_vars );
# Code to demonstrate factoring of regex min,max
# counts into BNF rules
@jeffreykegler
jeffreykegler / dyck_hollerith.pl
Created April 12, 2012 03:24
A Marpa parser for Flavio Poletti's Dyck-Hollerith language
use 5.010;
use strict;
use warnings;
use Data::Dumper;
use Scalar::Util;
use Marpa::XS;
# A Marpa::XS parser for the Dyck-Hollerith language
my $repeat;
@jeffreykegler
jeffreykegler / catalan.pl
Created June 26, 2012 21:07
A grammar that generates the Catalan numbers
#!perl
use 5.010;
use strict;
use warnings;
use English qw( -no_match_vars );
use Marpa::R2;
use MarpaX::Simple::Rules '0.2.6', 'parse_rules';
my $catalan_rules = parse_rules(<<"RULES");
@jeffreykegler
jeffreykegler / pascal.pl
Created June 26, 2012 21:08
A grammar that generates Pascal's triangle
#!perl
use 5.010;
use strict;
use warnings;
use English qw( -no_match_vars );
use Marpa::R2;
use MarpaX::Simple::Rules '0.2.6', 'parse_rules';
my $basic_pascal_rules = parse_rules(<<"RULES");
@jeffreykegler
jeffreykegler / wall.pl
Created June 26, 2012 21:09
A grammar that generates a variant of the Fibonacci series
#!perl
use 5.010;
use strict;
use warnings;
use English qw( -no_match_vars );
use Marpa::R2;
use MarpaX::Simple::Rules '0.2.6', 'parse_rules';
my $wall_rules = parse_rules(<<"RULES");
@jeffreykegler
jeffreykegler / curly2.t
Created July 25, 2012 17:03
Code for partial parsing of Perl
#!perl
# Copyright 2012 Jeffrey Kegler
# This file is part of Marpa::R2. Marpa::R2 is free software: you can
# redistribute it and/or modify it under the terms of the GNU Lesser
# General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# Marpa::R2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@jeffreykegler
jeffreykegler / round2.pl
Created August 6, 2012 05:37
Marpa v. Perl regex, round 2
#!perl
use 5.010;
use strict;
use warnings;
use autodie;
use Benchmark qw(timethis);
use List::Util qw(min);
use Regexp::Common qw /balanced/;
@jeffreykegler
jeffreykegler / round2_EASY.pl
Created August 7, 2012 01:37
Marpa v. Perl regex, round 2 (EASY)
#!perl
use 5.010;
use strict;
use warnings;
use autodie;
use Benchmark qw(timethis);
use List::Util qw(min);
use Regexp::Common qw /balanced/;