-
Notifications
You must be signed in to change notification settings - Fork 7
/
compiler.nqp
38 lines (34 loc) · 1.03 KB
/
compiler.nqp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use NQPHLL;
class Damn::Compiler is HLL::Compiler { }
grammar Damn::Grammar is HLL::Grammar {
token ws { <!ww> \h* || \h+ }
token TOP { <statementlist> }
rule statementlist { [ <statement> \n+ ]* }
proto token statement {*}
token statement:sym<exasperatedly shout> {
<sym> <.ws> <?[']> <quote_EXPR: ':q'>
}
}
class Damn::Actions is HLL::Actions {
method TOP($/) {
make QAST::Block.new(
QAST::Var.new( :decl<param>, :name<ARGS>, :scope<local>, :slurpy ),
$<statementlist>.ast,
);
}
method statementlist($/) {
my $stmts := QAST::Stmts.new( :node($/) );
$stmts.push($_.ast) for $<statement>;
make $stmts;
}
method statement:sym<exasperatedly shout>($/) {
make QAST::Op.new( :op<say>, $<quote_EXPR>.ast );
}
}
sub MAIN(*@ARGS) {
my $comp := Damn::Compiler.new();
$comp.language('damn');
$comp.parsegrammar(Damn::Grammar);
$comp.parseactions(Damn::Actions);
$comp.command_line(@ARGS, :encoding<utf8>);
}