[ILUG] Parsing script...
Mel Gorman
mel at csn.ul.ie
Mon Jan 26 18:58:16 GMT 2004
On Fri, 23 Jan 2004, Peter Aherne wrote:
> I stuck on yet another scripting problem. After much expermentation and
> googling I'm still nowhere. Here is the problem, I want a script to turn
> this :
>
> <snipped>
Not easily. For what it's worth, you are trying to do "Loop Unrolling"
which would normally be handled by the compiler optimizer so you could
try and search for programs which do automatic loop unrolling.
If you can't find one and you don't want to use flex and yacc to do this
(which is the right way), you can try a simple state machine in perl. i.e.
start in STATE_OUTSIDE_LOOP, search for stuff that looks like a for loop,
parse it and enter STATE_INSIDE loop. If you find a {, increment a brace
count, a } and decrement it. Once you have the full loop read, use regular
expression to replace i with each number in the interation. It's doable
within a few hours but will be very very very delicate. It depends on if
this is a once off job or not.
--
Mel Gorman
More information about the ILUG
mailing list