suaveant has asked for the wisdom of the Perl Monks concerning the following question:
In the past this was pure Perl/MySQL with mappings in the format definitions pointing either to MySQL table items or special perl functions to handle the data. Much of the calculations/login for report items were done by building MySQL statements with things such as +-*/ IFNULL IF CONCAT etc... Anything done in Perl was a special case that was coded by me rather than defined in the format editor.
The new format generator is to be more flexible. I am implementing an abstraction layer for the database so that I can just change a single mapping if a table changes rather than every format (really should have done that the first time around, sigh). I am also adding the possibility of other data sources, such as a system in another department we are able to call into.
In doing this, the old way of building everything into MySQL queries just isn't going to cut it, since some of this data won't be in MySQL and I don't want to put it into a temp table each time I run a report.
My thought, since the people making the format definitions are already familiar with the MySQL statement layout and basic functions they were using, is to parse this format into something that I can translate and use to do calculations in perl OR MySQL depending on where the data is coming from.
I need to build this into a logic engine that can be passed the data items and quickly generate the calculated value on a row by row basis.
So... that was the background... here is the real question. How would some of you go about this? I want to get it right this time around. Any help is appreciated.
My thoughts so far: I could write my own parser, but I was thinking it would be a good time to learn something like Parse::Recdescent or YAPP or something similar. I have never used any of these before and while I was looking I was having trouble figuring out how to do order of precedence.
Here are examples of what a statement might look like...
Anthing in the form of {n} maps back to a data item in the abstraction. Some abstractions will have
arguments (this is necessary since things like 1-n tables need some sort of wrapper to get the proper single field) they would look like {n(args)}.
1 + {3} * 5
#IF(test,then,else)
IF({3} > NOW()-INTERVAL 1 DAY, {3}, 'Some text')
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing and executing a psuedo-language
by samtregar (Abbot) on May 25, 2005 at 17:21 UTC | |
by suaveant (Parson) on May 25, 2005 at 18:44 UTC | |
by samtregar (Abbot) on May 25, 2005 at 21:56 UTC | |
|
Re: Parsing and executing a psuedo-language
by djohnston (Monk) on May 25, 2005 at 17:53 UTC | |
by BUU (Prior) on May 25, 2005 at 22:52 UTC | |
|
Re: Parsing and executing a psuedo-language
by terce (Friar) on May 25, 2005 at 16:24 UTC | |
by suaveant (Parson) on May 25, 2005 at 16:37 UTC | |
|
Re: Parsing and executing a psuedo-language
by phaylon (Curate) on May 25, 2005 at 16:13 UTC |