in reply to Maintaining horrible C with Parse::RecDescent

Do you REALLY need to parse C?

Could you instead reformat the tables to some easily parseable format, and maybe surround them with comment markers your perl script could locate?

That way, you only have to worry about parsing/generating the tables themselves, which is a MUCH simpler problem. You can probably even do it with relatively simple regexen, without having to drag in Parse::RecDescent.

There's nothing wrong with parser generators, and REALLY nothing wrong with P::RD, but I think it's probably overkill for what you need.

Replies are listed 'Best First'.
Re: Try another tack...
by isotope (Deacon) on Mar 15, 2002 at 16:17 UTC
    Could you instead reformat the tables to some easily parseable format

    That's the problem. I have several thousand tables I would have to reformat.

    --isotope
    http://www.skylab.org/~isotope/
      Ouch.

      Any chance you can automate the reformatting somehow?

      Even if you could just put in a "table starts here"/"table stops here" type of marker around the tables, then the rest of your problem gets a lot simpler.

      Given the number of tables you're dealing with, I agree that's probably not trivial. But if you're lucky, there's some indicator you can "grab on to" to start from. How are the tables declared, with [][][]...?

      I think there's got to be a way to get a start on the problem, but without knowing what the code looks like, it's hard to make intelligent guesses.

        Ok, here's an example of one of the smaller tables. (pardon the mangled SJIS Japanese comments)
Re: Try another tack...
by RMGir (Prior) on Mar 15, 2002 at 17:14 UTC
    (backing up a few levels, because the reply chain was getting pretty deep)

    Are all the tables STP_OLTAPON's? I'm pretty sure you can craft one (very ugly) //x regex to handle one of those tables, and reformat it. But it's not worth the effort if that particular type is only used for this one table...

    That is some scary stuff!

        Hmmm... If you do
        perl -ne'print if /^[A-Z_]+ [a-z_0-9]+ = {/' *.c
        does that catch all of the array declarations?

        Does it catch anything else?

        If that works, you're home free (almost) :). At least as far as marking the array starts goes...

        Let's back up a bit, again. What were you thinking of doing with the tables if you can find them? Extract the data to some more maintainable format and have scripts to go back and forth? Just format them in place so they're easier to read/edit?