Skip to content
Browse files

Getting Started

Result of running mk_language_shell.pl
  • Loading branch information...
0 parents commit a7400a9058a622c6dfea4450e1b74ccadb4e3892 Brian Gernhardt committed Jan 22, 2011
1 cish/PARROT_REVISION
@@ -0,0 +1 @@
+$Revision$
5 cish/README
@@ -0,0 +1,5 @@
+Language 'cish' was created with /usr/local/lib/parrot/3.0.0-devel/tools/dev/mk_language_shell.pl, r$Revision$.
+
+ $ parrot setup.pir
+ $ parrot setup.pir test
+
40 cish/cish.pir
@@ -0,0 +1,40 @@
+# $Id$
+
+=head1 TITLE
+
+cish.pir - A cish compiler.
+
+=head2 Description
+
+This is the entry point for the cish compiler.
+
+=head2 Functions
+
+=over 4
+
+=item main(args :slurpy) :main
+
+Start compilation by passing any command line C<args>
+to the cish compiler.
+
+=cut
+
+.sub 'main' :main
+ .param pmc args
+
+ load_language 'cish'
+
+ $P0 = compreg 'cish'
+ $P1 = $P0.'command_line'(args)
+.end
+
+=back
+
+=cut
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+
1 cish/cish/.ignore
@@ -0,0 +1 @@
+
107 cish/setup.pir
@@ -0,0 +1,107 @@
+#!/usr/bin/env parrot
+# $Id$
+
+=head1 NAME
+
+setup.pir - Python distutils style
+
+=head1 DESCRIPTION
+
+No Configure step, no Makefile generated.
+
+=head1 USAGE
+
+ $ parrot setup.pir build
+ $ parrot setup.pir test
+ $ sudo parrot setup.pir install
+
+=cut
+
+.sub 'main' :main
+ .param pmc args
+ $S0 = shift args
+ load_bytecode 'distutils.pbc'
+
+ .local int reqsvn
+ $P0 = new 'FileHandle'
+ $P0.'open'('PARROT_REVISION', 'r')
+ $S0 = $P0.'readline'()
+ reqsvn = $S0
+ $P0.'close'()
+
+ .local pmc config
+ config = get_config()
+ $I0 = config['revision']
+ unless $I0 goto L1
+ unless reqsvn > $I0 goto L1
+ $S1 = "Parrot revision r"
+ $S0 = reqsvn
+ $S1 .= $S0
+ $S1 .= " required (currently r"
+ $S0 = $I0
+ $S1 .= $S0
+ $S1 .= ")\n"
+ print $S1
+ end
+ L1:
+
+ $P0 = new 'Hash'
+ $P0['name'] = 'cish'
+ $P0['abstract'] = 'the cish compiler'
+ $P0['description'] = 'the cish for Parrot VM.'
+
+ # build
+# $P1 = new 'Hash'
+# $P1['cish_ops'] = 'src/ops/cish.ops'
+# $P0['dynops'] = $P1
+
+# $P2 = new 'Hash'
+# $P3 = split ' ', 'src/pmc/cish.pmc'
+# $P2['cish_group'] = $P3
+# $P0['dynpmc'] = $P2
+
+ $P4 = new 'Hash'
+ $P4['src/gen_actions.pir'] = 'src/cish/Actions.pm'
+ $P4['src/gen_compiler.pir'] = 'src/cish/Compiler.pm'
+ $P4['src/gen_grammar.pir'] = 'src/cish/Grammar.pm'
+ $P4['src/gen_runtime.pir'] = 'src/cish/Runtime.pm'
+ $P0['pir_nqp-rx'] = $P4
+
+ $P5 = new 'Hash'
+ $P6 = split "\n", <<'SOURCES'
+src/cish.pir
+src/gen_actions.pir
+src/gen_compiler.pir
+src/gen_grammar.pir
+src/gen_runtime.pir
+SOURCES
+ $S0 = pop $P6
+ $P5['cish/cish.pbc'] = $P6
+ $P5['cish.pbc'] = 'cish.pir'
+ $P0['pbc_pir'] = $P5
+
+ $P7 = new 'Hash'
+ $P7['parrot-cish'] = 'cish.pbc'
+ $P0['installable_pbc'] = $P7
+
+ # test
+ $S0 = get_parrot()
+ $S0 .= ' cish.pbc'
+ $P0['prove_exec'] = $S0
+
+ # install
+ $P0['inst_lang'] = 'cish/cish.pbc'
+
+ # dist
+ $P0['doc_files'] = 'README'
+
+ .tailcall setup(args :flat, $P0 :flat :named)
+.end
+
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+
55 cish/src/cish.pir
@@ -0,0 +1,55 @@
+# $Id$
+
+=head1 TITLE
+
+cish.pir - A cish compiler.
+
+=head2 Description
+
+This is the base file for the cish compiler.
+
+This file includes the parsing and grammar rules from
+the src/ directory, loads the relevant PGE libraries,
+and registers the compiler under the name 'cish'.
+
+=head2 Functions
+
+=over 4
+
+=item onload()
+
+Creates the cish compiler using a C<PCT::HLLCompiler>
+object.
+
+=cut
+
+.HLL 'cish'
+#.loadlib 'cish_group'
+
+.namespace []
+
+.sub '' :anon :load
+ load_bytecode 'HLL.pbc'
+
+ .local pmc hllns, parrotns, imports
+ hllns = get_hll_namespace
+ parrotns = get_root_namespace ['parrot']
+ imports = split ' ', 'PAST PCT HLL Regex Hash'
+ parrotns.'export_to'(hllns, imports)
+.end
+
+.include 'src/gen_grammar.pir'
+.include 'src/gen_actions.pir'
+.include 'src/gen_compiler.pir'
+.include 'src/gen_runtime.pir'
+
+=back
+
+=cut
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+
36 cish/src/cish/Actions.pm
@@ -0,0 +1,36 @@
+class cish::Actions is HLL::Actions;
+
+method TOP($/) {
+ make PAST::Block.new( $<statementlist>.ast , :hll<cish>, :node($/) );
+}
+
+method statementlist($/) {
+ my $past := PAST::Stmts.new( :node($/) );
+ for $<statement> { $past.push( $_.ast ); }
+ make $past;
+}
+
+method statement($/) {
+ make $<statement_control> ?? $<statement_control>.ast !! $<EXPR>.ast;
+}
+
+method statement_control:sym<say>($/) {
+ my $past := PAST::Op.new( :name<say>, :pasttype<call>, :node($/) );
+ for $<EXPR> { $past.push( $_.ast ); }
+ make $past;
+}
+
+method statement_control:sym<print>($/) {
+ my $past := PAST::Op.new( :name<print>, :pasttype<call>, :node($/) );
+ for $<EXPR> { $past.push( $_.ast ); }
+ make $past;
+}
+
+method term:sym<integer>($/) { make $<integer>.ast; }
+method term:sym<quote>($/) { make $<quote>.ast; }
+
+method quote:sym<'>($/) { make $<quote_EXPR>.ast; }
+method quote:sym<">($/) { make $<quote_EXPR>.ast; }
+
+method circumfix:sym<( )>($/) { make $<EXPR>.ast; }
+
7 cish/src/cish/Compiler.pm
@@ -0,0 +1,7 @@
+class cish::Compiler is HLL::Compiler;
+
+INIT {
+ cish::Compiler.language('cish');
+ cish::Compiler.parsegrammar(cish::Grammar);
+ cish::Compiler.parseactions(cish::Actions);
+}
57 cish/src/cish/Grammar.pm
@@ -0,0 +1,57 @@
+=begin overview
+
+This is the grammar for cish in Perl 6 rules.
+
+=end overview
+
+grammar cish::Grammar is HLL::Grammar;
+
+token TOP {
+ <statementlist>
+ [ $ || <.panic: "Syntax error"> ]
+}
+
+## Lexer items
+
+# This <ws> rule treats # as "comment to eol".
+token ws {
+ <!ww>
+ [ '#' \N* \n? | \s+ ]*
+}
+
+## Statements
+
+rule statementlist { [ <statement> | <?> ] ** ';' }
+
+rule statement {
+ | <statement_control>
+ | <EXPR>
+}
+
+proto token statement_control { <...> }
+rule statement_control:sym<say> { <sym> [ <EXPR> ] ** ',' }
+rule statement_control:sym<print> { <sym> [ <EXPR> ] ** ',' }
+
+## Terms
+
+token term:sym<integer> { <integer> }
+token term:sym<quote> { <quote> }
+
+proto token quote { <...> }
+token quote:sym<'> { <?[']> <quote_EXPR: ':q'> }
+token quote:sym<"> { <?["]> <quote_EXPR: ':qq'> }
+
+## Operators
+
+INIT {
+ cish::Grammar.O(':prec<u>, :assoc<left>', '%multiplicative');
+ cish::Grammar.O(':prec<t>, :assoc<left>', '%additive');
+}
+
+token circumfix:sym<( )> { '(' <.ws> <EXPR> ')' }
+
+token infix:sym<*> { <sym> <O('%multiplicative, :pirop<mul>')> }
+token infix:sym</> { <sym> <O('%multiplicative, :pirop<div>')> }
+
+token infix:sym<+> { <sym> <O('%additive, :pirop<add>')> }
+token infix:sym<-> { <sym> <O('%additive, :pirop<sub>')> }
11 cish/src/cish/Runtime.pm
@@ -0,0 +1,11 @@
+# language-specific runtime functions go here
+
+sub print(*@args) {
+ pir::print(pir::join('', @args));
+ 1;
+}
+
+sub say(*@args) {
+ pir::say(pir::join('', @args));
+ 1;
+}
6 cish/t/00-sanity.t
@@ -0,0 +1,6 @@
+# This just checks that the basic parsing and call to builtin say() works.
+say '1..4';
+say 'ok 1';
+say 'ok ', 2;
+say 'ok ', 2 + 1;
+say 'ok', ' ', 4;

0 comments on commit a7400a9

Please sign in to comment.
Something went wrong with that request. Please try again.