in reply to Re: Parse:RecDescent grammar help
in thread Parse:RecDescent grammar help
1) The first element of @item (ie $item[0]) is the PRD rule name. You will notice that in a lot of cases I am grabbing item 1+ and ignoring item 0 because we want the matched data, not the name of the rule. In the three 'method' rules we select 0,2,4/5 from @item which gives us the rule_name, var_name, assign_data. The rule name is the same as the method name. Get it? The rule we match also tells us what function to call to deal with the data.
2) The data is stored as array_refs or array_refs of array refs. See perlreftut. I have given you an example of how to access a typical value. The parse tree is an array ref, that hold more array refs, which probably hold yet more array refs. The first level of array refs if what we iterate over. We assign that to $item and this is the result of one successful rule parse. @$ syntax gets us an array from our array ref. $ref->[0] gets us item 0, rather than the whole list.
3) You can modify the grammar to your hearts content. The more complexity you add the more problems you are going to find. You have what looks a hell of a lot like Perl5 syntax and Perl is a bitch to parse. Why not just use a real language and let its parser generate a parse tree for you? I am not sure you have considered just how complex a project what you propose is.
cheers
tachyon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Parse:RecDescent grammar help
by pip9ball (Acolyte) on Oct 26, 2004 at 13:34 UTC |