Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Writing lex-like scanners in Perl

Reply
Thread Tools

Writing lex-like scanners in Perl

 
 
Clint Olsen
Guest
Posts: n/a
 
      11-18-2003
I read the example in perlre(1) regarding writing lexical analyzers in Perl
using /gc, but I was wondering if there might be another approach. One
problem with doing the if{}elsif{}..else{} technique is that this does not
really simulate traditional scanner behavior. Scanners always try to make
the longest match, not the first. One way to mimic the behavior more
faithfully would be to put the entire lexical analyzer in one pattern. But
I wasn't sure if it was possible (even legibly) using extended regular
expressions (/x) to put executable code and embed it in the patterns:

/(alt1) {return "alt1"} |(alt2) { return "alt2"}|(alt3) { return
"alt3"}.../iogc

and so on.

If anyone has any experience with this kind of application, I'd like to
hear from you.

Thanks,

-Clint
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      11-18-2003

Clint Olsen <(E-Mail Removed)> wrote:
> I read the example in perlre(1) regarding writing lexical analyzers in Perl
> using /gc, but I was wondering if there might be another approach. One
> problem with doing the if{}elsif{}..else{} technique is that this does not
> really simulate traditional scanner behavior. Scanners always try to make
> the longest match, not the first. One way to mimic the behavior more
> faithfully would be to put the entire lexical analyzer in one pattern. But
> I wasn't sure if it was possible (even legibly) using extended regular
> expressions (/x) to put executable code and embed it in the patterns:
>
> /(alt1) {return "alt1"} |(alt2) { return "alt2"}|(alt3) { return
> "alt3"}.../iogc


See (?{...}) and (??{...}) in perlre.

Ben

--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Clint Olsen
Guest
Posts: n/a
 
      11-18-2003
On 2003-11-18, Ben Morrow <(E-Mail Removed)> wrote:
>
> See (?{...}) and (??{...}) in perlre.


I did look at this, but I believe I found a problem with pos() for the
search string not being updated if I returned from the function from this
kind of code. So, I would repeat from the beginning of the string every
time. I'll give it a try again and defer the return until after the search
block.

Thanks,

-Clint
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLANs and scanners Pete Cisco 2 03-16-2006 01:04 AM
barcode scanners worked before SP2 =?Utf-8?B?c2x1ZGxvdw==?= Wireless Networking 1 08-23-2005 05:28 PM
Firefox & on-line virus scanners Geese_Hunter Firefox 0 04-01-2004 02:45 PM
Bar code scanners on a web application ? Mike Smith ASP .Net 1 03-01-2004 11:31 AM
Hiding a PIX from nmap and port-scanners. Francois Labreque Cisco 1 11-11-2003 06:42 AM



Advertisments