Homework #7

Assigned: November 10
Due: November 17, 4:30pm

Problem

(71 points) Automatically generate a lexical analyzer which outputs the uncommented and commented included header filenames from a stream of C/C++ source code.

Requirements

  1. Your program must read from standard input and write to standard output.
  2. Your program must support only two command-line options (-u and -c) and combinations of them.
  3. When run with no command-line options, your program must print both uncommented and commented included header filenames (and nothing else) using the format used in the sample output given below.
  4. When run with the -u command-line options, your program must print only the uncommented included header filenames (and nothing else) using the format used in the sample output given below.
  5. When run with the -c command-line options, your program must print only the commented included header filenames (and nothing else) using the format used in the sample output given below.
  6. When run with the -u and -c command-line options or the -uc or -cu command-line options, your program must print both the uncommented and commented included header filenames (and nothing else) using the format used in the sample output given below.
  7. You may assume that the input stream will never contain more than 50 (uncommented or commented) included header filenames.
  8. Your solution must contain only a lex specification file and a Makefile.
  9. Use macros and substitutions (e.g., digit [0-9]), where appropriate, to simply the pattern-matching rules in your lex specification file.
  10. Develop a Makefile which builds your lexical analyzer. Your Makefile must include target directives for every derived file produced during the compilation process (i.e., each program, each object file, and any other intermediate files produced during code generation and compilation). Make sure that each directive also lists all files on which the derived file depends in its dependency list. Also, your Makefile must be written so carries out only the commands necessary to bring any produced file up-to-date. Your Makefile must do just enough, but no extra, work to bring showheaders (the final executable for your lexical analyzer) up-to-date every time make is invoked. In addition, it must have an all directive and a clean directive to remove all generated files (including the pretty printed Postscript and pdf files). Use variables where appropriate in your Makefile to improve its readability.
  11. Your Makefile must bring everything up-to-date, using only flex and gcc, without any warnings or errors, when make is invoked on our system.

Sample test data

You will find a codebase of C/C++ source at ~perugini/C/hw7.tar. Output from sample test runs using this codebase is here.

How to submit

Note: All directory and filenames below are case-sensitive. You must use the directory and filenames exactly as shown below (i.e., all lower case).

Prepare your lex specification file as /home/<logname>/homeworks/hw7/showheaders.l and your Makefile as /home/<logname>/homeworks/hw7/Makefile, where <logname> is your login name (e.g., cps444-n1.19).

Archive only your specification file and Makefile by running the following command on system from your /home/<logname>/homeworks/hw7 directory:

tar cvf showheaders.tar Makefile showheaders.l
Only the file /home/<logname>/homeworks/hw7/showheaders.tar will be electronically collected from this location in your UNIX account on the deadline.

Failure to follow these submission requirements will result in a 10% penalty.

Evaluation

Ninety percent of your score will come from correctness and 10% of your score will come from following our programming style guide. Applicable submission penalties will then be applied.


Return Home