EVAL.BAS July 1997 by Marc Kummel aka Treebeard. Contact mkummel@rain.org, http://www.rain.org/~mkummel/ About EVAL: ------------- EVAL is recent code from the Vault, circa 1997. It's an MSDOS Basic math expression evaluator with a QBasic-like scripting language, written in MS Basic PDS v7.10. This code is now part of my Visual Basic 3.0 BNC program which features arbitrary precision string-based arithmetic routines and lots more features. So some things are done here with strings that could be better done with numbers, and it only works with single-precision numbers since my interest was the logic not the results. That could be changed. BNC (with source, of course!) is available from Treebeard's Basic Vault. EVAL will run with QBasic if you comment out all ON LOCAL ERROR and matching RESUME statements. EVAL.BAS comes from some ancient code I wrote for my Atari 800 in the hazy past, and have carried through many versions. The original inspiration was an artical in _Personal Computing_ magazine, January 1987, "Making a Calculator Out of a Computer" by Leon Starr. Thanks, Leon! EVAL uses GOSUBs and a local stack. Pretty funky, but it still works. The result is a Tiny Basic written in Basic! It's easy to add your own functions. I made this myself, and it's cool that it works, but I'm not proud of all the details. It's bottom-up not top-down, and remarkably s_l__o___w since it's strictly interpreted and not even tokenized. But BNC is even slower, so I don't care. Get it working, THEN speed... Sorry, there's not much help. Type "EVAL" to start, "BYE" to quit, and for *some* help. Check the code and experiment to figure it out. A few script files are available with a ".BNB" extension (not "BNC"!). Type "DIR" and "LOAD" to load a script from disk, or type "LOAD [1-11]" to see a few test files that are embedded in the EXE file. LIST shows the code, and RUN executes it. EDIT is a *very* primative line editor. EVAL is for study. If you really want to USE this program, get BNC! Operations and Functions: ------------------------- {[( )]} + - * / ^ $ \ % | & < > = == <= >= <> NOT OR AND XOR EQV IMP MOD LN() LOG() FAC() RND() EXP() SQR() ABS() INT() SGN() LEN() VAR() RAD() DEG() SIN() COS() TAN() COT() SEC() CSC() EOF() LOF() ISQR() ASIN() ACOS() ATAN() ACOT() ASEC() ACSC() SINH() COSH() TANH() COTH() SECH() CSCH() TIMER() ASINH() ACOSH() ATANH() ACOTH() ASECH() ACSCH() PRMDIV() PRMCNT() Variables and Constants: ------------------------ a-z variables e 2.718282 after CLEAR, but can be changed var() variable indexed as array, var(0)=a ... var(25)=z pi, phi constants true, false 1 and 0 for logic operations arg1, arg2 special variables for use with BNC ans always the last result a=b+2 assign value now a=#b+2 assign operation not value, evaluate when called a+=b+2 assign a=a+(b+2); {-*/\%} are also recognized a="" assign string, but evaluate as 0 a>b equals 1 if true, or 0 if false, all combos of <=> a==b, (a=b) force EQUALITY test rather than assignment Commands: --------- ?, HELP this help, such as it is {A-Z}: change drive BYE, QUIT quit the program CD [:][] change current directory CLEAR clear all variables except ANS; reset e = 2.718282 CLS clear screen DIR current directory DOS start DOS shell, type 'exit' to return EDIT [] very primative program editor EXEC execute one program instruction LOAD [""|] load program from file or memory [0-11] LIST [""|] list current program [and load] MEM memory report NEW clear program PRINT [] print any and current program to LPT1: PWD show current drive and directory RANDOMIZE randomize random number generator RUN [""|] run [and load] current program SAVE ["]["] save current program VARS list all non-null variables Program Statements: ------------------- 'comment