On Wednesday, Feb 4, 2004 PerlDiscuss - Perl Newsgroups and mailing lists said: > > With the following code fragment, I realise I can access the array > containing the term values using the notation $item[2] as shown below: > > SimpleExpression : term (AddOperator )(s?) > { > my $SimpleExpressionArray = $item[2]; > my @SimpleExpression = @$SimpleExpressionArray; > } > > However, if I have repetition of multiple statements such as (AddOperator > term )(s?) as show below. How can I access both the AddOperator values, > and the term values. If I access $item[2] as in the above example, it only > contains the term rule values and the AddOperator values apear to be lost. > > SimpleExpression : term (AddOperator term )(s?) > { > } > > I apologise if I have not included enough detail, I have tried to be > direct and to the point. Please let me know if you require more detail. > > Paul Kennerley >
Based on your code fragment the answer is "you can'". Or at least not without knowing what AddOperator and term are returning. If you want a higher parsing expression to know what a lower parsing expression is *doing*, the lower parsing expression has to tell it. This can be done either with global variables (a *bad* idea) or with return values. What does AddOperator and term return in their respective code fragments? If they *both* return something interesting it should be in the $item[n] array. Remember that what $item contains depends on what you coded, so you get the data structure you coded. Try returning what you want, and also try using Data::Dumper to make it clear what was returned. For example, in the code above, do this: SimpleExpression : term (AddOperator )(s?) { my $SimpleExpressionArray = $item[2]; my @SimpleExpression = @$SimpleExpressionArray; $DB::single=1; # breakpoint 1; } and invoke perl with the debugger (i.e. -d switch). When you hit the "breakpoint", you can use Data::Dumper to print out the entire recursive contents of @item and it will show you what is there. -- Intel, Corp. 5000 W. Chandler Blvd. Chandler, AZ 85226 -- Intel, Corp. 5000 W. Chandler Blvd. Chandler, AZ 85226