# Formula Solver 1.4 6/

``` BBS: Inland Empire Archive
Date: 03-19-93 (21:00)             Number: 373
From: QUINN TYLER JACKSON          Refer#: NONE
To: ALL                           Recvd: NO
Subj: Formula Solver 1.4    6/       Conf: (2) Quik_Bas```
```>>> Continued from previous message
SELECT CASE Phase%

CASE 1
' See if something of a higher precedence should be done first.
CALL sqjDesParse(2, x)

Op\$ = TOKEN\$(LvlPtr)

' The lowest level of precedence is handled by this Level.

DO WHILE fqjInList(LOGICAL, Op\$)
CALL sqjGetToken
CALL sqjDesParse(2, y)
CALL sqjApplyOp(Op\$, x, y)
Op\$ = TOKEN\$(LvlPtr)
LOOP

CASE 2
' See if something of a higher precedence should be done first.
CALL sqjDesParse(3, x)
Op\$ = TOKEN\$(LvlPtr)

CALL sqjGetToken
CALL sqjDesParse(3, y)
CALL sqjApplyOp(Op\$, x, y)
Op\$ = TOKEN\$(LvlPtr)
LOOP

CASE 3
' See if something of a higher precedence should be done first.
CALL sqjDesParse(4, x)

Op\$ = TOKEN\$(LvlPtr)

DO WHILE fqjInList(MULTDIV, Op\$)
CALL sqjGetToken
CALL sqjDesParse(4, y)
CALL sqjApplyOp(Op\$, x, y)
Op\$ = TOKEN\$(LvlPtr)
LOOP

CASE 4
' See if something of a higher precedence should be done first.
CALL sqjDesParse(5, x)

Op\$ = TOKEN\$(LvlPtr)

IF fqjInList(POWER, Op\$) THEN
CALL sqjGetToken
CALL sqjDesParse(5, y)
CALL sqjApplyOp(Op\$, x, y)
END IF

CASE 5
Op\$ = ""

IF TypeToken(LvlPtr) = OperatorClass AND (fqjInList(ADDSUB,_
TOKEN\$(LvlPtr))) THEN
Op\$ = TOKEN\$(LvlPtr)
CALL sqjGetToken
END IF

CALL sqjDesParse(6, x)

' This handles negative prefixes
SELECT CASE Op\$
CASE "-"
x = -x
END SELECT

CASE 6
' This level handles parentheses

IF TOKEN\$(LvlPtr) = "(" AND TypeToken(LvlPtr) = OperatorClass_
THEN
CALL sqjGetToken
CALL sqjDesParse(1, x)

IF TOKEN\$(LvlPtr) <> ")" THEN
ErrorCode = eqjMismatchedParenthesis
END IF

CALL sqjGetToken
ELSE
SELECT CASE TypeToken(LvlPtr)
CASE DigitClass
x = VAL(TOKEN\$(LvlPtr))
CALL sqjGetToken
CASE FunctionClass
x = fqjSolveFormula(TOKEN\$(LvlPtr))
TypeToken(LvlPtr) = DigitClass
CALL sqjGetToken
END SELECT
END IF
END SELECT
END SUB

SUB sqjGetToken ()

TOKEN\$(LvlPtr) = ""

DO WHILE fqjInList(WHITESPACE, MID\$(EXPR\$(LvlPtr), PTR(LvlPtr), 1))
PTR(LvlPtr) = PTR(LvlPtr) + 1
LOOP

Temp\$ = MID\$(EXPR\$(LvlPtr), PTR(LvlPtr), 1)
IF Temp\$ >= "0" AND Temp\$ <= "9" THEN

' Build up a number from its digits
DO WHILE INSTR(" ()" + OPERATOR\$, MID\$(EXPR\$(LvlPtr), PTR(LvlPtr),_
1)) = 0
TOKEN\$(LvlPtr) = TOKEN\$(LvlPtr) + MID\$(EXPR\$(LvlPtr),_
PTR(LvlPtr), 1)
PTR(LvlPtr) = PTR(LvlPtr) + 1
LOOP

TypeToken(LvlPtr) = DigitClass
EXIT SUB
END IF

IF INSTR("()" + OPERATOR\$, MID\$(EXPR\$(LvlPtr), PTR(LvlPtr), 1)) THEN

TypeToken(LvlPtr) = OperatorClass
TOKEN\$(LvlPtr) = MID\$(EXPR\$(LvlPtr), PTR(LvlPtr), 1)
PTR(LvlPtr) = PTR(LvlPtr) + 1

IF INSTR("()", TOKEN\$(LvlPtr)) THEN
EXIT SUB
ELSE
' see if it's a compound operator
IF INSTR(OPERATOR\$, MID\$(EXPR\$(LvlPtr), PTR(LvlPtr), 1)) THEN
Temp\$ = MID\$(EXPR\$(LvlPtr), PTR(LvlPtr), 1)
IF Temp\$ <> "-" THEN
TOKEN\$(LvlPtr) = TOKEN\$(LvlPtr) + Temp\$
PTR(LvlPtr) = PTR(LvlPtr) + 1
END IF
END IF
END IF
EXIT SUB
END IF

Temp\$ = MID\$(EXPR\$(LvlPtr), PTR(LvlPtr), 1)
IF Temp\$ >= "@" AND Temp\$ <= "Z" THEN
>>> Continued to next message

* OLX 2.1 TD * A program is just a big bug that happened to work....
```

Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET