CIS-4050 Homework #2: Integer Literals

Reading: Chapter 2 in the text covers scanners, regular expressions, NFAs and DFAs. Read sections 2.1 through 2.3. Sections 2.4 and 2.5 provide implementation details that you can skim or skip for now. Section 2.6 is on advanced topics that you can skip.

In this assignment you will implement a DFA that decodes the value of Augusta integer literals. To do this, you will create a small, independent Scala project. You won't be using the Augusta codebase directly for this assignment.

Part 1: Setting Up

For this assignment you will work inside the Augusta code base. However, to ensure the smoothest experience, it is best to work on a personal branch.

Proceed as follows:

  1. Update your clone of the Augusta project using:

        $ git pull
      
  2. Create a branch in your clone using:

        $ git branch homework-02
      

    You can name the branch anything you want, but in anticipation of creating separate branches for each assignment, it makes sense to use something like homework-02, homework-03, etc.

  3. Now, check out your new branch to switch to it:

        $ git checkout homework-02
      

    You are now working on a personal branch. You can commit to that branch freely without causing interference with any future changes in the main branch. If you want to go back to the original main branch, do:

        $ git checkout main
      
  4. Run the usual SBT commands to ensure everything is working as expected. Note that initially the tests will fail since you haven't implemented anything yet.

        $ sbt compile
        $ sbt test
      
  5. Open the project folder using your development tool of choice (VS Code, or IntelliJ IDEA).

  6. You are now ready to get started programming!

Part 2: Integer Literal Rules

Integer literals in Augusta are intended to follow the rules for literals in Ada as outlined in Section 2.4 of the Ada Reference Manual. A few important points are mentioned here:

This assignment is NOT about checking for the validity of an integer literal. You can assume that has already been done by the scanner. This assignment is about extracting the value of an integer literal, which you can assume is in a valid format. The value should be returned as a BigInt so that it can handle literals of any size.

Here are some examples of valid integer literals:

Part 3: Implementation

Write a function decodeIntegerLiteral with the following signature:

  def decodeIntegerLiteral(literal: String): BigInt

Start by designing a deterministic finite automaton (DFA) that can process integer literals and extract their value. You can assume the format of the literal has been previously checked and is known to be valid. This allows some simplification. Once you are confident that your DFA will work, the implementation should go smoothly.

Write appropriate test cases so that the command sbt test exercises your function in a meaningful way.

HINT! Don't try to get everything working all at once. Build up your solution in stages:

  1. Decimal literals without exponents (but handle the embedded underscores).
  2. Decimal literals with exponents.
  3. Full support, including based literals with exponents.

After each step, set aside your code so you have something working in reserve before embarking on the next step. This will be useful if you run out of time before completing everything.

Part 4: Submission

Submit your project folder as a ZIP file. Include all the source code, test code, and any other files needed to build and run your project.


Last Revised: 2025-02-03
© Copyright 2025 by Peter Chapin <peter.chapin@vermontstate.edu>