home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
QBAS
/
RECURSE.ZIP
/
RECURSE.BAS
< prev
next >
Wrap
BASIC Source File
|
1989-02-26
|
3KB
|
74 lines
DECLARE SUB L1 (R!)
DECLARE SUB GET.EXP (R!)
DECLARE SUB GET.TOKEN ()
DECLARE SUB L2 (R!)
DECLARE SUB L3 (R!)
DECLARE SUB ARITH (O$, R!, H!)
DECLARE SUB L4 (R!)
DECLARE SUB L5 (R!)
DECLARE SUB L6 (R!)
DECLARE SUB UNARY (O$, R!)
DECLARE SUB PRIMITIVE (R!)
10 DIM AR(26): COMMON SHARED AR(), PROG$, TOKEN$, TOK.TYPE, P: ON ERROR GOTO 1000
20 FOR L = 1 TO 26: AR(L) = L: NEXT
30 R = 0: PRINT "TYPE IN EQUATION (EXAMPLE: 2.1/33)": INPUT PROG$: P = 1: IF PROG$ = "" THEN END
40 CALL GET.EXP(R): PRINT R: GOTO 30
50 GOTO 30
1000 PRINT ERR; ERL: RESUME 1001
1001 STOP
270 SUB ARITH (O$, R, H)
280 IF O$ = "-" THEN R = R - H
290 IF O$ = "+" THEN R = R + H
300 IF O$ = "*" THEN R = R * H
310 IF O$ = "/" THEN R = R / H
320 IF O$ = "^" THEN R = R ^ H
321 IF O$ = "<" THEN R = R < H
322 IF O$ = ">" THEN R = R > H
323 IF O$ = "=" THEN R = R = H
330 END SUB
60 SUB GET.EXP (R) : CALL GET.TOKEN
70 CALL L1(R): END SUB
370 SUB GET.TOKEN : TOKEN$ = ""
380 WHILE MID$(PROG$, P, 1) = " ": P = P + 1: WEND
390 IF INSTR("-+*/^()<>=", MID$(PROG$, P, 1)) THEN TOK.TYPE = 1: TOKEN$ = MID$(PROG$, P, 1): P = P + 1: EXIT SUB
400 IF MID$(PROG$, P, 1) >= "0" AND MID$(PROG$, P, 1) <= "9" THEN WHILE INSTR(" -+*/^()<>=", MID$(PROG$, P, 1)) = 0: TOKEN$ = TOKEN$ + MID$(PROG$, P, 1): P = P + 1: WEND: TOK.TYPE = 2
410 END SUB
SUB L1 (R)
CALL L2(R): O$ = TOKEN$
WHILE O$ = "<" OR O$ = ">" OR O$ = "=": CALL GET.TOKEN: CALL L2(H): CALL ARITH(O$, R, H): O$ = TOKEN$: WEND
END SUB
80 SUB L2 (R) : CALL L3(R): O$ = TOKEN$
90 WHILE O$ = "+" OR O$ = "-": CALL GET.TOKEN: CALL L3(H): CALL ARITH(O$, R, H): O$ = TOKEN$
100 WEND: END SUB
110 SUB L3 (R) : CALL L4(R): O$ = TOKEN$
120 WHILE O$ = "*" OR O$ = "/": CALL GET.TOKEN: CALL L4(H): CALL ARITH(O$, R, H): O$ = TOKEN$
130 WEND: END SUB
140 SUB L4 (R) : CALL L5(R)
150 IF TOKEN$ = "^" THEN CALL GET.TOKEN: CALL L4(H): CALL ARITH("^", R, H)
160 END SUB
170 SUB L5 (R) : O$ = ""
180 IF TOK.TYPE = 1 AND (TOKEN$ = "+" OR TOKEN$ = "-") THEN O$ = TOKEN$: CALL GET.TOKEN
190 CALL L6(R): IF O$ <> "" THEN CALL UNARY(O$, R)
200 END SUB
210 SUB L6 (R) : IF TOKEN$ = "(" AND TOK.TYPE = 1 THEN 230
220 CALL PRIMITIVE(R): EXIT SUB
230 CALL GET.TOKEN: CALL L1(R): IF TOKEN$ <> ")" THEN PRINT "MISMATCHED PARENTHESIS"
240 CALL GET.TOKEN: END SUB
250 SUB PRIMITIVE (R) : IF TOK.TYPE = 2 THEN R = VAL(TOKEN$): CALL GET.TOKEN: EXIT SUB
260 PRINT "SYNTAX ERROR": END SUB
340 SUB UNARY (O$, R)
350 IF O$ = "-" THEN R = -R
360 END SUB