Skip to content

Instantly share code, notes, and snippets.

View jeffreykegler's full-sized avatar

Jeffrey Kegler jeffreykegler

View GitHub Profile
@jeffreykegler
jeffreykegler / basic.out
Created November 16, 2021 01:39
ESLIF benchmark for 847K file
perl bench.pl /usr/share/iso-codes/json/iso_639-3.json
Using /usr/share/iso-codes/json/iso_639-3.json
Using Marpa::R2 8
(warning: too few iterations for a reliable count)
(warning: too few iterations for a reliable count)
(warning: too few iterations for a reliable count)
s/iter ESLIF JSON SLIF JSON JSON::PP JSON::XS
ESLIF JSON 7.43 -- -10% -71% -100%
SLIF JSON 6.68 11% -- -68% -100%
JSON::PP 2.13 249% 214% -- -99%
@jeffreykegler
jeffreykegler / basic.out
Created November 15, 2021 15:25
ESLIF benchmark Nov 15 2021
make basic
perl bench.pl test.json
Using test.json
Using Marpa::R2 8
Rate SLIF JSON JSON::PP ESLIF JSON JSON::XS
SLIF JSON 107/s -- -71% -76% -100%
JSON::PP 366/s 241% -- -18% -99%
ESLIF JSON 449/s 318% 23% -- -99%
JSON::XS 38642/s 35944% 10465% 8514% --

The post An Overview Of The Marpa Parser was originally published at https://lukasatkinson.de/2015/marpa-overview/.


Parsing pervades all of computing. Whenever we are dealing with some data format or a programming language, something needs to parse that. But writing a good grammar for a given language, and picking a suitable parser is not always easy.

For example, let's look at some strings in an example language:

@jeffreykegler
jeffreykegler / dsl3.pl
Created August 30, 2012 02:39
Simple calculator DSL, for blog post
#!perl
# This calculator contains *TWO* DSL's.
# The first one is for the calculator itself.
# The calculator's grammar is written in OP2.
# OP2 is the second DSL, and its code is the
# second half of this file.
use 5.010;
use strict;
@jeffreykegler
jeffreykegler / ast.pl
Created February 10, 2013 00:24
Example of Marpa AST creation and use
#!/usr/bin/perl
# Copyright 2013 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 / fail.t
Created December 19, 2017 03:13
Example of how naive simplifying of Marpa::R2 Grammar breaks rule ranking
#!perl
use strict;
use warnings;
use 5.010;
use Data::Dumper;
use Marpa::R2;
sub My_Actions::dwim {
shift;
return $_[0] if scalar @_ == 1;
@jeffreykegler
jeffreykegler / longest.t
Created December 19, 2017 02:59
Marpa::R2 ranking longest high versus shortest high
#!perl
use strict;
use warnings;
use 5.010;
use Data::Dumper;
use Marpa::R2;
sub My_Actions::dwim {
shift;
return $_[0] if scalar @_ == 1;
@jeffreykegler
jeffreykegler / try2.t
Created December 18, 2017 05:51
PEG style ranking
#!perl
use strict;
use warnings;
use 5.010;
use Data::Dumper;
use Marpa::R2;
sub My_Actions::dwim {
shift;
return $_[0] if scalar @_ == 1;
#!perl
use strict;
use warnings;
use 5.010;
use Data::Dumper;
use Marpa::R2;
# This grammar tries to be equivalent to a PEG or Regex with ordered choice:
# List: Item*
# Item: VAR = VAR // VAR = // VAR
@jeffreykegler
jeffreykegler / Parus major subset
Created March 10, 2016 03:14
Marpa parse for subset of bird language
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use Data::Dumper;
use English qw( -no_match_vars );
use Test::More tests => 6;