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 / 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 / sat-life.w
Created April 22, 2017 18:39
Sample of CWeb, by Knuth himself
\datethis
@*Intro. This program generates clauses for the transition relation
from time $t$ to time $t+1$ in Conway's Game of Life, assuming that
all of the potentially live cells at time $t$ belong to a pattern
that's specified in |stdin|. The pattern is defined by one or more
lines representing rows of cells, where each line has `\..' in a
cell that's guaranteed to be dead at time~$t$, otherwise it has `\.*'.
The time is specified separately as a command-line parameter.
The Boolean variable for cell $(x,y)$ at time $t$ is named by its
@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;
@jeffreykegler
jeffreykegler / andreas.out
Created March 7, 2015 01:06
Example of SLIF rewrites for Andreas Kupries
DSL:
:default ::= action => [values] bless => ::lhs
lexeme default = action => [ start, length, value ]
bless => ::name latm => 1
:start ::= Script
Script ::= Expression+ separator => comma
comma ~ [,]
Expression ::=
Number bless => primary