Program Compiler for RPN89 by JPEW development ABOUT: This is a no-stub compiler designed to convert TEXT files into RPNP files. It was written in 100% C using the TIGCC compiler. It has been tested with AMS 2.05 for legal information, see the read-me file for RPN89 RPN89 programs may not be sold for profit or otherwise. They may be freely distributed with or with our source code. INSTALLATION: send "compiler.89z" to your calc (requires 5k ram) type "compiler()" to run. HOW TO USE: the compiler converts text commands into a series of number that RPN89 understands. Almost any command that RPN89 understands can be used. The language is simple, consisting of a handful of short words. THE SYNTAX: These are the commands that the compiler understands. for a better description of the commands, see the readme for RPN89. Note, however, that the line will be cleared or pushed before program execution. All commands must be lower case. Unless stated, spacing between commands does not matter. push = pushes next command (must be either or ) onto stack pop = pops stack and to stores next command (must be ) add = add command sub = subtract command mult = multiply command div = divide command clr = clear stack command rem = compiler ingnores the next command (comment line) cos = cos command sin = sin command tan = tan command asin = arcsin command acos = arccos command atan = arctan command flip = flip command del = pop stack (delete command) rup = rotate stack up rdown = rotate stack down ee = EE command pow = ^ command sqrt = square root command neg = negative command pi = pi command trunc = truncate function round = round function abs = abs function mod = mod function ceil = ceiling function mode = toggle angle mode if = conditional tester (see below) then = used with if (see below) end = used with if (see below) lbl = label statment (used with goto) goto = flow control statement quit = exit RPN89 command (note: program exectuion will stop when RPN89 exits) off = turn calc off. (program execution will continue once calc is turned back on. stop = this is a compiler directive. It will force the compiler quit here. Anything after this command is ingnored. The 'if' statement : An 'if' statment is constructed as follows :if: : The spacing between the and the is important, but the number of spaces is not. When encountered, RPN89 calculates the value of the statment (either TRUE or FALSE). If it is true, the next command is executed, if false, it is skipped. although :push : a is really two commands, :if: : push : a will not cause an error. The 'if...then...end' statement: is constructed as follows :if: :then : : ... :end when encountered, RPN89 calculates the value of the statment (either TRUE or FALSE). If it is true, the next command is executed, if false, RPN89 skips to the 'end' command, then continues execution. Nesting : nesting of 'if' statments is allowed, but only in 'then...end' blocks. thus :if: : if: : push : a will generate an error. The correct form is below :if : :then : if : : push : a :end The 'lbl' statment: is used to declare a label. Is is constructed as follows :lbl: may be up to 8 characters long, with no spaces. the 'lbl' statment is not allowed after an 'if' statment unless it is enclosed in a 'then...end' block. i.e. :if: : lbl: will generate an error (because it is redundant), while :if: :then : lbl: : ... :end will not. If there are two or more labels with the same name, the compiler will ignore all of them, and thus throw an error if a goto calls one. The 'goto' command : is declared as follows :goto: where string corresponds to a string after a 'lbl' statement. If no corresponding 'lbl' statment is found, an error will occur. you may jump in and out of an 'if' statment. When encountered, RPN89 will continue program execution at the corresponding 'lbl' statment. !!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!! The statment :lbl: a :goto: a is very dangerous, since it will cycle indefinitly until the calculator is reset, or the 'program break'(ON) key is pressed. If you do make a repeating statement, be sure to make an exit. i.e. :pop: a :lbl: begin :push: a :push: 2 :mult :if: a > 3 : goto: end :goto: begin :lbl: end :stop The type : is the symbols used by the TI-89 for equalities and in-equalities key : function = : equal 2nd + 0 (<) : less than 2nd + . (>) : greater than diamond + = (!=) : not equal diamond + 0 (<=) : less than or equal diamond + . (>=) : greater than or equal The Type : is a simple varible sotrage type. it can store a number of type . there are 26 storage spots that can be accesed by using the lower case letter that corespondes to it. i.e. :pop : a :push : a pops the number from the stack to varible "a", then pushes it back on. All varible are invalid numbers to begin with, so unless you pop to a varible, pushing it will do nothing. The compiler will not tell you if you are pushing a varible that is invalid. The Type: is a signed floating point number containing up to 16 sig. digits and a decimal point, 4 of which can be in the signed exponent. it can also contain an "e" (either the lowercase one, or the one generated with the "EE" key) symbol that represents scientific notation. valid numbers : -423. 677855.434^93 3747^-38 1.234e33 123.4e31 (although this and the previous are the same, the prevous is prefered) invalid numbers: 4/3 454.54^1/2 -3482974928374892749821749823749.42174892719e4791287492137 these rules are very loose, and the compiler will tell you if there is a problem System Varibles: Are varibles that are always of type . They may be used as any other type is used. name : symbol : value(s) angle mode : diamond + ^ (theta) : 0 = radian, 1 = degree pi : 2nd + ^ (pi) : 3.141593 thus :if: (theta) = 0 : ... will check to see if the angle format is in radians. The angle mode may be changed using the 'mode' command. :push: (pi) and :pi have the same effect, however the latter produces smaller code. MAKING A PROGRAM 1. enter the text editor by pressing "APPS" then "8" then "3" from the home screen 2. enter the name for the source code file. 3. begin typing. Each command must be sepreated by either a return, or a colon ":". Here is an example of an program to find the positive root of a quadratic function. (note that the colon in front of each line is put there by the text editor). this is saved as quads.TEXT :pop : c :pop : b : :rem : you can do parameters it this way : :pop :a : :rem : or this way : :rem : empty lines are ingnored, as well as spaces : push:b : neg : :rem : -b : :push: b :push: 2 :pow : :rem : -b, b^2 : :push : 4 :push : a :push : c : :mult : mult : :rem : multiple commands can be on a line if seperated by a colon, but it is not sugested. : :rem : -b, b^2, 4*a*c : :sub : :rem : -b, b^2-4*a*c : :sqrt :add :push : a :push : 2 :mult : :rem : -b + sqrt(b^2-4*a*c), 2*a : :div :stop :i can type whatever i want here. the compiler will stop on the previous line. (the source code for this file should be included with the program) 4. exit the text editor and type "compiler()" on the command line 5. select the folder and file that you entered your source code in, the hit enter 6. type the name of the program you want to be created (it will delete anything that already exist with that name), and select the folder to save it in. Then hit enter 7. if sucessful, the compiler will give a message. if unsucessful, it will give an error. press any key to exit. A WORD ON PROGRAMMING Program Parameters: a program that requires 3 parameters should begin like this. :pop : c :pop : b :pop : a where a is the first parameter (the highest on the stack). they must be in reverse order because the lowest parameter is popped off first. Pop and Push: Although they are the same to the compiler, I would suggest you use :push : a as oppoesed to :push :a This is to prevent confusion. Also, while the above command is correct, :push : :a is not, since it would be the same as :push : : a the same is true for lbl, goto, and rem Comments: you may notice that the example program has comment lines that look like this :rem : -b, b^2, 4*a*c this is simply a representation of the stack. Thus at this point in the program, I can tell you that A2 contains the value -b, A1 contains b^2, and A0 contains 4*a*c. I've found that this sort of "stack representation" makes it much easier to decide what command needs to come next. Besides, not every one thinks in RPN :) How to copy the contents of a varible to another: :pop : a :rem : get the inital value of a :push : a :pop : b :rem : when you push a varible, it still retains it's content Since the envoiroment that RPN89 program run in is a calculator, you will notice that you cannot do something like this :a = b + c instead (assuming b and c have a value...) :push : b :push : c :add :pop : a It is rather pointless to make RPN89 intrepret commands like the former. It is much easier to use commands it already knows. Besides, a = b + c isn't RPN :). Maybe someone else could write a better compiler that would allow you to directly modify varibles. This one simply writes the value of the command into the file, then adds the "next command" operator. it's a lot like ASM, the commands you write are the exact ones RPN89 receives, just in a numeric form. If you wish to create a better compiler, or have any questions or comments about anything, e-mail me at JPEWdev@delorean.com