CIS-4050/6050 Homework #1: Augusta Comments

Due: Thursday, January 31, 2019

Reading: Read Chapter 1 in the text. This chapter gives you an overview of the standard compiler pipeline and talks about the application of compiler technology in general.

To get set up for development, do the following:

  1. Install the sbt build tool (use the instructions here).
  2. (OPTIONAL) Install IntelliJ (Community Edition is fine), or any other development environment of your choice (but I have predefined project files for IntelliJ). Be sure to also install the Scala plug-in into IntelliJ.
  3. In IntelliJ, if you installed it, you'll want to configure a Java SDK (look under "Project Defaults" and then "Project Structure"). The built-in wizard does most of the work, you just need to tell it where the SDK is installed.
  4. Unpack the Samples archive in some suitable place. The archive contains: a defined sbt project, the corresponding IntelliJ project, and the comment stripping programming for C/C++ that includes support for nested comments (as is done in the D programming language). Be sure you can build and run that program.

You are now ready to do this assignment. Write a new program, in a manner similar to the given sample, that strips comments from Ada code. I recommend creating an entirely new file instead of editing the existing one so you always have the existing sample available as a reference.

Comments in Ada start with "--" and end at the end of the line. Be sure to properly handle (meaning ignore) "--" sequences that appear inside quoted string literals. Also be sure your program is not confused by string literals that contain quotation marks. In Ada this is handled by using two quotation marks back to back like this:

      "Peter said, ""I love Ada."" What does Jill think?"
    

I want you to deal with this be creating an additional state to handle the quotation mark at the end of the string. Although you don't need to worry about character conversions for this assignment, a real Ada compiler will need to convert the "" sequence into a single quotation mark when it makes the STRING_LITERAL token. For example, the string above would get tokenized as:

      STRING_LITERAL
        -> Text: Peter said, "I love Ada." What does Jill think?
    

In other words, just treating the "" sequence as the end of one string and the beginning of another, although it would work for this assignment, isn't sufficient... so don't do that.

Your program should also deal with character literals properly. In particular '--' is not the start of a comment. Note that Ada does not allow more than one character in a character literal so any use of '--' in a program is illegal. However, we want the error to eventually say something about "invalid character literal" and not some strange result of treating the malformed literal like a start of a comment. Your program does not need to report this error, but it shouldn't be confused by it either.

In Ada a character literal consisting of a single quote character is written like this:

      '''
    

This takes advantage of the fact that character literals are always three characters long. However, this also means that the second single quote character is not the end of the literal in this case.

You do not need to support proper handling of Ada attributes as explained in class.

Submit the new program (it should be a single .scala file) to Moodle.


Last Revised: 2019-01-22
© Copyright 2019 by Peter C. Chapin <pchapin@vtc.edu>