Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created January 2, 2017 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/59cc8f7413fce7920ae93cdab542a668 to your computer and use it in GitHub Desktop.
Save zoffixznet/59cc8f7413fce7920ae93cdab542a668 to your computer and use it in GitHub Desktop.
#!/usr/bin/env nqp
use NQPHLL;
grammar Zygote::Grammar is HLL::Grammar {
token TOP { <statementlist> }
rule statementlist { [ <statement> "\n"+ ]* }
proto token statement {*}
token statement:sym<say> {
<sym> <.ws> <?["]> <quote_EXPR: ':q'>
}
token ws { <!ww> \h* || \h+ }
}
grammar Zygote::Actions is HLL::Actions {
method TOP($/) {
make QAST::Block.new(
QAST::Var.new(:name<@*ARGS>, :scope<local>, :decl<param>),
$<statementlist>.ast,
);
}
method statementlist($/) {
my $stmts := QAST::Stmts.new( :node($/) );
for $<statement> {
$stmts.push($_.ast);
}
make $stmts;
}
method statement:sym<say>($/) {
make QAST::Op.new( :op('say'), $<quote_EXPR>.ast );
}
}
grammar Zygote::Compiler is HLL::Compiler {
}
sub MAIN (*@ARGS) {
my $comp := Zygote::Compiler.new;
$comp.language('Zygote');
$comp.parsegrammar(Zygote::Grammar);
$comp.parseactions(Zygote::Actions);
$comp.command_line(@ARGS, :encoding<utf8>);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment