Skip to content

Instantly share code, notes, and snippets.

Lukas Atkinson latk

Block or report user

Report or block latk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@latk
latk / solar_game.pl
Created Apr 25, 2013
A refactoring for sharksfan98's “Solar Game”. It now compiles with `use strict; use warnings`. Much of the repetitive code is offloaded into subs. The `ask_question` function takes a question string, the number of the correct answer, and an array reference (`[...]`) containing possible answers. The next refactoring step would put the questions t…
View solar_game.pl
#########################################
# Solar Game #
# #
# (C) 2013 Donovan Roudabush #
# GPU/Creative Commons #
# #
# sharksfan98@gmail.com #
# github.com/sharksfan98/solargame #
#########################################
@latk
latk / gist:5854616
Created Jun 24, 2013
Transforming Syntax – Marpa parsing example
View gist:5854616
use strict; use warnings; use 5.010;
use Data::Dumper;
my $data = <<'END';
If ((Myvalue.xyz == 1) Or (Frmae_1.signal_1 == 1)) Then a = 1
Else a = 0;
END
my $ast = Parser->parse(\$data);
@latk
latk / gist:5866025
Last active Dec 19, 2015
Transforming Syntax – Tree Cloning example
View gist:5866025
use strict; use warnings; use 5.010;
use Data::Dumper;
my $ast = bless( [
[
bless( [
bless( [
bless( [
bless( ['Myvalue.xyz'], 'Ast::Var' ),
'==',
@latk
latk / gist:5866146
Created Jun 26, 2013
Transforming Syntax – prettyprinting example
View gist:5866146
use strict; use warnings; use 5.010;
my $ast = bless( [
[
bless( [
bless( [
bless( [
bless( ['Myvalue.xyz'], 'Ast::Var' ),
'==',
bless( ['1'], 'Ast::Literal' )
@latk
latk / gist:5866793
Last active Dec 19, 2015
Transforming Syntax – optimizer example
View gist:5866793
use strict; use warnings; use 5.010;
my $ast = bless( [
[
bless( [
bless( [
bless( [
bless( ['Myvalue.xyz'], 'Ast::Var' ),
'==',
bless( ['1'], 'Ast::Literal' )
@latk
latk / test.pl
Last active Dec 23, 2015
Benchmarking 3rd element removal from large arrays
View test.pl
use 5.018; use strict; use warnings; use Benchmark ':all';
cmpthese $ARGV[0] => {
grep => \&with_grep,
grep_light => \&with_grep_light,
splice => \&with_splice,
slice => \&with_slice,
copy => \&with_copy,
};
View report.pl
use strict; use warnings;
use feature 'say';
use autodie;
use File::Slurp;
use Mojo;
use List::MoreUtils 'uniq';
use Data::Dump qw/dd pp/;
my %urls = (
@latk
latk / MarpaX::Interface::Inline Specification.md
Created Jan 10, 2014
MarpaX::Interface::Inline Specification
View MarpaX::Interface::Inline Specification.md

MarpaX::Interface::Inline Specification

The MarpaX::Interface::Inline module provides the Inline Rule Interface (IRIF) to write grammars for the [Marpa parser generator][Marpa::R2]. While Marpa already provides the Scanless Interface (SLIF), the IRIF tries to provide a more productive frontend:

  • Longest-Acceptable-Token Matching: The builtin lexer is smart and only tries to find tokens that can actually be used at the current position. This makes it easier to nest languages.
  • Inline Rules and Quantifiers: A regex like syntax allows you to specify rules where you need them – and not every rule has to be named. Quantifiers include support for Perl6's separation operator %.
  • Inline Actions: Each production is associated with an action that builds the AST. With the IRIF, these are specified inline, directly after the rule which they operate on.
View offside rule.md

Certain languages like Python use leading indentation to denote blocks. Wouldn't it be nice if a Marpa frontend like the IRIF would have support for this? Well, the problem is that implementing the Off-side Rule is similarly difficult to implementing here-docs: both are non-context free constructs, but are easy to implement by maintaining state in the scanner.

Consider this piece of Python code:

def foo(x, y):
    return x + (2*
y)

foo(1, 2) #=> 5
@latk
latk / GetoptSubset.pm
Created Sep 19, 2017
Getopt::Long alternative prototype
View GetoptSubset.pm
package GetoptSubset;
# Copyright 2017 Lukas Atkinson
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
You can’t perform that action at this time.