File: lexer.mll

package info (click to toggle)
ocaml-obuild 0.1.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 796 kB
  • sloc: ml: 6,570; sh: 171; ansic: 34; makefile: 11
file content (25 lines) | stat: -rw-r--r-- 734 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(* file: lexer.mll *)
(* Lexical analyzer returns one of the tokens:
   the token NUM of a floating point number,
   operators (PLUS, MINUS, MULTIPLY, DIVIDE, CARET, UMINUS),
   or NEWLINE.  It skips all blanks and tabs, unknown characters
   and raises End_of_file on EOF. *)
{
  open Rpncalc (* Assumes the parser file is "rpncalc.mly". *)
}
let digit = ['0'-'9']
rule token = parse
  | [' ' '\t']  { token lexbuf }
  | '\n'    { NEWLINE }
  | digit+
  | "." digit+
  | digit+ "." digit* as num
        { NUM (float_of_string num) }
  | '+'     { PLUS }
  | '-'     { MINUS }
  | '*'     { MULTIPLY }
  | '/'     { DIVIDE }
  | '^'     { CARET }
  | 'n'     { UMINUS }
  | _       { token lexbuf }
  | eof     { raise End_of_file }