XTRAN Example — Translate PL/I Calling Arguments to C

The following example uses the standard set of XTRAN rules for parsing PL/I and translating it to C.  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:

    DCL subr1 ENTRY;                    /*DCL subr1 ENTRY;*/
    DCL subr2 ENTRY (BINARY FLOAT(6),   /*DCL subr2 ENTRY (BINARY FLOAT(6),*/
      BINARY FIXED(31),                 /*BINARY FIXED(31),*/
      BINARY FLOAT(6));                 /*BINARY FLOAT(6));*/
    DCL subr3 ENTRY (BINARY FIXED(31),  /*DCL subr3 ENTRY (BINARY FIXED(31),*/

      BINARY FLOAT(6));                 /*BINARY FLOAT(6));*/
    DCL subr4 ENTRY (BINARY FLOAT(6),   /*DCL subr2 ENTRY (BINARY FLOAT(6),*/
      BINARY FLOAT(6));                 /*BINARY FLOAT(6));*/
    DCL func1 ENTRY (BINARY FIXED(31),  /*DCL func1 ENTRY (BINARY FIXED(31),*/

      BINARY FLOAT(6))                  /*BINARY FLOAT(6))*/
      RETURNS (BINARY FIXED(31));       /*RETURNS (BINARY FIXED(31));*/
    DCL func2 ENTRY (BINARY FLOAT(6),   /*DCL func2 ENTRY (BINARY FLOAT(6),*/
      BINARY FIXED(31))                 /*BINARY FIXED(31))*/
      RETURNS (BINARY FIXED(31));       /*RETURNS (BINARY FIXED(31));*/

proc1: PROCEDURE;
            CALL subr1;                 /*CALL subr1;*/
            CALL subr2(                 /*CALL subr2(*/
              a + 1.0,                  /*a + 1.0,*/
              func1(b, c + func2(d, 3)), /*func1(b, c + func2(d, 3)),*/
              e);                       /*e);*/
            CALL subr3(1, a);           /*CALL subr3(1, a);*/
            CALL subr4(a, b);           /*CALL subr4(a, b);*/
    END proc1;



Output from XTRAN:

    double subr1(void);                 /*DCL subr1 ENTRY;*/
    double subr2(double *, long *,
      double *);                        /*DCL subr2 ENTRY (BINARY FLOAT(6),*/
                                        /*binary fixed(31),*/
                                        /*binary float(6));*/
    double subr3(long *, double *);     /*DCL subr3 ENTRY (BINARY FIXED(31),*/

                                        /*binary float(6));*/
    double subr4(double *, double *);   /*DCL subr2 ENTRY (BINARY FLOAT(6),*/
                                        /*binary float(6));*/
    long func1(long *, double *);       /*DCL func1 ENTRY (BINARY FIXED(31),*/
                                        /*binary float(6))*/
                                        /*returns (binary fixed(31));*/
    long func2(double *, long *);       /*DCL func2 ENTRY (BINARY FLOAT(6),*/
                                        /*binary fixed(31))*/
                                        /*returns (binary fixed(31));*/

double proc1(void)
{
    double a;
    double b;
    double c;
    double d;
    double e;
    subr1();                            /*CALL subr1;*/
    {
    int f3_a2 = 3;
    double f2_a2 = c + func2(&d, &f3_a2);
    double f1_a1 = a + 1.0;
    long f1_a2 = func1(&b, &f2_a2);
    subr2(&f1_a1, &f1_a2, &e);          /*CALL subr2(*/
                                        /*a + 1.0,*/
                                        /*func1(b, c + func2(d, 3)),*/
                                        /*e);*/
    }
    {
    int f1_a1 = 1;
    subr3(&f1_a1, &a);                  /*CALL subr3(1, a);*/
    }
    subr4(&a, &b);                      /*CALL subr4(a, b);*/
}