dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]TreeCC language porting


From: Rhys Weatherley
Subject: Re: [DotGNU]TreeCC language porting
Date: Thu, 24 Oct 2002 16:01:29 +1000

minddog wrote:
> 
> I'm working on a language port to pnet using TreeCC, but I'm not fairly
> familiar with C, but I know enough to get around and get the job done once I
> have grasp on my structure, usually the case for many.  I've been sifting
> through the pnet/cscc/c directory looking at the .tc's and .y's to figure a
> starting point.  Now that I have a starting point I'm still confused as to
> where to go from grammar, coercions, and operations, etc. to getting this
> into the compiler as a plugin.  Any ideas, not code, but something pseudo so
> I can see how it works?!

Here is the "Simple 12 Step Process" to add a language plugin for
the hypothetical "DotGNU" language:

1. Create a "dg_main.c" in "cscc".  Start with "c_main.c" if your
   language is compiled one file at a time (like C), or with "cs_main.c"
   if your language is compiled many files at a time (like C#).
   The "common/cc_main.h" file describes what you need to provide.

2. Create a subdirectory for the "dotgnu" language, together with
   the necessary Makefile.am guff.  See "cscc/c" for details.

3. Write "dg_grammar.y" and "dg_scanner.l" to define the syntax
   and lexical conventions of the language.  On the first pass,
   don't worry about creating nodes and such.  Just get the syntax
   right.

4. Compile, edit, compile, edit, and compile some more until you
   have a working syntax checker.

5. Realize that you need a test suite to help you find all the
   syntax checking bugs and devise something to do this.  See
   cscctest for some ideas.

6. Create "cscc/dotgnu/dg_defs.tc", which includes "codegen/cg_all.tc".
   Define the semantic analysis node operation here, with a name
   like "DG_SemAnalysis".  Call this during parsing for each
   function for a C-like language, or after all parsing is done
   for a C#-like language.  This must be a non-virtual operation,
   or you'll get conflicts with "codegen".

7. Add the treecc support code to Makefile.am and type make.
   Now stub out the bazillion undefined operation cases that
   treecc will complain about.  Split them into separate *.tc
   files to organise things better, and include them from
   "dg_defs.tc".

8. If you need new node types, add them to "dg_defs.tc".

9. Modify "dg_grammar.y" to create the node types at the right
   places during parsing.

10. Fill in semantic analysis for each node type.

11. Realize that you need an even better test suite to help you
    find semantic analysis bugs, and go devise something.

12. Fix bugs until your eyes bleed. :-)

The rest, such as compiler initialization, code generation,
cleanup, etc, is done by "common/cc_main.c" and you normally
won't need to worry about it unless your language is funky
enough to require a different set of phases.

Cheers,

Rhys.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]