Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
Posted: Mon Dec 13, 2004 1:21 pm Post subject:
Dtf,
Are you referring a Quine(self-reproducing programs) ? If so you also need to add another condition, that the generated source should be error free when re-compiled once again.
Joined: 10 Dec 2004 Posts: 110 Topics: 8 Location: Colorado USA
Posted: Mon Dec 13, 2004 1:29 pm Post subject:
I guess I assumed that the program would have to be error free since the output of the program must by specification be exactly the same as the source code that generated it.
What I was trying to say about the "INPUT FILE" rule was that there would be no input data of any kind.
"Are you referring a Quine(self-reproducing programs) ?"
I am not familiar with this........ However if it is the same then I guess I am.
Joined: 10 Dec 2004 Posts: 110 Topics: 8 Location: Colorado USA
Posted: Mon Dec 13, 2004 2:24 pm Post subject:
A quick web seach of Quine did show me that the I am presenting the same problem. Interesting.........
So I guess it has been done mutiple times before. Over the years I wrote both a COBOL and ASSEMBLER solution. In COBOL I would disallow the use of COPY BOOKS (for obvious reasons), and in Assembler I would do the same. I would allow for use of standard system macros, but not user written macros, for the same reason.
Joined: 10 Dec 2004 Posts: 110 Topics: 8 Location: Colorado USA
Posted: Thu Dec 16, 2004 10:14 pm Post subject:
Code:
CLONE START 0
USING *,15
STM 14,12,12(13)
BAL 11,*+76
USING *,13
DS 18F
DROP 15
ST 13,4(11)
ST 11,8(13)
LR 13,11
LA 12,STMTS
LA 11,49
OPEN (STMTFILE,OUTPUT)
PUTLOOP1 PUT STMTFILE,0(12)
LA 12,80(12)
BCT 11,PUTLOOP1
LA 12,STMTS
LA 11,55
L 10,=A(DCLINE)
PUTLOOP2 MVC 20(46,10),0(12)
PUT STMTFILE,0(10)
LA 12,80(12)
BCT 11,PUTLOOP2
L 12,=A(REPLACE)
LA 11,5
MVC 45(35,12),79(12)
MVC 80(80,12),0(12)
LA 12,80(12)
MVI 19(12),QUOTE
MVI 39(12),QUOTE
MVI 42(12),QUOTE
MVI 45(12),QUOTE
MVI 51(12),QUOTE
MVI 53(12),QUOTE
MVI 56(12),QUOTE
MVI 59(12),QUOTE
MVI 65(12),QUOTE
MVI 67(12),QUOTE
PUTLOOP3 PUT STMTFILE,0(12)
LA 12,80(12)
BCT 11,PUTLOOP3
CLOSE (STMTFILE)
L 13,4(13)
LM 14,12,12(13)
BR 14
LTORG
STMTFILE DCB DDNAME=STMTFILE,DSORG=PS,MACRF=PM
QUOTE EQU 125
STMTS DS 0H
DC CL80'CLONE START 0 '
DC CL80' USING *,15 '
DC CL80' STM 14,12,12(13) '
DC CL80' BAL 11,*+76 '
DC CL80' USING *,13 '
DC CL80' DS 18F '
DC CL80' DROP 15 '
DC CL80' ST 13,4(11) '
DC CL80' ST 11,8(13) '
DC CL80' LR 13,11 '
DC CL80' LA 12,STMTS '
DC CL80' LA 11,49 '
DC CL80' OPEN (STMTFILE,OUTPUT) '
DC CL80'PUTLOOP1 PUT STMTFILE,0(12) '
DC CL80' LA 12,80(12) '
DC CL80' BCT 11,PUTLOOP1 '
DC CL80' LA 12,STMTS '
DC CL80' LA 11,55 '
DC CL80' L 10,=A(DCLINE) '
DC CL80'PUTLOOP2 MVC 20(46,10),0(12) '
DC CL80' PUT STMTFILE,0(10) '
DC CL80' LA 12,80(12) '
DC CL80' BCT 11,PUTLOOP2 '
DC CL80' L 12,=A(REPLACE) '
DC CL80' LA 11,5 '
DC CL80' MVC 45(35,12),79(12) '
DC CL80' MVC 80(80,12),0(12) '
DC CL80' LA 12,80(12) '
DC CL80' MVI 19(12),QUOTE '
DC CL80' MVI 39(12),QUOTE '
DC CL80' MVI 42(12),QUOTE '
DC CL80' MVI 45(12),QUOTE '
DC CL80' MVI 51(12),QUOTE '
DC CL80' MVI 53(12),QUOTE '
DC CL80' MVI 56(12),QUOTE '
DC CL80' MVI 59(12),QUOTE '
DC CL80' MVI 65(12),QUOTE '
DC CL80' MVI 67(12),QUOTE '
DC CL80'PUTLOOP3 PUT STMTFILE,0(12) '
DC CL80' LA 12,80(12) '
DC CL80' BCT 11,PUTLOOP3 '
DC CL80' CLOSE (STMTFILE) '
DC CL80' L 13,4(13) '
DC CL80' LM 14,12,12(13) '
DC CL80' BR 14 '
DC CL80' LTORG '
DC CL80'STMTFILE DCB DDNAME=STMTFILE,DSORG=PS,MACRF=PM'
DC CL80'QUOTE EQU 125 '
DC CL80'STMTS DS 0H '
DC CL80'DCLINE DC CL19* DC CL80*,X*7D*'
DC CL80',CL46* *,X*7D*,CL13* * '
DC CL80' ORG *-560 '
DC CL80'REPLACE EQU * '
DC CL80' ORG '
DC CL80' END '
DCLINE DC CL19' DC CL80',X'7D',CL46' ',X'7D',CL13' '
ORG *-560
REPLACE EQU *
ORG
END
//IBMUSERA JOB (,),'PL/I QUINE COMPILE/RUN',
// CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),REGION=256K
//QUINE EXEC PL1LFCLG,PARM='NOLIST'
//PL1L.SYSLIN DD UNIT=SYSDA
//PL1L.SYSIN DD *
QUINE: PROC OPTIONS(MAIN);
DCL I,J BIN FIXED;
DCL BL(19) CHAR(80) VAR INIT(
''''
,' '
,','
,' QUINE: PROC OPTIONS(MAIN);'
,' DCL I,J BIN FIXED;'
,' DCL BL(19) CHAR(80) VAR INIT('
,' );'
,' DO I=4 TO HBOUND(BL,1);'
,' PUT SKIP EDIT(BL(I))(A);'
,' IF I = 6 THEN DO;'
,' PUT SKIP EDIT(BL(2),BL(2),BL(1),BL(1),BL(1),BL(1))(A);'
,' PUT SKIP EDIT(BL(2),BL(3),BL(1),BL(2),BL(1))(A);'
,' PUT SKIP EDIT(BL(2),BL(3),BL(1),BL(3),BL(1))(A);'
,' DO J=4 TO HBOUND(BL,1);'
,' PUT SKIP EDIT(BL(2),BL(3),BL(1),BL(J),BL(1))(A);'
,' END;'
,' END;'
,' END;'
,' END QUINE;'
);
DO I=4 TO HBOUND(BL,1);
PUT SKIP EDIT(BL(I))(A);
IF I = 6 THEN DO;
PUT SKIP EDIT(BL(2),BL(2),BL(1),BL(1),BL(1),BL(1))(A);
PUT SKIP EDIT(BL(2),BL(3),BL(1),BL(2),BL(1))(A);
PUT SKIP EDIT(BL(2),BL(3),BL(1),BL(3),BL(1))(A);
DO J=4 TO HBOUND(BL,1);
PUT SKIP EDIT(BL(2),BL(3),BL(1),BL(J),BL(1))(A);
END;
END;
END;
END QUINE;
/*
//LKED.SYSLIB DD DSN=SYS1.PL1LIB,DISP=SHR
//GO.STEPLIB DD DSN=SYS1.PL1LIB,DISP=SHR
//
be carefull with the following MVS3.8 JES2 JCL+MVT COBOL code
(it really reproduces itself, not code text only but code run too).
Code is very similar to shown by previous post, but it was invented independently. It proves that there are no many ideas in the world
Code:
//IBMUSER JOB (,),,CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1)
//QUINE EXEC COBUCLG
//COB.SYSIN DD *
IDENTIFICATION DIVISION.
PROGRAM-ID. QUINE.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-360.
OBJECT-COMPUTER. IBM-360.
SPECIAL-NAMES.
CONSOLE IS CNSL.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OUTPUT-FILE
ASSIGN UT-S-OUTPUT.
DATA DIVISION.
FILE SECTION.
FD OUTPUT-FILE
RECORD CONTAINS 80 CHARACTERS
LABEL RECORDS ARE OMITTED
DATA RECORD IS OUTPUT-REC.
01 OUTPUT-REC PIC X(80).
WORKING-STORAGE SECTION.
01 W-SUB PIC 9(03).
01 W-SUB2 PIC 9(03).
01 N PIC 9(03) VALUE 68.
01 JCL-STATEMENTS.
02 FILLER PIC X(80) VALUE
'//IBMUSER JOB (,),,CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1) '.
02 FILLER PIC X(80) VALUE
'//QUINE EXEC COBUCLG '.
02 FILLER PIC X(80) VALUE
'//COB.SYSIN DD * '.
02 FILLER PIC X(80) VALUE
' IDENTIFICATION DIVISION. '.
02 FILLER PIC X(80) VALUE
' PROGRAM-ID. QUINE. '.
02 FILLER PIC X(80) VALUE
' ENVIRONMENT DIVISION. '.
02 FILLER PIC X(80) VALUE
' CONFIGURATION SECTION. '.
02 FILLER PIC X(80) VALUE
' SOURCE-COMPUTER. IBM-360. '.
02 FILLER PIC X(80) VALUE
' OBJECT-COMPUTER. IBM-360. '.
02 FILLER PIC X(80) VALUE
' SPECIAL-NAMES. '.
02 FILLER PIC X(80) VALUE
' CONSOLE IS CNSL. '.
02 FILLER PIC X(80) VALUE
' INPUT-OUTPUT SECTION. '.
02 FILLER PIC X(80) VALUE
' FILE-CONTROL. '.
02 FILLER PIC X(80) VALUE
' SELECT OUTPUT-FILE '.
02 FILLER PIC X(80) VALUE
' ASSIGN UT-S-OUTPUT. '.
02 FILLER PIC X(80) VALUE
' DATA DIVISION. '.
02 FILLER PIC X(80) VALUE
' FILE SECTION. '.
02 FILLER PIC X(80) VALUE
' FD OUTPUT-FILE '.
02 FILLER PIC X(80) VALUE
' RECORD CONTAINS 80 CHARACTERS '.
02 FILLER PIC X(80) VALUE
' LABEL RECORDS ARE OMITTED '.
02 FILLER PIC X(80) VALUE
' DATA RECORD IS OUTPUT-REC. '.
02 FILLER PIC X(80) VALUE
' 01 OUTPUT-REC PIC X(80). '.
02 FILLER PIC X(80) VALUE
' WORKING-STORAGE SECTION. '.
02 FILLER PIC X(80) VALUE
' 01 W-SUB PIC 9(03). '.
02 FILLER PIC X(80) VALUE
' 01 W-SUB2 PIC 9(03). '.
02 FILLER PIC X(80) VALUE
' 01 N PIC 9(03) VALUE 68. '.
02 FILLER PIC X(80) VALUE
' 01 JCL-STATEMENTS. '.
02 FILLER PIC X(80) VALUE
' 02 FILLER PIC X(80) VALUE '.
02 FILLER PIC X(80) VALUE
' 01 FILLER REDEFINES JCL-STATEMENTS. '.
02 FILLER PIC X(80) VALUE
' 02 JCL-STATEMENT PIC X(80) OCCURS 68 TIMES. '.
02 FILLER PIC X(80) VALUE
' 01 QUOTED-LINE. '.
02 FILLER PIC X(80) VALUE
' 02 FILLER PIC X(11) VALUE SPACES. '.
02 FILLER PIC X(80) VALUE
' 02 FILLER PIC X(1) VALUE QUOTE. '.
02 FILLER PIC X(80) VALUE
' 02 LINE-BODY PIC X(58). '.
02 FILLER PIC X(80) VALUE
' 02 FILLER PIC X(1) VALUE QUOTE. '.
02 FILLER PIC X(80) VALUE
' 02 EOSTMT PIC X(1). '.
02 FILLER PIC X(80) VALUE
' 02 FILLER PIC X(8) VALUE SPACES. '.
02 FILLER PIC X(80) VALUE
' 01 XPER PIC 9999 USAGE COMP VALUE 75. '.
02 FILLER PIC X(80) VALUE
' 01 XPER2 REDEFINES XPER. '.
02 FILLER PIC X(80) VALUE
' 02 FILLER PIC X(1). '.
02 FILLER PIC X(80) VALUE
' 02 PERIOD-MARK PIC X(1). '.
02 FILLER PIC X(80) VALUE
' PROCEDURE DIVISION. '.
02 FILLER PIC X(80) VALUE
' 000-DISPLAY. '.
02 FILLER PIC X(80) VALUE
' MOVE PERIOD-MARK TO EOSTMT. '.
02 FILLER PIC X(80) VALUE
' OPEN OUTPUT OUTPUT-FILE. '.
02 FILLER PIC X(80) VALUE
' PERFORM 000-WRITE VARYING W-SUB '.
02 FILLER PIC X(80) VALUE
' FROM 1 BY 1 UNTIL W-SUB > N. '.
02 FILLER PIC X(80) VALUE
' CLOSE OUTPUT-FILE. '.
02 FILLER PIC X(80) VALUE
' 000-WRITE. '.
02 FILLER PIC X(80) VALUE
' IF W-SUB = 28 ADD 1 TO W-SUB; '.
02 FILLER PIC X(80) VALUE
' PERFORM 001-WRITE VARYING W-SUB2 '.
02 FILLER PIC X(80) VALUE
' FROM 1 BY 1 UNTIL W-SUB2 > N. '.
02 FILLER PIC X(80) VALUE
' MOVE JCL-STATEMENT (W-SUB) TO OUTPUT-REC. '.
02 FILLER PIC X(80) VALUE
' WRITE OUTPUT-REC. '.
02 FILLER PIC X(80) VALUE
' 001-WRITE. '.
02 FILLER PIC X(80) VALUE
' MOVE JCL-STATEMENT (28) TO OUTPUT-REC. '.
02 FILLER PIC X(80) VALUE
' WRITE OUTPUT-REC. '.
02 FILLER PIC X(80) VALUE
' MOVE JCL-STATEMENT (W-SUB2) TO LINE-BODY. '.
02 FILLER PIC X(80) VALUE
' MOVE QUOTED-LINE TO OUTPUT-REC. '.
02 FILLER PIC X(80) VALUE
' WRITE OUTPUT-REC. '.
02 FILLER PIC X(80) VALUE
' 000-END. '.
02 FILLER PIC X(80) VALUE
' STOP RUN. '.
02 FILLER PIC X(80) VALUE
'//LKED.SYSLIB DD DSNAME=SYS1.COBLIB,DISP=SHR '.
02 FILLER PIC X(80) VALUE
'// DD DSNAME=SYS1.LINKLIB,DISP=SHR '.
02 FILLER PIC X(80) VALUE
'//GO.SYSPRINT DD SYSOUT=A '.
02 FILLER PIC X(80) VALUE
'//GO.SYSOUT DD SYSOUT=* '.
02 FILLER PIC X(80) VALUE
'//GO.OUTPUT DD SYSOUT=(A,INTRDR) '.
02 FILLER PIC X(80) VALUE
'// '.
01 FILLER REDEFINES JCL-STATEMENTS.
02 JCL-STATEMENT PIC X(80) OCCURS 68 TIMES.
01 QUOTED-LINE.
02 FILLER PIC X(11) VALUE SPACES.
02 FILLER PIC X(1) VALUE QUOTE.
02 LINE-BODY PIC X(58).
02 FILLER PIC X(1) VALUE QUOTE.
02 EOSTMT PIC X(1).
02 FILLER PIC X(8) VALUE SPACES.
01 XPER PIC 9999 USAGE COMP VALUE 75.
01 XPER2 REDEFINES XPER.
02 FILLER PIC X(1).
02 PERIOD-MARK PIC X(1).
PROCEDURE DIVISION.
000-DISPLAY.
MOVE PERIOD-MARK TO EOSTMT.
OPEN OUTPUT OUTPUT-FILE.
PERFORM 000-WRITE VARYING W-SUB
FROM 1 BY 1 UNTIL W-SUB > N.
CLOSE OUTPUT-FILE.
000-WRITE.
IF W-SUB = 28 ADD 1 TO W-SUB;
PERFORM 001-WRITE VARYING W-SUB2
FROM 1 BY 1 UNTIL W-SUB2 > N.
MOVE JCL-STATEMENT (W-SUB) TO OUTPUT-REC.
WRITE OUTPUT-REC.
001-WRITE.
MOVE JCL-STATEMENT (28) TO OUTPUT-REC.
WRITE OUTPUT-REC.
MOVE JCL-STATEMENT (W-SUB2) TO LINE-BODY.
MOVE QUOTED-LINE TO OUTPUT-REC.
WRITE OUTPUT-REC.
000-END.
STOP RUN.
//LKED.SYSLIB DD DSNAME=SYS1.COBLIB,DISP=SHR
// DD DSNAME=SYS1.LINKLIB,DISP=SHR
//GO.SYSPRINT DD SYSOUT=A
//GO.SYSOUT DD SYSOUT=*
//GO.OUTPUT DD SYSOUT=(A,INTRDR)
//
It does generate a few errors, but it will do what is advertised. Unless I'm very wrong, it's also the size-wise smallest PL/I quine that is possible.
I wrote my first PL/I quine about a decade ago, and the above version dates from 2003. I've revisited it a few times since then, but have been unable to squeeze out any more.
Please note that it does not compile with the shiny new Enterprise PL/I compiler!
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum