Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created August 10, 2016 15:37
Show Gist options
  • Save zoffixznet/521f1eb8943b457dd6329662eb72d35a to your computer and use it in GitHub Desktop.
Save zoffixznet/521f1eb8943b457dd6329662eb72d35a to your computer and use it in GitHub Desktop.
use NQPHLL;
grammar Rubyish::Grammar is HLL::Grammar {
token TOP { <statementlist> }
rule statementlist { [ <statement> \n+ ]* }
proto token statement {*}
token statement:sym<puts> {
<sym> <.ws> <?["]> <quote_EXPR: ':q'>
}
# Whitespace required between alphanumeric tokens
token ws { <!ww> \h* || \h+ }
}
class Rubyish::Actions is HLL::Actions {
method TOP($/) {
make QAST::Block.new( $<statementlist>.ast );
}
method statementlist($/) {
my $stmts := QAST::Stmts.new( :node($/) );
for $<statement> {
$stmts.push($_.ast)
}
make $stmts;
}
method statement:sym<puts>($/) {
make QAST::Op.new(
:op('say'),
$<quote_EXPR>.ast
);
}
}
class Rubyish::Compiler is HLL::Compiler {
}
sub MAIN(*@ARGS) {
my $comp := Rubyish::Compiler.new();
$comp.language('rubyish');
$comp.parsegrammar(Rubyish::Grammar);
$comp.parseactions(Rubyish::Actions);
$comp.command_line(@ARGS, :encoding('utf8'));
}
@zoffixznet
Copy link
Author

$ ./nqp-m training/compiler-basic training/code
Too many positionals passed; expected 0 arguments but got 1
at training/code:1 (:)
from gen/moar/stage2/NQPHLL.nqp:1508 (./NQPHLL.moarvm:eval)
from gen/moar/stage2/NQPHLL.nqp:1711 (./NQPHLL.moarvm:evalfiles)
from gen/moar/stage2/NQPHLL.nqp:1605 (./NQPHLL.moarvm:command_eval)
from gen/moar/stage2/NQPHLL.nqp:1579 (./NQPHLL.moarvm:command_line)
from training/compiler-basic:46 (:MAIN)
from training/compiler-basic:38 (:)
from gen/moar/stage2/NQPHLL.nqp:1508 (./NQPHLL.moarvm:eval)
from gen/moar/stage2/NQPHLL.nqp:1711 (./NQPHLL.moarvm:evalfiles)
from gen/moar/stage2/NQPHLL.nqp:1605 (./NQPHLL.moarvm:command_eval)
from gen/moar/stage2/NQPHLL.nqp:1579 (./NQPHLL.moarvm:command_line)
from gen/moar/stage2/NQP.nqp:4050 (nqp.moarvm:MAIN)
from gen/moar/stage2/NQP.nqp:4045 (nqp.moarvm:)
from :1 (nqp.moarvm:

)
from :1 (nqp.moarvm:)

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