1 /** \mainpage RPN Documentation
3 * \section intro Introduction
5 * RPN is an easy-to-use Reverse Polish Notation calculator with a fair amount
6 * of useful features. It started out as a sort of pet project, but has become
7 * somewhat serious to me.
9 * Even though I've never released it before, it's already up to version 1.3;
10 * at 1.0, this was a fully-function plain calculator, with not many bells and
11 * whistles. In 1.1, I added variables, and in 1.2 I ported this to the
12 * PlayStation portable. In this release, 1.3.0.0, I've ported this to the
13 * Nintendo Wii, and have fixed some potential bugs with Valgrind.
15 * \section features Features
17 * Like any calculator, RPN can calculate, so it supports many operators:
18 * addition, subtraction, multiplication, division, exponentiation, bitwise
19 * operations, etc. Unlike some, however, RPN has support for commands and
22 * Commands are like operators in implementation, but are separate because they
23 * affect the calculator as a whole--it's stack, variables, etc. Operators only
24 * affect the stack. This limitation is part of the design of the program. A
25 * downside to this is that operators can only have two operands. This isn't
26 * much of a problem yet, but it may be later if one wants to add a ternary
27 * operator. For now, anything that can't be implemented as an operator should
28 * be implemented as a command.
30 * Variables let you save the results of your expressions and keep shorthands
31 * for commonly used numbers. There are some predefined variables like PI, E,
32 * and kilobyte/kibibyte/etc. All predefined variables begin with an uppercase
33 * letter, but there are currently no limitations for a variable name except
34 * 1) it must have at least one non-numerical character, and 2) it cannot be the
35 * same as a command or operator. This gives you a lot of freedom to choose
36 * whatever name you want.
38 * \section about About the Program
40 * By default, the calculator uses "long doubles" to store values. On my 64-bit
41 * Pentium D processor, this is 128 bits wide, and can hold up to about 2 **
42 * 16383 before reaching "infinity"--a 4932 digit number. So, though this is not
43 * an arbitrary precision calculator, it should be good enough for most people.
44 * If you compile with the flag RPN_DOUBLE, however, then "doubles" will be used
47 * I'm not quite sure how portable this program is. It compiles on Ubuntu Linux,
48 * so it will likely compile on any GNU/Linux system with the right libraries. I
49 * believe that all the functions I use are POSIX, so hopefully this program can
50 * be ported easily to just about anything. The PSP port wasn't too difficult,
51 * though, and that required creating a custom input system!
53 * \section comp Compiling
55 * Hopefully, compiling can be as simple as "make; make install". However, you
56 * may need to make changes to the Makefile, and may need to type, for instance,
57 * "sudo make install" instead.
59 * Compiling for the PSP should not present any difficulties if you already have
60 * a PSP SDK and toolchain installed. If not, you can find a great tutorial on
61 * the Gentoo wiki. I used it to install the toolchain and SDK on Ubuntu 7.10
62 * without problem. See \ref psp-spec for more information about the PSP port.
64 * Likewise, compiling for the Wii should be simple if you already have a
65 * properly setup DevkitPPC toolchain; but that's easier said than done. See
66 * \ref wii-spec for more information abouth the Wii port.
68 * \section using Using the Program
70 * When you first run the program, you're presented with a simple prompt:
76 * The number in barckets is the topmost item of the stack. To push a number to
77 * it, just type it in and press enter.
84 * Great! But this is a calculator--how do you calculate? If you don't know what
85 * Reverse Polish Notation is, look it up on Wikipedia. Done yet? Good. If you
86 * want to multiply by five, type this.
93 * You can even do more than one operation per line.
100 * But what if you want to see the whole stack?
109 * How about removing the top item of the stack?
116 * How about duplicating the top item of the stack?
123 * Can you print the stack in more detail?
127 * [ 2.000000, 2.000000, 3.235988, ]
130 * \section thanks Thanks
132 * Much thanks to Troy Hanson for uthash. It made the program much better, and
133 * makes implementing hash tables wonderfully simple.
135 * The PSP port would not have been possible without the tutorials at
136 * psp-programming.com. The callback functions are almost carbon-copied form
139 * The Wii port would not have been possible without the help of wiibrew.org.
143 * \page psp-spec Specific Information About the PSP Port
145 * In the current version, the PSP port is very, very simple. It works, and you
146 * can actually type, though not easily. It is basically a full port, though the
147 * error module is simplified. The highest calculatable value, I believe, is
150 * Because not many people have a PSP toolchain on hand, I've included a
151 * pre-built EBOOT.PBP. Though compiled for firmware 1.50, I have successfully
152 * run it under 4.00 M33-2. To install it, simply copy EBOOT.PBP to
153 * ms0:/PSP/GAME/PSPRPN .
155 * \section psp-type How to Type on the PSP
157 * Typing numbers is a combination of cross, circle, and a directional button.
158 * Pressing cross alone is 0; pressing cross and up simultaneously is 1; cross
159 * and right 2; cross and down 3; and cross and left 4. This direction
160 * order--up, right, down, and left--is consistent thoughout all typing modes.
162 * There is also an alternate mod, accessed by pressing the right trigger once;
163 * think of it as a caps lock. Not all button combinations have alternate
164 * characters, however, so they do not change.
166 * If you make a mistake, there is no way (currently) to undo it. If you press
167 * the left trigger alone, however, any input you've entered will be discarded.
169 * Here is a table of typable characters.
173 * <TD><STRONG>Buttons</STRONG></TD>
174 * <TD><STRONG>Normal Character</STRONG></TD>
175 * <TD><STRONG>Alternate Character</STRONG></TD>
288 * <TD>LT X Right</TD>
309 * <TD>g</TD> <!-- This is SPARTAAA!!! -->
313 * <TD>LT () Right</TD>
318 * <TD>LT () Down</TD>
323 * <TD>LT () Left</TD>
338 * <TD>LT [] Right</TD>
343 * <TD>LT [] Down</TD>
348 * <TD>LT [] Left</TD>
363 * <TD>LT ^ Right</TD>
383 * <TD>LT RT X Up</TD>
388 * <TD>LT RT X Right</TD>
393 * <TD>LT RT X Down</TD>
398 * <TD>LT RT X Left</TD>
411 * \page wii-spec Specific Information about the Wii Port
413 * The Wii port, like the PSP port, is very simple. You can "type," and in a
414 * simpler way than the PSP, but it's still slow to use. In the future, I'll
415 * update the input module to be simpler to use, but for now it will suffice.
417 * \section wii-type How to Type on the Wii
419 * The input buffer is limited to 64 characters, and starts out as all spaces.
420 * Use the left and right buttons to navigate through the buffer, and the up and
421 * down buttons to change the character at that position of the buffer. Press A
422 * when done to evaluate the input.
426 * \page spec Specific Information About the Program
428 * This section conveys the basic structure of the program so that you can get
429 * an idea of what the hell I was thinking when writing this program. Not
430 * everything here applies to the PSP port; see \ref psp-spec to read more about
433 * \section exec Execution
435 * On startup, the program processes arguments. Some arguments, like "-v" and
436 * "-e", exit the program after completion.
438 * After this, a loop is entered that is controlled by the calculator's status.
439 * As long as the status equals RPN_STATUS_CONTINUE, the loop executes. Commands
440 * should exit the program by setting the status to RPN_STATUS_EXIT, unless some
441 * severe error occurs, in which case one should use exit() or a similar
444 * In the loop, the user is presented with a peek at the stack and a prompt to
445 * evaluate a string. Upon pressing Enter, the string is sent to RPN_eval, which
446 * uses RPN_splitString to get a list of tokens. It then iterates through the
447 * tokens, pushing numeric ones to the stack and delegating others to
450 * RPN_evalToken tries to find an operator equal to the token; if it can't, it
451 * sends the token to RPN_executeCommand, and if that cannot, the token is added
452 * to the variable table and its value set to the value of the topmost stack
455 * \section structs Structures
457 * The quintessential Reverse Polish Notation calculator structure is the stack.
458 * My stack is RPNStack, which holds only a pointer to the first node of the
459 * stack. The node structure, RPNNode, holds the value of the node and a pointer
460 * to the next node in the stack.
462 * An RPNOperator holds the name and function of an operator. A callback
463 * function for an operator looks like this:
466 * void customOperator(RPNValue a, RPNValue b)
471 * RPNOperators is a hash table, implemented with UTHash. It contains just a
472 * pointer to the UTHash table.
474 * RPNCommand and RPNCommands are almost exactly like RPNOperator and
475 * RPNOperators, respectfully, except that command callbacks are passed the
476 * entire calculator structure to give them more power. Here is what it looks
480 * void customCommand(RPNCalculator *calculator)
485 * RPNVariable and RPNVariables are also similar, except they have values
486 * instead of function pointers.