To parse Verilog, you can use Hardware::Verilog::Parser. I used this parser on a large Verilog library. It worked, but it was a bit slow for my purposes.

Maybe someone else knows of a C or C++ parser that is similar. Parsers are not generic because they depend on the grammar of the language being parsed.

If you store the code in a hash and want to re-assemble it, you'll need some way to get the code to come out in order, since an ordinary perl hash doesn't preserve order.

Instead of an ordinary hash, use one of perl's object-oriented data structure modules. The best module to choose for your task depends on a lot of details, so please describe your problem in more detail to get better advice on this.

It should work perfectly the first time! - toma

In reply to Re: looking Generic File Parser script? by toma
in thread looking Generic File Parser script? by EchoAngel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.