Theory of Programming Languages

Assignment #2

Lexical Analysis for Pascal

 

Due beginning of class on September 23, 2011

Introduction and Objective

The purpose of this assignment is to use Flex/Lex to develop two scanners: one for simple arithmetic expressions and the other for a subset of Pascal.  All programs are to be in C, not C++ (your output from Lex/Flex should be lex.yy.c ).

Project Details

  1. Using Lex or Flex write a scanner for simple integer arithmetic expressions.  Your program should read arithmetic expressions from standard input and output the token and lexeme to standard output.  Program termination is signaled by EOF (i.e. continue processing expressions until EOF is detected).  There is no user prompting and no other output statements other than the token type and lexeme.  Below is a sample execution of your program.  Your Lex/Flex input file must be named proj2a***.l, where *** is your initials.

    % ./proj2a
    (2+34)*42
    LPAR       (
    NUM        2
    ADDOP      +
    NUM        34
    RPAR       )
    MULOP      *
    NUM        42
    *     +     (    )     42    #     345
    MULOP      *
    ADDOP      +
    LPAR       (
    RPAR       )
    NUM        42
    ERROR      #
    NUM        345
    <EOF>
    %

  2. Using Lex or Flex, write a scanner for a subset of the Pascal programming language.  Here is a sample input test file. and its corresponding output.  Your Lex/Flex input file must be named proj2b***.l, where *** is your initials.

Other Information

A list of tokens for both problems can be found here.

A grammar for the Pascal language subset can be found here.

You must submit a Makefile for each part of this project that is capable of building each project.

Submitting Your Project

Prepare a program assignment package that is to be turned in using a folder with pockets (don't use fancy folders with pictures). Your name is to be on all materials, especially the outside of the folder. The only information that is to be printed is the source code for the Lex/Flex files and the make files, to allow me to write notes back to you. The rest of the materials may be in files on the CD-R. The following is to be included in the package:

Assessment and Grading

This is an individual assignment.  Write well structured, well documented, flex/Lex files.  This project is worth 100 points.