Assignment 1

CS 550 Programming Languages
Instructor: Jeremy Johnson 
Due date: Mon. April 13 at midnight

Parsing (50 points)

This assignment reviews the material in Lecture 1. You are to implement and test the list parser discussed in class. You will do this two different ways - 1) a recursive descent parser written by hand as shown in class and 2) an automatically generated parser like the one shown in class that uses bison/yacc (or the python or java equivalents Ply and CUP).

Your parser may be written in any of the following languages: C, C++, java, python. You may use the corresponding parser generators for the second part: bison and flex for C and C++ (see Lecture 2 for notes on using bison with C++, CUP for java, and PLY for python. Some CUP examples can be found in CUP/JFLex examples.

Background Information

Background information is obtained in chapter 4 of the text and the lecture outline in lecture 1, along with the reference materials for bison/CUP/PLY. Note that lecture 1 contains a bison grammar for the lists that you must parse.

You may want to consult the book:
John R. Levine, Tony Mason, Doug Brown, Lex & Yacc, 2nd/updated edition (October 1992), O'Reilly & Associates.

What to do

  1. Write a recursive descent parser that reads a list using the grammar:
    1. < list > &rarr ( < sequence > ) | ( )
    2. < sequence > &rarr < listelement > , < sequence > | < listelement >
    3. < listelement > &rarr < list > | NUMBER
    Your parser should construct an internal data structure containing the list that was read. Use a print routine to print the data structure, in the same format that was read, to verify correctness.
  2. Use a parser generator (e.g. bison with flex) to generate a function to read a list using the same grammar as above. The generated function should construct an internal data structure containing the list that was read (you must, as discussed in lecture, add action code to compute an attribute which is the desired list). Use a print routine to print the data structure, in the same format that was read, to verify correctness. See the files and for bison and flex files for the list grammar (without attributes). Also see Lecture 1 for instructions on how to build the parser from these files.

Recommenation

If you have time, you should do the assignment (at least the second part) using each of the different programming languages and parser tools (C++, java, python). You can assign different group members to work in the different platforms and compare approaches. This is a good opportunity to review/learn these languages and tools.

How to submit

Students should submit their solution electronically using webct. Only one submission is required per group. The group leader for the assignment should submit the assignment. Submit a gzipped tar file, called A1.tar.gz (the tar file should contain a directory called A1 which contains the files). The tar file should contain source code, instructions how to run your programs, sample input and output files, and a README file. The README file should describe all files that are included, contain instructions how to build and use the code, and outline how the code works. The README file should also contain a list of all group members and the group leader for the submitted assignment. You should also indicate how you tested your code. If your program is not working, you should clearly state this in the README file. Code should be documented (clear specifications and comments for any tricky parts of the code). Those questions that involve hand computations or proofs should be submitted as pdf or text files whose name indicates the question.