[svn:parrot] r38831 - trunk/docs/book

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Sat May 16 15:20:28 UTC 2009


Author: whiteknight
Date: Sat May 16 15:20:27 2009
New Revision: 38831
URL: https://trac.parrot.org/parrot/changeset/38831

Log:
[book] some clarifications in the first sections of chapter 4. These parts were a little confusing and probably need more work still

Modified:
   trunk/docs/book/ch04_compiler_tools.pod

Modified: trunk/docs/book/ch04_compiler_tools.pod
==============================================================================
--- trunk/docs/book/ch04_compiler_tools.pod	Sat May 16 15:08:33 2009	(r38830)
+++ trunk/docs/book/ch04_compiler_tools.pod	Sat May 16 15:20:27 2009	(r38831)
@@ -43,7 +43,7 @@
 
 Since Parrot would support the features of the major dynamic languages
 and wasn't biased to a particular syntax, it could run all these
-languages with little additional effort.  
+languages with little additional effort.
 
 Language interoperability is another core goal. Different languages are
 suited to different tasks, and picking which language to use in a large
@@ -60,31 +60,43 @@
 
 =head2 PCT Overview
 
-PCT is a collection of classes which handle the creation of a
-compiler and driver program for a high-level language. The
-C<PCT::HLLCompiler> class handles building the compiler front end
-while the C<PCT::Grammar>  and C<PCT::Grammar::Actions> classes handle
-building the parser and lexical analyzer. Creating a new HLL compiler
+The X<Parrot Compiler Tools;PCT> Parrot Compiler Tools (PCT) are a
+collection of tools and classes which handle the creation of a
+compiler and driver program for a high-level language on Parrot. The
+X<HLLCompiler> C<PCT::HLLCompiler> class specifies the interface for
+the compiler and implements the compiler object that is used at runtime
+to parse and execute code. The X<Parrot Compiler Tools;PCT::Grammar>
+C<PCT::Grammar> and X<Parrot Compiler Tools;PCT::Grammar::Actions>
+C<PCT::Grammar::Actions> classes are used to create the parser and
+lexical analyzer components respectivly. Creating a new HLL compiler
 is as easy as subclassing these three entities with methods specific
-to that high-level language.
+to the new high-level language.
 
 =head3 Grammars and Action Files
 
-Creating a compiler using PCT requires three basic files, plus any
-additional files needed to implement the languages logic and library:
+Creating a compiler using PCT requires three basic files: The main entry
+point file, the grammar specification file and the grammar actions file. In
+addition, compilers and the languages they implement often utilize large
+libaries of built-in routines to help support compile-time and runtime
+semantics.
 
 =over 4
 
-=item * A main file
+=item * The main file
 
-The main file should contain the C<:main> function that is the driver
-program for the compiler. Here, a new C<PCT::HLLCompiler> object is
-instantiated, libraries are loaded, and necessary special global
-variables are created. The driver program is typically written in PIR,
-although thankfully they tend to be very short. Most of the action
-happens elsewhere.
+The main file is typically written in PIR and should contain the C<:main>
+function that creates and executes the compiler object. The new
+C<PCT::HLLCompiler> object is located and instantiated, the various necessary
+libraries are loaded, and any special global variables are created and
+initialized.
+
+The main file tends to be very short, with the guts of the compiler logic
+implemented in the grammar and actions files, and the various classes and
+library routines implemented in other files. This is by convention, however,
+there is no particular reason why the main file cannot be large and complex
+if that's how you want to do it.
 
-=item * A parser file
+=item * A grammar file
 
 The grammar for the high level language is specified using the Perl 6
 grammar engine (PGE) and is stored in a C<.pg> file. This file should
@@ -93,15 +105,24 @@
 
 =item * An actions file
 
-Actions files are written in NQP. They take match objects generated by
-the grammar file and convert them into an Abstract Syntax Tree (AST)
+Actions files are written in NQP, a small language modeled on Perl 6 but
+with very few features and limited capabilities. The actions file contains
+methods on the C<PCT::Grammar:Actions> object which receive parse data
+from the grammar rules and use them to construct an
 X<Abstract Syntax Tree;Parrot Abstract Syntax Tree;AST;PAST>
-which is converted by PCT into PIR for compiling and execution.
-The PIR implementation of these AST trees and nodes is called the
-Parrot Abstract Syntax Tree (PAST).
+Abstract Syntax Tree (AST). Our particular implementation of an AST is
+called the Parrot Abstract Syntax Tree (PAST).
 
 =back
 
+PCT allows a customizable workflow, but the basic elements are simple.
+The source code of the high level language is passed into the grammar
+engine which parses it and returns a X<PGE;Match Object> special Match
+object that represents a pattern in the code. This match object is passed
+to the actions methods, which convert the match into a PAST tree. PCT then
+takes the PAST tree nd uses it to generate PIR code which can be saved
+to a file, converted to bytecode, or executed directly.
+
 =head3 C<make_language_shell.pl>
 
 The Parrot repository contains a number of helpful utilities for doing


More information about the parrot-commits mailing list