CS326 - Project 1 : Lexical Analysis

Due Date: Monday, March 9, 11:59 p.m.

In this part of the project, you must build a lexical analysis module for the FLAME language. To do this, you will an automatic lexical analysis tool "plex" (Python Lex).

The Project Ground Rules

As an experiment, I am making the compiler project an individual programming effort. However, later stages of the project will be difficult. Therefore, I want to encourage you to fully interact with your classmates throughout the quarter. The only thing not allowed is blatant copying of code or solutions.

Part 1 - Create a project directory

Create a project directory called 'flame'. This directory will contain all of the files of your compiler and readme files. Create a file 'README' that contains your name. You are strongly encouraged to manage your project under CVS. However, I'm not going to twist your arm.

Part 2 - FLAME BNF

Using the informal description of FLAME in the earlier handout, create a file 'grammar' that has a formal specification of the entire FLAME grammar. Your specification should include the following:

Part 3 - FLAME Lexer

Now, using the list of tokens and regular expressions defined in Part 2, you task is to write a lexical analysis module that reads an input file as a string and produces a list of tokens. To do this, perform the following steps: To test your lexer, simply run it on a test file. For example:
% python flamelex.py test.flm
The output of the lexer should be a list of tuples of the form (token_name, lexeme, lineno) like this:
(ID,'position',1)
(ASSIGN,':=',1)
(ID,'initial',1)
(PLUS,'+',1)
(ID,'rate',1)
(TIMES,'*',1)
(INUMBER,'60',1)
...
In addition, your lexer must produce error messages for various types of problems in the input text.

To test your lexer, we will run it out a variety of input files to see if it produces the expected output. The token names do not have to match the example above, but the lexeme values and line numbers must exactly match to pass a test.

The /stage/classes/current/CS326/Tests directory contains a variety of test files and samples of the expect output. Keep in mind, your implementation must exactly produce the same output including all error messages, lexeme values, and line numbers to pass.

Detailed documentation about 'plex' can be found by reading its source or looking at its docstring. For example:

% python
>>> import plex
>>> print plex.__doc__
...

Handin procedures

  1. Your lexer must be contained in a file 'flamelex.py'. We must be able to run this file as follows to run a test:
    % python flamelex.py testname.flm
    

  2. Make sure you have a README file that includes your name and anything notable about your implementation.

  3. Make sure you created a file 'grammar' that includes the formal specification of FLAME.

  4. Create a Unix tar file for your project. This tar file should contain the 'flame' directory and be based on your login name. For example:
    % tar -cf yourlogin.tar flame
    

  5. On classes.cs.uchicago.edu, copy your tar file to the directory /stage/classes/current/CS326/handin/project1 For example:
    % cp yourlogin.tar /stage/classes/current/CS326/handin/project1
    

  6. Late assignments are not accepted. The handin directory will be closed after the due date.

Errata