Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Perl not BNF-able??

by domm (Chaplain)
on Jul 01, 2005 at 10:26 UTC ( [id://471638]=note: print w/replies, xml ) Need Help??


in reply to Perl not BNF-able??

You may be interested in PPI.
-- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Replies are listed 'Best First'.
Re^2: Perl not BNF-able??
by anonymized user 468275 (Curate) on Jul 01, 2005 at 11:12 UTC
    Yes, thank you for that - PPI looks like the best approach so far and PPI::Dumper seems very useful for identifying the context interpretations previous posts show concern about.

    One world, one people

      But keep in mind that PPI is just guessing, some of the time, using the most likely parsing, rather than an absolute parsing. So, it's still not formal or official, it's merely workable on most programs. But there's no way to know in the code if it's ever done the wrong thing... you simply get a wrong parse and no indication.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

      Since I wrote PPI, I probably have struggled against more anti-BNF things that most. So here's a few.

      1. Source Filters
      use Acme::Buffy; BuFFy BUFfy bufFy Buffy...
      You can't handle source filters in BNF for obvious reasons.

      2. BEGIN blocks

      You can't (code) parse Perl without also executing it.
      BEGIN { die if is_christmas($today); }
      That code is legal Perl every day of the year except for Christmas, when it is not legal Perl code.

      3. Cannot be parsed when isolated
      use Some 'function'; function 'foo', 'bar';
      That code could mean either function('foo'), 'bar' or function( 'foo', 'bar' ) depending on what is in the Some module.

      If Some.pm isn't installed on your machine, how are you to know.

      PPI does what it does using more evil than Perl itself, and certainly more heuristics. It makes up for it's guesses by promising that what it writes out is ALWAYS character for character identical to what it read in, unless you change something.

      So if it has a problem, it won't break as long as you don't change that part of the tree.

      There's probably more reasons, but for me those are the big three.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (10)
As of 2024-04-18 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found