Problem with COMPILER version !!

Hello everyone,
Hope all are doing good. I'm a beginner One of my reference code found in 1977 journal was written with PL/I language. In order to understand the particular program, PL/I source code was translated into C++ based on this following link.
http://www.mpsinc.com/pl1c.html
Here attached the code below.
https://drive.google.com/file/d/1WkOb7hmp1Fk6pD4mTzi4W-2WWygrGHMj/view?usp=sharing
When I tried to compile the code, I get too many errors almost in each line. ERROR:'cin' 'cout' doesn't name a type.
I hope there is no problem with the code, there should be a problem with compiler version if I'm not wrong.
Kindly someone guide me here. Thank you all
add the line
using namespace std;
to the top of the file after includes where main() is located.
this is bad practice, but the quickest way to fix older code.

better, is to add a statement for each thing you use:
using std::cin
using std::cout

but there may be too many things to make that useful when coming into old projects.

your compiler is correct. the code is using an older version of C++ where having std::everything or using statements to avoid that was not required.
Last edited on
Hello,
Thank you for your response. I tried whatever you said, but nothing works.
When I try fixing "std::cin" the compiler says,
error: 'cin' in namespace 'std' does not name a type.

Could you please tell me how to proceed further.
Thank you again for your time ^^
The code is not a valid C++ program unfortunately. It uses variables that have not been declared. It doesn't close the class definition. A lot of the code would have to be put inside a function (but would still not be entirely valid).


Things like
 
cin >> PC,PH,PX,PN,PS);
is simply not correct syntax.

It should look more like
 
cin >> PC >> PH >> PX >> PN >> PS;
but for that to work the variables would have to be declare first.


This code doesn't make sense to me
 
for(i_tmp = 0; i_tmp <= (26][5); i_tmp++){
What is (26][5) supposed to mean? It's not C++, that's for sure.


This code
 
cout << "\n%s",ISTRING;
makes me suspect that they originally had a conversion tool to C that used printf for output and then tried (and failed miserably) to turn it into C++.

In C, with printf, it might look something like:
 
printf("\n%s", ISTRING);

But in C++, using cout, it should look like:
 
cout << "\n" << ISTRING;


The way they call strcmp and substr they can't be using std::string (std::string doesn't even have a strcmp function and substr only takes 2 arguments, not 3). They must be using some custom string class. Either that or they have just got it all wrong like so many other things.


Line 456 says:
implicit variables declared in this module

The rest of the file (more than 5000 lines) are not actually C++ code. It seems to be just a list of all the variables that have been used, but haven't been declared, but would have to be declared for the code to work.


To me it looks almost hopeless to try and piece it together into something that works. Probably easier to look at the original PL/I code and rewrite it in C++ by hand.
Last edited on
Hellp Peter, Thank you.
I'm hereby attaching the link, where it contains original PL/I and translated C++ code.
https://drive.google.com/file/d/1BlLHNtd0L_TNgL5zsst5zwaOl5MBjVew/view?usp=sharing
How to carry this work further ? I'm not good in rewriting C++.
Any ideas ?
Thank you
I don't know. I'm not going to do it. I don't know anything about PLI/I and even though I might be able to figure out what the code does and translate it into C++ it's not something I want to do. It's too much work. I guess you will either have to learn C++ well enough to do the conversion yourself (this will take time) or pay someone to do it.
Last edited on
If you look at the log.cpp file, there's a long list at the end of issues - mainly undefined variables/functions etc etc. There's also invalid syntax as per Peter87's comments above. It's really quite a bad attempt at a language conversion. To get this code into something that compiles (never mind works) is going to involve some (possibly a lot) effort - either by trying to fix the generated C++ code or by a manual conversion from the PL/1 code.

I wrote a few PL/I programs in the late 1970's when I had access to an IBM computer with a PL/I compiler. It's quite a nice general purpose language though never seemed to be much outside of IBM - which is probably why it didn't become as popular as Fortran/Cobol.

PS There is an alternative if you need to use this program.

