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>
object.

=cut

.namespace [ 'shakespeare';'Compiler' ]

.loadlib 'shakespeare_group'

.sub 'interactive' :method
    # ignored
    .param pmc adverbs         :slurpy :named
    .local pmc rgx, stdin, match
    .local pmc code # code has to be a pmc or a string conversion from null will die()
    .local string output, prompt
    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
    
    code = stdin.'readline_interactive'(prompt)
    if null code goto endloop
    unless code goto loop
    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/gen_builtins.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:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.