1 (* *********************************************************************)
3 (* The Compcert verified compiler *)
5 (* Xavier Leroy, INRIA Paris-Rocquencourt *)
7 (* Copyright Institut National de Recherche en Informatique et en *)
8 (* Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the GNU General Public License as published by *)
10 (* the Free Software Foundation, either version 2 of the License, or *)
11 (* (at your option) any later version. This file is also distributed *)
12 (* under the terms of the INRIA Non-Commercial License Agreement. *)
14 (* *********************************************************************)
18 exception Error of string
22 let blank = [' ' '\009' '\012' '\013']
24 ['0'-'9'] ['0'-'9' '_']*
25 ('.' ['0'-'9' '_']* )?
26 (['e' 'E'] ['+' '-']? ['0'-'9'] ['0'-'9' '_']*)?
27 let ident = ['A'-'Z' 'a'-'z' '_'] ['A'-'Z' 'a'-'z' '_' '0'-'9']*
28 let intlit = "-"? ( ['0'-'9']+ | "0x" ['0'-'9' 'a'-'f' 'A'-'F']+
29 | "0o" ['0'-'7']+ | "0b" ['0'-'1']+ )
30 let stringlit = "\"" [ ^ '"' ] * '"'
33 | ret { Misc.LexingExt.new_line lexbuf ; token lexbuf }
34 | blank + { token lexbuf }
35 | "/*" { comment lexbuf; token lexbuf }
38 | "&&" { AMPERSANDAMPERSAND }
41 | "!=f" { BANGEQUALF }
42 | "!=u" { BANGEQUALU }
49 | "default" { DEFAULT }
50 (* | "$" { DOLLAR } *)
54 | "==f" { EQUALEQUALF }
55 | "==u" { EQUALEQUALU }
59 | "float32" { FLOAT32 }
60 | "float64" { FLOAT64 }
61 | "floatofint" { FLOATOFINT }
62 | "floatofintu" { FLOATOFINTU }
66 | ">=" { GREATEREQUAL }
67 | ">=f" { GREATEREQUALF }
68 | ">=u" { GREATEREQUALU }
69 | ">>" { GREATERGREATER }
70 | ">>u" { GREATERGREATERU }
77 | "int8sto8" { INT8STO8 }
78 | "int8sto16" { INT8STO16 }
79 | "int8sto32" { INT8STO32 }
80 | "int8uto8" { INT8UTO8 }
81 | "int8uto16" { INT8UTO16 }
82 | "int8uto32" { INT8UTO32 }
83 | "int16sto8" { INT16STO8 }
84 | "int16sto16" { INT16STO16 }
85 | "int16sto32" { INT16STO32 }
86 | "int16uto8" { INT16UTO8 }
87 | "int16uto16" { INT16UTO16 }
88 | "int16uto32" { INT16UTO32 }
89 | "int32sto8" { INT32STO8 }
90 | "int32sto16" { INT32STO16 }
91 | "int32sto32" { INT32STO32 }
92 | "int32uto8" { INT32UTO8 }
93 | "int32uto16" { INT32UTO16 }
94 | "int32uto32" { INT32UTO32 }
95 | "intoffloat" { INTOFFLOAT }
96 | "intuoffloat" { INTUOFFLOAT }
99 (* | "{{" { LBRACELBRACE } *)
105 | "<=u" { LESSEQUALU }
106 | "<=f" { LESSEQUALF }
108 (* | "let" { LET } *)
113 | "->" { MINUSGREATER }
121 (* | "}}" { RBRACERBRACE } *)
123 | "return" { RETURN }
132 | "switch" { SWITCH }
133 | "tailcall" { TAILCALL }
139 | intlit { INTLIT(int_of_string(Lexing.lexeme lexbuf)) }
140 | floatlit { FLOATLIT(float_of_string(Lexing.lexeme lexbuf)) }
141 | stringlit { let s = Lexing.lexeme lexbuf in
142 STRINGLIT(String.sub s 1 (String.length s - 2)) }
143 | ident { IDENT(Lexing.lexeme lexbuf) }
145 | _ { raise(Error("illegal character `" ^ Char.escaped (Lexing.lexeme_char lexbuf 0) ^ "'")) }
149 | eof { raise(Error "unterminated comment") }
150 | _ { comment lexbuf }