Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: opons@aenegada.inria.fr (Olivier Pons)
Cc: caml-list@inria.fr
Subject: Re: lexer function .
Date: Mon, 4 Nov 1996 17:45:56 +0100 (MET)	[thread overview]
Message-ID: <199611041645.RAA05308@pauillac.inria.fr> (raw)
In-Reply-To: <199610311025.LAA08481@aenegada.inria.fr> from Olivier Pons at "Oct 31, 96 11:25:48 am"

> I have a little problem with the lexer function generated by make_lexer
> in the example below:
>    let lexer = make_lexer ["("; ")"; "/\\"; "\//"; "~"; "->"];; 
>    let a =  (lexer(stream_of_string"a/\~a"));; (* there is no blank*)
>    a : token stream = <abstr>
>    #let b = (lexer(stream_of_string"a/\ ~a"));;(* there is a blank*)
>    b : token stream = <abstr>
> I don't understand why in the first case the keywords /\\ and ~ are
> not recognized ?

Lexers generated by "genlex" first split the input stream into
literals, identifiers and "special characters", then match the
identifiers and special characters against the keyword table.
In the first case of your example, the stream is split as
        a       /\~     a
and since /\~ is not a keyword, it's returned as an identifier.
In the second case, the stream is split as
        a       /\      ~       a
and /\ is recognized as a keyword.

This behavior is consistent with that of the Caml lexer itself:

#1+-2;;
Toplevel input:
>1+-2;;
> ^^
The value identifier +- is unbound.
#1 + -2;;
- : int = -1

So, use blanks liberally.

- Xavier Leroy





      reply	other threads:[~1996-11-05  8:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-31 10:25 Olivier Pons
1996-11-04 16:45 ` 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=199611041645.RAA05308@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=opons@aenegada.inria.fr \
    /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