Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

is it possible?

by suno (Acolyte)
on Aug 13, 2012 at 13:17 UTC ( [id://987111]=perlquestion: print w/replies, xml ) Need Help??

suno has asked for the wisdom of the Perl Monks concerning the following question:

say my code is :
ROUTINE#1 MVC A,B EX R1,ROUTINE#2 . . . ROUTINE#2 ST R2,VAR1
here.. when it reaches "EX R1,ROUTINE#2" ,"ST R2,VAR1" is substituted in place of ROUTINE#2. and ROUTIE#2 has to be deleted.Is it possible for me to rewrite the code using perl,so that my final code should look like,
ROUTINE#1 MVC A,B ST R2,VAR1 . . .

Replies are listed 'Best First'.
Re: is it possible?
by Old_Gray_Bear (Bishop) on Aug 13, 2012 at 14:58 UTC
    As a matter of pure nosy curiosity, why are using Perl for this project?

    Since you are refactoring IBM Basic Assembler, I suspect that you are running on a zOS system. That being the case, I would have turned to REXX, as a 'native' solution, rather than Perl. (Never mind that I'd be doing it inside the ISPF editor and not get involved with a one-off custom conversion tool in the first place....)

    REXX (and EXEC2) were written in and for the IBM ecosystem (MVS and VM370/CMS). Perl is cross-ported from the UNIX world. There are different underlying assumptions between the two operating environments, and that may make REXX a better language for the job. Certainly the debugging and performance tools provided by MVS will be a better fit to REXX code than code written in Perl.

    ----
    I Go Back to Sleep, Now.

    OGB

      Hi PerlMonks!.thanks for the help.. but still i am struggling with this logic... so i kind of trying with my own logic... what i am doing here is, as soon as i encounter 'EX R1,ROUTINE#2' instruction, whatever label(ROUTINE#2)it is pointing to,i am storing that label and the next line to a separate file..that is i am storing 'ROUTINE#2 ST R2,VAR1' to a an intermediate file.then parse the code from the begining.when 'EX R1,ROUTINE#2' is reached, goto the intermediate file and retreive the value corresponding to ''ROUTINE#2'and replace it with the EX statement... i hope this works..i know this is lengthy process..is there any other way i can do it? here i have reached till storing values to the intermediate values... need to do the rest....
Re: is it possible?
by BrowserUk (Patriarch) on Aug 13, 2012 at 13:44 UTC

    Presumably, you are looking to use Perl to manipulate the source code of some assembler like language?

    If so, the answer is yes. It would be a relatively simply s/// substitution.

    But, in order to help you, you'll have to more clearly define

    • the circumstances under when that substitution to take place;

      Is it whenever the text ROUTINE#2 occurs (other than its definition)?

      Or only when it appears as the second parameter to the EX instruction?

      Only when it is the second argument and R1 is the first?

    • the scope of the substitutions;

      Is this all contained in one file? Multiple files?

    • Much more information.

    That said, whilst it could certainly be done with Perl, you may be better off using a proper macro processor like M4 or even a C pre-compiler.

    Clearer questions lead to better answers -- and stop people misinterpreting the questions.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Hi,...

      Whenever "EX" instruction is there in the first column followed by 2 arguments, whatever is there in the 2nd argument will be another routine(this routine will be in the same file.). that has to be substituted in place of the entire EX statement..

        Whenever "EX" instruction is there in the first column followed by 2 arguments, whatever is there in the 2nd argument will be another routine(this routine will be in the same file.). that has to be substituted in place of the entire EX statement..

        Okay, so you would need 3 passes.

        1. Load the file into an array line-by-line: my @file = <$fh>;
        2. Scan the lines and record the routine names from the EX statements:
          my %exs; $file[ $_ ] =~ m[\s+EX\s+[^,]+,(\S+)] and push @{ $exs{ $1 } }, $_ for + 0 .. $#file;
        3. Now locate the routines referenced in the EX lines and make the substitutions:
          for my $rtn ( keys %exs ) { my $n = 0; ++$n until $file[ $n ] =~ m[$rtn\s+(\S+)]; my $subst = $1; $file[ $_ ] = "\t$subst" for @{ $exs{ $rtn } }; }
        4. Write out the modified array to a new file.

        Of course, that only deals with single line substitutions; you'd need to add error checking for routines referenced but not found; and you might want to remember the lines where the substituted routines were found and remove them before output; etc. but that should get you started.

        As OGB said; I can't believe that there isn't an ISPF macro to do this already in existance.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Re: is it possible?
by moritz (Cardinal) on Aug 13, 2012 at 13:23 UTC
Re: is it possible?
by Anonymous Monk on Aug 13, 2012 at 13:23 UTC
    And your perl question is?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://987111]
Approved by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found