COMP 144 Programming Language Concepts
Spring 2004


Assignment 3: First Perl Script

Due Date: Mon Feb. 9

Description

Your task in this assignment will be to write a Perl script that does simplified MACRO PREPROCESSING like the C compiler does.

An input file will look something like this:


   MACROS

   #define student   hard working intellectual
   #define job       high-paying career
   #define PI        3.1415926

   PROGRAM
  
   Here a student making a data file can have 
   any text ... 

   Macro declarations come first, program text after.

   The job of the macro procesor will be to find
   the target strings whenever they appear and 
   replace them with the rest of the line that
   follows the target string in the corresponding
   macro definition

   public class fooBar {
      // the job of this class is...
      //
      public static int pi = PI;
      void getPi ( ) { return pi; }
   }

The output file will the test after "PROGRAM" line with all the proper macro substitutions done.

Extra Credit

For extra points you may make your program do these things:
  1. Instead of having "MACROS" and "PROGRAM" delimit the macro declaration section, simply find all #define lines and do macro replacement from the point of the line on...
  2. Allow prior macro definitions to cause replacement to take place inside subsequent macro declarations.
  3. Allow a macro declaration target string to contain blanks... something like this:
       #define "some target string"  the replacement part follows to EOL
    
  4. Allow a macro definition to specify that case may be ignored... maybe like this:
       $define bday/i  date of birth
    

How to get Perl

Perl.com is a clearinghouse of information about Perl. The binary distribution link at this site point you to ActivePerl.

You should go to ActivePerl for Windows and Unix implementations of Perl. Download the binaries and follow the installation instructions.

The department has Perl installed on our Unix compute servers (eagle, capefear). It is located at "/usr/local/bib/perl" and you can that one if you have an account.

You can develop your programs with any Perl you have, but you must make sure it runs correctly under ActivePerl on a PC, or under the Unix Perl.

Submission

This assignment is due Feb. 9 (by class time). Late assignments get 25% off each day they are late. Your submission will be electronic. Your electronic submission will be an e-mail sent to wluebke@cs.unc.edu with the subject

COMP 144 Assignment 3 Submission

and a single .zip file attached to it. This file should have the following content:

Grading

I will grade both the quality of the source code (design and documentation) and the output. I will not grade programs that do not compile. Collaboration is encouraged, but you cannot share source code. Honor Code applies to this program. Please, read http://www.cs.unc.edu/Admin/Courses/HonorCode.html for more details.