×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Perl 6 Grammars and Regular Expressions

CmdrTaco posted more than 9 years ago | from the zztop-wants-a-perl-necklace dept.

Perl 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."

cancel ×
This is a preview of your comment

No Comment Title Entered

Anonymous Coward 1 minute ago

No Comment Entered

202 comments

Better asked at slashcode.com perhaps, but (2, Interesting)

Scott Lockwood (218839) | more than 9 years ago | (#10755955)

How will this affect people running slash? In a slightly related question, when will Slash support Mod_Perl 2.x, and Apache 2?

Re:Better asked at slashcode.com perhaps, but (2, Funny)

Zorilla (791636) | more than 9 years ago | (#10755986)

About the same time they get around to supporting XHTML and CSS.

MOD PARENT DOWN, KNOWN GAY LOVER OF TROLLAXOR!!!! (-1, Troll)

Anonymous Coward | more than 9 years ago | (#10755990)

Go away YOU PERVERT!

Re:Better asked at slashcode.com perhaps, but (1)

Neil Watson (60859) | more than 9 years ago | (#10756210)

When mod_perl 2 (actually, 1.99_17) is no longer a development release.

Perl goodness (5, Funny)

Zorilla (791636) | more than 9 years ago | (#10755961)

HXGF*&#$()#P*&ULJKDFHV)(&*#$utrhk:jlhdsf(p*&#$OJDF >KLJDFP)(*$#&pyu:

Crap, I think I just accidentally programmed a web browser in Perl

Re:Perl goodness (1)

Commander Doofus (776923) | more than 9 years ago | (#10756532)

There's a bug in your code, it should be HXGF*&#$()#P*&ULJKDFHV)(&*#$utrhk:jlkdsf(p*&#$OJDF >KLJDFP)(*$#&pyu: . Hope this helps.

Re:Perl goodness (2, Insightful)

Black Perl (12686) | more than 9 years ago | (#10756861)

Just so people know, Perl gets its reputation for being line noise largely from its early adoption of regular expressions. For example:
s/^\/\\\$(.*)$/\/\/$1\//;
But now this syntax has made it into just about every other language. And so now you can accidentally program a web browser in any language.

I can't remember all that! (4, Funny)

warrax_666 (144623) | more than 9 years ago | (#10756993)

... so when I need a webserver, I just

$ cat /dev/urandom | perl

It usually works in 3 tries or less.

Grammar (4, Insightful)

dprust (316840) | more than 9 years ago | (#10755965)

It is good to see PERL focussing on what makes it great. There is no other language, IMHO, that handles text input as well as PERL does. Adding this level of processing just makes it even more powerful.

Re:Grammar (2, Funny)

Anonymous Coward | more than 9 years ago | (#10755997)

Perl is made great by its ability to provoke raging flame wars over ephemeral points:

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 (5, Informative)

Mr. Muskrat (718203) | more than 9 years ago | (#10756391)

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 (1)

pclminion (145572) | more than 9 years ago | (#10756934)

If that's true, then how come Larry himself writes in the preface to Schwartz's Perl book that Perl was named for "Practical extraction and report language?"

I mean, it's from the horse's mouth.

Re:Grammar (1)

TheFlyingGoat (161967) | more than 9 years ago | (#10756416)

Yeah, now that I've RTFA, I realize just how cool these advances are. They've basically taken some of LISP and built it into Perl, but added a few extensions and predefined strings on top of it. Besides looking MUCH cleaner and being MUCH easier to read/maintain, it should be much more powerful for programmers that know LISP.

hrm... (5, Funny)

Anonymous Coward | more than 9 years ago | (#10755973)

"...zztop-wants-a-perl-necklace dept."

i do not think that means what you think it means.

Re:hrm... (2, Funny)

bluelip (123578) | more than 9 years ago | (#10756355)

I disagree. Unlike the unsuspecting females I've offered them to recently, I think they knew exactly what it means. :)

Ok, start the flame wars under this post (-1, Troll)

JUSTONEMORELATTE (584508) | more than 9 years ago | (#10755982)

Perl scripting language? Man, why not just bathe in gasoline and play with matches?

--

Re:Ok, start the flame wars under this post (0, Troll)

DAldredge (2353) | more than 9 years ago | (#10756031)

We are talking about Perl, not (L(I(S(P))))

Re:Ok, start the flame wars under this post (-1, Flamebait)

Anonymous Coward | more than 9 years ago | (#10756364)

STFU! Retard! Damn don't you ever quit! Have you ever posted anything worthwhile on /.!?

Re:Ok, start the flame wars under this post (1, Funny)

Zorilla (791636) | more than 9 years ago | (#10756035)

Ok, folks; choose your topic:

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 (0)

Anonymous Coward | more than 9 years ago | (#10756078)

45 RPM LPs sound better than reel-to-reel!

You have GOT to be kidding!

Re:Ok, start the flame wars under this post (1)

Zorilla (791636) | more than 9 years ago | (#10756122)

Haha, yeah, I know. I was pulling crap out of a hat at the end there, but I knew I had to provide at least one retarded audiophile option.

Re:Ok, start the flame wars under this post (1, Funny)

kclittle (625128) | more than 9 years ago | (#10756237)

Face it! Ancient vac-tubes from old Russian radar units (putting out, oh, 15 watts) and getting their signal from running a sharp-pointed stick 'round a piece of congealed petroleum is the best audio technology in the world!

-- Mr. Luddite

Re:Ok, start the flame wars under this post (1)

Stradenko (160417) | more than 9 years ago | (#10756189)

Yeah, no kidding. Everyone knows that an LP runs at thirty-three and one-third RPMs.

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 (0)

Anonymous Coward | more than 9 years ago | (#10756445)

Not all LPs were 33 1/3, some were released on 45 (and in some occasions, both) for 'improved quality'. Take for example, Metallica's Master of Puppets, released on both 1 33 1/3 RPM LP, and on 2 45 RPM LPs.

Runs great under Gentoo (-1, Flamebait)

G27 Radio (78394) | more than 9 years ago | (#10756114)

I love firing up vi for a cool Perl 6 coding session. And it flies under optimized Gentoo.

I'm sure I'll probably get modded down by some Debian/BSD zealot. They're probably just pissed off because their rigs are so bogged down from emacs and python trying to run together on a non-optimized system.

amateur! (-1, Troll)

Anonymous Coward | more than 9 years ago | (#10756496)

my Amiga 500 can do more stuff in 512K (yes, that's kilobytes sonny!) than you could ever dream of with your p4 and "optimized" gentoo, and with only a M68000 7MHz cpu. yes, bow down your heads silly gentoo fans for your OS doesn't hold a candle to the glory of what Amiga achieved almost 20 years ago. hell i bet your mouse pointer slows down when you format a floppy disk. pah! you silly people!

Re:Ok, start the flame wars under this post (4, Insightful)

TheFlyingGoat (161967) | more than 9 years ago | (#10756171)

Those of us that use Perl as more than just system duct-tape know it's a programming language. Perl 6 will make that even more clear by being based on OO fundamentals rather than being a procedural language with OO tacked on top of it. This is just another debate that makes the OS community look like a bunch of freaks and zealots... just like the GNU/Linux thing. Get over it and start focusing on what the software does, not how to classify/name it.

Re:Ok, start the flame wars under this post (1)

owlstead (636356) | more than 9 years ago | (#10756617)

Those of us that use Perl as more than just system duct-tape know it's a programming language.

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 (1)

mr_z_beeblebrox (591077) | more than 9 years ago | (#10756900)

Get over it and start focusing on what the software does, not how to classify/name it.

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 (3, Interesting)

Anonymous Coward | more than 9 years ago | (#10756224)

I've got a fully multithreaded perl script running under Win32. It wasn\'t too bad to write but some parts sucked. One of the things sucked because Win32 doesn't support alarm() calls and you have to manually poll sockets and I hate that shit, or use vec() and that's just insane (how many people understand how vec() works anyway???) The other big thing that sucked was the crappy mechanism for sharing complex data structures between threads. All's honky-dory if you're just sharing a scalar variable, but don't try a HoH or anything like that cause you'll find out that there's no auto-vivification, and you have to manually create the data structure in every thread that needs to access it, and that right there leads to lots of possibilities for "interesting" bugs to show up (it's not very fun to code or pretty to look at or understand once it's done).
But anyway none of that is really here nor there, but I just wanted to comment that Perl "scripting" isn't just CGI forms and stuff like that. You can really do complex applications in Perl. It's a full-featured language, portable (moreso that even Java, just look at the list of archs in the Configure.sh script), and able to handle most tasks that don't require a tiny memory footprint or direct CPU register manipulation.

Write Only Software (0)

Anonymous Coward | more than 9 years ago | (#10756427)

We all know that reusability is a BAD thing. If you code in Perl you never have to worry about making your code reusable, since there is no chance in hell of ever reusing it.

Perl - brings the idea of reinventing the wheel to a whole new level :)

Re:Write Only Software (0)

Anonymous Coward | more than 9 years ago | (#10756689)

And yet there's CPAN, the largest "non-reusable" code archive on the Internet that constantly gets re-used by Perl coders eveywhere...

Please! (0, Flamebait)

DAldredge (2353) | more than 9 years ago | (#10756013)

Can we PLEASE just talk about Perl? 5000+ posts about why ruby and python are better from people who have never programmed something important get a little old...

Re:Please! (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#10756203)

I looked over the posts so far, and the only person to mention ruby or python is you. (as of about 25 posts) Jumping the gun perhaps?

Re:Please! (1, Funny)

DAldredge (2353) | more than 9 years ago | (#10756255)

No. Much like I have faith that the sun will rise tomorrow I have faith in my fellow /. posters to take this discussion off target.

Re:Please! (1)

Zorilla (791636) | more than 9 years ago | (#10756362)

Don't worry. Leave it to Slashdot mods to mark anything that doesn't mention Perl at least 6 times to get marked offtopic.

(Hell, my sig gets even the most innocent of my posts marked as troll )

Re:Please! (-1, Troll)

Anonymous Coward | more than 9 years ago | (#10756348)

DAldrege is mental ill. Please ignore anything posted by him.

Re:Please! (1)

Pxtl (151020) | more than 9 years ago | (#10756359)

Noticed that... at any rate, I will now. Python is cooler than Perl - yes, its just as crufty and bloated, but its legible. And yes, I have worked on large-scale Python projects.

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?

An anecdote and an opinion. (2, Insightful)

pragma_x (644215) | more than 9 years ago | (#10756586)

Actually, I for one tried to learn perl once.

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 generally a good language (but not completely bad) is evident in the very syntax of perl itself.

Useful code shouldn't be as inscrutable as its compiled counterpart since that defeats the whole point. Perl is a language, so it follows that it is a communication medium. By that it should be able to communicate something to a party outside just the author and the perl interpreter. It can accomplish this, but not without the reader having to go through the mental gyrations of what could be best called linguistic decompression. The language has this tendency to impose this extra step to yield the information communicated. Simply put: it gets in its own way.

Now, useful programs on the other hand follow a different set of criteria of course. I've used perl-coded stuff online all the time, and enjoy its reliability and speed.

I'll give credit to the fact that perl is compact, terse, to the point and has a reputation for string manipulation. It fills this niche rather well, and is a prime example of the being "the right tool for the right job".

IMO, "the right job" for perl is about 2% of all programming tasks out there. This is evident by the fact that even though perl was the prominent CGI language of the mid-nineties, it lost the overwhelming majority of that interest with alarming speed.

As for python, I'm sure it fills a niche too... whatever the hell it is.

Perl perspective (2, Insightful)

Anonymous Coward | more than 9 years ago | (#10756936)

I find that reaction to Perl by people familiar with highly structured languages is common. I think this is because Perl has things like weak typing and overly flexible syntax, things that make experienced programmers vomit in their own mouths. But what's great about Perl is that you CAN have strict grammar, and you CAN have strong typing, if you desire. It's just not required.

This makes Perl very strong as a teaching tool for beginner programmers. They can start out writing loose, messy code that gets the job done, and slowly work towards stronger, more structured language. People that wouldn't have the logical dicipline to jump directly into C++ can use Perl to learn logical programming one concept at a time, and eventually be ready to grasp required C++ concepts like objects. But you'll find that people raised on Perl, even if they primarily program with C++ or Java, always come back to Perl for the quick scripting or text-processing tasks.

Re:An anecdote and an opinion. (4, Insightful)

adamruck (638131) | more than 9 years ago | (#10756937)

I think you went about things the wrong way. Why would you ever look at the nitty gritty syntax rules first when trying to learn a language. First do some simple examples to get the general feel of the langauage. Then learn the nitty gritty stuff as required.

"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. (2, Interesting)

Anonymous Coward | more than 9 years ago | (#10756970)

I don't quite understand where you're coming from, because Perl is one of the few languages that has allowed me to code in the way I think. For most languages, I have to think like the computer does, ie. momentarily turn my brain into an i386 CPU (or whatever arch it is). But not so with Perl. It's been a real joy to be able to write in an almost Enlish-like syntax, eg:
foreach $line (@data) {
chomp $line;
my ($x, $y, $z) = split(':', $line);
update_coords($x, $y, $z);
}

Re:An anecdote and an opinion. (3, Interesting)

MrBoombasticfantasti (593721) | more than 9 years ago | (#10756984)

I tried to absorb the syntax docs one afternoon, but it gave me nightmares. [...] Ever since I've been haunted by perverse unreadbility of it all.

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 string manipulation.

I just love it for the short development times, and the fact that you can really use it for just about any environment. Want to do CGI? Sure! Just GUI? No problem! Connect to about every database there is, that's no biggie.

And what about CPAN? That's a part of Perl too! You get all that ready-to-run code for just about any problem domain.

IMO, "the right job" for perl is about 2% of all programming tasks out there.

Maybe you are right, but somehow I get a lot of those 2% jobs... ;-)

Now you have to excuse me, I have some perl coding to do! ;-)

Perl is the Windows of script languages (-1, Flamebait)

Anonymous Coward | more than 9 years ago | (#10756027)

I think the aim here to keep bloating perl until it becomes completely useless as a scripting language. It's already got the most overly complex syntax of any language. Someone forgot that scripting languages do not make good application languages.

Perl is Visual Basic of the 1990's. (-1, Troll)

oodl (398345) | more than 9 years ago | (#10756214)

Perl is Visual Basic of the 1990's.

Correction: Perl is the Visual Basic of the... (-1, Troll)

oodl (398345) | more than 9 years ago | (#10756242)

Correction: Perl is the Visual Basic of the late 1990's.

Big problem (2, Interesting)

Smallpond (221300) | more than 9 years ago | (#10756053)

Perl 6 will support Perl 5 regular expressions by using the :p5 modifier.

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 (3, Informative)

WWWWolf (2428) | more than 9 years ago | (#10756115)

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 (5, Informative)

Speare (84249) | more than 9 years ago | (#10756138)

Um, ALL PERL CODE IS TREATED AS PERL5 CODE unless you use a specific Perl 6 keyword in your script. Perl 6 interpreters will not require you modify your scripts AT ALL to use Perl 5 scripts.

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 (5, Informative)

Zaak (46001) | more than 9 years ago | (#10756432)

Meaning that it is not backward compatible without modifying your source code.

Thus spake Larry Wall in Apocalypse 5:
...we took several large steps in Perl 5 to enhance regex capabilities. We took one large step forwards with the /x option, which allowed whitespace between regex tokens. But we also took several large steps sideways with the (?...) extension syntax. I call them steps sideways, but they were simultaneously steps forward in terms of functionality and steps backwards in terms of readability. At the time, I rationalized it all in the name of backward compatibility, and perhaps that approach was correct for that time and place. It's not correct now, since the Perl 6 approach is to break everything that needs breaking all at once.


And unfortunately, there's a lot of regex culture that needs breaking.

And from Apocalypse 1:
It would be rather bad to suddenly give working code a brand new set of semantics. The answer, I believe, is that it has to be impossible by definition to accidentally feed Perl 5 code to Perl 6. That is, Perl 6 must assume it is being fed Perl 5 code until it knows otherwise.

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 (0)

Anonymous Coward | more than 9 years ago | (#10756685)

In other words, it is backwards compatible, it isn't backwards compatible, and when you install Perl 6, you are installing both.


Flip-flopper!!!

Re:Big problem (1)

Tassach (137772) | more than 9 years ago | (#10756749)

That still doesn't answer the fundimental question:

Will it be possible to distinguish Perl6 code from line noise?

Re:Big problem (1)

jdavidb (449077) | more than 9 years ago | (#10756851)

The first line of most of my Perl programs is

#!/usr/local/bin/perl5.6.1

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 perl without interfering with the one installed or with any programs that are using it (and I intend to play this card at work at some point).

Why would a satisfied Perl5 user migrate? (4, Insightful)

winkydink (650484) | more than 9 years ago | (#10756117)

What does Perl6 offer a satisfied Perl5 user? Is it faster? Smaller?

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? (3, Informative)

Speare (84249) | more than 9 years ago | (#10756180)

From what I've seen, it's more amenable to modular libraries and structured design. As for basic scripting where you may not even use a "package" statement, you probably won't care.

Re:Why would a satisfied Perl5 user migrate? (1)

XMyth (266414) | more than 9 years ago | (#10756207)

See

http://it.slashdot.org/comments.pl?sid=128918&ci d= 10756138

Re:Why would a satisfied Perl5 user migrate? (2, Informative)

winkydink (650484) | more than 9 years ago | (#10756317)

I've heard/seen that "this upgrade won't affect your existing code" song and dance before. In my youth, I actually believed it.

Re:Why would a satisfied Perl5 user migrate? (1)

XMyth (266414) | more than 9 years ago | (#10756795)

I know what you mean, and really I haven't read into detail about this particular situation. However, if it truly executes code using perl5 by default unless a perl6 declaration is made then that would be more than just "backwards" compabability

Re:Why would a satisfied Perl5 user migrate? (5, Interesting)

WWWWolf (2428) | more than 9 years ago | (#10756339)

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? (0)

Anonymous Coward | more than 9 years ago | (#10756671)

It uses a compiled p-code interpereter, with (eventually) optimizations, while still supporting dynamic code interperetation (eval's and the like). Yah, that's a trick. So it should run faster (even running P5 code).

Your P5 code doesn't have to be touched to run (all code is P5 unless it says it's P6), but if you touch it you can get improved regex grammar (see the article), access to non-perl(!) modules and libraries (python at least is being ported, and some low level stuff is being written in p-code directly) and the new object model, which should involve fewer buckys per common operation.

Of course, no-one's forcing you (unless you're not root on your system...)

Re:Why would a satisfied Perl5 user migrate? (1)

gurps_npc (621217) | more than 9 years ago | (#10756788)

You left out the other two possible improvements.

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? (1)

winkydink (650484) | more than 9 years ago | (#10756948)

If I am a current, satisfied user, the last two are less important than the first two, as current & satisfied infers that I have all the features I need and already know how to use/understand.

wow, looks like boost::spirit (3, Interesting)

Sebastopol (189276) | more than 9 years ago | (#10756205)

I'm surprised by the regex grammar. It looks a lot like how I use boost::spirit::rule for parsing regex in C++:

Perl6---

# note this is just a language example, not an accurate name matcher
grammar Names
{
rule name :w { };
rule singlename { + };
};

C++::boost::spirit--- // rule for parsing a token string
rule split = *(*space_p >>
(+graph_p)[append(tok)] >>
*space_p);

msg "Parsing input\n"; // 1. Parse declarations
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! ;-)

It is about time to change the name from (2, Interesting)

musterion (305824) | more than 9 years ago | (#10756233)

Regular Expressions to Context Sensitive (at least) Parsing. I'm not a big Perl Geek, but I use it on a daily basis.

GREAT ! (-1, Troll)

Anonymous Coward | more than 9 years ago | (#10756234)

I can't wait !

Just think....

* More cruddy syntax
* "More ways to do the same thing" (I tell you, if I read that just one more time.....)
* It will be even easier to write complete gibberish and have it run WITH NO ERRORS (even though it's COMPLETE GIBBERISH)
* It will be bigger and cruddier ! (an excuse to buy a bigger drive to load it on to)
* Want to do something complex ? No problem - there's a one-liner that will do it !!!
* Want to do something dead simple ? No problem - there's this huge bloat of a module that you have to install. Oh yes, it depends on half a dozen other modules too. That's what makes Perl so "good" (?!)

No, I really can't wait !

Perl is OK in one or two areas. ie - the areas that everyone quotes - string handling and regular expressions.

The thing is, the world has moved on and this stuff is available in a lot of scripting languages. And they are smaller, they have better syntax (they could NOT POSSIBLY BE WORSE !) and they make more sense.

Perl is for people who don't have a life and can't admit that it was an ok idea that went horribly wrong.

Adoption (4, Interesting)

base_chakra (230686) | more than 9 years ago | (#10756251)

Years ago, Eric Raymond wrote [python.org]:
"Perl XS is acknowledged to be a nasty mess. My guess is the Perl guys would drop it like a hot rock for our [Python's] stuff --
that would be as clear a win for them as co-opting Perl-style regexps was for us." [emphasis added]
Maybe I misinterpreted ESR's intended message, but it would be disappointing if hypercompetition prevented Perl's already-influential regex extensions from exerting a positive influence on other platforms. Raymond seems to imply that the Python team only grudgingly included support for Perl-style regex. I understand that developement teams in similar niches each want to make a big splash in the industry, hopefully Python's great increase in popularity has softened the survivalist attitude that seems to characterize this Raymond quote from Python-Dev. Evolving regex can benefit everyone.

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 (0)

Anonymous Coward | more than 9 years ago | (#10756635)

Raymond seems to imply that the Python team only grudgingly included support for Perl-style regex

That's not what I got from his quote at all. He said that it was a clear win for the Python people to use Perl-style regular expressions. And likewise, it would be a clear win for the Perl people to use Python-style C extensions.

Re:Adoption (4, Insightful)

Black Perl (12686) | more than 9 years ago | (#10756687)

Yes, you did misinterpret the message. Eric Raymond was a former Perl programmer, and is now a Python programmer. He was saying that Python's native-code-binding facility is superior than Perl's XS, and it would benefit Perl to adopt it. He mentions that Python benefitted from adopting Perl's regex syntax. Nowhere does he say or imply it was "grudgingly" done.

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.

Complex grammars in Perl (4, Insightful)

imnoteddy (568836) | more than 9 years ago | (#10756329)

I can understand a desire for adding grammars that are more powerful than regular expressions in Perl 6 but it opens up a whole new can of worms.

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 (1)

Abcd1234 (188840) | more than 9 years ago | (#10756489)

What bugs me is they don't describe the type of parser being generated. Parse::RecDescent does just what it says... it generates recursive decent parsers. However, recursive descent parsers are not as powerful as the bottom-up parsers generated by, for example, Yacc/Bison (LL vs LR).

Yes. (1)

MenTaLguY (5483) | more than 9 years ago | (#10756559)

Perl 6 grammars are a full citizen of the language on a level with subroutines and classes (loosely speaking, in Perl 6, rule:grammar::method:class, actually). They're effectively Turing-complete as a result, since Perl 6 is obviously Turing-complete.

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. (1)

sheetsda (230887) | more than 9 years ago | (#10756868)

I use quotes since Perl 5 regexps are already marginally more powerful than "pure" regexps

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.

OMG! (-1, Flamebait)

Libor Vanek (248963) | more than 9 years ago | (#10756332)

Oh My God! This will make Perl code look really crazy. I'm managing 15 kSLOC Perl SW an 50 kSLOC PHP SW. Making changes to Perl code is at least twice as hard and requires much more time to re-study the code (and that both SW are written by myself with trying to keep the "code style" like no $tmp vars etc.).

Perl is usefull for 1-100 lines "maintenance" scripts but writting some reall SW in it just sucks...

You're a language bigot (3, Interesting)

Mr. Muskrat (718203) | more than 9 years ago | (#10756503)

Sounds to me like you prefer PHP and therefore spent more time perfecting your understanding of it. If you know and understand a language (any language) your work will require less time and will (surprise, surprise) be easier for you.

(I'm a recovering language bigot so I can say this. :-P )

No Dupes? (-1)

Anonymous Coward | more than 9 years ago | (#10756428)

A whole morning of Taco and no Dupes...OMG the world is ending. IT IS THE SEVENTH SIGN! Zeus, Jehovah, Buddha, Jim (for agnostics), SAVE ME!!!

Perl6 -- an interesting curiosity (0)

Anonymous Coward | more than 9 years ago | (#10756446)

Oh yeah. Larry and Co. went off the deep end with Perl6. I mean now they DO have the kitchen sink in there.

That's what happens when you take a philosophy "more than one way to do it" and run with it.. straight off a cliff.

It is impressive the way they unify everything though. I guess if you can't make a language simple and elegant, you might as well try and make it consistent.

And the new regexp syntax is sorely needed. Regexps have grown up now and the syntax needs to be rethought. So I hope the other less confusing languages like Ruby will pick up the new regexp syntax someday.

I would also love to see a relational query language (NOT SQL THOUGH.. maybe something like Tutorial D) embedded right in the language like regexps are... but that's a discussion for another time. Let's get some real relational databases first.

Anyway, Perl6 is quite fascinating, but slightly insane.

Did you ever go drinking one night, but decide to NOT drink and just pull out a lawn chair and watch what people are like when they are drunk? That's how I feel watching Perl 6 evolve from the cozy comfort of Ruby. Lots of fun as long as nobody pukes on me!

Re:Perl6 -- an interesting curiosity (2, Funny)

TimToady (52230) | more than 9 years ago | (#10756875)

Lawn chairs are fine, but in actual fact, kitchen sinks are more useful.

bad example? (0)

TheSnakeMan (59408) | more than 9 years ago | (#10756482)

I have to question how good this guy is, given that it seems as though he has a mistake in his first set of examples:

'whereas in Perl 5 you can match "hello there" with "hello there" itself, in Perl 6 you'd have to ask for /hello <sp> there/ instead.'

Then: grammar English { rule name :w { <singlename> <singlename> }; rule singlename { <[A-Z]><[a-z]>+ }; };

Shouldn't this be: "{ <singlename> <sp> <singlename> };"?

Re:bad example? (2, Informative)

TheSnakeMan (59408) | more than 9 years ago | (#10756576)

Next time, I swear I'll read the comments:

# Perl 6 :w modifier surrounds all tokens with "automagic" whitespace,
# which basically means it will match what most people would call
# "words"

Load More Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Sign up for Slashdot Newsletters
Create a Slashdot Account

Loading...