I like to call the code that wraps the scanner specification and grammar specification together into a PCCTS "grammar" file the "PCCTS glue." It's a bit messy at first, but if we really think about what it does, step-by-step, at least some of the mystery should disappear.

First, let's look at the overall design of a PCCTS-based parser.

Let's consider what information we already have. We have already defined how we want to group input characters into tokens in our scanner definition. We have defined the syntax of our language in our grammar definition. But what gets generated when these definitions are processed by DLG and ANTLR?

We need the startup code (a "main" function), a shell class to hold the parser definition, and references to all the fun definitions that ANTLR and DLG need to create an executable. Without saying much more (I may later), we have the following. Note that we'll be changing some of it later when we add trees, symbols and other compiler goodies...



// any definitions that you need in the generated files


<<// scanner definitions would go here

#include "DLexerBase.h"

    // Base info for DLG-generated scanner

#include "DLGLexer.h"

    // The scanner generated by DLG from this file

#include "AToken.h"

    // Base token definitions for ANTLR

typedef ANTLRCommonToken ANTLRToken;

  // Define your token type (ANTLRToken) as just

  // ANTLRCommonToken (basically just token type

  // and text

int main(int argc, char **argv)


    // define input file; standard input for this one

    DLGFileInput in(stdin);

    // define an instance of your scanner

    DLGLexer scanner(&in);

    // define token buffer between scanner and parser

    ANTLRTokenBuffer pipe(&scanner);

    // create a token to use as a model

    ANTLRToken tok;     >

    // tell the scanner what type the token is


    // create an instance of your parser

    XLParser xlParser(&pipe);

    // initialize your parser


    // start first rule


    return 0; // it's over Johnnie... it's over



// scanner rules would go here

// tell ANTLR that your grammar class starts here

class XLParser



    // parser definitions go here


        void init()



            // any specific initialization you need

            // (if none, don't override 

            //    the init() method



// parser rules would go here

} // end grammar class


Now we know everything that needs to go into our recognizer. Let's put it together and compile/test it!