caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Michael Leary <leary@nwlink.com>
Cc: caml <caml-list@inria.fr>
Subject: Re: [Caml-list] lexer disambiguation?
Date: Mon, 10 Sep 2001 17:31:18 +0200	[thread overview]
Message-ID: <20010910173118.A12822@pauillac.inria.fr> (raw)
In-Reply-To: <20010831140925.U2959@ip178.usw22.rb1.bel.nwlink.com>; from leary@nwlink.com on Fri, Aug 31, 2001 at 02:09:25PM -0700

> since the lexer looks like an ordinary ocaml function (more or less), does
> the disambiguation boil down to:
> 
> 1. the longest series of bytes that matches a single rule
> 2. match the first rule in the function that matches #1

I'm not sure which lexer you're talking about.

Lexers generated by ocamllex do indeed implement the behavior you
describe: longest match + first rule if several rules matches the same
maximal-length substring.  (But they sure don't look like ordinary
OCaml functions: they just call an underlying table-driven DFA engine
that does all the hard work!)

Lexers written using stream parsers behave like all stream parsers:
they select the first pattern that matches the beginning of the
stream, then "commit" to this pattern, matching the remainder of the
pattern without backtracking.  This "commit" behavior is different
from regular pattern-matching on (say) lists, which backtracks as
necessary.

The OCaml lexer (used by the compilers and the toplevel), as well as
the generic lexer in module Genlex, also implement the longest-match
rule, so that for instance abcd is one identifier, not four
identifiers a, b, c, and d.

I hope this answers your question.

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


      reply	other threads:[~2001-09-10 15:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-31 21:09 Michael Leary
2001-09-10 15:31 ` Xavier Leroy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010910173118.A12822@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=leary@nwlink.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).