Document Actions

Code generator generator

by Édouard Mercier posted at 2006-12-11 22:02 last modified 2006-12-21 19:35

Infinite mirrors

OK, there is something that sometimes haunts me:

"Is it possible to write a piece of source-code, that once compiled, is able to produce some source code file, which on its turn onced compiled, produces the same algorithmic?"

State of mind

I will not try to find any heuristic or algorithmic that tries to find a solution to that problem. I am more interested in the possible approaches and fields that this question may arise or resort to.

Let's admit that I do not always live with that piece of thought in mind. I have to confess that I never took the time in order to handle this question.

Obviously, the way the question is expressed, needs to be refined and clarified a bit, because it has been introduced in a rough manner. What is this question about, and cannot it be expressed in a more articulated way?

Formalism?

I'd just like to whether this is possible to write a piece of code (let's say in Java, for instance, since this is a modern object-oriented language, with the introspection moreover), that - provided it has been properly compiled - produces some files. We assume that the generated file contain code instrusctions for which a grammar already exists (or even, that has been generated by the program on-the-fly). A compiler is supposed t exist for the grammar that is associated with the language (we discard the case when the program has also geneated the compiler code, because this code will need on its turn to be compiled by an already existing compiler, which only postpone the problem). This means that this code can be compiled. If we run the resulting executable, is is possible that it does the same thing as the original program (i.e. generate the source code)?

OK, the concept of grammar needs to be precisely addressed, the concept of compilation and compiler all the same.

The question has the benefit to ask new questions. And while trying to enlight the original question, other questions ill raise at the same time.

Different languages

Even if the question is not defined clearly enough, I feel that the answer may depend on the languages that we consider:

  • there are interpreted languages (source-code that gets read and converted to the microprocessor basic instructions on-the-fly) like Prolog,
  • there are compiled languages (source-code that gets formerly transformed only once in instructions for a specific microprocessor) like C++,
  • and there are semi-interpreded languages (that are first transformed only once in lower-level instructions, independtly of the target microprocessor, and those instructions converted on-the-fly into the actual microprocessor instructions at runtime) like Java.

Those languages do not offer the same features, and this means that depending on the languages involved, their may be classes of languages for which the answer to the question is definitevely no.

Two approaches

As already said, in order to answer to the question, there are two main approaches (which should be considerded, by the way, only once the question has been enough formalised in order to removed any obscur understanding):

  1. either I try to think on how I would do to write such a program,
  2. or you feel more interested on what it sounds by you.

The latter is the approach I am interested in. And I prefer to try thinking on the consequences that it brings whether the assertion is right or wrong. There are chances that there are configurations (depending on the class of languages involved, like the three classes we have already mentionned) when the answer is always yes, and configurations when the answer is always true. At least, there must be configurations where the answer is sometimes yes, sometimes no, but you cannot get an automatic answer.

If this is false

In that case, I'd love to have a demonstration that this is not possible under certain circumstances. I'm confident that this has something in relation with the information theory.

If this is true

If, under certain circumstances, the answer to the question is yes, it means that we can create kind of a fractalistic movement, that starts from some source code, that generates some source code (can it be exactly the same?), which on its turns runs exactly the same way as the original program. When I say "run", I mean has exactly the same behavior as the initial one.

The URL to Trackback this entry is:
http://edouardmercier.fr/blog/code-generator-generator/tbping

Re:Code generator generator

Posted by Ghis at 2006-12-23 13:09

Great question! The answer is yes as love can generate love.

« September 2010 »
Su Mo Tu We Th Fr Sa
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Recent entries
Le corps humain n'a pas suivi l'évolution de l'esprit edouard_mercier 2007-11-08
L'informatique, c'est comme la médecine ! edouard_mercier 2007-09-10
Vision de code malveillant edouard_mercier 2007-09-06
Chaque année passée est plus courte que la précédente ! edouard_mercier 2007-05-06
Ma Google-mania edouard_mercier 2007-02-02
Un programme comme une démonstration edouard_mercier 2007-01-12
Code generator generator edouard_mercier 2006-12-11
Entrez dans un monde "del.icio.us" edouard_mercier 2006-12-11
C'est quoi RSS ? edouard_mercier 2006-11-29
Pourquoi j'utilise FireFox edouard_mercier 2006-11-17
Recent comments
Re:Ma Google-mania edouard_mercier 2007-04-21
Re:Code generator generator Ghis 2006-12-23
Re:C'est quoi RSS ? edouard_mercier 2006-12-15
Re:C'est quoi RSS ? Philou 2006-12-15
Re:De l'intérêt d'avoir toujours sur soi une carte de visite Ghis 2006-10-31
Re:Victime de piratage Florent 2006-10-09
Re:Victime de piratage edouard_mercier 2006-10-09
Re:Review of new Plone products edouard_mercier 2006-02-14