source: project/release/4/miniML/trunk/miniML.l @ 22116

Last change on this file since 22116 was 20899, checked in by Ivan Raikov, 10 years ago

miniML: removing NineML-related syntactic pollution

File size: 3.9 KB
Line 
1;; -*- Hen -*-
2;;
3;;  The lexical analyzer for mini-ML.
4;;
5;;  Based on the code and paper by Xavier Leroy (2000): A modular
6;;  module system. Journal of Functional Programming, 10, pp 269-303
7;;  doi:10.1017/S0956796800003683
8;;
9;;
10;; Copyright 2010 Ivan Raikov and the Okinawa Institute of
11;; Science and Technology.
12;;
13;; This program is free software: you can redistribute it and/or
14;; modify it under the terms of the GNU General Public License as
15;; published by the Free Software Foundation, either version 3 of the
16;; License, or (at your option) any later version.
17;;
18;; This program is distributed in the hope that it will be useful, but
19;; WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21;; General Public License for more details.
22;;
23;; A full copy of the GPL license can be found at
24;; <http://www.gnu.org/licenses/>.
25;;
26
27upper    [A-Z]
28lower    [a-z]
29hex      [0-9A-Fa-f]
30octal    [0-7]
31binary   [0-1]
32decimal  [0-9]
33
34%%
35
36;; Lexer rules
37
38"module"           (tok (MODULE))
39"val"              (tok (VALUE))
40"fun"              (tok (FUNCTION))
41"let"              (tok (LET))
42"struct"           (tok (STRUCT))
43"end"              (tok (END))
44"functor"          (tok (FUNCTOR))
45"type"             (tok (TYPE))
46"sig"              (tok (SIG))
47"in"               (tok (IN))
48"if"               (tok (IF))
49"then"             (tok (THEN))
50"else"             (tok (ELSE))
51
52
53({lower}|{upper})({lower}|{upper}|_|{decimal})*    (tok (IDENT ,(ident-create yytext)))
54`({lower}|{upper})({lower}|{upper}|_|{decimal})*   (tok (LABEL ,(string->symbol (substring yytext 1 (string-length yytext)))))
55
560(x|X)({hex})+                             (tok (NAT ,(string->number (substring yytext 2 (string-length yytext)) 16)))
570(o|O)({octal})+                           (tok (NAT ,(string->number (substring yytext 2 (string-length yytext)) 8)))
580(b|B)({binary})+                          (tok (NAT ,(string->number (substring yytext 2 (string-length yytext)) 2)))
590(d|D)({decimal})+                         (tok (NAT ,(string->number (substring yytext 2 (string-length yytext)) 10)))
60
61-?(({decimal}+(\.{decimal}+)?)|(\.{decimal}+))([eE]([-+])?{decimal}+)?   (tok (REAL ,(string->number yytext)))
62
63"(*"                       (let loop ((kont yycontinue))
64                             (let ((c (yygetc)))
65                               (cond ((eq? 'eof c) (lexer-error "unexpected end of comment"))
66                                     ((and (char=? #\* c) (char=? #\) (yygetc))) (kont))
67                                     ((and (char=? #\( c) (char=? #\* (yygetc))) (loop loop))
68                                     (else (loop kont)))))
69
70"("                                (tok (LPAREN))
71")"                                (tok (RPAREN))
72"."                                (tok (DOT))
73";"                                (tok (SEMICOLON))
74";;"                               (tok (SEMISEMI))
75"->"                               (tok (ARROW))
76"="                                (tok (EQUAL))
77","                                (tok (COMMA))
78"'"                                (tok (QUOTE))
79":"                                (tok (COLON))
80"*"                                (tok (STAR))
81"+"                                (tok (PLUS))
82"-"                                (tok (MINUS))
83"/"                                (tok (SLASH))
84"=="                               (tok (EQ))
85"<>"                               (tok (LG))
86"<"                                (tok (LESS))
87">"                                (tok (GREATER))
88"<="                               (tok (LEQ))
89">="                               (tok (GEQ))
90\10+                               (yycontinue)
91\9+                                (yycontinue)
92\13+                               (yycontinue)
93\32+                               (yycontinue)
94
95
96
97<<EOF>>                            '*eoi*
98<<ERROR>>                          (lexer-error (conc yyline ": illegal character") (yygetc))
Note: See TracBrowser for help on using the repository browser.