WMich Home

 

CS Home

 

Ajay Gupta's Home

 

CS4850 Home
Class Policies  & Syllabus
Topics Covered
Home Work I
Home Work II
Home Work III
Home Work IV
Home Work V
Home Work VI
 
 
 
 
 
Message  Board
Class List
Reading List

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Email webmaster

 

 

 

CS 4850 - Programming Languages

HW3

SummerII 2007

 

Given: July 23, 2007

Due August 3, 2007 (1:30pm), postponed to 08/06/07, 11:59pm. - Cancelled due to non-submission by the most of the students.

 

You are to write a parser for LISP s-expressions. For the sake of this parser, you may define s-expressions according to the following grammer. The terminals are token, integer, real number and string atoms (denoted as tok, int, realNum and st, respectively), as well as the left paren and the right paren.

         <s-expression> := tok | int | realNum | st | ( <rest-of-list>

         <rest-of-list> := ) | <s-expression> <rest-of-list>

You are to demonstrate your parser by using the input which conforms to the above grammer. When a properly formed s-expression is typed (possibly across several lines of input) your program should

  1. print the s-expression in “list form,” and
  2. print the s-expression in “dotted form” (to show the link lists created by your parser).

These two forms are identical for atomic s-expressions. The general rule is that list (S1 S2 . . . Sn) is equivalent to the dotted form (S1.(S2.( . . . (Sn.nil) . . . ))). The Si ’s denote s-expressions. For example, if the input lines are


( A (
         B C ) D
)


then your program should respond with the dotted form
      ( A ( B C ) D ) – – (on this print, you are to actually show the lexemes in the input)
followed by the list
      
( A . ( ( B . ( C . nil ) ) . ( D . nil ) ) ) – – (on this print show the symbol table addresses, as in HW#1, for all elements except the parentheses)


Your program should accomplish the parsing by first modifying the input into “expanded quote form” (for example (CAR ’(A B C)) is expanded to (CAR (QUOTE (A B C))). Essentially speaking replace ’ by (QUOTE and insert ) at the appropriate place), then dynamically building the internal LISP structure (or s-expression) as the token strings produced by HW#1 arrive. This internal LISP structure should be returned as an instance of the pointer type S_expr which points to a variant type of record. The following C definitions might be used (convert to appropriate syntax if you are using C++/Java):

typedef enum {TRUE, FALSE} boolean;
typedef struct {
       boolean isatom;
       union {
             atomic_type atom_value; // define atomic_type, exists when isatom = TRUE
             S_expr carptr; // non-atomic, exists when isatom = FALSE
             } variant;
      S_expr cdrptr;
       } node;
typedef S_expr *node;


When a proper s-expression is parsed, an S_expr should be returned by the parser. The procedure which has called the parser can then send this S_expr to to two print routines. The first will take the S_expr and print the input lisp expression, and the second will take the S_expr and print it in the dotted notation using the addresses in the symbol table as constructed from HW#1.

It will be possible to get an improper sequence of tokens. You will need to recover from this situation and continue parsing. Use exception handling to accomplish this. Try to recover as gracefully as possible. In doing so you may find that you have to ignore some input. If necessary, this is okay.

You may use lex/flex and yacc/bison for this assignment.

The data file will be similar to hw3.dat.

Penalty for Late Submission

10% per day (including weekends). Turn in programs at the start of class when due.

 

Any student may be asked to show and discuss his solution in class, so be ready with your presentation.

For programming assignments, submit a zipped file of your source codes, scripts (to run your program) and report along with a hardcopy of your source codes, scripts, a couple of sample executions of your solution and report.

Use <hw#cs4850_yourlastname_mmddyy.{zip,ppt,doc,tex}> as the naming convention for your zipped, ppt, MS-Word, or LaTex files when emailing your submission to ajay.gupta@wmich.edu. . Replace '#' with the appropriate homework number.

REMINDER: You are responsible for making yourself aware of and understanding the policies and procedures in the undergraduate (pp. 268-270) [Graduate (pp. 24-26)] Catalog that pertain to Academic Integrity. Additionally, easy availability of information, material, source codes, lecture notes etc on the Internet may make it possible to find solutions to your assignments on the Internet or elsewhere. It is okay to refer to those, understand them and use them to enhance your solutions, generate your own ideas etc. However, you must give proper and full credit to original authors of the work, if you include their ideas. Failing to do so is part of academic and professional dishonesty. It will not be tolerated in this class. Do not give in to temptations....

 

 

 

 


Home