Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: •Re: Parse::RecDescent and mini-language parsing

by Flame (Deacon)
on Mar 31, 2003 at 05:26 UTC ( [id://246849]=note: print w/replies, xml ) Need Help??


in reply to •Re: Parse::RecDescent and mini-language parsing
in thread Parse::RecDescent and mini-language parsing

Note: Before I start, I have noticed your other suggestion, however this is based off of this code.

Well, I've modified your suggestion a little, and assuming I understood your suggestion's intent, I seem to have screwed it up somewhere along the line, because it still does not handle ( ) properly, but I can't see why. This is what I now have:

use Parse::RecDescent; use Data::Dumper; use strict; use warnings; $::RD_TRACE = 1; my $grammar = q~ expression: <leftop: term termop term> eod termop: /and/i | /xor/i | /or/i term: '(' <commit> expression ')' | condition condition: element comparison element element: '<' <commit> /-?\w+/ '>' | /\d+/ comparison: /=[><]=/ <commit> <error: Unable to match comparison> | /=?[><]=?/ | '=' | '!=' eod: /^\Z/ ~; my $parser = new Parse::RecDescent($grammar) or die; #defined($parser->RecTest('h =>= h')) or die; my $test = '(<MONTH> => <DAY>)'; # or (<MONTH> = <MARCH> and <DAY> = < +TUESDAY>)'; print Dumper($parser->expression($test));

I repeatedly get "$VAR1 = undef;" in reply, as well as enough debugging info to scroll off my screen (unfortunately I can't capture it into a file either, Parse::RecDescent overrides any re-declarations on STDERR, and I can't use "perl language.pl | more" or any other similar methods since those don't want to capture the error messages...) Anyone see what I'm missing, it's probably obvious, but I've been staring at it for 4 hours now without anything more constructive happening than the condensing of a few rules in the grammar declaration.





My code doesn't have bugs, it just develops random features.

Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Replies are listed 'Best First'.
Re: Re: &bull;Re: Parse::RecDescent and mini-language parsing
by Flame (Deacon) on Mar 31, 2003 at 20:01 UTC
    Flame feels rediculously stupid.

    Ok, found THAT problem. The "eod" rule at the end of "expression", was being called upon whenever expression was used, meaning that the ')' had to somehow come after the end of the data. With that fixed, I need to do a few more tests, but this is how it looks NOW:

    my $grammar = q~ logic: expression eod expression: <leftop: term termop term> termop: /and/i | /xor/i | /or/i term: '(' <commit> expression ')' | condition condition: element comparison element element: '<' <commit> /-?\w+/ '>' | /\d+/ comparison: /=[><]=/ <commit> <error: Unable to match comparison> | /=?[><]=?/ | '=' | '!=' eod: /^\Z/ ~;




    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246849]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found