Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Perl Parsing Power

by protist (Monk)
on Sep 24, 2012 at 10:03 UTC ( #995337=perlmeditation: print w/ replies, xml ) Need Help??

I talked to an older computer science professor today. He showed me compilers he had written in C that compiled a language he had made to assembly. He had never heard of Perl. He seemed astonished when I showed him one line of Perl that demonstrated recursive descent parsing.

I am not attempting to denigrate his compiler, which was awesome. I aim only to share a story of a seeming anachronism.

Comment on Perl Parsing Power
Re: Perl Parsing Power
by BrowserUk (Pope) on Sep 24, 2012 at 10:09 UTC
    He seemed astonished when I showed him one line of Perl that demonstrated recursive descent parsing.

    Recursive descent parsing in one line of Perl; I'd like to see that?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      Admittedly, it is a basic example, although powerful in its implications.
      print "good string\n" if $_~~ /^({(?:[^{}]++|(?1))*+})/;
      It tests for proper nesting of brackets, anchored to the beginning of the line. You can try it out:
      perl -ne 'print "good string\n" if $_~~ /^({(?:[^{}]++|(?1))*+})/;'

        You can do that like this:

        C:\test>perl -nE"my$t; /{/&&++$t or /}/&&--$t for split''; say $t ? $t + : 'good string'" {} good string {}} -1 {{}} good string {{}{}} good string {{}{}}} -1 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}}}}}}}}}} 11 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}}}}}}} 14 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} +}}}} 6 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} +}}}}}}}}}} good string

        But I wouldn't call it RDP :)

        The problem with doing RDP with regex is that you have to match the entire stream with one (possibly (hopefully :) composite) regex. Which is fine for yes/no booleans, but it makes both debugging the regex and reporting where and why parsing errors occur extremely messy if not impossible.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        RIP Neil Armstrong

Re: Perl Parsing Power
by sundialsvc4 (Abbot) on Sep 24, 2012 at 13:07 UTC

    I think that he was being polite to you ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://995337]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-09-20 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls