Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* lexer function .
@ 1996-10-31 10:25 Olivier Pons
  1996-11-04 16:45 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Olivier Pons @ 1996-10-31 10:25 UTC (permalink / raw)
  To: caml-list



	hello !


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>

and now I just inspect  the token stream generated

   #stream_next a;;                                              
   - : token = Ident "a"
   #stream_next b;;                            
   - : token = Ident "a"

but in the next call 

   #stream_next a;;
   - : token = Ident "/\\~"

   #stream_next b;;
   - : token = Kwd "/\\

   #stream_next a;;
   - : token = Ident "a"

   #stream_next b;;
   - : token = Kwd "~"
   .......

I don't understand why in the first case the keywords /\\ and ~  are not recognized ?

thank in advance


Olivier






^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: lexer function .
  1996-10-31 10:25 lexer function Olivier Pons
@ 1996-11-04 16:45 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 1996-11-04 16:45 UTC (permalink / raw)
  To: Olivier Pons; +Cc: caml-list

> 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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-11-05  8:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-10-31 10:25 lexer function Olivier Pons
1996-11-04 16:45 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox