Sunday, March 11, 2012

Scratch Regular Expressions

Hi,

We had another group meeting this Sunday, and we got everyone on the same page for the project. In particular, we fixed a lot of issues pertaining to project setup that were preventing most people from getting anything working. Apart from a delay due to DST, the meeting went well.

I have been working on the regular expression matcher--or, more precisely, I was. I decided that regular expressions are messy and overkill for the application (purpose being merely to reformat the GWT output).

Instead, the new plan is to use a simple algorithm (string search) to find and format tags. This is simpler and cleaner. In addition, it has the advantage of being strongly linear time (which is only the best case for regular expressions). I could throw in some flak about Java not supporting pointer arithmetic, but at this point, I'm just glad that I'm writing algorithms :-)

Additionally, there will need to be a formatter API for the parser. This is implemented as a simple class that can (optionally) be passed to .generate(...). The class is analogous to a "struct", in that the point is to set various data fields, with others being set to defaults, and then pass it to a function.

I'm not entirely satisfied with this implementation, because the "struct" needs a public method ".apply()", which applies the struct's data values to an input string. It's paradoxical because this method must be public so that the parser can call it, but only the parser needs it. So, I'm violating encapsulation. Yet, I can't just move the .apply() method to be a private method of the parser because that violates encapsulation (the method really should be a method of the "struct"). In C++, I'd make parser a friend class, but in Java . . .

Final notes:
-I'm creating a new project wherein I can test my parser separate from the other modules of the program. Normally, I wouldn't care, but GWT is too unreliable and slow to fit my mandate of obscene amounts of runtime testing. It's a code quality thing.
-I'm working on the project mid semester self-evaluation (http://cs.unm.edu/~Ackley/460/selfEvaluation.html). I'm . . . not psyched.

Ian

No comments:

Post a Comment