Digital Research offer a free PL/I compiler for CP/M and MS-DOS (https://winworldpc.com/product/digital-research-pl-i-compiler/1x)

If you install say a MS-DOS emulator (eg DOSBOX), then the PL/I compiler you should be able to compile and run the original Pl/I code.
Last edited on
Hello Peter, Thank you for your time.

Hello seeplus, Thank you for sharing your thoughts. Let me explain my journey in short that why I'm here. I'm a PhD student who works in OpenFOAM background. I was given a job to analyze a phenomenon about pyrolysis. While referring some research papers, I found a thesis in 1977. The author used PL/I language, where I came to know PL/I was used by IBM users in the past. Then out of nowhere, I posted my query in PL/I forum to understand the language. There I got a help from a gentleman who helped me to run the PL/I program using the MUSIC/SP mainframe emulator. I compiled my program well and good, reproduced the same result, however I couldn't able to understand certain lines of code. These lines are key to reframe the code in OpenFOAM format.
1
2
3
4
5
6
7
8
9
10
11
    IF INDEX(ISTRING,'=')>0 THEN DO;   /* any '=' in input string? */
        IF INDEX(ISTRING,';')=0 THEN   /* no ';' ? */
         SUBSTR(ISTRING,80,1)=';';     /* end string With ; */
         /*GET STRING(ISTRING) DATA COPY; */   /* get data,name=value*/
         GET STRING(ISTRING) DATA ;    /* get data,name=value  from instring*/
         /*GET EDIT(NAME) (A(80)) COPY;*/       /* read sysin to name*/
         GET EDIT(NAME) (A(20)) ;      /* read sysin to name*/
         END;

    ELSE NAME=SUBSTR(ISTRING,1,20);  /* read NAME from istring */
One of my well wisher who is helping me for this project is good in MATLAB and C language. Actually there are 3 parts of code. I compiled 2 parts of the code in MATLAB. The 3rd part is still a unfinished business. So in order to make my well wisher understand, I need this code in MATLAB or C language, so he can make me understand and move ahead. The google says, PL/I conversion is applicable only for C++, Java and so on, not MATLAB. And I stuck with C language now.

So, now what can be done:
(1) Rewrite the code in C language, yes that's hectic job, however not an impossible task but I need to start everything from the scratch.
(2) (or) I should rewrite in MATLAB, only if I understand the complete code (as mentioned few lines I couldnt understand)

So Mr. Seeplus, can you help me to understand some lines of code in PL/I language ?
I'm very hazy now on PL/I (over 45 years since last used!) - but I'll give it a shot.

INDEX(A, B) - returns the leftmost position in A where B begins. If B doesn't exist in A then it returns 0.

SUBSTR(A, B, C) - The result is the substring of A beginning at position B and ending with B + C - 1

IF - is the usual if statement. If true, the following statement is executed. DO; ... END; mark a compound statement to be executed if true. So if the result of the IF in L1 is true then L2-L7 are executed (same as {} in C ). If L2 is true then only L3 is executed.

GET obtains input data. L7 means obtain a string from input as alpha for 20 chars.

I'm not sure about L5. I can't remember!

As C++, something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
std::string ISTRING, NAME;

std::cin >> ISTRING;

if (ISTRING.find('=') != std::string::npos) {
    if (ISTRING.find(';') == std:string::npos)
         ISTRING += ';'

    // Do something with ISTRING
    std::cin >> NAME;

} else 
    NAME = ISTRING.substr(0, 20);


However, looking at the PL/I code, after this code section, ISTREAM/NAME is only used in 1 other place for output!

1
2
3
4
5
6
PUT EDIT(NAME)(PAGE,X(35),A(20));
PUT EDIT('INPUT DATA')(SKIP(2),X(5),A);
IF INDEX(ISTRING, '=')>0 THEN DO;
    PUT SKIP(2) EDIT('PROGRAMME CONTROL DATA')(COL(5),A);
    PUT SKIP    EDIT(ISTRING)                 (COL(5),A);
END;


So NAME and ISTRING are only used for some output display and have no other use within the program. To get the program working, the PL/I lines in the code above can be just ignored and NAME and ISTRING set to whatever is required to be output!

1
2
std::string ISTRING {"=This is ISTRING"};    // = determines whether ISTRING is displayed or not
std::string NAME {"This is NAME"};


Good luck!
Last edited on
Kumaresh0402,
Surely, if you want to understand the "phenomenon about pyrolysis" embodied in a 1977 thesis, you read the theoretical material in the thesis, not what is written in 45-year-old code. Your snippets of code in this thread look more like reading an input file than any serious combustion chemistry.

OpenFOAM already has a pyrolysis model in it.
Last edited on
Perhaps you should use different command line options on the PL/I to C++ translator.
Topic archived. No new replies allowed.