Daniel is a web developer, system programmer and software architect with 12 years of experience...
web developer & system programmer
coder . cl
here you can find daniel's articles on programming, software development and ramblings on his current projects...
a meta parser model
by Daniel Molina Wegener on 02.02.2010One of my most recent projects is a Meta-Parser. The core requirement is to write a dynamic parser, which can be configured, allowing the user to setup certain patterns around the given input and extract those pattern tokens to being exposed to other layers of the main project. Surely this is a challenge, and interesting part of the global project. I’ve finished to work on this part of the project, it is implemented in C++ as the client requires it, and I’ve made a simple model based on the PAC architectural pattern.
overview
First we need a concrete class implementing the parser, but it needs an abstraction layer and also something which provides the proper parsing states to its internals. Finally we need to expose those extracted tokens outside of this component — the meta-parser.
Clearly the abstraction is made in top of a single template, the control is given from the ParserService class and the presentation is provided through the Token interface with the proper implementations.
substring automaton
Another interesting point is how specific string parsing is implemented. The system uses an FSM, which implements a simple automaton:
So, parsing the left hand token
implies parsing the value token
and then it states the right hand token, to complete the cycle reaching again the stored value token
. This is used to extract substrings. Where every token is configurable with a proprietary language. Finally, the full parser specific implementation is made on top of state machines which are used according the proper configuration representation using thitd party classes and structures, so is possible to extract the required tokens from the input source.
Also, each configuration and parser instances are designed for concurrency. The project will be running on with parallel tasks inside a mutithreaded — and possibly multiprocess — service daemon. Driven by my client schedule, I can not implement wait free algorithms, so I will be using standard operating system provided locks — and more easy to handle algorithms.
in deep with abstractions
Although the PAC pattern is designed for user interfaces, the usage of this pattern to communicate components and generate strong abstraction layers helps a lot on design and maintainability issues. Indeed, this patterns guarantee a reward while we are coding some design patterns. In this case, for example the MetaParser and the ParserService are both an instance of Adapters, where a transformation is made from one layer to other. While MetaParser is a strong abstraction layer for the given implementations.
Finally ParserService provide us the proper way to handle different parsing tasks, so we can determine inside it which abstraction to use though the proper MetaParser instance.
conclusion
The PAC pattern can be used to implement component communications and proper abstraction between application layers, among the usage on user interfaces. Does it falls in other architectural pattern? Anyone knows?.
Leave a Reply
You need to log in to vote
The blog owner requires users to be logged in to be able to vote for this post.
Alternatively, if you do not have an account yet you can create one here.
Powered by Vote It Up



