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

Last change on this file since 740 was 740, checked in by ayache, 10 years ago

New memory model and bug fixes in 8051 branch. Added primitive operations in interpreters from Clight to LIN.

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  | "ptr" { PTR }
84  | "{"    { LBRACE }
85(*  | "{{"    { LBRACELBRACE } *)
86  | "["    { LBRACKET }
87  | "<"    { LESS }
88  | "<u"    { LESSU }
89  | "<f"    { LESSF }
90  | "<="    { LESSEQUAL }
91  | "<=u"    { LESSEQUALU }
92  | "<=f"    { LESSEQUALF }
93  | "<<"    { LESSLESS }
94(*  | "let"     { LET } *)
95  | "loop"    { LOOP }
96  | "("    { LPAREN }
97  | "match" { MATCH }
98  | "-"    { MINUS }
99  | "->"    { MINUSGREATER }
100  | "-f"    { MINUSF }
101  | "%"    { PERCENT }
102  | "%u"    { PERCENTU }
103  | "+"    { PLUS }
104  | "+f"    { PLUSF }
105  | "?"    { QUESTION }
106  | "}"    { RBRACE }
107(*  | "}}"    { RBRACERBRACE } *)
108  | "]"    { RBRACKET }
109  | "return"    { RETURN }
110  | ")"    { RPAREN }
111  | ";"    { SEMICOLON }
112  | "/"    { SLASH }
113  | "/f"    { SLASHF }
114  | "/u"    { SLASHU }
115  | "stack"    { STACK }
116  | "*" { STAR }
117  | "*f"    { STARF }
118  | "switch"    { SWITCH }
119  | "tailcall"  { TAILCALL }
120  | "~"    { TILDE }
121  | "var"    { VAR }
122  | "void"    { VOID }
123  | "goto" { GOTO }
124  | "block" { BLOCK }
125  | intlit    { INTLIT(int_of_string(Lexing.lexeme lexbuf)) }
126  | floatlit     { FLOATLIT(float_of_string(Lexing.lexeme lexbuf)) }
127  | stringlit { let s = Lexing.lexeme lexbuf in
128                STRINGLIT(String.sub s 1 (String.length s - 2)) }
129  | ident    { IDENT(Lexing.lexeme lexbuf) }
130  | eof      { EOF }
131  | _        { raise(Error("illegal character `" ^ Char.escaped (Lexing.lexeme_char lexbuf 0) ^ "'")) }
132
133and comment = parse
134    "*/"     { () }
135  | eof      { raise(Error "unterminated comment") }
136  | _        { comment lexbuf }
Note: See TracBrowser for help on using the repository browser.