Arithmetica User's Manual
Table of Contents
| Section 1 ~ Intro to and General Overview of Arithmetica | |
| Section 2 ~ Specific Features: Examples, and Expected Output | |
| 2.1 Constants | |
| 2.2 Binary Operators | |
| 2.3 Unary Operators | |
| 2.4 Parentheses | |
| 2.5 Assignment | |
| 2.6 Variables | |
| 2.7 Comments | |
| 2.8 Postfix Unary Operators | |
| Section 3 ~ Possible Extensions to Arithmetica | |
Section 1 ~ Intro and General Overview of Arithmetica
Welcome to Arithmetica, a simple interactive arithmetic interpreter. This program allows users to enter simple arithmetic expressions while the program keeps track of them. The program utilizes exptression trees to keep track of these. Types of Expressions the user can input are explained in the following section. To begin the program, enter arithmetica at the prompt. The program looks like this when first started:
| Welcome to Arithmetica! |
| -> |
Section 2 ~ Specific Features: Examples and Expected Output
| 2.1 Constants | ||||||||||||||||||||
|
User can enter any integer constant, and the program will output the constant, also saving the constant as its current expression.
|
||||||||||||||||||||
| 2.2 Binary Operators | ||||||||||||||||||||
|
Binary Operators combine 2 expressions into a single expression (in precedence order). The following binary operators have been implemented, in precedence order from highest to lowest
The following shows program output when binary operators are used:
|
||||||||||||||||||||
| 2.3 Unary Operators | ||||||||||||||||||||
|
Unary operators prefix an expression. Negation is implemented here. This is translated as a '-' is placed directly before an operand or parenthesis. If there is a space between the '-' and any other input, it is assumed to be a minus rather than a negative. The negative sign has a higher precedence than all implemented binary operators. The following shows an example output.
|
||||||||||||||||||||
| 2.4 Parentheses | ||||||||||||||||||||
|
Parentheses () are also implemented, and they have the highest precedence. More example output:
|
||||||||||||||||||||
| 2.5 Assignment | ||||||||||||||||||||
|
Expressions can be assigned to a specific variable that the user specifies. This is done using '=' and it has the lowest precedence. Expressions not assigned to a variable are saved as current. Variables can be retrieved and evaluated at any time. Any variable name user inputs that has not already been defined is defined as 0. Following output:
|
||||||||||||||||||||
| 2.6 Variable | ||||||||||||||||||||
|
Not only can a user assign expressions to variables, these variables' values can be used in future expressions.
|
||||||||||||||||||||
| 2.7 Comments | ||||||||||||||||||||
|
Lines of input beginning with a '#' are taken as comments and are ignored.
|
||||||||||||||||||||
| 2.8 Postfix Unary Operators | ||||||||||||||||||||
|
As extra credit, ability to evaluate a factorial '!' was implemented.
|
||||||||||||||||||||
Section 3 ~ Possible Extensions to Arithmetica
Not all of the extra credit was implemented. Unary functions are possible, it would involve, I think, making the function names "special" words that cannot be used as variables. It would be the same implementation as parentheses, but with these function names as part of the operator, and can be evaluated in exptree.