COS 320, Spring 2000. Programming Assignment

Programming Assignment 2: Lexical Analyzer

For this assignment, you will build a lexer for the Fun language.  In order to do this, you will need to figure out all of the tokens that you need to lex.  The definition of Fun is here.  This document should contain definitions of all of the tokens you need to lex.  You should not produced tokens for whitespace. 

You will be building your lexer using ML-LEX.  There is more online documentation on ML-LEX here.  There is also some help in your textbook (Appel, chapter 2).

 

Using ml-lex

  1. Make a new directory as2 for this assignment.
  2. Copy the files from /u/cos320/chap2/ into as2.  This will include *.sml  *.sig *.lex and *.cm files.
  3. Please, familiarize yourself with the code that is already there.
  4. Run sml and compile the code using CM.make();
  5. Edit the code in fun.lex. You will have to remove some of the sample code and add a lot of your own.  Keep the following information in mind as you develop your lexer:

      

     

     

  6. You also might notice that the file fun.sml has been extended.  The set of types now includes reference types and there are operations to create new references and to get and set references.  As an optional exercise, you can extend the interpreter from last week to handle these references.  There is also an example test function in test.sml.
  7. Submit all your files including a README that explains any decisions you had to make. Use submit 2 <all files>.