|
Post by ptitjoz on Feb 6, 2021 10:59:10 GMT 1
Hello I have instructions in a file from another programming language. I am looking for a way to translate these instructions and run them in the same bacon program. Do you think this is possible?
Best regards
Here is a piece of code:
DATA "Rep 10","PRINT i%","Ret"
FOR i=1 TO 3 READ a$ IF LEFT$(a$,3)="Rep" THEN a$="FOR i%=1 TO "&RIGHT$(a$,LEN(a$)-4) END IF
IF a$="Ret" THEN a$="NEXT" END IF PRINT a$
NEXT The generated code that I would like to run :
FOR i%=1 TO 10 PRINT i% NEXT
|
|
|
Post by rikky on Feb 7, 2021 0:14:47 GMT 1
DATA "Rep 10","PRINT i%","Ret"
FOR i=1 TO 3 READ a$ IF LEFT$(a$,3)="Rep" THEN a$="FOR i%=1 TO "&RIGHT$(a$,LEN(a$)-4) END IF
IF a$="Ret" THEN a$="NEXT" END IF b$ = b$ & a$ & NL$
NEXT
SAVE b$ TO "/tmp/" & STR$(MYPID) & ".bac" SYSTEM "bacon /tmp/" & STR$(MYPID) & ".bac &>/dev/null" IF NOT(RETVAL) THEN SYSTEM "/tmp/" & STR$(MYPID) result: 1 2 3 4 5 6 7 8 9 10
Rik
|
|
|
Post by ptitjoz on Feb 7, 2021 10:06:42 GMT 1
Hello and thanks Rik!
I think the second SYSTEM command starts before the compilation is complete. In fact I added the SLEEP instruction which seems to work. However, this does not appear to me to be a good solution. There should be a more appropriate test. Do you have an idea ? Best regards
Converting '/tmp/6635.bac'... done, 4 lines were processed in 0.001 seconds. sh: 1: /tmp/6635: not found Creating lexical analyzer... done. Compiling '/tmp/6635.bac'... cc -c 6635.bac.c cc -o 6635 6635.bac.o -lm Done, program '6635' ready. >Exit code: 0
Then I have added a command sleep
SAVE b$ TO "/tmp/" & STR$(MYPID) & ".bac" SYSTEM "bacon /tmp/" & STR$(MYPID) & ".bac &>/dev/null" SLEEP 1500 IF NOT(RETVAL) THEN SYSTEM "/tmp/" & STR$(MYPID)
Converting '/tmp/7027.bac'... done, 4 lines were processed in 0.002 seconds. Creating lexical analyzer... done. Compiling '/tmp/7027.bac'... cc -c 7027.bac.c cc -o 7027 7027.bac.o -lm Done, program '7027' ready. 1 2 3 4 5 6 7 8 9 10 >Exit code: 0
|
|
|
Post by rikky on Feb 7, 2021 12:50:23 GMT 1
Oh, you have a supercomputer. Well, maybe you can force your program to wait for the result of the command with EXEC$. DATA "Rep 10","PRINT i%","Ret"
FOR i=1 TO 3 READ a$ IF LEFT$(a$,3)="Rep" THEN a$="FOR i%=1 TO "&RIGHT$(a$,LEN(a$)-4) END IF
IF a$="Ret" THEN a$="NEXT" END IF b$ = b$ & a$ & NL$
NEXT
SAVE b$ TO "/tmp/" & STR$(MYPID) & ".bac"
result$ = EXEC$("bacon /tmp/" & STR$(MYPID) & ".bac")
IF INSTR(result$,"Done, program '" & STR$(MYPID) & "' ready.") AND NOT(RETVAL) THEN SYSTEM "/tmp/" & STR$(MYPID)
Or build a waiting loop. WHILE NOT(FILEEXISTS("/tmp/" & STR$(MYPID))) 'boire un tasse de cafe WEND
Rik
|
|