Syntax Coloring Assignment

CSC 7000-002 Algorithms & Programming
Fall 1999, Mendel 115
Dr. David Matuszek

The idea of this assignment is to prepare a C program so that it looks good on the Web. The purpose of this assignment is to give you practice with strings and file I/O.

Documents for the Web are written in HTML (HyperText Markup Language). HTML uses tags, enclosed in angle brackets, to tell your browser how to format things. For example, <b>enclosed text</b> causes the enclosed text to be made bold. The entire document should be enclosed in assorted other tags, as follows:

<html>
<head>
<title>Syntax coloring assignment by
(your name goes here)</title>
</head>
<body>
<pre>
   
Your document (C program) goes here.
</pre>
</body>
</html>

Many modern program editors use syntax coloring: keywords, strings, and comments are set off by putting them in different colors. Your job is to write a program to do very simple syntax "coloring":

  1. Read in a C program from a file (get the file name from the command line).
  2. Embed the program in the necessary HTML tags, perform the necessary character conversions (see below), and use <b> ... </b> tags to make all the keywords bold.
  3. Write out the C program on a new file, replacing the .c in the file name with .html; e.g. if your input file is sample.c, your output file should be sample.html.

Since HTML uses the characters < (less than), > (greater than), and & (ampersand) for its own purposes, you will have to replace these in the C program you are processing with &lt; &gt;  and &amp;  respectively.

For extra credit, use <i> ... </i> (italic) tags around quoted strings, and do not embolden any keywords that might occur in those strings, e.g. "Not for sale."

When you have your program running, apply it to itself. Print the result out (from Netscape or Internet Explorer) and hand it in.