Computer Science 4627
Written Assignment 1

Due date for all except Exercise 2.24: Wednesday, January 19, in class.

Due date for Exercise 2.24: Friday, January 21. Just print it and turn in the printed Flex program. Do not turn in the C program that is generated by Flex.

These exercises are from Chapters 1 and 2 of the text.

  1. Exercise 1.10, page 29. Give a short, clear explanation, using Tee diagrams as examples.

  2. Exercise 2.1 (a-e), page 91.

  3. Exercise 2.8 (a-e), page 91.

  4. Exercise 2.17, page 93.

  5. Exercise 2.24, page 93. This is a small programming exercise. Write your program in Flex, and test it. You can use three global variables for the counters of the number of characters, the number of words and the number of lines. Flex is available in Unix, and is called flex. If you run

        flex prog.l
      
    then flex will produce a program written in C (not C++) called lex.yy.c, defining a function called yylex. Stick with C for this program; using C++ here is useless, and will only cause headaches.

    Normally, yylex reads one token and returns. This program is different. It just keeps reading until the end. The yylex function will automatically return 0 when it encounters the end of file. Include a main function that calls yylex. When yylex is done, the main program should print the counts.

    Note that spaces and punctuation do not count in words, but they do count as characters. To count lines, just count the number of newline characters. Do not worry about what happens if you are reading a file that does not end on a newline character.