Project 1, A Multi-number System Calculator.

Short Description:

Create a simple calculator that can work with a number of different number systems.

Goals

When you finish this homework, you should have:

Formal Description

You are friends with the famous archaeologist Dr. Edinburgh MacJones, or Eddie for short, who has been working on solving an ancient puzzle. This puzzle includes numbers carved in artifacts from several different ancient civilizations. Eddie is convinced he could solve the puzzle if he only had a method of computing across these different systems. Your job is to implement a simple calculator capable of assisting Eddie in his work.

Calculator Architecture

Eddie would like a calculator the follow properties:

Calculator Command Language

The language for the calculator is a simple prefix notation. In general, the operator is given first and any operands follow. This is very close to most assembly languages.
In the following table, the operator is the command to be executed and the operand(s) are the values to be used by that operator. Note that commands have between 0 and 2 operands. In addition, please note that the number formats will be explained later.
Operator Operand CountOperand Type Example
dump 0 na dump
print 0 na print
input 1 numeric constant input .|,|:maya
load 1 memory location load A
store 1 memory location store C
output_base 1 number system abbreviation output_base murn
mathematical operation 2 numeric constant + XXX:unry 3:deci
memory location - A B
memory location, numeric constant * C //\:murn
numeric constant, memory location ^ XCI:posi D

Calculator Operation

In general the calculator should:
  1. Read in a command.
  2. Print the phrase "Processing Command: "
  3. Print the command back to the screen.
  4. Print a new line character.
  5. Execute the command.
  6. Print a blank line.
The calculator operates in batch mode, reading in all input from the file computations.cmds. You may assume that all commands are correct and in the correct format. Execution stops when the calculator reaches the end of the file. The file is in standard unix format with a newline at the end of each line, including the last line in the file. There is no line-feed character. Each element of the command is separated by a single space with no space after the last element.

Calculator Command Detail

Number Systems

Eddie has determined that you need to support the following number systems:
  1. Decimal
  2. Boolean
  3. Unary
  4. Positionless
  5. Modified Urnfield
  6. Mayan
This list might grow, so please keep your program as flexible as possible.

Decimal
This is the standard system you know and use daily.
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Abbreviation: deci
Representation:

abcd:deci
     where abcd = a*103 + b*102 + c*101 + d*100.
     There is no limit on the number of digits, but the number value will not exceed machine size.

     Numbers may be proceeded by a - which makes them negative.
     Representation is unique.
Boolean
This is a simple version of the binary number system.
Digits: TF, where T = 1 and F = 0
Abbreviation: bool
Representation:
abcd:bool
     where abcd = a*23 + b*22 + c*21 + d*20.
     There is no limit on the number of digits, but the number value will not exceed machine size.

     Numbers may be proceeded by a - which makes them negative.
     Representation is unique.
Unary
This system was probably the first invented.
Digits: X
Abbreviation: unry
Representation:
abcd:unry
     where abcd = 1 + 1 + 1 + 1
     There is no limit on the number of digits, but the number value will not exceed machine size.
     Numbers may be proceeded by a - which makes them negative.
     Representation is unique.
     Represent 0:deci as 0:unry
Positionless
This is a simple grouping by 10 system.
Digits: I, X, C, K, M, G, T, P
Digit Value base 10
I 1
X 10
C 100
K 1,000
M 10,000
G 100,000
T 1,000,000
P 10,000,000

Abbreviation: posi
Representation:
abcd:posi
     where abcd = value(a) + value(b) + value(c) + value(d)
     There should be no more than 9 of each letter in a computation.
     The largest number is PPPPPPPPPP:posi-I:posi
     Numbers may be proceeded by a - which makes them negative.
     Representation is not unique
         IIX = IXI = XII
     Represent 0:deci as 0:posi
Modified Urnfield
The Urnfield culture was an early European culture. Eddie has extended this system with several symbols. The original contained values from 1 to 24. This is essentially a base 5 system with special characters.
Digits: /,\,(,),[,],<,>
Digit Value base 10
/ 1
\ 5
( 25
) 125
[ 625
] 3125
< 15,625
> 78,125

Abbreviation: murn
Representation:
digits are placed in ascending order using as few digits as possible.
     \:murn is correct for 5
         /////:murn is not the correct representation for 5.
     //\:murn   is the correct representation for 7, 
           /\/:murn and \//:murn are incorrect.

     The largest number is ////\\\\(((())))[[[[]]]]<<<<>>>>:murn
     Numbers may be proceeded by a - which makes them negative.
     Representation is unique.
     Represent 0:deci as 0:murn
Mayan
The Mayans had a base 20 system, but their digits were composed of multiple characters.
Digits: combinations of 0, .,|
Digit Value base 10
0 0
. 1
- 5
Unlike the Urnified system, groups of digits repeat.  The Myans stacked their symbols vertically.  Since we can not do that, we will separate digits by commas.
   
Myan digits are constructed in ascending order using the minimal number of symbols.
Mayan Digit Value
0 0
. 1
.. 2
... 3
.... 4
| 5
.| 6
some digits missing
....| 0
|| 10
some digits missing
....||| 19

Abbreviation: maya
Representation:
a,b,c,d:maya
     where a,b,c,d:maya= a*203 + b*202 + c*201 + 2*100.
     There is no limit on the number of digits, but the number value will not exceed machine size.

     Numbers may be proceeded by a - which makes them negative.
     Representation is unique.

Examples:

Decimal ValueBoolean UnaryPositionless Modified UrnfieldMayan
0 0 0 0 00
1 T X I /.
2 TF XX II //..
5 TFT XXXXX IIIII \|
20 TFTFF (omitted) XX \\\\.,0
42 TFTFTF (omitted) IIXXXX //\\\(..,..
314 TFFTTTFTF (omitted) IIIIXCCC ////\\(()) |||,....||
78125 TFFTTFFFTFFTFTTFT (omitted) IIIIIXXCKKKKKKKKMMMMMMM >....|,|||,.|,|

Notes

Required Files

A single tar or zip file containing the source code and makefile for this program.

Submission

Submit the assignment to the D2L folder Project 1 by the due date.