Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Parsing CCL (Common Command Language) commands

by perlcgi (Hermit)
on Oct 17, 2002 at 12:01 UTC ( [id://205992]=note: print w/replies, xml ) Need Help??


in reply to Parsing CCL (Common Command Language) commands

The best approach IMHO is not to reinvent the wheel. As CCL is a standard, (ANSI/NISO Z39.58-1992), it is hard to believe that code is not already available somewhere.
That said, the many implementations in library catalogs for example, are commercially sensitive and you may well have to roll your own.
On the positive side, much of the work has been done for you, given that you have the grammar. I would check out Damian Conway's module Parse::RecDescent. The following are useful starting sources:
Data Munging with Perl by davorg - I found this treatment of Parse::RecDescent particularly easy to digest
The FAQ
Damian Conway's TPJ article
Best of luck,
perlcgi
  • Comment on Re: Parsing CCL (Common Command Language) commands

Replies are listed 'Best First'.
Re:x2 Parsing CCL (Common Command Language) commands
by grinder (Bishop) on Oct 17, 2002 at 12:18 UTC

    Just keep in mind that Parse::RecDescent is painfully slow for anything beyond a toy. It's not for nothing that Damian Conway is planning on writing a Parse::FastDescent.

    In the meantime, you'll get good mileage out of Parse::Yapp, which basically redoes yacc(1) in Perl.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
      Thank you for alle the surgestions!

      print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
      This REALLY says all about my relations to parsers! :-(

      I've gone for the YAPP and taken the Calp.yp example and replaced the grammer with the CCL grammer (leaving out the "Set" statement for now). Compiled it using:

      yapp -v myParser.yp
      with one message:
      1 shift/reduce conflict
      Then I've written a test:
      use MyParser; $parser=new MyParser(); $value=$parser->YYParse(yylex => \&lexer_sub, yyerror => \&error_sub +); $nberr=$parser->YYNberr(); $parser->YYData->{DATA}= [ 'a and ( b or c)' ]; $data=$parser->YYData->{DATA}[0];
      All this gives is a:
      Syntax error. Can't locate object method "new" via package "MyParser" (perhaps you f +orgot to l oad "MyParser"?) at myparser.pl line 2, <STDIN> line 1.
      • How do I really activate this parser?
      • How do I add my functions to process the searching?
      "If there are two or more ways to do something and one of them can lead to a disaster, then one or more persons will do it"
      Edgar A. Murphy, Captain in U.S. Air Force (1949)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found