Skip to content

Instantly share code, notes, and snippets.

@snarkyboojum
Created April 26, 2010 15:30
Show Gist options
  • Save snarkyboojum/379470 to your computer and use it in GitHub Desktop.
Save snarkyboojum/379470 to your computer and use it in GitHub Desktop.
use v6;
my $VERSION = '2010.05';
grammar Yapsi::Perl6::Grammar {
regex TOP { ^ <statementlist> $ }
regex statementlist { <statement> ** <eat_terminator> }
token statement { <expression> }
token eat_terminator { <?after '}'> \n || <.ws> ';' <.ws> }
token expression { <assignment> || <binding> || <variable> || <literal>
|| <declaration> || <saycall> || <increment>
|| <block> || <empty> }
token lvalue { <declaration> || <variable> || <increment> }
token value { <variable> || <literal> || <declaration> || <saycall>
|| <increment> }
token variable { '$' \w+ }
token literal { \d+ }
token empty { '' }
rule declaration { 'my' <variable> }
rule assignment { <lvalue> '=' <expression> }
rule binding { <lvalue> ':=' <expression> }
rule saycall { 'say' <expression> } # very temporary solution
rule increment { '++' <value> }
token block { <.ws> '{' <.ws> <statementlist> <.ws> '}' }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment