home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / BASIC / QBS_0103 / QBS103-4.DOC < prev    next >
Text File  |  1993-04-30  |  40KB  |  1,286 lines

  1. ════════════════════════════════════════════════════════════════════════════════
  2.  Area:    QuickBasic
  3.   Msg:    #4740
  4.  Date:    03-20-93 11:45 (Public)
  5.  From:    JEFF FREEMAN
  6.  To:      ALL
  7.  Subject: Copyright laws in the USA
  8. ────────────────────────────────────────────────────────────────────────────────
  9. I just spent 2 hours at the library reading copyright laws and how-to books.
  10. This is what I came up with.  This information contradicts a few of the
  11. opinions that had been expressed in this echo, but since the following
  12. information is easily verifiable, I am not inviting debate.  In other words,
  13. if you don't believe me then go to the library and look it up for yourself -
  14. THEN post.
  15.  
  16. Everything you write is automatically owned by you (you own the copyright).
  17. Copyrights last for the remainder of your life, plus 50 years.
  18.  
  19. Publication (posting in the echo, giving to a friend, uploading to a BBS) of
  20. your work without a copyright notice puts the work in the public domain.
  21.  
  22. However, you may still register the copyright within 5 years and take other
  23. action to re-claim/recover from publishing a work without a copyright notice.
  24.  
  25. Anyone may publish your work if it is in the Public Domain.
  26.  
  27. Being in the Public Domain means the work is unprotected by Copyright laws.
  28.  
  29. Within 3 months of publication, two copies (one for computer programs) of the
  30. work must be deposted in the Copyright Office (address follows).
  31.  
  32. Only original works of authorship may be copyrighted.  You cannot copyright
  33. someone else's work.
  34.  
  35. Why register a copyright?
  36.  
  37.     If registered prior to infringement, you may receive Damages and Attorney
  38. fees.  Otherwise you must pay attorney fees and are not entitled to Damages.
  39.  
  40.     You must register to file a suit.  If a copyright infringement occurs
  41. before you have registered the copyright, for example, you must register the
  42. copyright to sue the infringer.  Still, you cannot be awarded Damages and
  43. must pay your own attorney fees.
  44.  
  45.     The burden of proof lies on the infringer.  If you register my work, for
  46. example, the burden of proof is mine.
  47.  
  48.     You must register to overcome publishing your work without a copyright
  49. notice.
  50.  
  51.     You needn't be the author in order to obtain a copyright if:
  52.  
  53.         The Author has Asigned you the right.
  54.         You employed the Author to create the work.
  55.  
  56.     In regards to the current echowide project, each contributor retains the
  57. copyright for their contribution, however the compiler may copyright the work
  58. as a whole.
  59.  
  60.     Lastly, what all this means is that if you post something without a
  61. copyright notice in this echo then anyone may publish that work, but no one
  62.  
  63. can copyright it.
  64.  
  65.     If you post something and include the copyright notice, then by statute
  66. you should depost (within 3 months) a copy of the program in the Copyright
  67. Office. Mail form TX and A filing fee of $10 plus $4 per additional
  68. certificate.  Write to the following address for form TX, fill it out and
  69. mail in a copy of your program:
  70.  
  71.             Register of Copyrights
  72.             Copyright Office
  73.             Library of Congress
  74.             Washington, DC  20559
  75.  
  76.     You may register the copyright within 5 years of publication (with the
  77. copyright notice).  You SHOULD register the copyright within 3 months of
  78. publication.
  79.  
  80.     You *cannot* register someone else's copyright!  If you want to release
  81. code to the "public domain", simply omit the copyright notice and make no
  82. attempt to reclaim it.
  83.  
  84. ---
  85.  * Origin: WarWorld's point away from home... (1:124/7006.1)
  86.  
  87.  
  88.  
  89. ════════════════════════════════════════════════════════════════════════════════
  90.  Area:    QuickBasic
  91.   Msg:    #4914
  92.  Date:    03-19-93 21:00 (Public)
  93.  From:    QUINN TYLER JACKSON
  94.  To:      ALL
  95.  Subject: Formula Solver 1.4    1/
  96. ────────────────────────────────────────────────────────────────────────────────
  97. ________O_/________________________| SNIP |______________________\_O_______
  98.         O \                        | HERE |                      / O
  99. 'This file created by PostIt! v4.0.
  100. '>>> Start of page 1.
  101.  
  102.  '     THE                                *                  RDF14.BAS
  103.  '  JACK MACK                            *
  104.  '  RECURSIVE                           * ***    *     *
  105.  '   DESCENT                           *     *     * *
  106.  '  ALGEBRAIC       ******             *     *     * *
  107.  '   FORMULA            *               `****'   *     *
  108.  '     AND             **      ***************************************
  109.  '  DEFINABLE            *    *
  110.  '  FUNCTIONS            *   *
  111.  '   ENGINE         *****'  *         *              *
  112.  '                         *         *                *
  113.  '        *               *         *                  *
  114.  '       * *             *         *    5(100-x+2b)     *   *     *
  115.  '      *   *           *          *                    *   *     *
  116.  '           *         *           *   *************    *   *     *
  117.  '            *       *            *                    *   `******
  118.  '             *     *             *       3!+35y       *         *
  119.  '              *   *               *                  *          *
  120.  '               * *                 *                *      `****'
  121.  '  v1.4          *                   *              *
  122.  '              Public Domain Code Written By Quinn Tyler Jackson
  123.  '
  124.  '
  125.  '           *                        *                           *
  126.  '            ****************************************************
  127.  '            *ALL FUTURE VERSIONS WILL LOSE QBASIC COMPATIBILITY*
  128.  '          ***     AND WILL ADOPT PDS/VBDOS EXTENSIONS, SO      ***
  129.  '            *           GRAB THIS ONE WHILE YOU CAN!           *
  130.  '            ****************************************************
  131.  '           *                        *                           *
  132.  '
  133.  '
  134.  ' DEDICATION:
  135.  '
  136.  ' This program is dedicated to my wife Laleh, and our three children,
  137.  '  Ozra, Shahraam, and Arehzou, who give up a lot of their time with
  138.  '           me so I can program at this infernal keyboard!
  139.  '
  140.  ' The superlative, full-featured equation solver, featuring:
  141.  '
  142.  '  1. STANDARD AND ADVANCED OPERATORS
  143.  '  2. STANDARD PRECEDENCE SOLVING ALGORITHM
  144.  '  3. ASSIGNABLE VARIABLES WITH DESCRIPTIVE NAMES
  145.  '  4. NEW TO VERSION 1.4!!!!  Function definition!
  146.  '
  147.  '  I've supplied the module, you figure it out!
  148.  
  149. DECLARE FUNCTION funSolveEquation! (InText$)
  150.  
  151. DECLARE FUNCTION fqjEval! (InText$)
  152. DECLARE FUNCTION fqjVAL! (InText$)
  153. DECLARE FUNCTION fqjFetchVar! (VarName$)
  154. DECLARE FUNCTION fqjInList% (OpTyp$, Op$)
  155. DECLARE FUNCTION fqjSolveFormula! (InToken$)
  156. DECLARE FUNCTION fqjEvalErrMsg$ ()
  157. DECLARE FUNCTION fqjEvaluate! (InText$)
  158. DECLARE SUB sjfParse (Word$(), Txt$, Spt$, WordNum%)
  159. DECLARE SUB sqjApplyOp (Op$, x!, y!)
  160. DECLARE SUB sqjAssignFun (FunctName$, Formula$, Protection%)
  161. DECLARE SUB sqjAssignVar (VarName$, VarValue!, Protection%)
  162. DECLARE SUB sqjDesParse (Phase%, x!)
  163. DECLARE SUB sqjGetToken ()
  164.  
  165. CONST TRUE = -1
  166. CONST FALSE = NOT TRUE
  167.  
  168. CONST ASSIGNMENT = ":="     ' This can be changed to suit your needs
  169.                             ' Using a simple = is possible, since
  170. ' logical
  171.                             ' equality is a double == with this parser,
  172.                             ' but the PASCAL standard := is easier to
  173. ' deal
  174.                             ' with as an assignment operator for some.
  175.  
  176. ' Operator classes                PRECEDENCE
  177. '---------------------------------------------------
  178. CONST POWER = "^}?**>><<!`#"       ' FIRST
  179. CONST MULTDIV = "*/\%"             ' SECOND
  180. CONST ADDSUB = "+-"                ' THIRD
  181. CONST LOGICAL = "&|=~<=<>==>"      ' FOURTH
  182. CONST UNARY = "!#`"                ' UNARY operators
  183.  
  184.  
  185. DIM SHARED WHITESPACE AS STRING
  186. DIM SHARED OPERATOR AS STRING
  187.  
  188. CONST OperatorClass = 1
  189. CONST DigitClass = 2
  190. CONST FunctionClass = 3
  191.  
  192. CONST MAXLEVELS = 10    ' Numbers of levels of nesting allowed
  193. CONST MAXCOMMANDS = 10  ' Number of commands per statement
  194. CONST MAXPARAMS = 10    ' Number of parameters in a function allowed
  195. CONST SYMMAX = 200      ' Total number of symbols allowed
  196. CONST VARMAX = 100      ' Total number of variables allowed
  197. CONST FUNMAX = 100      ' Total number of definable functions allowed
  198. CONST SYSMAX = 25
  199.  
  200. TYPE SymbolTableType
  201.         SymName AS STRING * 30  ' Name of the symbol
  202.         SymLvl AS INTEGER       ' Level that it was assigned
  203.         SymType AS INTEGER      ' Whether it is a variable or function
  204.  
  205.         TabPtr AS INTEGER       ' Ptr to data tables
  206. END TYPE
  207.  
  208. ' Used by SymType
  209. CONST SymVARIABLE = 0
  210. CONST SymFUNCTION = 1
  211.  
  212. CONST PROTECTED = -1
  213. CONST UNPROTECTED = 1
  214.  
  215. DIM SHARED ErrorCode AS INTEGER
  216. DIM SHARED WarningCode AS INTEGER
  217. ' Error code constants
  218. CONST eqjDivisionByZero = 1
  219. CONST eqjProtectedFunction = 2
  220. CONST eqjProtectedVariable = 3
  221. CONST eqjSymbolTableFull = 4
  222. CONST eqjVariableTableFull = 5
  223. CONST eqjFucntionTableFull = 6
  224. CONST eqjMismatchedParenthesis = 7
  225. CONST eqjUndefinedVariable = 8
  226. CONST eqjFunctionDefaultUsed = 9
  227. CONST eqjSyntaxError = 10
  228.  
  229. ' Variables global to this module...
  230. DIM SHARED SymTable(SYMMAX) AS SymbolTableType  ' Table holds symbols
  231. DIM SHARED VarTable(VARMAX) AS SINGLE           ' Table hold variable_
  232.  data
  233. DIM SHARED ParTable(FUNMAX) AS STRING   ' Table holds function_
  234.  parameters
  235. DIM SHARED ForTable(FUNMAX) AS STRING   ' Table holds function formulas
  236. DIM SHARED SysTable(SYSMAX) AS STRING
  237.  
  238. DIM SHARED SymPtr AS INTEGER    ' Points to highest symbol in table
  239. DIM SHARED VariPtr AS INTEGER   ' Points to highest variable in table
  240. DIM SHARED FunPtr AS INTEGER    ' Points to highest function in table
  241. DIM SHARED LvlPtr AS INTEGER    ' Indicates the current level being
  242.                                 ' evaluated
  243. >>> Continued to next message
  244.  
  245.  * OLX 2.1 TD * A program is just a big bug that happened to work....
  246.  
  247. --- Maximus/2 2.01wb
  248.  * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
  249.  
  250.  
  251.  
  252. ════════════════════════════════════════════════════════════════════════════════
  253.  Area:    QuickBasic
  254.   Msg:    #4915
  255.  Date:    03-19-93 21:00 (Public)
  256.  From:    QUINN TYLER JACKSON
  257.  To:      ALL
  258.  Subject: Formula Solver 1.4    2/
  259. ────────────────────────────────────────────────────────────────────────────────
  260. >>> Continued from previous message
  261. DIM SHARED PTR(MAXLEVELS) AS INTEGER    ' Points to location in string_
  262.  being
  263.                                         ' evluated
  264. DIM SHARED EXPR$(MAXLEVELS)       ' Expression being evaluated
  265. DIM SHARED TOKEN$(MAXLEVELS)            ' Current token being evaluated
  266. DIM SHARED TypeToken(MAXLEVELS)         ' Type of current token
  267.  
  268. CLEAR , , 1024 * 4
  269.  
  270.  
  271. CLS
  272. ' Initialize tables
  273. nul = fqjEvaluate("")
  274.  
  275. ' The following module level code is used for testing and debugging.
  276.  
  277. DO
  278.     LvlPtr = 0
  279.     TestDeep% = 0   ' Find all cases of TestDeep% and erase when
  280.                     ' you modify this module to fit into your programs,
  281.                     ' since it is only used for testing purposes
  282.     LOCATE 4
  283.     PRINT "Formula --->" + SPACE$(80);
  284.     LOCATE 4, 16
  285.     LINE INPUT Test$
  286.     LOCATE 6
  287.     Synch! = TIMER          'synchronize to the system timer
  288.     DO
  289.       Start! = TIMER
  290.     LOOP WHILE Start! = Synch!
  291.     PRINT "Result ---->", funSolveEquation(Test$); "                   "
  292.     LOCATE 3
  293.     PRINT "Time ------>"; TIMER - Start!; "                "; TAB(50);_
  294.  "Recursion Depth: "; TestDeep%
  295.     LOCATE 1
  296.     PRINT "Last error->", fqjEvalErrMsg$; "                            "+_
  297. "                           "
  298.  
  299.     VIEW PRINT 8 TO 24
  300.     FOR i% = 1 TO SymPtr
  301.         IF i% MOD 17 = 0 THEN
  302.             LOCATE 8
  303.             Sec% = TRUE
  304.         END IF
  305.  
  306.         IF Sec% THEN
  307.             LOCATE , 40
  308.         END IF
  309.  
  310.         SELECT CASE SymTable(i%).SymType
  311.             CASE SymVARIABLE
  312.                 PRINT "V: "; RTRIM$(SymTable(i%).SymName); " -->";
  313.  
  314.                 SELECT CASE SymTable(i%).SymLvl
  315.                     CASE IS > PROTECTED
  316.                         PRINT VarTable(SymTable(i%).TabPtr); "         "+_
  317. " "
  318.                     CASE ELSE
  319.                         PRINT fqjFetchVar(RTRIM$(SymTable(i%).SymName))_
  320. ; "          "
  321.                 END SELECT
  322.             CASE SymFUNCTION
  323.                 PRINT "F: "; RTRIM$(SymTable(i%).SymName)
  324.         END SELECT
  325.     NEXT i%
  326.     Sec% = FALSE
  327.     VIEW PRINT
  328. LOOP
  329.  
  330.  
  331. PredefinedFunctionData:
  332.  
  333. ' The following functions are read into the symbol table the first
  334. ' time the function is called.  I thought they would be of some help.
  335. ' Note that they are PROTECTED.  That is to say, they cannot be
  336. ' redefined
  337. ' by the user, in the same way the user cannot redefine built-in
  338. ' functions
  339. ' in BASIC.  Add any to this list any functions that would suit your
  340. ' needs.
  341.  
  342. DATA "square_root[x]","2}x"
  343. DATA "cube_root[x]","3}x"
  344. DATA "rand[high:100,seed:timer]","high?seed"
  345. '                          ^
  346. '                          |
  347. '         seeds with timer if no seed supplied
  348. '
  349. DATA "area_of_circle[r,pi:3.1415926]","pi*r^2"
  350. '                         ^^^^^^^^^
  351. '                             |
  352. '                  defaults if none supplied
  353. '                       |          |
  354. '                       V          V
  355. DATA "distance[x1,y1,z1:0,x2,y2,z2:0]","square_root[(x1-x2)^2+(y1-y2"+_
  356. ")^2+(z1-z2)^2]"
  357. DATA "*END*",""
  358.  
  359. ' These following system variables.  They cannot be redefined, since
  360. ' they
  361. ' return system information.  When you add a system variable to this
  362. ' list, you must also add it to the SELECT CASE VarName$ structure in
  363. ' the FUNCTION fqjFetchVar.  Here are a few to get you started.
  364.  
  365. SystemVariableData:
  366. DATA "timer"
  367.  
  368. DATA "string_mem"
  369. DATA "free_mem"
  370. DATA "stack"
  371. DATA "rnd"
  372. DATA "*END*"
  373.  
  374. FUNCTION fqjEval (InText$)
  375.  
  376. EXPR$(LvlPtr) = UCASE$(InText$)
  377.  
  378. PTR(LvlPtr) = 1
  379.  
  380. AssignmentPtr% = INSTR(EXPR$(LvlPtr), ASSIGNMENT)
  381. ParenPtr% = INSTR(EXPR$(LvlPtr), "[")
  382.  
  383. IF AssignmentPtr% = 0 THEN ' just do a simple evaluation
  384.             EXPR$(LvlPtr) = EXPR$(LvlPtr)
  385.             CALL sqjGetToken
  386.             CALL sqjDesParse(1, x)
  387.             fqjEval = x
  388. ELSE                       ' assign a variable or function!
  389.     VariableName$ = LTRIM$(RTRIM$(LEFT$(EXPR$(LvlPtr), AssignmentPtr% -_
  390.  1)))
  391.  
  392.     SELECT CASE (ParenPtr% > 0) AND (ParenPtr% < AssignmentPtr%)
  393.         CASE 0
  394.                 Valu = fqjEval(MID$(EXPR$(LvlPtr), AssignmentPtr% + 2))
  395.                 CALL sqjAssignVar(VariableName$, Valu, LvlPtr)
  396.                 fqjEval = Valu
  397.         CASE ELSE
  398.                 Formula$ = LTRIM$(MID$(EXPR$(LvlPtr), AssignmentPtr% +_
  399.  2))
  400.                 CALL sqjAssignFun(VariableName$, Formula$, UNPROTECTED)
  401.     END SELECT
  402. END IF
  403. END FUNCTION
  404.  
  405. FUNCTION fqjEvalErrMsg$ ()
  406. >>> Continued to next message
  407.  
  408.  * OLX 2.1 TD * A program is just a big bug that happened to work....
  409.  
  410. --- Maximus/2 2.01wb
  411.  * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
  412.  
  413.  
  414.  
  415. ════════════════════════════════════════════════════════════════════════════════
  416.  Area:    QuickBasic
  417.   Msg:    #4916
  418.  Date:    03-19-93 21:00 (Public)
  419.  From:    QUINN TYLER JACKSON
  420.  To:      ALL
  421.  Subject: Formula Solver 1.4    3/
  422. ────────────────────────────────────────────────────────────────────────────────
  423. >>> Continued from previous message
  424. ' This function returns either a null string for no error, or a
  425. ' description
  426. ' of the most recent error that occurred in processing a statement.
  427. ' Errors
  428. ' terminate the process and return 0, whereas warnings continue
  429. ' functioning
  430. ' and return a value based upon defaults.
  431.  
  432. SELECT CASE ErrorCode + WarningCode
  433.     CASE 0
  434.         T$ = ""
  435.     CASE eqjDivisionByZero
  436.         T$ = "Division by zero"
  437.     CASE eqjProtectedVariable
  438.         T$ = "Attempt to overwrite protected variable"
  439.     CASE eqjProtectedFunction
  440.         T$ = "Attrmpt to redefine protected function"
  441.     CASE eqjSymbolTableFull
  442.         T$ = "Symbol table full"
  443.     CASE eqjVariableTableFull
  444.         T$ = "Variable table full"
  445.     CASE eqjFunctionTableFull
  446.         T$ = "Function table full"
  447.     CASE eqjMismatchedParenthesis
  448.         T$ = "Mismatched parenthesis encountered"
  449.     CASE eqjUndefinedVariable
  450.         T$ = "Undefined variable referenced -- assuming value of 0"
  451.     CASE eqjFunctionDefaultUsed
  452.         T$ = "Function parameter not supplied -- default assumed"
  453.     CASE eqjSyntaxError
  454.         T$ = "General syntax error"
  455. END SELECT
  456.  
  457. fqjEvalErrMsg$ = T$
  458. END FUNCTION
  459.  
  460. FUNCTION fqjEvaluate (InText$)
  461.  
  462.  
  463. InText$ = LTRIM$(InText$)
  464.  
  465. ' Expand unary suffixes for easier parsing
  466.  FOR i% = 1 TO LEN(UNARY)
  467.     Temp$ = MID$(UNARY, i%, 1)
  468.     IF INSTR(InText$, Temp$) THEN
  469.         TempPtr = 1
  470.         DO
  471.             Char$ = MID$(InText$, TempPtr, 1)
  472.             IF fqjInList(UNARY, Char$) THEN
  473.                 InText$ = LEFT$(InText$, TempPtr) + "0" + MID$(InText$,_
  474.  TempPtr + 1)
  475.             END IF
  476.  
  477.             TempPtr = TempPtr + 1
  478.         LOOP UNTIL TempPtr >= LEN(InText$)
  479.     END IF
  480. NEXT i%
  481.  
  482. fqjEvaluate = fqjVAL(InText$)
  483.  
  484. END FUNCTION
  485.  
  486. FUNCTION fqjFetchVar (VarName$)
  487.  
  488. SELECT CASE VarName$
  489.     CASE "TIMER"
  490.         fqjFetchVar = TIMER
  491.     CASE "STRING_MEM"
  492.         fqjFetchVar = FRE("A")
  493.     CASE "FREE_MEM"
  494.         fqjFetchVar = FRE(-1)
  495.     CASE "STACK"
  496.         fqjFetchVar = FRE(-2)
  497.     CASE "RND"
  498.         fqjFetchVar = RND
  499.     CASE ELSE
  500.         FOR i% = SymPtr TO 1 STEP -1
  501. '            IF SymTable(i%).SymLvl = LvlPtr OR SymTable(i%).SymLvl = 1
  502. ' THEN
  503.                 IF SymTable(i%).SymType = SymVARIABLE THEN
  504.                     IF RTRIM$(SymTable(i%).SymName) = VarName$ THEN
  505.                         fqjFetchVar = VarTable(SymTable(i%).TabPtr)
  506.                             EXIT FUNCTION
  507.                     END IF
  508.                 END IF
  509. '            END IF
  510.         NEXT i%
  511.         WarningCode = eqjUndefinedVariable
  512. END SELECT
  513. END FUNCTION
  514.  
  515. FUNCTION fqjInList% (OpTyp$, Op$)
  516.  
  517. IF LEN(Op$) THEN
  518.     IF INSTR(OpTyp$, Op$) > 0 THEN
  519.         fqjInList% = TRUE
  520.     END IF
  521. END IF
  522. END FUNCTION
  523.  
  524. FUNCTION fqjSolveFormula (InToken$)
  525.  
  526. DIM Param$(MAXPARAMS)
  527. DIM Default(MAXPARAMS)
  528. DIM ParValue$(MAXPARAMS)
  529. DIM ParValue(MAXPARAMS)
  530.  
  531.  
  532. Paren% = INSTR(InToken$, "[")
  533. FunctName$ = LTRIM$(RTRIM$(LEFT$(InToken$, Paren% - 1)))
  534. Par$ = MID$(InToken$, Paren% + 1, LEN(InToken$) - Paren% - 1)
  535.  
  536. FOR i% = 1 TO SymPtr
  537.     IF SymTable(i%).SymType = SymFUNCTION THEN
  538.         IF RTRIM$(SymTable(i%).SymName) = FunctName$ THEN
  539.             Formula$ = ForTable(SymTable(i%).TabPtr)
  540.             Para$ = ParTable(SymTable(i%).TabPtr)
  541.             CALL sjfParse(Param$(), Para$, ",", Tot%)
  542.             FOR a% = 1 TO Tot%
  543.                 Temp$ = Param$(a%)
  544.                 TempPtr = INSTR(Temp$, ":")
  545.                 SELECT CASE TempPtr
  546.                     CASE 0
  547.                         ' Do nothing
  548.                         Default(a%) = 0
  549.                     CASE ELSE
  550.                         Param$(a%) = LEFT$(Temp$, TempPtr - 1)
  551.                         Default(a%) = fqjEvaluate(MID$(Temp$, TempPtr +_
  552.  1))
  553.                 END SELECT
  554.             NEXT a%
  555.             EXIT FOR
  556.         END IF
  557.     END IF
  558. NEXT i%
  559.  
  560. CALL sjfParse(ParValue$(), Par$, ",", Tot2%)
  561.  
  562. FOR i% = 1 TO Tot%
  563.  
  564.     IF ParValue$(i%) = "" THEN
  565.         ParValue(i%) = Default(i%)
  566.         WarningCode = eqjFunctionDefaultUsed
  567.     ELSE
  568.         ParValue(i%) = fqjEvaluate(ParValue$(i%))
  569.     END IF
  570. >>> Continued to next message
  571.  
  572.  * OLX 2.1 TD * A program is just a big bug that happened to work....
  573.  
  574. --- Maximus/2 2.01wb
  575.  * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
  576.  
  577.  
  578.  
  579. ════════════════════════════════════════════════════════════════════════════════
  580.  Area:    QuickBasic
  581.   Msg:    #4917
  582.  Date:    03-19-93 21:00 (Public)
  583.  From:    QUINN TYLER JACKSON
  584.  To:      ALL
  585.  Subject: Formula Solver 1.4    4/
  586. ────────────────────────────────────────────────────────────────────────────────
  587. >>> Continued from previous message
  588.     ' Push the parameters to the variable stack temporarily
  589.  
  590.     IF SymPtr < SYMMAX THEN
  591.         ' Since it wasn't, put it there
  592.         VariPtr = VariPtr + 1
  593.         SymPtr = SymPtr + 1
  594.  
  595.         IF VariPtr <= VARMAX THEN
  596.             SymTable(SymPtr).SymName = Param$(i%)
  597.             SymTable(SymPtr).SymType = SymVARIABLE
  598.             SymTable(SymPtr).TabPtr = VariPtr
  599.             SymTable(SymPtr).SymLvl = LvlPtr + 1
  600.             VarTable(VariPtr) = ParValue(i%)
  601.         ELSE
  602.             ErrorCode = eqjVariableTableFull
  603.         END IF
  604.     ELSE
  605.         ErrorCode = eqjSymbolTableFull
  606.     END IF
  607.  
  608. NEXT i%
  609.  
  610. fqjSolveFormula = fqjEvaluate(Formula$)
  611.  
  612. VariPtr = VariPtr - Tot%    ' Clear the variable stack of
  613. SymPtr = SymPtr - Tot%      ' variables used in parameter
  614. END FUNCTION
  615.  
  616. FUNCTION fqjVAL (InText$)
  617.  
  618. ' Initialize some variables....
  619.  
  620. IF LvlPtr < MAXLEVELS THEN
  621.     LvlPtr = LvlPtr + 1
  622.  
  623.     DIM CommandArray$(MAXCOMMANDS)
  624.  
  625.         ' separate statement by semicolons
  626.         CALL sjfParse(CommandArray$(), InText$, ";", Tot%)
  627.  
  628.         FOR i% = 1 TO Tot%
  629.             fqjVAL = fqjEval(CommandArray$(i%))
  630.  
  631.             IF ErrorCode THEN
  632.                 fqjVAL = 0
  633.                 EXIT FUNCTION
  634.             END IF
  635.         NEXT i%
  636.  
  637.     LvlPtr = LvlPtr - 1
  638.  
  639.     ELSE
  640.  
  641.         ErrorCode = eqjNestedTooDeep
  642. END IF
  643. END FUNCTION
  644.  
  645. FUNCTION funSolveEquation (InText$)
  646.  
  647. STATIC Initialized%
  648.  
  649. IF Initialized% = FALSE THEN
  650.     RESTORE PredefinedFunctionData
  651.     DO
  652.         READ N$, F$
  653.         IF N$ <> "*END*" THEN
  654.             CALL sqjAssignFun(N$, F$, PROTECTED)
  655.         END IF
  656.     LOOP UNTIL N$ = "*END*"
  657.  
  658.     RESTORE SystemVariableData
  659.     DO
  660.         READ N$
  661.         IF N$ <> "*END*" THEN
  662.             CALL sqjAssignVar(N$, 0, PROTECTED)
  663.         END IF
  664.     LOOP UNTIL N$ = "*END*"
  665.  
  666.     Initialized% = TRUE
  667. END IF
  668.  
  669. OPERATOR = ADDSUB + MULTDIV + POWER + LOGICAL
  670. WHITESPACE = " " + CHR$(13) + CHR$(9) + CHR$(10)
  671.  
  672. ErrorCode = 0
  673. WarningCode = 0
  674. LvlPtr = 0
  675. funSolveEquation = fqjEvaluate(InText$)
  676.  
  677. END FUNCTION
  678.  
  679. SUB sjfParse (Word$(), Txt$, Spt$, WordNum%)
  680.  
  681. Text$ = Txt$
  682. WordNum% = 0
  683. SepLen% = LEN(Spt$)
  684.  
  685. DO
  686.     WordNum% = WordNum% + 1
  687.     EndWord% = INSTR(Text$, Spt$)
  688.     IF EndWord% THEN
  689.         Word$(WordNum%) = LEFT$(Text$, EndWord% - 1)
  690.         Text$ = MID$(Text$, EndWord% + SepLen%)
  691.     ELSE
  692.         Word$(WordNum%) = Text$
  693.         Text$ = ""
  694.  
  695.     END IF
  696. LOOP WHILE LEN(Text$)
  697. END SUB
  698.  
  699. SUB sqjApplyOp (Op$, x, y)
  700.  
  701. ' This is the meat of the operator section, and can be modified to
  702. ' includ ANY symbol as an operator, or any two byte symbol combination.
  703. ' Any symbol added has to be added to the constant that sets its
  704. ' level of precedence.
  705.  
  706. SELECT CASE Op$
  707.     CASE "-"    ' subtraction
  708.         x = x - y
  709.     CASE "+"    ' addition
  710.         x = x + y
  711.     CASE "*"    ' multiplication
  712.         x = x * y
  713.     CASE "/"    ' division
  714.         IF y <> 0 THEN
  715.             x = x / y
  716.         ELSE
  717.             ErrorCode = eqjDivisionByZero
  718.         END IF
  719.     CASE "\"    ' integer division
  720.         IF y <> 0 THEN
  721.             x = x \ y
  722.         ELSE
  723.             ErrorCode = eqjDivisionByZero
  724.         END IF
  725.     CASE "%"    ' modulo division
  726.         IF y <> 0 THEN
  727.             x = x MOD y
  728.         ELSE
  729.             ErrorCode = eqjDivisionByZero
  730.         END IF
  731.     CASE "^", "**"  ' exponentation
  732.         x = x ^ y
  733.     CASE "}"    ' the rth root of y
  734.         IF y <> 0 THEN
  735.             x = y ^ (1 / x)
  736. >>> Continued to next message
  737.  
  738.  * OLX 2.1 TD * A program is just a big bug that happened to work....
  739.  
  740. --- Maximus/2 2.01wb
  741.  * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
  742.  
  743.  
  744.  
  745. ════════════════════════════════════════════════════════════════════════════════
  746.  Area:    QuickBasic
  747.   Msg:    #4918
  748.  Date:    03-19-93 21:00 (Public)
  749.  From:    QUINN TYLER JACKSON
  750.  To:      ALL
  751.  Subject: Formula Solver 1.4    5/
  752. ────────────────────────────────────────────────────────────────────────────────
  753. >>> Continued from previous message
  754.         ELSE
  755.             ErrorCode = eqjDivisionByZero
  756.         END IF
  757.     CASE "?"    ' random number from 0 to x, seed y
  758.         RANDOMIZE y
  759.         x = RND * x
  760.     CASE "<<"   ' bitshift left y by x bits
  761.         x = INT(y) * 2 ^ INT(x)
  762.     CASE ">>"   ' bitshift right y by x bits
  763.         x = INT(y) \ 2 ^ INT(x)
  764.     CASE "!"    ' factorial
  765.         Temp& = 1
  766.         FOR i% = 1 TO x
  767.                 Temp& = Temp& * i%
  768.         NEXT i%
  769.         x = Temp&
  770.     CASE "`"
  771.         x = ABS(x)
  772.     CASE "#"    ' absolute
  773.         x = INT(x)
  774.     CASE "<"    ' logical less than than
  775.         x = x < y
  776.     CASE "<=", "=<" ' logical less than or equal to
  777.         x = x <= y
  778.     CASE ">"    ' logical greater than
  779.         x = x > y
  780.     CASE ">=", "=>" ' logical greater than or equal to
  781.         x = x >= y
  782.     CASE "=="    ' logical equality
  783.         x = x = y
  784.     CASE "<>" ' logical inequality
  785.         x = x <> y
  786.     CASE "|=", "=|" ' logical implication
  787.         x = x IMP y
  788.     CASE "&=", "=&" ' logical equivlance
  789.         x = x EQV y
  790.     CASE "&"   ' bitwise AND
  791.         x = x AND y
  792.     CASE "|"    ' bitwise OR
  793.         x = x OR y
  794.     CASE "~"    ' bitwise XOR
  795.         x = x XOR y
  796. END SELECT
  797. END SUB
  798.  
  799. SUB sqjAssignFun (FunctName$, Formula$, Protection%)
  800.  
  801. FunctName$ = UCASE$(FunctName$)
  802.  
  803. ParPtr% = INSTR(FunctName$, "[")
  804. NamePart$ = LEFT$(FunctName$, ParPtr% - 1)
  805. ParamPart$ = MID$(FunctName$, ParPtr% + 1, LEN(FunctName$) - ParPtr% -_
  806.  
  807.  1)
  808.  
  809. ' First we see if this function is already in the list
  810. FOR i% = 1 TO SymPtr
  811.     IF SymTable(i%).SymType = SymFUNCTION THEN
  812.         IF RTRIM$(SymTable(i%).SymName) = NamePart$ THEN
  813.             IF SymTable(i%).SymLvl <> PROTECTED THEN
  814.                 ' Since it was, just change its formula
  815.                 IF ParamPart$ <> "" THEN
  816.                     ' Make sure it just isn't a formula
  817.                     ' that uses empty parenthesis for the params.
  818.                     ParTable(SymTable(i%).TabPtr) = ParamPart$
  819.                 END IF
  820.             ELSE
  821.                 ErrorCode = eqjProtectedFunction
  822.             END IF
  823.             ForTable(SymTable(i%).TabPtr) = Formula$
  824.             EXIT SUB
  825.         END IF
  826.     END IF
  827. NEXT i%
  828.  
  829. IF SymPtr < SYMMAX THEN
  830.     ' Since it wasn't, put it there
  831.     FunPtr = FunPtr + 1
  832.     SymPtr = SymPtr + 1
  833.  
  834.     IF FunPtr <= FUNMAX THEN
  835.         SymTable(SymPtr).SymName = NamePart$
  836.         SymTable(SymPtr).SymType = SymFUNCTION
  837.         SymTable(SymPtr).SymLvl = Protection%
  838.         SymTable(SymPtr).TabPtr = FunPtr
  839.         ParTable(FunPtr) = ParamPart$
  840.         ForTable(FunPtr) = Formula$
  841.     ELSE
  842.         ErrorCode = eqjFunctionTableFull
  843.     END IF
  844. ELSE
  845.     ErrorCode = eqjSymbolTableFull
  846. END IF
  847. END SUB
  848.  
  849. SUB sqjAssignVar (VarName$, VarValue, Protection%)
  850. VarName$ = UCASE$(VarName$)
  851.  
  852. ' First we see if this variable is already in the list
  853. FOR i% = 1 TO SymPtr
  854.     IF SymTable(i%).SymType = SymVARIABLE THEN
  855.         IF RTRIM$(SymTable(i%).SymName) = VarName$ THEN
  856.             IF SymTable(i%).SymLvl <> PROTECTED THEN
  857.                 IF SymTable(i%).SymLvl = LvlPtr THEN
  858.                     ' Since it was, just change its value
  859.                     VarTable(SymTable(i%).TabPtr) = VarValue
  860.  
  861.                     EXIT SUB
  862.                 END IF
  863.             ELSE
  864.                 ErrorCode = eqjProtectedVariable
  865.                 EXIT SUB
  866.             END IF
  867.         END IF
  868.     END IF
  869. NEXT i%
  870.  
  871. IF SymPtr < SYMMAX THEN
  872.     ' Since it wasn't, put it there
  873.     VariPtr = VariPtr + 1
  874.     SymPtr = SymPtr + 1
  875.  
  876.     IF VariPtr <= VARMAX THEN
  877.         SymTable(SymPtr).SymName = VarName$
  878.         SymTable(SymPtr).SymType = SymVARIABLE
  879.         SymTable(SymPtr).TabPtr = VariPtr
  880.         SymTable(SymPtr).SymLvl = Protection%
  881.         VarTable(VariPtr) = VarValue
  882.     ELSE
  883.         ErrorCode = eqjVariableTableFull
  884.     END IF
  885. ELSE
  886.     ErrorCode = eqjSymbolTableFull
  887. END IF
  888. END SUB
  889.  
  890. SUB sqjDesParse (Phase%, x)
  891.  
  892. SHARED TestDeep%    ' This variable used for testing how deep recursion_
  893.  goes
  894. ' This is the central cortex of this module.
  895. ' It uses wicked recursion, so beware!  In fact, this routine is so
  896. ' recursive that unless you're a major masochist, you'd better leave it
  897. ' well enough alone!
  898. TestDeep% = TestDeep% + 1   ' Used for testing phase only
  899. >>> Continued to next message
  900.  
  901.  * OLX 2.1 TD * A program is just a big bug that happened to work....
  902.  
  903. --- Maximus/2 2.01wb
  904.  * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
  905.  
  906.  
  907.  
  908. ════════════════════════════════════════════════════════════════════════════════
  909.  Area:    QuickBasic
  910.   Msg:    #4919
  911.  Date:    03-19-93 21:00 (Public)
  912.  From:    QUINN TYLER JACKSON
  913.  To:      ALL
  914.  Subject: Formula Solver 1.4    6/
  915. ────────────────────────────────────────────────────────────────────────────────
  916. >>> Continued from previous message
  917. SELECT CASE Phase%
  918.  
  919.     CASE 1
  920.         ' See if something of a higher precedence should be done first.
  921.         CALL sqjDesParse(2, x)
  922.  
  923.         Op$ = TOKEN$(LvlPtr)
  924.  
  925.         ' The lowest level of precedence is handled by this Level.
  926.  
  927.         DO WHILE fqjInList(LOGICAL, Op$)
  928.             CALL sqjGetToken
  929.             CALL sqjDesParse(2, y)
  930.             CALL sqjApplyOp(Op$, x, y)
  931.             Op$ = TOKEN$(LvlPtr)
  932.         LOOP
  933.  
  934.     CASE 2
  935.         ' See if something of a higher precedence should be done first.
  936.         CALL sqjDesParse(3, x)
  937.         Op$ = TOKEN$(LvlPtr)
  938.  
  939.         DO WHILE fqjInList(ADDSUB, Op$)
  940.             CALL sqjGetToken
  941.             CALL sqjDesParse(3, y)
  942.             CALL sqjApplyOp(Op$, x, y)
  943.             Op$ = TOKEN$(LvlPtr)
  944.         LOOP
  945.  
  946.     CASE 3
  947.         ' See if something of a higher precedence should be done first.
  948.         CALL sqjDesParse(4, x)
  949.  
  950.         Op$ = TOKEN$(LvlPtr)
  951.  
  952.         DO WHILE fqjInList(MULTDIV, Op$)
  953.             CALL sqjGetToken
  954.             CALL sqjDesParse(4, y)
  955.             CALL sqjApplyOp(Op$, x, y)
  956.             Op$ = TOKEN$(LvlPtr)
  957.         LOOP
  958.  
  959.     CASE 4
  960.         ' See if something of a higher precedence should be done first.
  961.         CALL sqjDesParse(5, x)
  962.  
  963.         Op$ = TOKEN$(LvlPtr)
  964.  
  965.         IF fqjInList(POWER, Op$) THEN
  966.             CALL sqjGetToken
  967.             CALL sqjDesParse(5, y)
  968.             CALL sqjApplyOp(Op$, x, y)
  969.  
  970.         END IF
  971.  
  972.     CASE 5
  973.         Op$ = ""
  974.  
  975.         IF TypeToken(LvlPtr) = OperatorClass AND (fqjInList(ADDSUB,_
  976.  TOKEN$(LvlPtr))) THEN
  977.             Op$ = TOKEN$(LvlPtr)
  978.             CALL sqjGetToken
  979.         END IF
  980.  
  981.         CALL sqjDesParse(6, x)
  982.  
  983.         ' This handles negative prefixes
  984.         SELECT CASE Op$
  985.             CASE "-"
  986.                 x = -x
  987.         END SELECT
  988.  
  989.     CASE 6
  990.         ' This level handles parentheses
  991.  
  992.         IF TOKEN$(LvlPtr) = "(" AND TypeToken(LvlPtr) = OperatorClass_
  993.  THEN
  994.             CALL sqjGetToken
  995.             CALL sqjDesParse(1, x)
  996.  
  997.             IF TOKEN$(LvlPtr) <> ")" THEN
  998.                 ErrorCode = eqjMismatchedParenthesis
  999.             END IF
  1000.  
  1001.             CALL sqjGetToken
  1002.         ELSE
  1003.             SELECT CASE TypeToken(LvlPtr)
  1004.                 CASE DigitClass
  1005.                     x = VAL(TOKEN$(LvlPtr))
  1006.                     CALL sqjGetToken
  1007.                 CASE FunctionClass
  1008.                     x = fqjSolveFormula(TOKEN$(LvlPtr))
  1009.                     TypeToken(LvlPtr) = DigitClass
  1010.                     CALL sqjGetToken
  1011.             END SELECT
  1012.         END IF
  1013. END SELECT
  1014. END SUB
  1015.  
  1016. SUB sqjGetToken ()
  1017.  
  1018. TOKEN$(LvlPtr) = ""
  1019.  
  1020. DO WHILE fqjInList(WHITESPACE, MID$(EXPR$(LvlPtr), PTR(LvlPtr), 1))
  1021.     PTR(LvlPtr) = PTR(LvlPtr) + 1
  1022. LOOP
  1023.  
  1024.  
  1025. Temp$ = MID$(EXPR$(LvlPtr), PTR(LvlPtr), 1)
  1026. IF Temp$ >= "0" AND Temp$ <= "9" THEN
  1027.  
  1028.     ' Build up a number from its digits
  1029.     DO WHILE INSTR(" ()" + OPERATOR$, MID$(EXPR$(LvlPtr), PTR(LvlPtr),_
  1030.  1)) = 0
  1031.         TOKEN$(LvlPtr) = TOKEN$(LvlPtr) + MID$(EXPR$(LvlPtr),_
  1032.  PTR(LvlPtr), 1)
  1033.         PTR(LvlPtr) = PTR(LvlPtr) + 1
  1034.     LOOP
  1035.  
  1036.     TypeToken(LvlPtr) = DigitClass
  1037.     EXIT SUB
  1038. END IF
  1039.  
  1040. IF INSTR("()" + OPERATOR$, MID$(EXPR$(LvlPtr), PTR(LvlPtr), 1)) THEN
  1041.  
  1042.     TypeToken(LvlPtr) = OperatorClass
  1043.     TOKEN$(LvlPtr) = MID$(EXPR$(LvlPtr), PTR(LvlPtr), 1)
  1044.     PTR(LvlPtr) = PTR(LvlPtr) + 1
  1045.  
  1046.     IF INSTR("()", TOKEN$(LvlPtr)) THEN
  1047.         EXIT SUB
  1048.     ELSE
  1049.         ' see if it's a compound operator
  1050.         IF INSTR(OPERATOR$, MID$(EXPR$(LvlPtr), PTR(LvlPtr), 1)) THEN
  1051.             Temp$ = MID$(EXPR$(LvlPtr), PTR(LvlPtr), 1)
  1052.             IF Temp$ <> "-" THEN
  1053.                 TOKEN$(LvlPtr) = TOKEN$(LvlPtr) + Temp$
  1054.                 PTR(LvlPtr) = PTR(LvlPtr) + 1
  1055.             END IF
  1056.         END IF
  1057.     END IF
  1058.     EXIT SUB
  1059. END IF
  1060.  
  1061. Temp$ = MID$(EXPR$(LvlPtr), PTR(LvlPtr), 1)
  1062. IF Temp$ >= "@" AND Temp$ <= "Z" THEN
  1063. >>> Continued to next message
  1064.  
  1065.  * OLX 2.1 TD * A program is just a big bug that happened to work....
  1066.  
  1067. --- Maximus/2 2.01wb
  1068.  * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
  1069.  
  1070.  
  1071.  
  1072. ════════════════════════════════════════════════════════════════════════════════
  1073.  Area:    QuickBasic
  1074.   Msg:    #4920
  1075.  Date:    03-19-93 21:00 (Public)
  1076.  From:    QUINN TYLER JACKSON
  1077.  To:      ALL
  1078.  Subject: Formula Solver 1.4    7/
  1079. ────────────────────────────────────────────────────────────────────────────────
  1080. >>> Continued from previous message
  1081.     ' Build up a variable name based upon letters
  1082.     DO WHILE INSTR(" ()" + OPERATOR$, MID$(EXPR$(LvlPtr), PTR(LvlPtr),_
  1083.  1)) = 0
  1084.         Temp$ = MID$(EXPR$(LvlPtr), PTR(LvlPtr), 1)
  1085.         IF Temp$ <> "[" THEN
  1086.             TOKEN$(LvlPtr) = TOKEN$(LvlPtr) + Temp$
  1087.             PTR(LvlPtr) = PTR(LvlPtr) + 1
  1088.         ELSE
  1089.             TOKEN$(LvlPtr) = TOKEN$(LvlPtr) + "["
  1090.             DO WHILE SepPtr% <> -1
  1091.                 PTR(LvlPtr) = PTR(LvlPtr) + 1
  1092.                 T$ = MID$(EXPR$(LvlPtr), PTR(LvlPtr), 1)
  1093.                 SELECT CASE T$
  1094.                     CASE "["
  1095.                         SepPtr% = SepPtr% + 1
  1096.                     CASE "]"
  1097.                         SepPtr% = SepPtr% - 1
  1098.                 END SELECT
  1099.                 TOKEN$(LvlPtr) = TOKEN$(LvlPtr) + T$
  1100.             LOOP
  1101.             PTR(LvlPtr) = PTR(LvlPtr) + 1
  1102.             TypeToken(LvlPtr) = FunctionClass
  1103.             EXIT SUB
  1104.         END IF
  1105.     LOOP
  1106.  
  1107.     TOKEN$(LvlPtr) = STR$(fqjFetchVar(TOKEN$(LvlPtr)))
  1108.     TypeToken(LvlPtr) = DigitClass
  1109.     EXIT SUB
  1110. END IF
  1111. END SUB
  1112.  
  1113.  
  1114. ________O_/________________________| SNIP |______________________\_O_______
  1115.         O \                        | HERE |                      / O
  1116.  
  1117.  
  1118.  * OLX 2.1 TD * A program is just a big bug that happened to work....
  1119.  
  1120. --- Maximus/2 2.01wb
  1121.  * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
  1122.  
  1123.  
  1124.  
  1125. ════════════════════════════════════════════════════════════════════════════════
  1126.  Area:    QuickBasic
  1127.   Msg:    #4921
  1128.  Date:    03-19-93 21:58 (Public)
  1129.  From:    QUINN TYLER JACKSON
  1130.  To:      ALL
  1131.  Subject: About Formula Solver
  1132. ────────────────────────────────────────────────────────────────────────────────
  1133. The previous seven part post is the revised version of my formula
  1134. solver.  New to this version are definable functions and some bug fixes
  1135. to version 1.0.  I've numbered this 1.4 because there were 3
  1136. intermediate versions at my end before reaching this one.
  1137.  
  1138. This message is to serve as a brief tutorial on the syntax of the
  1139. FUNCTION funSolveEquation(InText$).
  1140.  
  1141. First of all, there are standard statements:
  1142.  
  1143. 1+1
  1144. 2+3
  1145. 9*2+2
  1146. etc.
  1147.  
  1148. That's fairly simple.  Then, there are more advanced operators, such as
  1149. ` and # and }.
  1150.  
  1151. -4` = 4  That is to say, ` returns the ABSOLUTE value of x.
  1152.  
  1153. 4.5# = 4  That is to say, # returns the integer part of x.
  1154.  
  1155. 2}4 means "the square root of 4"
  1156. 3}8 means "the cube root of 4"
  1157.  
  1158. That is, n}x returns the nth root of x.
  1159.  
  1160. Then, there are exotic operators, such as !, which is the factorial
  1161. symbol, which means that 5! returns 5 factorial, or 1x2x3x4x5, or 120.
  1162. 0! is 1 by definition.
  1163.  
  1164. There are other operators:
  1165.  
  1166. 5%2 works as 5 MOD 2
  1167. 5\2 does integer division
  1168. 5~7 works as 5 XOR 7
  1169. 5&7 works as 5 AND 7
  1170. 5|7 works as 5 OR 7
  1171.  
  1172. Some logical operators:
  1173.  
  1174. 1>2 returns 0, for false
  1175. 1<>2 returns -1, for true
  1176. 5==2 returns 0, for false
  1177. (1<3)|=(2==1) returns -1, for IMPLIED TRUTH
  1178.  
  1179. Parenthesis override standard BODMAS precedence.  Therefore:
  1180.  
  1181. 5*(1+2) returns 15, rather than 7.
  1182.  
  1183. VARIABLE ASSIGNMENT:
  1184.  
  1185. Variables are case insensitive, and can consist of:
  1186.  
  1187.  
  1188.         first character must be either @ or A-Z
  1189.         subsequent characters can be anything but spaces or
  1190.         operators (numbers or commas are legal, as are underscores, but
  1191.         A^TEST would be a to the power of test.
  1192.  
  1193. Variable assignment is achieved by the statment:
  1194.  
  1195. Variable:=equation
  1196.  
  1197. Therefore, one could do any of the following:
  1198.  
  1199. STATEMENT                          VALUE OF A
  1200. ___---------------------------------------------
  1201. A:=10                                10
  1202. A:=10*2                              20
  1203. A:=square_root[9]                     3
  1204.  
  1205. Suppose A is equal to 10, the following would change its value to 20:
  1206.  
  1207. A:=A*2
  1208.  
  1209. FUNCTIONS:
  1210.  
  1211. Functions are assigned in a similar fashion to variables.
  1212.  
  1213. square[x]:=x^2
  1214.  
  1215. Now, whenever a value for the x parameter is supplied, it is put into
  1216. the formula, and the function returns the result.  Variables in function
  1217. parameters are local to those functions and are dynamic.  That is to
  1218. say, if x is specified as being 100 somewhere else, that doesn't affect
  1219. the function.
  1220.  
  1221. Therefore,
  1222.  
  1223. square[10] would return 100.
  1224. square[n] would return 4 if n were equal to 2
  1225. square[1+5] would return 36 and
  1226. square[square[2]] would return 16, and is an example of the nesting that
  1227. is possible with functions.
  1228.  
  1229. In the definition of the function, one can assign parameter defaults.
  1230. That is, one can supply values for the parameters that are used as a
  1231. default value if that parameter is not supplied in the call.
  1232.  
  1233. area[radius,pi:(22/7)]:=pi*radius^2
  1234.  
  1235. As it stands, suppose someone were to then call the function like this:
  1236.  
  1237. area[10]
  1238.  
  1239. This would return 31.429, using the default of 22/7 for pi, which is a
  1240.  
  1241. rough approximation.  However, if a stickler were to come along and
  1242. demand a more accurate value for pi, he could supply the missing
  1243. parameter:
  1244.  
  1245. area[10,3.14159]
  1246.  
  1247. and the function would use this value for pi rather than the default.
  1248.  
  1249. Note that when the default parameter is at the END of the paremeter list
  1250. in the function definition, there is no need for a placeholder.  In
  1251. other locations, one is required:
  1252.  
  1253. area[pi:22/7,radius]:=pi*radius^2
  1254.  
  1255. Now, to call this using the default value for pi, one would have to do
  1256. this:
  1257.  
  1258. area[,10]
  1259.  
  1260. The , serves as a place holder for the missing parameter, just as in the
  1261. BASIC statement:
  1262.  
  1263. LOCATE ,10
  1264.  
  1265. SOME ADVANCED TOPICS:
  1266.  
  1267. Multiline statements are possible.  The result of the LAST calculation
  1268. in the list is what funSolveEquation returns.  Therefore, one could do
  1269. this:
  1270.         2
  1271. a:=1;b:=2;c:=3;a+b+c
  1272.  
  1273. This would return the value 6.
  1274. Functions canNOT take advantage of this feature.
  1275.  
  1276. I leave you to figure out the rest....
  1277. Quinn
  1278.  
  1279.  
  1280.  * OLX 2.1 TD * Programming is never saying you're finished....
  1281.  
  1282. --- Maximus/2 2.01wb
  1283.  * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
  1284.  
  1285.  
  1286.