Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Perl Cannot Be Parsed: A Formal Proof

by moritz (Cardinal)
on Jan 22, 2008 at 13:31 UTC ( #663570=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Perl Cannot Be Parsed: A Formal Proof
in thread Perl Cannot Be Parsed: A Formal Proof

Actually Perl 6 is even harder to (statically) parse than Perl 5, because it is much easier to change the syntax.

You can, for example, introduce new operators very easily:

multi sub prefix:<foo> (Str $a) { return $a eq "foo" ?? "bar" !! "foo"; }

This will define an unary prefix operator that takes one string as an argument. When somebody writes

foo "foo";

You can't know if that's a method call or a call to an operator. You'd think it makes no difference - but wait until precedence comes into the play:

BEGIN { eval " multi * prefix:<foo> (Str $a) is tighter(&infix:<~>) { return $a eq 'foo' ?? 'bar' !! 'foo'; "; } # and later in the code: foo "fo" ~ "o";

If that foo parsed as a sub call the precedence is lower than that of the concatenation ~, and the other way round if it's parsed as an operator.

This is quite a complicated example, but there are much easier ones with "real" macros. (But since no implemenation really implements macros by now, I don't really know much about them).


Comment on Re^3: Perl Cannot Be Parsed: A Formal Proof
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (16)
As of 2015-07-02 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls