Assignment 1

CS 550 Programming Languages Instructor: Jeremy Johnson  Due date: Sun. April 14 at 9am

Parsing (100 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 2 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:

    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, on a single line, to stdout, 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.

Second Language

You will do part 2 again, in a different language.

Input

Each of your parsers will read from stdin. It will attempt to parse a list, as described in the grammar, above.

See sample.input .

Output

After the outer-most list is read, print the list to stdout, on a single line (followed by a newline). If the input is invalide, print -error-.

The list will be denoted by parentheses, elements will be separated by commas.

Given the example in sample.input, you would print:

( 99, ( 43, 86 ), 24, 42 )

Grading

Points will be assigned as follows:

35 part 1 [25 points for correctness, 10 points for style/doc]
35 part 2.1 [25 points for correctness, 10 points for style/doc]
20 part 2.2 [10 points for correctness, 10 points for style/doc]
10 README

How to Submit

Since you can do this in a number of languages, submit a makefile . Here is a sample makefile. Please ask for help w/makefiles.

Submit the following files to Bb Vista:

Please just submit files, rather than a tarball. If you *need* subdirectories, tar up what is needed within your directory; i.e., don't include the top-level directory in the tarball, submit your makefile separately, and include another target, unpack .

Note: Please pay attention to file names. E.g., makefile is not Makefile, and README is not README.txt.