riffraff / shakespeare-parrot
A Parrot based interpreter for the Shakespeare programming language
Clone this repository (size: 640.1 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/riffraff/shakespeare-parrot/
| commit 92: | e4f0025e7622 |
| parent 91: | dfcc448b7385 |
| branch: | default |
| tags: | tip |
properly release as Beer Ware code
shakespeare-parrot /
shakespeare.pir
| r92:e4f0025e7622 | 110 loc | 2.3 KB | embed / history / annotate / raw / |
|---|
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | =head1 TITLE
shakespeare.pir - A shakespeare compiler.
=head2 Description
This is the base file for the shakespeare 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 'shakespeare'.
=head2 Functions
=over 4
=item onload()
Creates the shakespeare compiler using a C<PCT::HLLCompiler>
object.
=cut
.namespace [ 'shakespeare';'Compiler' ]
.loadlib 'shakespeare_group'
.sub 'interactive' :method
# ignored
.param pmc adverbs :slurpy :named
.local pmc rgx, stdin, match
.local string output, prompt, code
prompt = '>'
stdin = getstdin
say "Thou hast entered the interactive sentence verifier"
say "Enter a Sentence to see How It Parses"
rgx= get_hll_global ['shakespeare';'Grammar'], 'sentence'
loop:
unless stdin goto endloop
# need a pmc or a string conversion from null will die()
$P0 = stdin.'readline_interactive'(prompt)
if null $P0 goto endloop
code = $P0
unless code goto loop
downcase code
match = rgx(code)
if match goto dump
say "no match"
goto loop
dump:
output = match.'dump_str'()
say output
goto loop
endloop:
.end
.sub 'onload' :anon :load :init
.local pmc p6meta
load_bytecode 'PCT.pbc'
$P0 = get_hll_global ['PCT'], 'HLLCompiler'
$P1 = $P0.'new'()
p6meta = new 'P6metaclass'
$P0 = p6meta.'new_class'('shakespeare::Compiler', 'parent'=>'PCT::HLLCompiler')
$P1 = $P0.'new'()
$P1.'language'('shakespeare')
$P1.'parsegrammar'('shakespeare::Grammar')
$P1.'parseactions'('shakespeare::Grammar::Actions')
$P1.'addstage'('lc', 'before'=>'parse')
.end
.sub 'lc' :method
.param string source
.param pmc adverbs :slurpy :named
downcase source
.return (source)
.end
=item main(args :slurpy) :main
Start compilation by passing any command line C<args>
to the shakespeare compiler.
=cut
.sub 'main' :main
.param pmc args
$P0 = compreg 'shakespeare'
$P1 = $P0.'command_line'(args)
.end
.include 'src/builtins/base.pir'
.include 'src/gen_grammar.pir'
.include 'src/gen_actions.pir'
=back
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
|
