1. riffraff
  2. shakespeare-parrot


shakespeare-parrot / shakespeare.pir

=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>


.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'
    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
    code = downcase code
    match = rgx(code)
    if match goto dump
    say "no match"
    goto loop
    output = match.'dump_str'()
    say output
    goto loop

.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.'addstage'('lc', 'before'=>'parse')

.sub 'lc' :method
    .param string source
    .param pmc adverbs         :slurpy :named

    source = downcase source
    .return (source)

=item main(args :slurpy)  :main

Start compilation by passing any command line C<args>
to the shakespeare compiler.


.sub 'main' :main
    .param pmc args

    $P0 = compreg 'shakespeare'
    $P1 = $P0.'command_line'(args)

.include 'src/builtins/base.pir'
.include 'src/gen_grammar.pir'
.include 'src/gen_actions.pir'



# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: