source: Deliverables/D2.2/8051/src/cminor/cminorLexer.mll @ 486

Last change on this file since 486 was 486, checked in by ayache, 9 years ago

Deliverable D2.2

File size: 4.3 KB
Line 
1(* *********************************************************************)
2(*                                                                     *)
3(*              The Compcert verified compiler                         *)
4(*                                                                     *)
5(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
6(*                                                                     *)
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.     *)
13(*                                                                     *)
14(* *********************************************************************)
15
16{
17  open CminorParser
18  exception Error of string
19}
20
21let ret = ['\010']
22let blank = [' ' '\009' '\012' '\013']
23let floatlit =
24  ['0'-'9'] ['0'-'9' '_']*
25  ('.' ['0'-'9' '_']* )?
26  (['e' 'E'] ['+' '-']? ['0'-'9'] ['0'-'9' '_']*)?
27let ident = ['A'-'Z' 'a'-'z' '_'] ['A'-'Z' 'a'-'z' '_' '0'-'9']*
28let intlit = "-"? ( ['0'-'9']+ | "0x" ['0'-'9' 'a'-'f' 'A'-'F']+
29                               | "0o" ['0'-'7']+ | "0b" ['0'-'1']+ )
30let stringlit = "\"" [ ^ '"' ] * '"'
31
32rule token = parse
33  | ret   { Misc.LexingExt.new_line lexbuf ; token lexbuf }
34  | blank +      { token lexbuf }
35  | "/*"         { comment lexbuf; token lexbuf }
36  | "absf" { ABSF }
37  | "&" { AMPERSAND }
38  | "&&" { AMPERSANDAMPERSAND }
39  | "!"    { BANG }
40  | "!="    { BANGEQUAL }
41  | "!=f"    { BANGEQUALF }
42  | "!=u"    { BANGEQUALU }
43  | "|"     { BAR }
44  | "||"    { BARBAR }
45  | "^"     { CARET }
46  | "case"  { CASE }
47  | ":"    { COLON }
48  | ","    { COMMA }
49  | "default" { DEFAULT }
50(*  | "$"    { DOLLAR } *)
51  | "else"    { ELSE }
52  | "="    { EQUAL }
53  | "=="    { EQUALEQUAL }
54  | "==f"    { EQUALEQUALF }
55  | "==u"    { EQUALEQUALU }
56  | "exit"    { EXIT }
57  | "extern"    { EXTERN }
58  | "float"    { FLOAT }
59  | "float32"    { FLOAT32 }
60  | "float64"    { FLOAT64 }
61  | "floatofint"    { FLOATOFINT }
62  | "floatofintu"    { FLOATOFINTU }
63  | ">"    { GREATER }
64  | ">f"    { GREATERF }
65  | ">u"    { GREATERU }
66  | ">="    { GREATEREQUAL }
67  | ">=f"    { GREATEREQUALF }
68  | ">=u"    { GREATEREQUALU }
69  | ">>"    { GREATERGREATER }
70  | ">>u"    { GREATERGREATERU }
71  | "if"    { IF }
72(*  | "in"    { IN } *)
73  | "int"    { INT }
74  | "int16"    { INT16 }
75  | "int16s"    { INT16S }
76  | "int16u"    { INT16U }
77  | "int32"    { INT32 }
78  | "int8"    { INT8 }
79  | "int8s"    { INT8S }
80  | "int8u"    { INT8U }
81  | "intoffloat"    { INTOFFLOAT }
82  | "intuoffloat"    { INTUOFFLOAT }
83  | "{"    { LBRACE }
84(*  | "{{"    { LBRACELBRACE } *)
85  | "["    { LBRACKET }
86  | "<"    { LESS }
87  | "<u"    { LESSU }
88  | "<f"    { LESSF }
89  | "<="    { LESSEQUAL }
90  | "<=u"    { LESSEQUALU }
91  | "<=f"    { LESSEQUALF }
92  | "<<"    { LESSLESS }
93(*  | "let"     { LET } *)
94  | "loop"    { LOOP }
95  | "("    { LPAREN }
96  | "match" { MATCH }
97  | "-"    { MINUS }
98  | "->"    { MINUSGREATER }
99  | "-f"    { MINUSF }
100  | "%"    { PERCENT }
101  | "%u"    { PERCENTU }
102  | "+"    { PLUS }
103  | "+f"    { PLUSF }
104  | "?"    { QUESTION }
105  | "}"    { RBRACE }
106(*  | "}}"    { RBRACERBRACE } *)
107  | "]"    { RBRACKET }
108  | "return"    { RETURN }
109  | ")"    { RPAREN }
110  | ";"    { SEMICOLON }
111  | "/"    { SLASH }
112  | "/f"    { SLASHF }
113  | "/u"    { SLASHU }
114  | "stack"    { STACK }
115  | "*" { STAR }
116  | "*f"    { STARF }
117  | "switch"    { SWITCH }
118  | "tailcall"  { TAILCALL }
119  | "~"    { TILDE }
120  | "var"    { VAR }
121  | "void"    { VOID }
122  | "goto" { GOTO }
123  | "block" { BLOCK }
124  | intlit    { INTLIT(int_of_string(Lexing.lexeme lexbuf)) }
125  | floatlit     { FLOATLIT(float_of_string(Lexing.lexeme lexbuf)) }
126  | stringlit { let s = Lexing.lexeme lexbuf in
127                STRINGLIT(String.sub s 1 (String.length s - 2)) }
128  | ident    { IDENT(Lexing.lexeme lexbuf) }
129  | eof      { EOF }
130  | _        { raise(Error("illegal character `" ^ Char.escaped (Lexing.lexeme_char lexbuf 0) ^ "'")) }
131
132and comment = parse
133    "*/"     { () }
134  | eof      { raise(Error "unterminated comment") }
135  | _        { comment lexbuf }
Note: See TracBrowser for help on using the repository browser.