Just looking at your grammar, it seems to me that statement and function_method are infinitely recursive with respect to brace_statement, paren_statement and bracket_statement (which themselves are defined in terms of statement).

Since you are not trying to actually parse the contents of functions, but simply return the contents wholesale (in order to associate it with the function name in a hash), why not make it simple for yourself?

For each function, there are two things you need: the contents of the parentheses and those of the curly braces, either of which may be nonexistent (empty). In order to recognize the end of a particular set of parens (or braces), you need to be able to identify any embedded matching pairs (or parens, braces or square brackets), which is why you should identify symbols, quoted strings, etc. as well.

Okay, you have these basic building blocks. Now you need to combine them in ways in which they might actually appear within programs without overcomplicating your task.

For instance, I think in your grammar, the statement rule is over-used (incorrectly). I'm uncertain, but I don't think the parameter list of a function can consist of arbitrarily complex statements; likewise, for the contents of expressions within square brackets. Perhaps you should describe expression in a rule. Then, your definition of statement could be comprised of several different kinds of expressions (e.g., assignment).

It would be interesting to know where you are taking this; are you building a Javascript debugger in Perl?

dmm

If you GIVE a man a fish you feed him for a day
But,
TEACH him to fish and you feed him for a lifetime

In reply to Re: Rec::Descent Woes - Parsing JavaScript Files and Other Issues by dmmiller2k
in thread Rec::Descent Woes - Parsing JavaScript Files and Other Issues by Incognito

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.