FAQ
I have created a grammar for processing basic rules for a pbem I am
writing. I have also written an object for then processing the resulting
parse tree. What is happening is this: If I simply parse the input and
dump the tree, everything parses fine. The second I even "use" my
processing object module (which happens to be called "Process") the parse
fails. I did a TRACE and what seems to happen is the parser doesn't
ignore the newlines in the 2nd instance. I am totally confused. Below is
the snippet of my code in question. I can include copies of the grammar
andthe TRACE if that would be helpful. Any ideas? Thanks so much for
your help.


#START CODE
my $parser = new Parse::RecDescent ($grammar);
my $parsetree = $parser->orderset($bodytxt);

if (! defined $parsetree)
{die "Grammar parse failed!\n";}
else
{
use YAML;
print &Dump($parsetree), "\n";

#if I uncomment the below code, the parse fails
#
#use Process;
#my $process = Process::new();
#$process->processTree($parsetree);
#print $process->{results}, "\n";
}
#END CODE

--
Aaron Dalton
aaron@finch.st
http://aaron.finch.st

Search Discussions

  • Orton, Yves at Dec 17, 2003 at 1:45 pm
    I cant say if this is the cause of your problem but you are making errors
    and using error prone syntax in your method calls.

    my $parser = new Parse::RecDescent ($grammar); # not wrong but better
    written as
    my $parser = Parse::RecDescent->new($grammar);

    my $process = Process::new(); # Almost certainly wrong...
    my $process = Process->new(); # Probably correct.

    Also this syntax (with the &Dump) is not very current and slightly
    errorprone( &Foo isnt the same as Foo()). just omit the & symbol.

    print &Dump($parsetree), "\n"; # You dont n

    But as I said I have no idea if this is the cause of your program. I just
    know I would make the suggested changes before I looked elsewhere.

    Yves

    -----Original Message-----
    From: Aaron Dalton
    Sent: 17 December 2003 13:45
    To: recdescent@perl.org
    Subject: Very odd parsing problem


    I have created a grammar for processing basic rules for a pbem I am
    writing. I have also written an object for then processing
    the resulting
    parse tree. What is happening is this: If I simply parse the
    input and
    dump the tree, everything parses fine. The second I even "use" my
    processing object module (which happens to be called
    "Process") the parse
    fails. I did a TRACE and what seems to happen is the parser doesn't
    ignore the newlines in the 2nd instance. I am totally
    confused. Below is
    the snippet of my code in question. I can include copies of
    the grammar
    andthe TRACE if that would be helpful. Any ideas? Thanks so much for
    your help.


    #START CODE
    my $parser = new Parse::RecDescent ($grammar);
    my $parsetree = $parser->orderset($bodytxt);

    if (! defined $parsetree)
    {die "Grammar parse failed!\n";}
    else
    {
    use YAML;
    print &Dump($parsetree), "\n";

    #if I uncomment the below code, the parse fails
    #
    #use Process;
    #my $process = Process::new();
    #$process->processTree($parsetree);
    #print $process->{results}, "\n";
    }
    #END CODE

    --
    Aaron Dalton
    aaron@finch.st
    http://aaron.finch.st
  • Aaron Dalton at Dec 17, 2003 at 2:21 pm
  • Orton, Yves at Dec 17, 2003 at 2:35 pm

    Thank you, Yves. I am only a hobby programmer and am always
    grateful for style tips.
    No problem.
    I made the changes you suggested but I am still having
    problems. I am attaching the trace output from both the correct and
    incorrect parses. I am also including the grammar below. I thank you
    again for any help you can offer.
    Well the code below doesnt make much sense to me off the top of my head.
    What is the Process module?
    #IF I UNCOMMENT THE BELOW CODE THE PARSE FAILS
    #
    #use Process;
    #my $process = Process->new();
    #$process->processTree($parsetree);
    #print $process->{results}, "\n";
    Anyway, it looks to me like somehow the whitespace definition is changing
    somehow. Does Process.pm mess with the regular expression engine somehow?
    Thats the only way that I can see this having any effect at all. (But im no
    authority)

    But im mostly guessing. Without seeing your full code its hard to say.

    Can you minimize the code in Process down to a test case that we could
    repeat?

    Also, you may find that perlmonks.org is useful to you.

    rgds,
    yves
  • Ron D. Smith at Dec 17, 2003 at 8:45 pm

    On Wednesday, Dec 17, 2003 Aaron Dalton said:
    I have created a grammar for processing basic rules for a pbem I am
    writing. I have also written an object for then processing the resulting
    parse tree. What is happening is this: If I simply parse the input and
    dump the tree, everything parses fine. The second I even "use" my
    processing object module (which happens to be called "Process") the parse
    fails.
    You should remember the semantics of "use". When you include a use statement
    in your code, the code is compiled and executed *before* the main code is
    even finished being compiled. (In other words the use statement has side
    effects at compile, not just run time.)

    For example, consider the following:

    test.pm

    emacs
    test.pl

    use test;

    if *l;q gpslq;tpyuawt

    ---------

    Now what will happen is that you will get the printout *AND* a compile
    failure!

    chlx330> emacs test.pm # create pm from above
    chlx330> emacs test.pl # create pl from above
    chlx330> /usr/intel/pkgs/perl/5.6.1/bin/perl test.pl
    hello there
    I'm executing.
    syntax error at test.pl line 3, near "if *l"
    Can't find string terminator "g" anywhere before EOF at test.pl line 3.
    chlx330>

    You *must* have executable statements in your use file, not just subroutine
    declarations, and these are obviously causing side effects.

    My suggestion is to keep cutting stuff off of your Process module until the
    problem goes away. When the problem goes away, whatever you cut away is
    causing the problem, somehow. My bet is that once you see the actual
    offending code, it will become "clear" what is wrong.

    Don't worry about the fact that cutting off whole sections of your module
    screws up the operation, the operation is already screwed up by your
    description... If you can parse, you are better off, and if you can't parse
    you have not identified the problem.

    So:

    do
    {
    cut a self consistent chunk of code off of your Process module;
    run the code up to the parser;
    }
    while (parse fails)

    Keep doing this until you identify the exact line.
    I did a TRACE and what seems to happen is the parser doesn't
    ignore the newlines in the 2nd instance. I am totally confused. Below is
    the snippet of my code in question. I can include copies of the grammar
    andthe TRACE if that would be helpful. Any ideas? Thanks so much for
    your help.


    #START CODE
    my $parser = new Parse::RecDescent ($grammar);
    my $parsetree = $parser->orderset($bodytxt);

    if (! defined $parsetree)
    {die "Grammar parse failed!\n";}
    else
    {
    use YAML;
    print &Dump($parsetree), "\n";

    #if I uncomment the below code, the parse fails
    #
    #use Process;
    #my $process = Process::new();
    #$process->processTree($parsetree);
    #print $process->{results}, "\n";
    }
    #END CODE

    --
    Aaron Dalton
    aaron@finch.st
    http://aaron.finch.st

    --
    Intel, Corp.
    5000 W. Chandler Blvd.
    Chandler, AZ 85226

    --
    Intel, Corp.
    5000 W. Chandler Blvd.
    Chandler, AZ 85226
  • Aaron Dalton at Dec 18, 2003 at 8:06 am

    On Wed, 17 Dec 2003, Ron D. Smith wrote:

    On Wednesday, Dec 17, 2003 Aaron Dalton said:
    I have created a grammar for processing basic rules for a pbem I am
    writing. I have also written an object for then processing the resulting
    parse tree. What is happening is this: If I simply parse the input and
    dump the tree, everything parses fine. The second I even "use" my
    processing object module (which happens to be called "Process") the parse
    fails.
    You should remember the semantics of "use". When you include a use statement
    in your code, the code is compiled and executed *before* the main code is
    even finished being compiled. (In other words the use statement has side
    effects at compile, not just run time.)

    My suggestion is to keep cutting stuff off of your Process module until the
    problem goes away. When the problem goes away, whatever you cut away is
    causing the problem, somehow. My bet is that once you see the actual
    offending code, it will become "clear" what is wrong.

    Again, thank you all for your time and patience. I am usually very good
    at "reading the freaking manual" but I missed some fine print. The
    problem ended up being my use of the Perl module RFC::RFC822::Address
    which states at the bottom of its page that it screws up all other RD
    parsers by changing $skip. I am sorry to have bothered you all and thank
    you again for your help.

    Cheers!

    --
    Aaron Dalton
    aaron@finch.st
    http://aaron.finch.st

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprecdescent @
categoriesperl
postedDec 17, '03 at 12:45p
activeDec 18, '03 at 8:06a
posts6
users3
websitemetacpan.org...

People

Translate

site design / logo © 2019 Grokbase