CS 4300
Fall 2006


A program in lex. (Modifed from original assignment by Jose Amaral.)

The files that you need for this homework can be found in zscan-calc.tar.gz.


The file scan.l contains the description of tokens to generate a scanner using lex. To generate the scanner use the following command:

 lex scan.l
You will notice that lex created the file lex.yy.c in your current directory. Now you must compile this file into an executable program. Do so with the following:
 cc -o scanner lex.yy.c
Now you can run the executable scanner and play with it by typing in text and checking if it is recognized as a token. You may want to consult the file scan.l as you play with the scanner to understand how the tokens are specified. Make sure and try operators, words, parenthesis, etc. The scanner will output the type of symbol that it recognized for the input that you typed. What are the functions of period, space, and comma in this scanner? Can you list all the characters that are interpreted as special symbols by the scanner? You can use CTRL-D to terminate the scanner. 

Now that you have played with the scanner,  examine the file scan.l and try to identify how the tokens are specified. Did you miss some of the special symbols when you played with the scanner?