Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Prolog: base conversion transformation


1. Prolog: base conversion transformation

2. C code
Here is some C code to do a base conversion of the integer 156.

Here is the C code.

Here is the output of the C code.


3. Prolog code
In the following Prolog program, the above C code is encoded into the term structure of the simple Prolog compiler.

Here is the Prolog code.

The output is a C program that converts the while and if statements in the encoded syntax tree of the original C program to goto statements and outputs the resulting C program.

Here is the output of the Prolog code.

Here is the output of the above Prolog program that is now run as a C program.

Here is the C code.

The output is the same as the original C program.

Here is the output of the C code.


4. Comparison
Here is the C code.

Compare the above code using goto statements with the original code not using goto statements. Which is more concise? Which is more clear? Which might be considered better?

5. End of page