Skip to content

Instantly share code, notes, and snippets.

@rns
Created September 7, 2014 12:13
Show Gist options
  • Select an option

  • Save rns/40d83c119ba7ae53a8fc to your computer and use it in GitHub Desktop.

Select an option

Save rns/40d83c119ba7ae53a8fc to your computer and use it in GitHub Desktop.
use 5.010;
use strict;
use warnings;
use Data::Dumper;
use Marpa::R2 2.090; # for parse()
my $g = Marpa::R2::Scanless::G->new( {
source => \(<<'END_OF_SOURCE'),
:default ::= action => [symbol, name, value]
lexeme default = action => [symbol, name, value] latm => 1
e ::= n name => 'num'
| e '*' e name => 'mul'
|| e '+' e name => 'add'
n ~ [\d]
:discard ~ whitespace
whitespace ~ [\s]+
END_OF_SOURCE
} );
my $input = <<EOI;
1 + 1
EOI
say Dumper ${
$g->parse({
input => \$input,
# trace_terminals => 1
})
};
@rns

rns commented Sep 7, 2014

Copy link
Copy Markdown
Author
$VAR1 = [
          'e[0]',
          'add',
          [
            'e[1]',
            'num',
            [
              'n',
              'n',
              '1'
            ]
          ],
          '+',
          [
            ${\$VAR1->[2][0]},
            ${\$VAR1->[2][1]},
            [
              ${\$VAR1->[2][2][0]},
              ${\$VAR1->[2][2][1]},
              '1'
            ]
          ]
        ];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment