This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.14.2; | |
use List::Util 'sum'; | |
# power a n = a if n == 1 | |
# power a n = power (power a 2) (n/2) if n is even | |
# power a n = (power (power a 2) (n/2)) * a if n is odd | |
sub power { | |
my ($op, $a, $n) = @_; | |
if ($n == 1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Marpa::XS; | |
use MarpaX::Simple::Lexer; | |
use IO::String; | |
my $grammar = Marpa::XS::Grammar->new( { | |
start => 'Parser', | |
rules => [ | |
[ 'Parser' => [ 'X' ] ], | |
], | |
terminals => [qw/X/], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Data::Dumper; | |
use Parse::RecDescent; | |
$Parse::RecDescent::skip = ''; | |
my $grammar = q{ | |
line: ip ws '-' ws user ws datetime ws request ws status ws responsesize | |
ws referrer ws useragent "\n" | |
{ $return = { | |
ip => $item[1], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Demo::MarpaX::Makefile; | |
use strict; | |
use Marpa::R2; | |
sub new { | |
my ($class) = @_; | |
my $self = bless {}, $class; | |
$self->{grammar} = Marpa::R2::Scanless::G->new( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Marpa::R2 2.023008; | |
use Data::Dumper; | |
my %type = ( | |
boy => 'noun', | |
girl => 'noun', |