Assignment 4 (100 Points) - Due Wednesday, November 16, 11:59PM

Announcements and Clarification

November 28: A draft Assignment 4 Grading Rubric is available. Please note that minor changes to the grading rubric may be made during the grading process.

Ye Olde Adding Machine

Create an yeoldecalc program capable of interpreting a sequence of basic arithmetic operations and output operations specified using Olde English phrases defined within an input calculation file.

Commandline Arguments

Your program must be capable of utilizing a commandline argument to specify the input file.

yeoldecalc inputFile


Your program must ensure the user has correctly provided the required commandline argument and display a usage statement if the provided arguments are incorrect.

Input Calculation File

The input calculation will consist of a sequence of operations, where each operation is either a value assignment, arithemtic computation, or an output statement. The program will evaluate each operation in the order it is read from the input file, where each operation is specified on a single line within the input calculation file. The following describes the input calculation file format and program functionality:

  1. Empty lines and lines containing only whitespace should be ignored.
  2. Lines starting with the # character are considered comments and should be ignored. The following is an example of a comment:
    # Thou art allowed to haveth comments in thine file
  3. The file format is case sensitive.
  4. All keywords, variables, and integer constants will be whitespace delimited.
  5. Value Assignment Statements allow an integer value or existing variable to be assigned to a variable using the following format, in which var is the name of the variable and val is a numerical integer value or existing variable to be assigned to the variable.
    henceforth var shalt holde ye olde val
    If the variable has not been previously assigned, the program should create a new variable (see note below regarding the binary search tree requirements) and assign the integer value. If the variable has been previously assigned, the new integer value will be assign to that variable.
    The following provides an example Value Assignment Statement assigning the integer value 7 to the variable a:
    henceforth a shalt holde ye olde 7
  6. The following keywords are received and cannot be used for variable names:
    henceforth printeth doneth shalt holde ye olde thine pluseth minuseth timeth divideth by exulted
  7. Variable Assignment Statements allow the value of an existing variable to be assigned to a another variable using the following format, in which inputVar is the name of the existing variable and outputVar is the variable being assigned.
    henceforth outputVar shalt holde thine inputVar
    The following provides an example Variable Assignment Statement assigning the variable b to the variable c:
    henceforth c shalt holde thine b
  8. Arithmetic Assignment Statements specify that the result of an arithmetic operation on two input variables be assigned to a variable using the following format, in which inputVar1 is the name of the first input variable, inputVar2 is the name of the second input variable, outputVar is the name of the output variable, and op is the desired operation.
    henceforth outputVar shalt holde inputVar1 op inputVar2
    Valid operations include pluseth (addition), minuseth (subtraction), timeth (multiplication), and divideth by (division). The input variables must have been previously assigned before being used within an Arithmetic Assignment Statement.
    The following provides an example Arithmetic Assignment Statement assigning the sum of variables a and b to the variable d:
    henceforth d shalt holde a pluseth b
  9. Exponent Assignment Statements specify that the result of raising one variable to another variable be assigned to a variable using the following format, in which inputVar1 is the name of the base input variable, inputVar2 is the name of the exponent input variable, and outputVar is the name of the output variable.
    henceforth outputVar shalt holde inputVar1 exulted inputVar2
    The input variables must have been previously assigned before being used within an Exponent Assignment Statement.
    Your program can utilize the pow() within the C Math Library to perform this operation. Please see the CMake Template with C Math Library Inclusion at the end of the assignment description for deals on how to include the C Math Library when linking your program.
    The following provides an example Exponent Assignment Statement assigning the variable d raised to the exponent one to the variable d:
    henceforth d shalt holde d exulted one
  10. Output Statements allow the calculation to specify when the value of a variable should be displayed by your program using the following format, in which var is the name of the variable to be displayed.
    printeth var
    The variable must have been previously assigned before being used within an Output Statement.
    The following provides an example Output Statement to display the value of the variable a :
    printeth a
    Your program should display the current value of the variable by printing the variable name, a space, and equal sign, another space, and the integer value of the variable on a single line. For example, the following is the expected output for the above Output Statement:
  11. Exit Statements can be used to stop the execution of the calculation. If the following statement is encountered, your program should stop processing/interpreting the input calculation file and exit.
    doneth

Example Calculation File

The following provides an example of the input calculation file format including an example of all commands and operations:

ye_old_sample_calculation.txt

Binary Search Tree Requirement

For each variable defined within the input calculation file, your program will need to maintain the current value of the variable. To maintain this data, your program must utilize a binary search tree.

Error Handling

Your program should detect and report ALL possible errors.

CMake Template with C Math Library Inclusion

bang_bam_pow.tgz is a simple CMake template project that links in the C math library. This is needed to use the C math library on the ece3 server as the library is not linked by default.

Extra Credit (5%)

Extend Ye Olde Adding Machine to implement a whereas conditional statement and a whilst loop as follows.

  1. Conditional Statements (2%) allow a sequence of operations specified within the statement's start (doeth) and end (endeth) to be executed only if the specified condition is true. The Conditional Statement should have the following format, in which inputVar1 is the name of the first input variable, inputVar2 is the name of the second input variable, and comparison is the comparison being performed for evaluating the condition.
    whereas thine inputVar1 beeth comparison thine inputVar2 doeth

    # Thine statements shalt be inserted hereth

    endeth
    Valid comparisons include equal to, less than, and greater than.
    The following provides an example Conditional Statement for determining the maximum of two input variables a and b:
    henceforth maximum shalt holde thine a
    whereas thine b beeth greater than thine a doeth
        henceforth maximum shalt holde thine b
    endeth
  2. Loop Statements (3%) will continue to execute the operations within the loop's start (doeth) and end (endeth) as long as the loops condition is true. The Loop Statement should have the following format, in which inputVar1 is the name of the first input variable, inputVar2 is the name of the second input variable, and comparison is the comparison being performed for evaluating the loops condition.
    whilst thine inputVar1 beeth comparison thine inputVar2 doeth

    # Thine loop statements shalt be inserted here

    endeth

In your README file be sure to indicate if your program supports the whensoever and whilst statements.