First some general advise. I personally prefer alternations instead of multiple rule definitions, if only for the fact that it makes the grammar look more BNF-ish (which is easy for me to read) Thus:

Address : '(' /address/i '=' AddressTCP ')' Address : '(' /address/i '=' AddressIPC ')' Address : '(' /address/i '=' AddressSPX ')' Address : '(' /address/i '=' AddressPipe ')'

Would become:

Address: '(' /address/i '=' (AddressTCP | AddressIPC | AddressSPX | Ad +dressPipe ) ')'

Or better yet:

Address: '(' /address/i '=' AddressProtocol ')' AddressProtocol: AddressTCP | AddressIPC | AddressSPX | AddressPipe

Also:

TNSEntry : NetServiceName '=' Description TNSEntry : NetServiceName '=' DescriptionList

Would become:

TNSEntry: NetServiceName '=' (Description | DescriptionList)

Note: In this last example order can matter in some situtations, you'll just have to play with it.

Now as far as:
The second problem is tied to the order of the clauses to be matched. If I take the following line:
AddressTCP : Community(?) ProtocolTCP Host Port
It will match the code only if they come in that exact order. There are no rules stating that Community needs to be first and Protocol needs to be second ... The obvious solution is to create create every permutation of this line. My question is "Is there an easier way?" What could be a relatively small program could otherwise become quite unwieldly.

I guess I don't understand what you are talking about here. The rule that you have states: AddressTCP by definition is: An optional Community followed by required Protocol, Host, and Port. So yes order does matter here. The rule does require that if a community appears, it must come before the protocol. I don't know enough about the TNSNAMES.ORA file to divine the intended meaning. A clearer description of the exact syntax of this line may help.

Also are you parsing each line individually just so you can report which lines contain errors? If so you can accomplish the same thing by letting Parse::RecDescent parse the entire input for you. There's no need to parse the document before you "parse" the document. Anyway that's just my $.02 I could be wrong.


In reply to Re: TNSNAMES.ORA and Recdescent by linux454
in thread TNSNAMES.ORA and Recdescent by jmr4096

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.