Skip to content

Instantly share code, notes, and snippets.

View pstuifzand's full-sized avatar

Peter Stuifzand pstuifzand

View GitHub Profile
@pstuifzand
pstuifzand / marpa-grammar.vim
Created April 8, 2012 11:02
Vim syntax highlighting for Marpa
" Vim syntax file
" Language: Marpa grammar
" Maintainer: Peter Stuifzand <peter@tweevijftig.nl>
" URL: http://peterstuifzand.nl
" Version: 1
" Last Change: 2012 Apr 1
"
" Read the HTML syntax to start with
if version < 600
@pstuifzand
pstuifzand / fib.php
Created July 12, 2012 10:18
Fibonacci for web developers
<?php
include "config.php";
$n = $_GET['n'];
if ($n == 1) {
echo "fib($n) == 1";
mysql_query("REPLACE INTO `fib` (`n`, `fib`) VALUES ('1','1')");
}
else if ($n == 2) {
@pstuifzand
pstuifzand / test.pl
Created January 3, 2013 10:21
test script
#!/usr/bin/env perl
use strict;
use Marpa::R2 2.038000;
use Data::Dumper;
my $grammar = Marpa::R2::Scanless::G->new(
{
action_object => 'My_Actions',
default_action => 'do_first_arg',
@pstuifzand
pstuifzand / test2.pl
Created January 3, 2013 12:13
Another test program. The input string is a comma separated list of multi-digit integers. The output should be a `Dumper`ed array-ref. $VAR1 = [100,3,4]. Without the ":discard" rules I get an error about how it can only parse the first number "100" and stops at the ",".
use strict;
use Marpa::R2 2.038000;
use Data::Dumper;
my $grammar = Marpa::R2::Scanless::G->new(
{
action_object => 'My_Actions',
default_action => 'do_first_arg',
source => \(<<'END_OF_SOURCE'),
@pstuifzand
pstuifzand / MarpaX-JSON.pm
Last active December 10, 2015 14:28
A JSON parser in Marpa.
package MarpaX::JSON;
use strict;
use Marpa::R2 2.039_000;
sub new {
my ($class) = @_;
my $self = bless {}, $class;
$self->{grammar} = Marpa::R2::Scanless::G->new(
@pstuifzand
pstuifzand / Demo-MarpaX-Makefile.pm
Last active December 10, 2015 14:38
Completely incomplete parser for Makefiles
package Demo::MarpaX::Makefile;
use strict;
use Marpa::R2;
sub new {
my ($class) = @_;
my $self = bless {}, $class;
$self->{grammar} = Marpa::R2::Scanless::G->new(
@pstuifzand
pstuifzand / test-string-parse.pl
Created January 6, 2013 11:22
Parsing a JSON string with Marpa.
use strict;
use Marpa::R2;
my $g = Marpa::R2::Scanless::G->new({
action_object => 'main',
default_action => 'do_first_arg',
source => \(<<'END_OF_SOURCE'),
:start ::= string
@pstuifzand
pstuifzand / fixed-script.pl
Last active December 11, 2015 04:58
Fix script for Marpa question
#!/usr/bin/perl
use strict;
use warnings;
use Marpa::R2 2.023008;
use Data::Dumper;
my %type = (
boy => 'noun',
girl => 'noun',
package Logic;
use strict;
use Marpa::R2 2.041_000;
sub new {
my ($class) = @_;
my $self = bless {}, $class;
$self->{grammar} = Marpa::R2::Scanless::G->new(
@pstuifzand
pstuifzand / RR.pm
Last active December 11, 2015 20:59
Parse -> Rewrite tree -> Serialize
package RR;
use strict;
use Marpa::R2 2.042000;
use Data::Dumper;
use base 'Exporter';
our @EXPORT_OK = qw/replace/;
sub new {
my ($class) = @_;