1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 10:37:58 +03:00
mal/basic/step1_read_print.in.bas

68 lines
1.0 KiB
QBasic
Raw Normal View History

2016-09-05 04:42:50 +03:00
GOTO MAIN
REM $INCLUDE: 'readline.in.bas'
REM $INCLUDE: 'types.in.bas'
REM $INCLUDE: 'reader.in.bas'
REM $INCLUDE: 'printer.in.bas'
REM $INCLUDE: 'debug.in.bas'
REM READ(A$) -> R%
2016-09-05 04:42:50 +03:00
MAL_READ:
GOSUB READ_STR
RETURN
REM EVAL(A%, E%) -> R%
2016-09-05 04:42:50 +03:00
EVAL:
R%=A%
RETURN
REM PRINT(A%) -> R$
2016-09-05 04:42:50 +03:00
MAL_PRINT:
2016-09-12 05:36:15 +03:00
AZ%=A%: PR%=1: GOSUB PR_STR
2016-09-05 04:42:50 +03:00
RETURN
REM REP(A$) -> R$
2016-09-05 04:42:50 +03:00
REP:
GOSUB MAL_READ
IF ER%<>0 THEN GOTO REP_DONE
A%=R%: GOSUB EVAL
IF ER%<>0 THEN GOTO REP_DONE
A%=R%: GOSUB MAL_PRINT
RT$=R$
REP_DONE:
REM Release memory from EVAL
AY%=R%: GOSUB RELEASE
R$=RT$
RETURN
2016-09-05 04:42:50 +03:00
REM MAIN program
2016-09-05 04:42:50 +03:00
MAIN:
GOSUB INIT_MEMORY
ZT%=ZI%: REM top of memory after base repl_env
REPL_LOOP:
A$="user> ": GOSUB READLINE: REM call input parser
IF EOF=1 THEN GOTO QUIT
A$=R$: GOSUB REP: REM call REP
2016-09-05 04:42:50 +03:00
IF ER%<>0 THEN GOSUB PRINT_ERROR: GOTO REPL_LOOP
PRINT R$
GOTO REPL_LOOP
2016-09-05 04:42:50 +03:00
QUIT:
REM P1%=ZT%: P2%=-1: GOSUB PR_MEMORY
2016-09-12 05:36:15 +03:00
GOSUB PR_MEMORY_SUMMARY
END
PRINT_ERROR:
PRINT "Error: "+ER$
ER%=0: ER$=""
RETURN