Skip to content

Instantly share code, notes, and snippets.

View jeffreykegler's full-sized avatar

Jeffrey Kegler jeffreykegler

View GitHub Profile

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:

#!/usr/bin/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 / test.pl
Last active December 17, 2015 02:09 — forked from pstuifzand/test.pl
use 5.10.0;
use Marpa::R2 2.053_006;
use Data::Dumper;
my $grammar = Marpa::R2::Scanless::G->new({
source => \<<'SOURCE',
:start ::= numbers
event number_found = completed number
package MonthTotals;
use 5.010;
use strict;
use Marpa::R2;
use Data::Dumper;
sub new {
my ($class) = @_;
my $self = bless {
grammar => Marpa::R2::Scanless::G->new({
package MarpaX::JSON;
use 5.010;
use strict;
use warnings;
use Marpa::R2 2.060000;
sub new {
my ($class) = @_;