Programming Assignment 4 (due midnight 03/19/14)

Penalty for late submission: 10% less credit/day.

Implement, document (i.e. provide specifications), and test all your code. Make sure all your code is thoroughly tested and runs on tux.

  1. (10 Points) Lab 6 - Introduction to Recursive Descent Parsers
  2. (40 Points) Create a Recursive Descent Parser for Regular Expressions.

    Write a parser for regular expressions using Python by implementing a recursive descent parser. The input and output of the parser is the same as PA3. The implementation will be different. Your parser will take a regular expression as input. It will output a DOT file with the NDFA that accepts the regular expression. (more on DOT files below). Your recursive descent parser should be similar to that seen in Lab 6. You may reuse your code to generate the DOT files from PA3. You may not reuse any parsing code. The parser must be a hand written recursive descent parser.

    Input Format
    Your parser should except regular expressions built up from:

    The precedence of these operators should be: closure highest, concatenation next highest and union lowest. The binary operators for union and concatenation should be left associative. You should model your grammar after the mathematic grammar from Lab 6. (Hint: The precedence of the math operators was exponent highest, multiplication next highest, and addition lowest.)

    Here are some examples:

    Note that the comments are not part of the actual input. Nor are you responsible for parsing comments.

    Your program will read from stdin; there will be one expression per line.

    Output Format
    Your output should be a DOT file with the NDFA for the regular expression. We recommend Graphviz for viewing your dot files. On tux you can convert DOT files to images using the dot program. For example, you can convert output_0.dot to 0.gif by entering:
    dot -Tgif -o0.gif output_0.dot
    You should create a DOT file for each line of input. The first regular expression should be output as 0.dot. The next expression parsed should be named 1.dot. Continue accepting strings until the user enters Ctrl-D for end of file. You do not need to implement a quit command.
    Here are some example REGEXP to NDFA examples:

    REGEXP DOT file DOT image (NDFA)
    a|b
    digraph{ 
        rankdir=LR;
        start[shape=none];
        end[shape=doublecircle];
        node0 [shape = circle];
        node1 [shape = circle];
        node2 [shape = circle];
        node3 [shape = circle];
        node4 [shape = circle];
        node5 [shape = circle];
        start->node0 [label = "EPSILON"]
        node0->node1 [label = "EPSILON"]
        node0->node2 [label = "EPSILON"]
        node1->node3 [label = "a"]
        node2->node4 [label = "b"]
        node3->node5 [label = "EPSILON"]
        node4->node5 [label = "EPSILON"]
        node5->end [label = "EPSILON"]
    }
    aorb
    a(b*)
    digraph{ 
        rankdir=LR;
        start[shape=none];
        end[shape=doublecircle];
        node0 [shape = circle];
        node1 [shape = circle];
        node2 [shape = circle];
        start->node0 [label = "EPSILON"]
        node0->node1 [label = "a"]
        node1->node2 [label = "EPSILON"]
        node2->node2 [label = "b"]
        node2->end [label = "EPSILON"]
    }
    aandbstar
  3. (50 Points) Adding Relational Operators to the Mini Language

    Extend the mini language and interpreter introduced in week 10.
    The code can be downloaded from here

    The operators are < > <= >= == !=

    You have some choices where you want to stick them in the grammar. E.g., you can describe a separate conditional category, or you might just make them expressions.

    The following syntax must be allowed:

    The following constructs will be allowed (but not required):

    An easy solution is to allow a boolean to be a number, then use 0 for false, and 1 for true.

    Note, the four operators < > <= >= all have the same precedence, lower than addition, and higher than assignment. The last two, == != have precedence just lower than the other four, still above assignment (everybody's above assignment).

    You'll need to add some tokens to your grammar, and make your lexer a little smarter. You'll also need to add new classes, for these operators.

  4. (Extra credit, 12.5 points) Exercise 4.4 of SICP II, section 4.1.2. Scheme interpreter from SICP
  5. (Extra credit, 25 points) Exercise 4.9 of SICP II, section 4.1.2. Scheme interpreter from SICP
  6. (Extra credit, 12.5 points) Exercise 4.11 of SICP II, section 4.1.3. Scheme interpreter from SICP
  7. (Extra credit, 25 points) Implement problem 1 of PA3 in the query language of SICP III. Query language interpreter from SICP

Submission Guidelines

  1. Assignments must be submitted via Email.
    Email the Assignment to au49@drexel.edu
    CC a copy to Professor Nowak kn33@drexel.edu
  2. The Title of the Email must be [CS360] Programming Assignment 4
  3. Attach all solutions in a single zip or tar.gz file. Name the file username_a4.zip or username_a4.tar.gz where username is your drexel login. For example, mine would be au49_a4.zip. Here is a useful website for making zip/tar.gz/etc in linux
  4. In the body of the email list all the files you are submitting. Give the name of the compressed file and a list of the contents. If any files are missing/corrupted, then I will know what you submitted.
  5. Submit one text file for each question. You should submit the following files:
    1. *** Readme.txt - A readme file explaining how to run and test all your files ***
    2. RecursiveDescent_math.py - Your modified version from lab 6 handling exponents.
    3. The entire MiniPython directory with modifications to:
      1. interpreterext.py
      2. programext.py
      3. Test Files showing that your additions work as intended
    4. recursiveparser.py - Recursive Descent Parser for Regular Expressions
    5. You may include supporting files for your python implementation, for example, if you wrote a special class or library and stored it in a different file.
    6. test_input.txt - (Optional) a test file for the python parser. python recursiveparser.py < test_input.txt
    7. ch4-mceval-4.scm - Extra credit exercise 4.4
    8. ch4-mceval-9.scm - Extra credit exercise 4.9
    9. ch4-mceval-11.scm - Extra credit exercise 4.11
    10. ch4-query-31.scm - Extra credit exercise 14.3.1
    11. ch4-query-92.scm - Extra credit exercise 14.9.2
  6. Each file should contain:
    1. Your Name
    2. Comments documenting all functions included in the file
    3. Your function definition
    4. Tests for your functions
  7. All your code MUST run on tux.cs.drexel.edu.