Perl-Sensitive Sunglasses | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
This is certainly not an easy problem. It's easy to write a piece
of code that will only terminate because it has exhausted all memory,
or ran out of stack space - because you can have loops. Furthermore,
even if there aren't loops, a naive approach might lead to a program
that runs in time quadratic to the number of defines.
I suggest approaching the problem as seeing the file as a graph. Each #define is a node, with as (outgoing) edges edges to nodes its definition is refering to. Now that you have made a graph, first you need to find out whether there are any loops - if there are, determine what you are going to do with them. Throw them out, die(), whatever. Second, do a topological sort, then you can process the defines like you are doing now:
Luckely, there's a graph module on CPAN that could help you. Abigail In reply to Re: Parse C-like define statements
by Abigail-II
|
|