Perl 6 Grammars and Regular Expressions 202
An anonymous reader writes "Perl 6 is finally coming within reach. This article gives you a tour of the grammars and regular expressions of the Perl 6 language, comparing them with the currently available Parse::RecDescent module for Perl 5. Find out what will be new with Perl 6 regular expressions and how to make use of the new, powerful incarnation of the Perl scripting language."
Perl goodness (Score:5, Funny)
Crap, I think I just accidentally programmed a web browser in Perl
Re:Perl goodness (Score:5, Funny)
Re:Perl goodness (Score:5, Funny)
Re:Perl goodness (Score:3, Insightful)
Re:Perl goodness (Score:5, Insightful)
Re:Perl goodness (Score:4, Insightful)
No, it most certainly did not. Regular expressions as they exist in Perl today are a direct descendant of POSIX regular expressions which derive from the original work done by Ken Thompson (which resulted in the grep program, which stands for "global regular expression print"). That syntax further dates back to the giants in the field of computational theory, and was specialized only slightly for text matching.
grep, awk, sed, ed, vi, emacs, and dozens of other programs and languages for Unix used this notation before Perl came along and adopted it, so let's not pretend that this syntax is somehow Perl's doing.
The extended regular expression syntax of today IS perl's doing and in almost all cases it has been a process of making regular expressions both more powerful and more readable, culminating in Perl6's rule syntax which is highly readable by comparison.
Re:Perl goodness (Score:4, Informative)
There really aren't many choices. The current regular expression syntax is the only form I've seen tried, with only minor variation.
as he has done somewhat with the Perl 6 expressions
Perl 6 regular expressions have almost exactly the same syntax as Perl 5. The parts that are new are not regular expressions. Cosmetic differences (like [] vs <[]> are fairly ignorable syntactically. It would be like saying that Perl 5 will use
All of the inline comments and whitespace are part of Perl 5 extended expressions, though the word-matching on whitespace is new to Perl 6.
POSIX on the other hand ignored most of that historic syntax and instead chose their horribly bloated keyword syntax.
That's not really part of the regular expression syntax. Having [[:digit:]] as an alias for Perl's \d is hardly a different syntax so much as sugar. The fundamentals of POSIX regular expressions are the fundamentals of all modern regex syntaxes:
I've often thought that the ease with which regular expressions can be accessed within per was a blessing and a curse. So many people like yourself seem to think that Perl championed regular expressions, when in fact it just followed AWK's lead in integration between C and Ken Thompson's regular expression implementation (which in turn inspired the version that was written from scratch by Henry Spencer and used by Larry for Perl).
If you have a new syntax in mind, I suggest introducing it and seeing how it does. Modern regular expressions are an incremental improvement on classical set notations, and have served us well to date, but I'm sure someday someone will see a better way.
Re:Perl goodness (Score:2)
Re:Perl goodness (Score:3, Insightful)
Re:Perl goodness (Score:3, Insightful)
and
Using ',' for the delimiter of the RE means you don't have to backslash-quote the forward slash to use it in a match.
This
I can't remember all that! (Score:5, Funny)
$ cat
It usually works in 3 tries or less.
Heh. (Score:2)
$ cat bla | prog1 | prog2 |
"flowing" purely from left-to-right, as opposed to
$ prog1 < bla | prog2 |
where input flows from right-to-left then right again.
Also, the former is marginally easier to modify if you need another stage of processing before prog1.
To each his own, I guess.
Re:Perl goodness (Score:5, Interesting)
Comment removed (Score:4, Insightful)
Re:Grammar (Score:2, Funny)
It's "perl", you strongly-typed, weak-minded illiterate; not "PERL". Everyone knows that as of Sep. 17, 1999, the perl community decided arbitrarily (and overnight) that it isn't an acronym anymore.
Re:Grammar (Score:5, Informative)
Perl never was an acronym. It's a backronym.
Perl is the language and perl is the interpreter. Remember, "only perl can parse Perl" and it's easy to remember.
Re:Grammar (Score:2)
I mean, it's from the horse's mouth.
Re:Grammar (Score:2)
Re:Grammar (Score:2)
hrm... (Score:5, Funny)
i do not think that means what you think it means.
Re:hrm... (Score:2, Funny)
You asked for it! (Score:2)
Big problem (Score:2, Interesting)
Meaning that it is not backward compatible without modifying your source code.
Note to those who are going to respond "Just install both!": look at the first line of your perl scripts.
Re:Big problem (Score:3, Informative)
The idea of :p5 is not just that you can take Perl 5 code and modify it to make it work.
The idea is that if you don't bother to write a zillion-rule grammar to match whatever you're trying to match, you can still use the P5-style regular expressions you know and love. It's another case of Not Swatting A Fly With The Nuke.
Re:Big problem (Score:5, Informative)
Therefore, it's just Perl 6 scripts which want to use Perl 5 regular expression syntax, which would want to use the :p5 modifier.
Don't get your knickers in a bunch.
Re:Big problem (Score:5, Informative)
Thus spake Larry Wall in Apocalypse 5:
And from Apocalypse 1:
In other words, it is backwards compatible, it isn't backwards compatible, and when you install Perl 6, you are installing both.
TTFN
Re:Big problem (Score:2)
Will it be possible to distinguish Perl6 code from line noise?
Re:Big problem (Score:2)
The first line of most of my Perl programs is
I admit that's an ancient version of Perl, but unfortunately that's what I'm stuck with here. At home it might say perl5.8.5 or so.
I realized a long time ago [perl.org] that I'd better have every program I wrote tied to specific installation of a specific version of Perl, to avoid problems in installing future versions or new modules. Has nothing to do with Perl 6; it's just good configuration management. I can at any time install another
Re:Big problem (Score:4, Informative)
The
Why would a satisfied Perl5 user migrate? (Score:5, Insightful)
To this user, the last several releases (5.x) have looked more like opportunities for continuing royalty streams for perl authors (new versions of old books) than significant releases.
Re:Why would a satisfied Perl5 user migrate? (Score:4, Informative)
Re:Why would a satisfied Perl5 user migrate? (Score:2)
http://it.slashdot.org/comments.pl?sid=128918&c
Re:Why would a satisfied Perl5 user migrate? (Score:3, Informative)
Re:Why would a satisfied Perl5 user migrate? (Score:2)
Re:Why would a satisfied Perl5 user migrate? (Score:5, Interesting)
Yeah, Perl 5 hasn't changed that much over time. But it has been around for a while. Perl 6 is just different.
From what I have seen from the announcements, the Perl 6 syntax looks far cleaner, probably more consistent and less ugly. Some of the new tricks look genuinely handy. For example, if it seems like type checking would be a good idea, you can have it if you want it, even on compile time!
Especially the regular expressions side seems pretty interesting, as noted in this article. Regular expressions have always been a poor but effective replacement for grammar-based parsing, and now finally Perl is going to have both integrated. There's probably going to be less whining about line noise.
And then there's something that I find especially interesting, though it hasn't been explained in detail yet: Complete tuning of the object system. In case you haven't noticed, Perl 5's object system is a complete and utter mess that looks and smells like it has been added as an afterthought, and rest assured it's going to be changed radically for better in Perl 6. I'm definitely waiting eagerly to see what Perl 6's take is going to look like - I sure hope it's something like Ruby, only it smells like a camel =)
Re:Why would a satisfied Perl5 user migrate? (Score:2)
If you even consider it an object system; I use it daily and I'm still skeptical about calling it object oriented programming. Reminds me really of ADT with C with some new 'features' added to make it slightly easier. Not that I don't like it, I still find it very useful but....
Re:Why would a satisfied Perl5 user migrate? (Score:2)
Programs/Languages can be:
Faster
Smaller
More powerfull (more available features)
Simpler to use/understand
From reading this article, it mainly focuses on the last two that you did not mention. Perl 6 is trying to be a little bit more powerfull and a little bit easier to use /understand.
Re:Why would a satisfied Perl5 user migrate? (Score:2)
Re:Why would a satisfied Perl5 user migrate? (Score:2)
Faster means faster than perl 5. smaller means smaller than perl 5. Got it? I have no desire to understand programs written by others. I have a staff for that. I'm only concerned about the ones I write myself.
Call your pharmacist, dude. You seem to be running low on anti-psychotics.
oh, and it's spelled "grammar"
jerk
Re:Why would a satisfied Perl5 user migrate? (Score:3, Insightful)
Reasons to convert to Ponie (Perl 6 on Parrot):
Reasons to convert from Ponie to Perl 6:
Re:Why would a satisfied Perl5 user migrate? (Score:2)
Re:Why would a satisfied Perl5 user migrate? (Score:3, Interesting)
It features better support for key paradigms, including object-oriented
programming (finally, a real object model), functional programming (we're
getting continuations), and even some improvements for contextual programming.
In other words, Perl6 will be a substitute not just for Perl5 but also for
Scheme and Smalltalk.
Also, the whole Parrot thingydoo is going to allow software written in one
language to seamlessly use libraries written i
Re:Why would a satisfied Perl5 user migrate? (Score:2)
aw hell (Score:5, Funny)
wow, looks like boost::spirit (Score:4, Interesting)
Perl6---
# note this is just a language example, not an accurate name matcher
grammar Names
{
rule name
rule singlename { + };
};
C++::boost::spirit---
rule split = *(*space_p >>
(+graph_p)[append(tok)] >>
*space_p);
msg "Parsing input\n";
while (!header_ok && getline(input, line) && input.good())
{
tok.clear();
parse(line.c_str(), split);
There are even grammar classes in Spirit.
I sure hope perl6 is faster!
Re:wow, looks like boost::spirit (Score:2)
Isn't Spirit a LALR parser? Or an LL(1) parser?
It's not going to be faster than Spirit, because GLR parsers are slower than every other kind of parser.
On the other hand, you don't have to do all the wierd stuff you have to do with Spirit because it's mostly just syntactic sugar on top of C++, and therefore uses only C++ syntax (which doesn't look much like the natural pseudoco
Re:wow, looks like boost::spirit (Score:3, Informative)
Re:wow, looks like boost::spirit (Score:4, Interesting)
It is about time to change the name from (Score:2, Interesting)
Adoption (Score:5, Interesting)
Note to those ready to mod me Troll/Flamebait: I'm not trying to pick on Python, I just happened to be acquainted with this candid quote.
Re:Adoption (Score:5, Insightful)
By the way, not long after he wrote that, Perl coders started using the Inline:: modules like Inline::C [cpan.org] instead of XS, which is very easy to use. I do not know if this was an adoption of Python's technique, but I don't think so.
Re:Adoption (Score:2)
Thanks for mentioning that. You are absolutely right, and shortly after I posted the message I stuck my foot in my mouth when I saw to my horror that I had gotten it totally backwards and maligned Eric Raymond in the process!! Another casualty of the rush to post while the
Re:Adoption (Score:4, Informative)
Not much hypercompetition there, if you ask me. But then, it might as well be me who misunderstood the quote.
Re:Adoption (Score:3, Interesting)
Of course, the basic approaches to language design follow different philosophies (Perl's is one of inclusion, Python's is one of exclusion... both a
Re:Adoption (Score:2)
Re:Adoption (Score:2)
The point I was developing is that is an example of small thinking. When all your language objects are belong to Parrot, swapping out various regex engines, database engines, XML parsers, etc. suddenly enters the realm of the possible.
Someday.
Complex grammars in Perl (Score:5, Insightful)
The grammars appear to be in a class called "context free languages"(CFGs). Some CFGs are ambiguous in the sense that a given "sentence" can be derived from more than one set of rules. Traditional tools such as yacc/bison tell you where there is ambiguity in your rules - even then it isn't always easy to remove the ambiguity (trust me on this). If the Perl 6 system doesn't help the programmer debug the grammar he/she will not be happy when the parsing doesn't work as expected.
In addition, the article ends the description of features with "And much more...". It appears that Perl 6 grammars are more powerful than CFGs. If they can simulate a Turing machine...
Re:Complex grammars in Perl (Score:2)
Re:Complex grammars in Perl (Score:2)
That's backwards. Recursive decent with backtracking can parse all LL(k) grammars for arbitrary k. OTOH, yacc/bison can only parse LR(1) which, although sufficient for most realistic grammars, definitely is not as general as a full LL(k) method.
Left-recursive grammars are a red herring -- you can always eliminate the recursion, and with backtracking you can deal with arbitrar
Yes. (Score:2)
Perl 5 "regexps", by contrast, are more of a specialized second language bolted onto the side (I use quotes since Perl 5 regexps are already marginally more powerful than "pure" regexps).
Re:Yes. (Score:2)
Are you sure? I looked into this because my instinct told me you were right and I wanted to know how much more powerful but then I found this line in the Camel Book: "The Perl Engine uses a nondeterministic finite-state automaton (NFA) to find a match" (Programming Perl 2nd ed., page 60). If correct that would suggest that Perl regexps and "pure" automata regexps are equivalent.
Re:Yes. (Score:3, Interesting)
...and (some) context-sensitive grammars...
correction (Score:2)
Pet Project (Score:3, Funny)
Re:Pet Project (Score:2, Informative)
Guess Mark wants to resolve a host name. Here is a working link:
http://www.ozonehouse.com/mark/blog/code/Periodic
Let me guess.... the usual Perl backlash (Score:5, Interesting)
Yes, it does include a lot of symbols, but there is payback to learning them, and really most programs won't use much beyond $ % # () [] {}. Unlike some languages [java.com], Perl is not what I would describe as a 'bondage' language. If you want to program sloppy, you can program sloppy. That's fine by Perl. And this generousity is what gives Perl its bad reputation. This is funny since I and most knowledgeable Perl programmers can write perfectly clear and maintainable code. The way we do this is no secret--it's just by commenting appropriately, using meaningful identifier names and following the Perl style guidelines [cpan.org].
People can mock Perl all they like, but it is still a widely used powerful programming language and I am more productive in it than any other language. As a parting comment, a Cisco employee once told me (off the record of course!) that "Cisco would fall apart without Perl".
Re:Let me guess.... the usual Perl backlash (Score:2)
Why do people have such a problem with Perl? It's an excellent, high-level general purpose programming language with a huge range of extension modules available. I have personally used Perl for many projects, as do TicketMaster, ValueClick, Morgan Stanley and Ryanair
How compelling, you just named some of Slashdot's favorite companies.
Re:Let me guess.... the usual Perl backlash (Score:3, Interesting)
The purist Computer Scientist in me loathes it. It is ugly, dangerous and has a weird botched together syntax.
Just as I self rightously convince myself of these self evident facts, some real cool trick saves the day and the wild inner hacker in me starts telling the CS part to stop being such a bore
Perl is a great language, though like all powerful tools it can be dangerous if misused. It is sometimes ugly, and just as often beautiful.
All that said
You'll love this quote then ;-) (Score:3, Interesting)
"Much as I hate to say it, the Computer Science view of language design has gotten too inbred in recent years. The Computer Scientists should pay more attention to the Linguists, who have a much better handle on how people prefer to communicate."
--Larry Wall
Dangerous? (Score:3, Interesting)
In my experience (as a IT security guy) C and PHP are more dangerous than perl.
C - "runs arbitrary code of the attacker's choice" given _common_ stupid programmer mistakes.
PHP - developers fond of features that encourage bad/insecure ways of doing things - e.g. magic quotes, global track vars. Take away such popular PHPisms and PHP starts to look like perl
Re:Better asked at slashcode.com perhaps, but (Score:2, Funny)
Re:Better asked at slashcode.com perhaps, but (Score:2)
Re:Ok, start the flame wars under this post (Score:2, Funny)
a) Is it called GNU/Linux or Linux?
b) Emacs vs Vi
c) "Ok" goes on the left, "Cancel" goes on the right.
d) Security is based on market share - NO! Apache is more secure despite bla bla bla!
e) 45 RPM LPs sound better than reel-to-reel!
Re:Ok, start the flame wars under this post (Score:2)
Re:Ok, start the flame wars under this post (Score:2)
Personally, I think that the 72RPM phonograph records sound best, but that may just be a reflection of the kind of music that's most often found on them. They certainly have more character!
Re:Ok, start the flame wars under this post (Score:2)
Re:Ok, start the flame wars under this post (Score:2)
Re:Ok, start the flame wars under this post (Score:2)
/Too young to remember.
Re:Ok, start the flame wars under this post (Score:5, Insightful)
Re:Ok, start the flame wars under this post (Score:3, Insightful)
Re:Ok, start the flame wars under this post (Score:2, Insightful)
Re:Ok, start the flame wars under this post (Score:2)
Those of you that use Perl for more than just system duct-tape should have their head examined.
Note title.
Re:Ok, start the flame wars under this post (Score:2)
I disagree with this comment classifying and naming software makes it sound alive. I think we should describe or label it.
Re:Ok, start the flame wars under this post (Score:3, Interesting)
Re:Runs great under Gentoo (Score:2)
Re:Runs great under Gentoo (Score:2, Funny)
An anecdote and an opinion. (Score:2, Insightful)
I tried to absorb the syntax docs one afternoon, but it gave me nightmares. Literally. It was as if the C-programming-part of my brain was in conflict with the oddball operators and constructs presented in the perl language. Ever since I've been haunted by perverse unreadbility of it all. I liken the experence to attempting to think in brainfuck [c2.com].
So by this I know for a fact that perl is Not My Thing(tm).
Now, a more objective reason as to why perl isn't gene
Perl perspective (Score:2, Insightful)
This makes Perl very strong as a teaching tool for beginner programmers. They can start out writing loose, messy code that gets
Re:An anecdote and an opinion. (Score:5, Insightful)
"IMO, "the right job" for perl is about 2% of all programming tasks out there."
76 percent of all statistics..... You get the point. You really dont have any valid point here, every language is designed to do certain things, and people will use it for those things and more. Trying to say whats the best langague out there is stupid. Trying to say what percent of projects perl should be used on is also stupid.
"It can accomplish this, but not without the reader having to go through the mental gyrations of what could be best called linguistic decompression."
Have you tried to program in a logical language lately? Have you tried to program in a functional language lately? Have you tried to program in anything but your standard imperical/oo language lately? There are tons of styles of languages, and each one required its own linguistic decompression. Which one feels more natural its a matter of opinion.
Re:An anecdote and an opinion. (Score:2, Interesting)
foreach $line (@data) {
chomp $line;
my ($x, $y, $z) = split(':', $line);
update_coords($x, $y, $z);
}
Re:An anecdote and an opinion. (Score:3, Interesting)
When I started to learn Perl (coming from a C background) I had quite a different experience. I really felt I had "come home", or something like that. Sure, you can write obscure code, but that's no different from C. But you don't have to, it can be very clear.
I'll give credit to the fact that perl is compact, terse, to the point and has a reputation for strin
Re:An anecdote and an opinion. (Score:4, Insightful)
Re:An anecdote and an opinion. (Score:2)
Why don't you chill out? I am a mod_perl developer. What I meant by that comment is that you don't find mod_perl hosting environments as readily as PHP or ASP hosting environments, because mod_perl isn't provided in turnkey server setups that web hosting farms set up for their co-los. The reason for that is because Perl isn't seen as a web development language like PHP or ASP so it's not on the list of prerequisites for a web-server-in-a-box. Wishful thinking won't change t
Re:Please! (Score:2)
Ruby looks really cool, but I'd rather just have Ruby blocks added into Python than sacrifice legibility as much as Ruby does. Python closures/lambdas are teh suck compared to Ruby blocks.
So, what does this news mean for Parrot? We any closer to seeing our sexy cross-language interpreter/VM yet?
Re:Please! (Score:2)
(Hell, my sig gets even the most innocent of my posts marked as troll )
You're a language bigot (Score:3, Interesting)
(I'm a recovering language bigot so I can say this. :-P )
Re:You're a language bigot (Score:2)
Bash
C/C++
Delphi
i386 ASM
Java
Pascal
Perl
PHP
Prolog
Python
Rub y
Visual Basic
So I have some experiences. But I see this also all around - I'm managing also 5 other SW guys and those who write in Perl produce really unmaintable code while the same ppl in C/PHP produce really nice code (when run through indent
Re:bad example? (Score:3, Informative)
# Perl 6 :w modifier surrounds all tokens with "automagic" whitespace,
# which basically means it will match what most people would call
# "words"
Re:Perl6 -- an interesting curiosity (Score:2, Funny)
Re:so many for so long (Score:3, Funny)