Allison Randal > parrot-1.0.0 > Getting

Download:
parrot-1.0.0.tar.gz

Annotate this POD

Website

View/Report Bugs

Source  

NAME ^

Getting Started with the Parrot Compiler Tools

DESCRIPTION ^

This document can be considered your Number One entry point for starting to use the Parrot Compiler Tools (PCT). As there's a whole lot of acronyms flying around (see Parrot's glossary at http://www.parrotcode.org/glossary.html), this document will get you up and running within 10 minutes (that excludes building Parrot). Once you begin, it's a matter of getting your hands dirty and get experienced using the tools. Feel free to ask questions on irc.parrot.org#parrot.

GETTING STARTED ^

Getting started using the PCT is easy. The steps are:

The acronyms you will encounter, are:

Now we discussed the most important acronyms, it's time to get up and running.

Download and Build Parrot

Get Parrot from http://www.parrot.org/download and build it. If you're lucky and you have a fast computer, it should be done within 5 minutes. It's always useful to run the test suite by typing:

 $ make test

Generate a Language Stub

There's a special script for newcomers: tools/dev/mk_language_shell.pl. Invoke it from Parrot's root directory:

 $ perl tools/dev/mk_language_shell I<language> I<location>

For instance, if you want to create a language called Foo in the directory languages/foo, type:

 $ perl tools/dev/mk_language_shell Foo languages/foo

This will create a complete language that compiles out of the box. You first need to run the Configure.PL Perl script to generate the Makefile. Then you can run make and make test.

 $ cd languages/foo
 $ perl Configure.pl
 $ make
 $ make test

Yes, that's right, there's even a test file already created for you. This makes setting up the tests for your language very easy!

The generated directories and files have the following structure:

 foo/
    /Configure.pl                # configuration script
    /config/makefiles/root.in    # input for the Makefile generator
                                 # as long as you don't add source files,
                                 # there's no need to update this file.
    /src/
        /parser/
               /actions.pm       # the language's grammar rules; a file
               /grammar.pm       # containing the parse actions;
               /grammar-oper.pg  # file containing a default operator table.

        /builtins/
                 /say.pir        # a file containing a built-in function

        /pmc/
                 /foo.pmc        # file defining vtable functions 

        /ops/
                 /foo.ops        # file defining opcodes 
                                 # TODO: add more "standard library" routines here
    /t/
      /00-sanity.t               # a test file
      /harness                   # file to set up the test framework
                                 # more tests can be added here

    /foo.pir                     # file containing the main routine
    /README                      # an almost empty readme file
    /STATUS                      # an almost empty status file
    /MAINTAINER                  # a file for you to add your details to

When you want to run a script through your language's compiler, (assuming you're in your language's directory, in this case languages/foo) type:

 $ ../../parrot foo.pbc file.foo

You can give an command line option to your compiler which specifies what kind of output you want. This is the target option:

 $ ../../parrot foo.pbc --target=pir file.foo

this will print the generated PIR instructions to stdout. Other options for the target option are parse, past, and post.

Customize Your Language

You probably have some language syntax in mind to implement. Note that the grammar defined in the file languages/foo/src/parser/grammar.pg and the parse actions in the file languages/foo/src/parser/actions.pm are closely related (especially note the names of the action methods). It's very important to update the methods accordingly if you change the grammar rules.

COMMON ERROR MESSAGES ^

This section describes some common error messages and how to resolve them. This is a work in progress, so you might not find your issue/solution here. If you have anything new to add, please send a patch (or an email) to parrotbug@parrotcode.org.

WHERE TO GO FROM HERE? ^

Documents

The following documents might be useful to learn more:

Other Languages

You can also have a look at some existing languages that are being developed using the PCT, all located in the languages subdirectory of Parrot. These are: perl6 (commonly referred to as Rakudo), lua (see the "pct" in lua directory), ecmascript (a standardized JavaScript), punie (Perl 1 on Parrot), pynie (Python on Parrot), and cardinal (Ruby on Parrot).

IRC

Everyday, a bunch of Parrot enthusiasts can be found on #parrot on irc.parrot.org. You're welcome to ask questions.

SUGGESTIONS ^

If you have suggestions, improvements, tips or complaints about this document, please send an email to parrot-dev@lists.parrot.org.