Writing lex-like scanners in Perl

Discussion in 'Perl Misc' started by Clint Olsen, Nov 18, 2003.

  1. Clint Olsen

    Clint Olsen Guest

    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
     
    Clint Olsen, Nov 18, 2003
    #1
    1. Advertising

  2. Clint Olsen

    Ben Morrow Guest

    Clint Olsen <> 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] *
     
    Ben Morrow, Nov 18, 2003
    #2
    1. Advertising

  3. Clint Olsen

    Clint Olsen Guest

    On 2003-11-18, Ben Morrow <> 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
     
    Clint Olsen, Nov 18, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Smith

    Bar code scanners on a web application ?

    Mike Smith, Feb 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    411
    Francois Verbeeck
    Mar 1, 2004
  2. Replies:
    1
    Views:
    1,402
  3. Joe Kesselman
    Replies:
    0
    Views:
    842
    Joe Kesselman
    Sep 8, 2011
  4. Peter Flynn
    Replies:
    0
    Views:
    836
    Peter Flynn
    Sep 8, 2011
  5. Replies:
    1
    Views:
    98
Loading...

Share This Page