Last semester at University, I took a course based around ‘Formal Languages and Compilers’ aka COSC261. We had weekly quizzes to complete, which was great, but there was one task that always felt a lot more tedious than it needed to be: translating JFLAP diagrams to a transition table in to list of lists e.g. [ [ ], [ ] ] format, as required by the University’s quiz server.
I felt a couple stabs to the grade-book as I hastily submitted DFAs that worked perfectly on my local machine, but were rejected via the quiz server. The rejection was solely caused by mishandling of the data entry. As any geek would, I raged at the thought of mindless data entry and studied the implementation of JFLAP. It turns out that JFLAP saves as a .jff file, which does sound mysterious, until I inspected it in vim. Below is a screenshot of the inspection and the implementation.
Sure enough, it was a neat XML representation. Have a look for yourself, the developers put a lot of effort into the formatting (thanks a lot, team).
$ vim yourJFLAPfile.jff
Once in vim, you’ll need to enter :q! to exit, yes include the colon. This quits without saving, as you probably don’t want to modify the file directly (i.e. likelihood of adding errors).
Recently I had been working on processing data-feeds, which the majority of which were RSS/XML based, so this was a breath of familiar air indeed. My implementation is merely a proof of concept and definitely encourage anyone with enough time to improve upon it! The output is currently a tuple (FROM, [TO, SYMBOL]). As a trivial exercise you’re welcome to convert this to a list of lists, so that the quiz server does indeed accept it.
I’ll leave challenge of interpreting the parsing as homework. The script and all directions are on GitHub: https://github.com/C-Kenny/DFA_parser_COSC261
Some of the issues I ran into were:
- Parsing Epsilon
- Withholding the frustrated knowledge of how many marks could have been saved
- Implement for NFA, currently it works great with DFA (I’ve already added the ability to process Epsilon and the entries for each node are not statically typed)
- Build an implementation of the script that links to our schools variant of Moodle, so that students can upload the JFLAP files (be sure to watch out for that nasty XML).