Skip to content

Instantly share code, notes, and snippets.

@jddurand
jddurand / c2ast.pl
Last active March 20, 2016 07:24
C to AST using Marpa::R2. Update to update version of Marpa -;
#!env perl
# Execute this script with no parameter to get the online help
use strict;
use diagnostics;
use Marpa::R2;
use File::Slurp;
use Data::Dumper;
use POSIX;
#!env perl
use strict;
use diagnostics;
use Marpa::R2;
use POSIX;
use Data::Dumper;
my $source = do { local $/; <DATA> };
my $grammar = Marpa::R2::Scanless::G->new( { bless_package => 'test', source => \$source });
#!env perl
use strict;
use diagnostics;
use POSIX;
use MarpaX::Import;
use Log::Log4perl qw /:easy/;
use Log::Any::Adapter;
my $conf = q(
log4perl.rootLogger = WARN, Screen
@jddurand
jddurand / MarpaX::Import::Example::Embedded_Actions_And_Lexer_Actions.pl
Last active December 15, 2015 14:29
Example of scanless grammar for a calculator, with embedded actions, using MarpaX::Import, a scanless interface built on top of the Marpa::R2 reconizer. The lexer actions have to be in separated explicit namespace for the moment, could be supported embedded also if there is a neeed for it... The main code of the calculator is just compiling the …
#!env perl
package My_Lex_Actions;
use strict;
use diagnostics;
use Log::Any qw/$log/;
sub new {
my $class = shift;
@jddurand
jddurand / gist:5522268
Last active December 17, 2015 00:38
c2ast - with typedef/enum resolv - BEING TESTED
#!env perl
# Execute this script with no parameter to get the online help
# ****************************************************************************
#
# This script will do a C language -> AST using Marpa parser
#
# C.f. https://groups.google.com/forum/?fromgroups=#!forum/marpa-parser
#
@jddurand
jddurand / perl6advent.day18.with.marpa.pl
Last active June 21, 2017 18:38
Marpa::R2 version of Perl6 Advent Calendar - Day 18 – A Grammar with Duplicate checking Reference: https://perl6advent.wordpress.com/2013/12/18/day-18-a-grammar-with-duplicate-checking/
#!env perl
use strict;
use diagnostics;
use Marpa::R2;
use Encode;
use Carp qw/croak/;
use Data::Section -setup;
# Guess why
# ---------
@jddurand
jddurand / literal.pl
Created December 20, 2013 05:55
Marpa literal() and UTF8 flag
#!env perl
use strict;
use diagnostics;
use Marpa::R2;
use Devel::Peek;
my $grammar_source = do {local $/; <DATA>};
my $input = "\x{2665}";
print "INPUT:\n--------------------\n";
Dump($input);
@jddurand
jddurand / perl6advent.day18.with.marpa.pl
Last active March 20, 2016 07:29
Perl 6 advent blog post, adapted to Marpa
#!env perl
use strict;
use warnings FATAL => 'all';
use Marpa::R2;
use Data::Section -setup;
use open ':std', ':encoding(utf8)';
our $DATA = __PACKAGE__->local_section_data;
# Grammar and test suite are in __DATA__
@jddurand
jddurand / gist:8071223
Last active January 1, 2016 01:09
R->new() should not play with user's arguments...!
#!env perl
use strict;
use warnings FATAL => 'all';
use Marpa::R2;
use Data::Section -setup;
use open ':std', ':encoding(utf8)';
our $DATA = __PACKAGE__->local_section_data;
# Grammar and test suite are in __DATA__
@jddurand
jddurand / perl-5.18.1.csv
Created December 25, 2013 16:18
c2ast on perl-5.18.1
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 4. in line 1.
File Line Identifier Message
gv.c 42 S_autoload The header file fcntl.h reserves names prefixed with 'l_', 'F_', 'O_', and 'S_'
gv.c 42 S_autoload The header file sys/stat.h reserves names prefixed with 'st_' and 'S_'
gv.c 43 S_autolen The header file fcntl.h reserves names prefixed with 'l_', 'F_', 'O_', and 'S_'
gv.c 43 S_autolen The header file sys/stat.h reserves names prefixed with 'st_' and 'S_'
gv.c 413 S_gv_init_svtype The header file fcntl.h reserves names prefixed with 'l_', 'F_', 'O_', and 'S_'
gv.c 413 S_gv_init_svtype The header file sys/stat.h reserves names prefixed with 'st_' and 'S_'
gv.c 446 S_maybe_add_coresub The header file fcntl.h reserves names prefixed with 'l_', 'F_', 'O_', and 'S_'
gv.c 446 S_maybe_add_coresub The header file sys/stat.h reserves names prefixed with 'st_' and 'S_'
gv.c 656 topgv Names that begin with either 'is' or 'to' followed by a lowercase letter may be used for additional character testing and conversion functions.