Implement, document (i.e. provide specifications), and test all your code. Make sure all your code is thoroughly tested and runs on tux.
| ?- min(10,[1,2,3,4,5]). no | ?- min(1,[1,2,3]). true ? yes | ?- min(X,[2,5,1,4,2]). X = 1 ?
| ?- sentence([the,boy,pets,a,dog]). yes | ?- sentence([the,girl,sees,a,cat]). yes | ?- sentence([girl,pets,boy]). No
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)
You can download PLY from http://www.dabeaz.com/ply/. PLY is used for the example parser in Lab 5.
Input Format
Your parser should except regular expressions built up from union "|",
concatenation (juxtoposition), and closure "*" and symbols coming from the
alphabet of single lower case letters. You should also allow "(" 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 mathmatic grammar from Lab 5. (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. It can be downloaded from http://www.graphviz.org/. 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:
a|b View DOT File View Image
a(b*) View DOT File View Image
python regparser.py < test_input.txt