XTRAN Example — Translate PL/M CALL Statement to C

The following example uses the standard set of XTRAN rules for parsing PL/M and translating it to C.  The input and output are untouched.

NOTE that the translation shown below was done with default conditions.  XTRAN provides many options for controlling the way it translates.

Process Flowchart

Here is a flowchart for this process, in which the elements are color coded:

process flowchart

Input to XTRAN

proc1:  PROCEDURE (arg1, arg2) EXTERNAL; /*proc1: PROCEDURE (arg1, arg2) EXTERNAL;*/
        DECLARE (arg1, arg2) WORD;      /*DECLARE (arg1, arg2) WORD;*/
        END proc1;

proc2:  PROCEDURE;                      /*proc2: PROCEDURE;*/
        CALL proc1(1, 2);               /*CALL proc1(1, 2);*/
        RETURN;                         /*RETURN;*/
        END proc2;

proc3:  PROCEDURE;                      /*proc3: PROCEDURE;*/
        DECLARE (i, j) WORD;            /*DECLARE (i, j) WORD;*/
        DECLARE prcnam POINTER;         /*DECLARE prcnam POINTER;*/
        CALL proc1(i, j);               /*CALL proc1(i, j);*/
        prcnam = @proc2;                /*prcnam = @proc2;*/
        CALL prcnam;                    /*CALL prcnam;*/
        END proc3;

Output from XTRAN

        extern void proc1(unsigned short arg1,
          unsigned short arg2);                 /*proc1: PROCEDURE (arg1, arg2) EXTERNAL;*/
                                                /*DECLARE (arg1, arg2) WORD;*/

static void proc2(void)                         /*proc2: PROCEDURE;*/
        proc1(1, 2);                            /*CALL proc1(1, 2);*/
        return;                                 /*return;*/

static void proc3(void)                         /*proc3: PROCEDURE;*/
        static unsigned short i, j;             /*DECLARE (i, j) WORD;*/
        static void (*prcnam)(void);            /*DECLARE prcnam POINTER;*/
        proc1(i, j);                            /*CALL proc1(i, j);*/
        prcnam = proc2;                         /*prcnam = @proc2;*/
        (*prcnam)();                            /*CALL prcnam;*/