Debian Codegraph @

examples/05-lex-yacc/src/lexer.mll

raw
1 {
2 module P = Parser
3
4 exception Error of string
5 let error fmt = Printf.kprintf (fun msg -> raise (Error msg)) fmt
6
7 let get = Lexing.lexeme
8 }
9
10 rule token = parse
11 | [' ' '\t' '\n'] { token lexbuf } (* skip blanks *)
12 | ['0'-'9']+ as lxm { P.INT(int_of_string lxm) }
13 | '+' { P.PLUS }
14 | '-' { P.MINUS }
15 | '*' { P.TIMES }
16 | '/' { P.DIV }
17 | '(' { P.LPAREN }
18 | ')' { P.RPAREN }
19 | eof { P.EOF }
20 | _ { error "don't know how to handle '%s'" (get lexbuf) }
21
22