Created
January 2, 2017 19:55
-
-
Save zoffixznet/59cc8f7413fce7920ae93cdab542a668 to your computer and use it in GitHub Desktop.
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 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