Programming Assignment 3 (due midnight 03/05/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. (30 Points) Write Prolog code answering the query of FCS problem 14.3.1 and proving the facts formulated in FCS problem 14.9.2.
2. (10 Points) Lab 5 - Introduction to Parser Generators.
3. (60 Points) Create a Parser Generator for Regular Expressions.

Write a parser for regular expressions using Python with the parser generator PLY. 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)

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

• union "|"
• concatenation (juxtaposition)
• closure "*"
• symbols coming from the alphabet of single lower case letters
• "(" and ")" for grouping

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 5. (Hint: The precedence of the math operators was exponent highest, multiplication next highest, and addition lowest.)

Here are some examples:

• `a` # single letter
• `b` # single letter
• `ab` # concatenation
• `a|b` # union
• `a*` # closure
• `a|ba` # union of a and ba (due to precedence rules)
• `(a|b)a` # concatenation of (a|b) and a
• `ab*` # concatenation of a and b*
• `(ab)*` # closure of concatenation ab
• `(a|b)*abb`

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"]
}```
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"]
}```

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 3
3. Attach all solutions in a single zip or tar.gz file. Name the file username_a3.zip or username_a3.tar.gz where username is your drexel login. For example, mine would be au49_a3.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:
2. math_example.py - Your modified version from lab 5 handling exponents.
3. regparser.py - Regular Expression Parser using PLY.
4. 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.
5. test_input.txt - (Optional) a test file for the python parser. `python regparser.py < test_input.txt`
6. Each file should contain: