lustrec / src / lexer_prelude.mll @ 0cbf0839
History | View | Annotate | Download (3.54 KB)
1 |
(* ---------------------------------------------------------------------------- |
---|---|
2 |
* SchedMCore - A MultiCore Scheduling Framework |
3 |
* Copyright (C) 2009-2011, ONERA, Toulouse, FRANCE - LIFL, Lille, FRANCE |
4 |
* |
5 |
* This file is part of Prelude |
6 |
* |
7 |
* Prelude is free software; you can redistribute it and/or |
8 |
* modify it under the terms of the GNU Lesser General Public License |
9 |
* as published by the Free Software Foundation ; either version 2 of |
10 |
* the License, or (at your option) any later version. |
11 |
* |
12 |
* Prelude is distributed in the hope that it will be useful, but |
13 |
* WITHOUT ANY WARRANTY ; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
* Lesser General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU Lesser General Public |
18 |
* License along with this program ; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
*---------------------------------------------------------------------------- *) |
22 |
|
23 |
{ |
24 |
open Parser_prelude |
25 |
open Utils |
26 |
|
27 |
exception Error of Location.t |
28 |
|
29 |
(* As advised by Caml documentation. This way a single lexer rule is |
30 |
used to handle all the possible keywords. *) |
31 |
let keyword_table = |
32 |
create_hashtable 20 [ |
33 |
"true", TRUE; |
34 |
"false", FALSE; |
35 |
"stateless", STATELESS; |
36 |
"if", IF; |
37 |
"then", THEN; |
38 |
"else", ELSE; |
39 |
"merge", MERGE; |
40 |
"arrow", ARROW; |
41 |
"fby", FBY; |
42 |
"when", WHEN; |
43 |
"whennot", WHENNOT; |
44 |
"every", EVERY; |
45 |
"node", NODE; |
46 |
"sensor", SENSOR; |
47 |
"actuator", ACTUATOR; |
48 |
"let", LET; |
49 |
"tel", TEL; |
50 |
"returns", RETURNS; |
51 |
"var", VAR; |
52 |
"imported", IMPORTED; |
53 |
"wcet", WCET; |
54 |
"int", TINT; |
55 |
"bool", TBOOL; |
56 |
"float", TFLOAT; |
57 |
"real", TREAL; |
58 |
"clock", TCLOCK; |
59 |
"rate", RATE; |
60 |
"due", DUE; |
61 |
"not", NOT; |
62 |
"tail", TAIL; |
63 |
"and", AND; |
64 |
"or", OR; |
65 |
"xor", OR; |
66 |
"mod", MOD; |
67 |
"pre", PRE; |
68 |
"div", DIV; |
69 |
"const", CONST; |
70 |
"include", INCLUDE |
71 |
] |
72 |
|
73 |
(* Update line number for location info *) |
74 |
let incr_line lexbuf = |
75 |
let pos = lexbuf.Lexing.lex_curr_p in |
76 |
lexbuf.Lexing.lex_curr_p <- { pos with |
77 |
Lexing.pos_lnum = pos.Lexing.pos_lnum + 1; |
78 |
Lexing.pos_bol = pos.Lexing.pos_cnum; |
79 |
} |
80 |
} |
81 |
|
82 |
let newline = ('\010' | '\013' | "\013\010") |
83 |
let notnewline = [^ '\010' '\013'] |
84 |
let blank = [' ' '\009' '\012'] |
85 |
|
86 |
rule token = parse |
87 |
| "/*" |
88 |
{ comment 0 lexbuf } |
89 |
| "--" notnewline* (newline|eof) |
90 |
{ incr_line lexbuf; |
91 |
token lexbuf } |
92 |
| newline |
93 |
{ incr_line lexbuf; |
94 |
token lexbuf } |
95 |
| blank + |
96 |
{token lexbuf} |
97 |
| ['0'-'9'] ['0'-'9']* '.' ['0'-'9']* |
98 |
{FLOAT (float_of_string (Lexing.lexeme lexbuf))} |
99 |
| ['0'-'9']+ |
100 |
{INT (int_of_string (Lexing.lexeme lexbuf)) } |
101 |
| ['0'-'9']+ '.' ['0'-'9']+ 'E' ('+'|'-') ['0'-'9'] ['0'-'9'] as s {REAL s} |
102 |
| "tel." {TEL} |
103 |
| "tel;" {TEL} |
104 |
| ['_' 'A'-'Z' 'a'-'z'] ['A'-'Z' 'a'-'z' '_' '0'-'9']* |
105 |
{let s = Lexing.lexeme lexbuf in |
106 |
try |
107 |
Hashtbl.find keyword_table s |
108 |
with Not_found -> |
109 |
IDENT s} |
110 |
| "->" {ARROW} |
111 |
| "=>" {IMPL} |
112 |
| "<=" {LTE} |
113 |
| ">=" {GTE} |
114 |
| "<>" {NEQ} |
115 |
| '<' {LT} |
116 |
| '>' {GT} |
117 |
| "!=" {NEQ} |
118 |
| '-' {MINUS} |
119 |
| '+' {PLUS} |
120 |
| '/' {DIV} |
121 |
| '*' {MULT} |
122 |
| '=' {EQ} |
123 |
| '(' {LPAR} |
124 |
| ')' {RPAR} |
125 |
| ';' {SCOL} |
126 |
| ':' {COL} |
127 |
| ',' {COMMA} |
128 |
| '=' {EQ} |
129 |
| '/' {DIV} |
130 |
| "&&" {AMPERAMPER} |
131 |
| "||" {BARBAR} |
132 |
| "*^" {UCLOCK} |
133 |
| "/^" {DCLOCK} |
134 |
| "~>" {PHCLOCK} |
135 |
| "::" {COLCOL} |
136 |
| "^" {POWER} |
137 |
| '"' {QUOTE} |
138 |
| eof { EOF } |
139 |
| _ { raise (Error (Location.curr lexbuf)) } |
140 |
and comment n = parse |
141 |
| eof |
142 |
{ raise (Error (Location.curr lexbuf)) } |
143 |
| "/*" |
144 |
{ comment (n+1) lexbuf } |
145 |
| "*/" |
146 |
{ if n > 0 then comment (n-1) lexbuf else token lexbuf } |
147 |
| newline |
148 |
{ incr_line lexbuf; |
149 |
comment n lexbuf } |
150 |
| _ { comment n lexbuf } |