Skip Menu |

This queue is for tickets about the Parse-RecDescent CPAN distribution.

Report information
The Basics
Id: 55494
Status: resolved
Priority: 0/
Queue: Parse-RecDescent

People
Owner: Nobody in particular
Requestors: anand.vn [...] hcl.in
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Recdescent - Production Unit Fails Becoz of Empty Function
Date: Fri, 12 Mar 2010 15:24:11 +0530
To: "bug-Parse-RecDescent [...] rt.cpan.org" <bug-Parse-RecDescent [...] rt.cpan.org>
From: "Anand Venkatesan, ERS, HCLTech" <anand.vn [...] hcl.in>
Hi, I have a query regarding the return item and the function call inside the actions block of a production unit. If nothing is returned from a production unit, the value of the last component of the production unit will be returned. But in my below program the production unit (declare_statement) got failed if nothing is returned, where a function call alone placed inside the action block and that function has nothing to execute (empty function). But if I add any code in the empty function, the production unit got passed. Is it a bug or the normal behavior of the Rec-descent package? Recdescent version : Parse-RecDescent-1.964 Perl Version : v5.8.8 built for MSWin32-x86-multi-thread ####### Program Starts ########## use strict; use warnings; use Data::Dumper; use Parse::RecDescent; my $Parser = q{ statement : declare_statement | return_statment | <error: $text> declare_statement : data_type var_name ';' { ::process_declaration(@item); } return_statment : 'return' var_name ';' var_name : /[_a-zA-Z0-9]+/ data_type : ('int' | 'char') {$return = $item[1];} }; my $Data = join '', <DATA>; my $C_Parser_Obj = Parse::RecDescent->new($Parser); $C_Parser_Obj->statement($Data); sub process_declaration { #Empty Function causes the Production Unit "declare_statement" To Fail! #my (@Data) = @_; #uncomment this line to pass the production unit } __DATA__ int myvar; return myvar; ####### Program Ends ########## Thanks & Regards, Anand V DISCLAIMER: ----------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any mail and attachments please check them for viruses and defect. -----------------------------------------------------------------------------------------------------------------------

Message body is not shown because it is too large.

Subject: Re: [rt.cpan.org #55494] Recdescent - Production Unit Fails Becoz of Empty Function
Date: Fri, 12 Mar 2010 21:57:39 +1100
To: bug-Parse-RecDescent [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Hi, Show quoted text
> If nothing is returned from a production unit, the value of the last > component of the production unit will be returned. But in my below > program the production unit (declare_statement) got failed if nothing > is returned, where a function call alone placed inside the action > block and that function has nothing to execute (empty function). > > But if I add any code in the empty function, the production unit got > passed. Is it a bug or the normal behavior of the Rec-descent package?
That is normal behaviour. An empty block returns undef, which becomes the return value of the rule. But an undefined return value always denotes failure of the rule. All the best, Damian
Subject: RE: [rt.cpan.org #55494] Recdescent - Production Unit Fails Becoz of Empty Function
Date: Tue, 16 Mar 2010 19:52:49 +0530
To: "bug-Parse-RecDescent [...] rt.cpan.org" <bug-Parse-RecDescent [...] rt.cpan.org>
From: "Anand Venkatesan, ERS, HCLTech" <anand.vn [...] hcl.in>
Hi Damian, Thanks for your time. I was little bit inaccurate in explaining the actual problem in my earlier mail. An empty block of a productioin unit returns undef, which in turn causes the matched production unit to FAIL. This is okay. But in my case it is not an empty block. It contains a global variable value update and a function call. Please have a look at the simple example below, ##### Code Begins ##### our $Line_Number = 0; my $Parser = q{ declare_statement : data_type var_name ';' { $::Line_Number = $thisline; $::Line_Number = $Line_number + 1; #Do Simply ::process_declaration(@item); } }; Sub process_declaration { #This sub routine has nothing to do } ##### Code Ends ##### Only because of this empty function "process_declaration()" the production unit (declare_statement) got failed though it matched. Just want to confirm is it the normal behavior of Recdescent parser. Please correct me if my understanding was wrong. Thanks, Anand V Show quoted text
-----Original Message----- From: damian@conway.org via RT [mailto:bug-Parse-RecDescent@rt.cpan.org] Sent: Friday, March 12, 2010 6:56 PM To: Anand Venkatesan, ERS, HCLTech Subject: Re: [rt.cpan.org #55494] Recdescent - Production Unit Fails Becoz of Empty Function <URL: https://rt.cpan.org/Ticket/Display.html?id=55494 > Hi,
> If nothing is returned from a production unit, the value of the last > component of the production unit will be returned. But in my below > program the production unit (declare_statement) got failed if nothing > is returned, where a function call alone placed inside the action > block and that function has nothing to execute (empty function). > > But if I add any code in the empty function, the production unit got > passed. Is it a bug or the normal behavior of the Rec-descent package?
That is normal behaviour. An empty block returns undef, which becomes the return value of the rule. But an undefined return value always denotes failure of the rule. All the best, Damian DISCLAIMER: ----------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any mail and attachments please check them for viruses and defect. -----------------------------------------------------------------------------------------------------------------------
Subject: Re: [rt.cpan.org #55494] Recdescent - Production Unit Fails Becoz of Empty Function
Date: Wed, 17 Mar 2010 07:08:57 +1100
To: bug-Parse-RecDescent [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Show quoted text
> An empty block of a productioin unit returns undef, which in turn causes the matched production unit to FAIL. This is okay. But in my case it is not an empty block. It contains a global variable value update and a function call.
Yes, but the function's body is empty, which means it returns undef. And since the function call is the last thing in the block, that means the block returns undef too. This is normal Perl behaviour, and correct behaviour for Parse::RecDescent as well. The solution is to ensure that the last statement in your block doesn't evaluate to undef in any way. For example: ##### Code Begins ##### our $Line_Number = 0; my $Parser = q{ declare_statement      :    data_type var_name ';'                                     {                                  $::Line_Number = $thisline;                                  $::Line_Number = $Line_number + 1; #Do Simply                                           ::process_declaration(@item); 1;                                      } }; Damian
The ticket history appears to indicate that this issue is resolved.