You will suffer greatly if you try to write your own general Verilog parser.

There are modules on CPAN that can do it for you. Maybe Verilog::Parser or Verilog::SigParser?

If you need to parse some auto-generated file or a restricted subset of the language, you stand a better chance. Is your example data auto-generated? Who but a machine would omit the carriage return following the ";" before the always block?

I don't know what you want to DO with the always block (and the rest of that Verilog code). What are you building in Perl and what data do you want to collect from the code to make it happen?

For your example code block, it is straightforward to pull out the clock, the reset (and it's polarity) and the expression this DFF uses. The next always block might be a latch, or a flop with synchronous reset, or no reset, or have multiple signals, or use SystemVerilog always_ff, or be an entire state-machine, or call a task, etc. In short, you need a language parser.

My advice is to use, or build on, what exists if possible. If not, then restrict what you are doing and start small.


In reply to Re: Reading block by shoness
in thread Reading block by ravi030

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.