]> matita.cs.unibo.it Git - pkg-cerco/acc.git/blob - src/cminor/cminorLexer.mll
Package description and copyright added.
[pkg-cerco/acc.git] / src / cminor / cminorLexer.mll
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
21 let ret = ['\010']
22 let blank = [' ' '\009' '\012' '\013']
23 let floatlit = 
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 = "\"" [ ^ '"' ] * '"'
31
32 rule 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   | "int8"    { INT8 }
75   | "int16"    { INT16 }
76   | "int32"    { INT32 }
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 }
97   | "ptr" { PTR }
98   | "{"    { LBRACE }
99 (*  | "{{"    { LBRACELBRACE } *)
100   | "["    { LBRACKET }
101   | "<"    { LESS }
102   | "<u"    { LESSU }
103   | "<f"    { LESSF }
104   | "<="    { LESSEQUAL }
105   | "<=u"    { LESSEQUALU }
106   | "<=f"    { LESSEQUALF }
107   | "<<"    { LESSLESS }
108 (*  | "let"     { LET } *)
109   | "loop"    { LOOP }
110   | "("    { LPAREN }
111   | "match" { MATCH }
112   | "-"    { MINUS }
113   | "->"    { MINUSGREATER }
114   | "-f"    { MINUSF }
115   | "%"    { PERCENT }
116   | "%u"    { PERCENTU }
117   | "+"    { PLUS }
118   | "+f"    { PLUSF }
119   | "?"    { QUESTION }
120   | "}"    { RBRACE }
121 (*  | "}}"    { RBRACERBRACE } *)
122   | "]"    { RBRACKET }
123   | "return"    { RETURN }
124   | ")"    { RPAREN }
125   | ";"    { SEMICOLON }
126   | "/"    { SLASH }
127   | "/f"    { SLASHF }
128   | "/u"    { SLASHU }
129   | "stack"    { STACK }
130   | "*" { STAR }
131   | "*f"    { STARF }
132   | "switch"    { SWITCH }
133   | "tailcall"  { TAILCALL }
134   | "~"    { TILDE }
135   | "var"    { VAR }
136   | "void"    { VOID }
137   | "goto" { GOTO }
138   | "block" { BLOCK }
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) }
144   | eof      { EOF }
145   | _        { raise(Error("illegal character `" ^ Char.escaped (Lexing.lexeme_char lexbuf 0) ^ "'")) }
146
147 and comment = parse
148     "*/"     { () }
149   | eof      { raise(Error "unterminated comment") }
150   | _        { comment lexbuf }