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 * At 1.0, this was a fully-function plain calculator, with not many bells and
10 * whistles. In 1.1, I added variables, and in 1.2 I ported this to the
11 * PlayStation portable. In 1.3, I ported this to the Nintendo Wii, and fixed
12 * some potential bugs with Valgrind.
14 * In the current version, 2.0.0.0, I've re-written the program in C++.
15 * The source code is now less than half of what the C code was, though the
16 * compiled executable is larger. This release has the same PSP and Wii
17 * ports, though I've not tested them well; however, I don't expect any problems
20 * \section features Features
22 * Like any calculator, RPN can calculate, so it supports many operators:
23 * addition, subtraction, multiplication, division, exponentiation, bitwise
24 * operations, etc. Unlike some, however, RPN has support for commands and
27 * Commands are like operators in implementation, but are separate because they
28 * affect the calculator as a whole--it's stack, variables, etc. Operators only
29 * affect the stack. This limitation is part of the design of the program. A
30 * downside to this is that operators can only have two operands. This isn't
31 * much of a problem yet, but it may be later if one wants to add a ternary
32 * operator. For now, anything that can't be implemented as an operator should
33 * be implemented as a command.
35 * Variables let you save the results of your expressions and keep shorthands
36 * for commonly used numbers. There are some predefined variables like PI, E,
37 * and kilobyte/kibibyte/etc. All predefined variables begin with an uppercase
38 * letter, but there are currently no limitations for a variable name except
39 * 1) it must have at least one non-numerical character, and 2) it cannot be the
40 * same as a command or operator. This gives you a lot of freedom to choose
41 * whatever name you want.
43 * \section about About the Program
45 * By default, the calculator uses "long doubles" to store values. On my 64-bit
46 * Pentium D processor, this is 128 bits wide, and can hold up to about 2 **
47 * 16383 before reaching "infinity"--a 4932 digit number. So, though this is not
48 * an arbitrary precision calculator, it should be good enough for most people.
49 * If you compile with the flag RPN_DOUBLE, however, then "doubles" will be used
52 * I'm not quite sure how portable this program is. It compiles on Ubuntu Linux,
53 * so it will likely compile on any GNU/Linux system with the right libraries. I
54 * believe that all the functions I use are POSIX, so hopefully this program can
55 * be ported easily to just about anything. The PSP port wasn't too difficult,
56 * though, and that required creating a custom input system!
58 * \section comp Compiling
60 * Hopefully, compiling can be as simple as "make; make install". However, you
61 * may need to make changes to the Makefile, and may need to type, for instance,
62 * "sudo make install" instead.
64 * Compiling for the PSP should not present any difficulties if you already have
65 * a PSP SDK and toolchain installed. If not, you can find a great tutorial on
66 * the Gentoo wiki. I used it to install the toolchain and SDK on Ubuntu 7.10
67 * without problem. See \ref psp-spec for more information about the PSP port.
69 * Likewise, compiling for the Wii should be simple if you already have a
70 * properly setup DevkitPPC toolchain; but that's easier said than done. See
71 * \ref wii-spec for more information abouth the Wii port.
73 * \section using Using the Program
75 * When you first run the program, you're presented with a simple prompt:
81 * The number in barckets is the topmost item of the stack. To push a number to
82 * it, just type it in and press enter.
89 * Great! But this is a calculator--how do you calculate? If you don't know what
90 * Reverse Polish Notation is, look it up on Wikipedia. Done yet? Good. If you
91 * want to multiply by five, type this.
98 * You can even do more than one operation per line.
105 * But what if you want to see the whole stack?
114 * How about removing the top item of the stack?
121 * How about duplicating the top item of the stack?
128 * Can you print the stack in more detail?
132 * [ 2.000000, 2.000000, 3.235988, ]
135 * \section thanks Thanks
137 * Much thanks to Troy Hanson for uthash. It made the program much better, and
138 * makes implementing hash tables wonderfully simple.
140 * The PSP port would not have been possible without the tutorials at
141 * psp-programming.com. The callback functions are almost carbon-copied form
144 * The Wii port would not have been possible without the help of wiibrew.org.
148 * \page psp-spec Specific Information About the PSP Port
150 * In the current version, the PSP port is very, very simple. It works, and you
151 * can actually type, though not easily. It is basically a full port, though the
152 * error module is simplified. The highest calculatable value, I believe, is
155 * Because not many people have a PSP toolchain on hand, I've included a
156 * pre-built EBOOT.PBP. Though compiled for firmware 1.50, I have successfully
157 * run it under 4.00 M33-2. To install it, simply copy EBOOT.PBP to
158 * ms0:/PSP/GAME/PSPRPN .
160 * \section psp-type How to Type on the PSP
162 * Typing numbers is a combination of cross, circle, and a directional button.
163 * Pressing cross alone is 0; pressing cross and up simultaneously is 1; cross
164 * and right 2; cross and down 3; and cross and left 4. This direction
165 * order--up, right, down, and left--is consistent thoughout all typing modes.
167 * There is also an alternate mod, accessed by pressing the right trigger once;
168 * think of it as a caps lock. Not all button combinations have alternate
169 * characters, however, so they do not change.
171 * If you make a mistake, there is no way (currently) to undo it. If you press
172 * the left trigger alone, however, any input you've entered will be discarded.
174 * Here is a table of typable characters.
178 * <TD><STRONG>Buttons</STRONG></TD>
179 * <TD><STRONG>Normal Character</STRONG></TD>
180 * <TD><STRONG>Alternate Character</STRONG></TD>
293 * <TD>LT X Right</TD>
300 * <TD>D</TD> <!-- This is SPARTAAA!!! -->
318 * <TD>LT () Right</TD>
323 * <TD>LT () Down</TD>
328 * <TD>LT () Left</TD>
343 * <TD>LT [] Right</TD>
348 * <TD>LT [] Down</TD>
353 * <TD>LT [] Left</TD>
368 * <TD>LT ^ Right</TD>
388 * <TD>LT RT X Up</TD>
393 * <TD>LT RT X Right</TD>
398 * <TD>LT RT X Down</TD>
403 * <TD>LT RT X Left</TD>
416 * \page wii-spec Specific Information about the Wii Port
418 * The Wii port, like the PSP port, is very simple. You can "type," and in a
419 * simpler way than the PSP, but it's still slow to use. In the future, I'll
420 * update the input module to be simpler to use, but for now it will suffice.
422 * \section wii-type How to Type on the Wii
424 * The input buffer is limited to 64 characters, and starts out as all spaces.
425 * Use the left and right buttons to navigate through the buffer, and the up and
426 * down buttons to change the character at that position of the buffer. Press A
427 * when done to evaluate the input.
431 * \page spec Specific Information About the Program
433 * This section conveys the basic structure of the program so that you can get
434 * an idea of what the hell I was thinking when writing this program. Not
435 * everything here applies to the PSP port; see \ref psp-spec to read more about
438 * \section exec Execution
440 * On startup, the program processes arguments. Some arguments, like "-v" and
441 * "-e", exit the program after completion.
443 * After this, a loop is entered that is controlled by the calculator's status.
444 * As long as the status equals RPN_STATUS_CONTINUE, the loop executes. Commands
445 * should exit the program by setting the status to RPN_STATUS_EXIT, unless some
446 * severe error occurs, in which case one should use exit() or a similar
449 * In the loop, the user is presented with a peek at the stack and a prompt to
450 * evaluate a string. Upon pressing Enter, the string is sent to RPN_eval, which
451 * uses RPN_splitString to get a list of tokens. It then iterates through the
452 * tokens, pushing numeric ones to the stack and delegating others to
455 * RPN_evalToken tries to find an operator equal to the token; if it can't, it
456 * sends the token to RPN_executeCommand, and if that cannot, the token is added
457 * to the variable table and its value set to the value of the topmost stack
460 * \section structs Structures
462 * The quintessential Reverse Polish Notation calculator structure is the stack.
463 * My stack is RPNStack, which holds only a pointer to the first node of the
464 * stack. The node structure, RPNNode, holds the value of the node and a pointer
465 * to the next node in the stack.
467 * An RPNOperator holds the name and function of an operator. A callback
468 * function for an operator looks like this:
471 * void customOperator(RPNValue a, RPNValue b)
476 * RPNOperators is a hash table, implemented with UTHash. It contains just a
477 * pointer to the UTHash table.
479 * RPNCommand and RPNCommands are almost exactly like RPNOperator and
480 * RPNOperators, respectfully, except that command callbacks are passed the
481 * entire calculator structure to give them more power. Here is what it looks
485 * void customCommand(RPNCalculator *calculator)
490 * RPNVariable and RPNVariables are also similar, except they have values
491 * instead of function pointers.