1 /*******************************************************************************
2 * Reverse Polish Notation calculator. *
3 * Copyright (c) 2007-2008, Samuel Fredrickson <kinghajj@gmail.com> *
4 * All rights reserved. *
6 * Redistribution and use in source and binary forms, with or without *
7 * modification, are permitted provided that the following conditions are met: *
8 * * Redistributions of source code must retain the above copyright *
9 * notice, this list of conditions and the following disclaimer. *
10 * * Redistributions in binary form must reproduce the above copyright *
11 * notice, this list of conditions and the following disclaimer in the *
12 * documentation and/or other materials provided with the distribution. *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS *
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY *
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
25 ******************************************************************************/
27 /*******************************************************************************
28 * This is stack-based, so expressions can be as long as memory will allow. *
29 * Operators must be one-character long. You can add your own by editing *
30 * the RPN_operator function in parser.c. *
31 * I've commented this code to explain any 'magic' or otherwise cryptic *
32 * sections. I hope they will suffice. *
33 ******************************************************************************/
44 /* This wonderful header provides hashing for C structures. I use it to
45 * implement a hash table to store and find variables, commands, and operators.
47 * No library is needed; it is implemented entirely as C macros in the header.
52 //! The major version number.
53 #define __RPN_MAJOR__ 1
54 //! The minor version number.
55 #define __RPN_MINOR__ 3
56 //! The revision version number.
57 #define __RPN_REVIS__ 1
58 //! The build version number.
59 #define __RPN_BUILD__ 1
62 //! Handy-dandy macro for allocating structures
63 #define new(x) (x*)RPN_malloc(sizeof(x))
66 // setup the type of RPNValue and other auxillary macros.
67 #ifdef RPN_LONG_DOUBLE
68 typedef long double RPNValue
;
69 #define RPN_VALUE_LONG_FORMAT "%Lf"
70 #define RPN_VALUE_SHORT_FORMAT "%Lg"
71 #define RPN_strtod strtold
74 typedef double RPNValue
;
75 #define RPN_VALUE_LONG_FORMAT "%f"
76 #define RPN_VALUE_SHORT_FORMAT "%g"
77 #define RPN_strtod strtod
80 #error Please define either RPN_LONG_DOUBLE or RPN_DOUBLE.
83 // header for circular-dependency of structures.
87 #include "console/arguments.h"
88 #include "console/error.h"
89 #include "console/help.h"
92 // headers for structures and their methods.
93 #include "calculator.h"
96 #include "operators.h"
100 #include "variables.h"
102 /* Conditionally include PSP declarations.
108 /* Conditionally include Wii declarations.
116 #endif // __cplusplus