;; -*- Hen -*- ;; ;; A lexical analyzer for I-expressions ;; ;; ;; Copyright 2010 Ivan Raikov and the Okinawa Institute of Science ;; and Technology. ;; ;; This program is free software: you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; A full copy of the GPL license can be found at ;; . ;; char_qword ([\33-\38]|[\40-\55295]|[\57344-\65533]|[\65536-\1114109]) char_space (\32) char_tab (\9) break (\13|\10)+ word (([\33\35-\38]|[\42\43\45-\47\58-\55295]|[\57344-\65533]|[\65536-\1114109])([\33-\38]|[\42\43\45-\55295]|[\57344-\65533]|[\65536-\1114109])*) hex [0-9A-Fa-f] octal [0-7] binary [0-1] decimal [0-9] %% ;; Lexer rules \' (let loop ([cs '()]) (let ([c (yygetc)]) (cond [(eq? 'eof c) (lexer-error "unexpected end of string constant")] [(char=? c #\\) (let ((n (yygetc))) (loop (cons n cs)))] [(char=? c #\') (tok (WORD ,(reverse-list->string cs))) ] [else (loop (cons c cs))]))) \" (let loop ([cs '()]) (let ([c (yygetc)]) (cond [(eq? 'eof c) (lexer-error "unexpected end of string constant")] [(char=? c #\\) (let ((n (yygetc))) (loop (cons n cs)))] [(char=? c #\") (tok (WORD ,(reverse-list->string cs))) ] [else (loop (cons c cs))]))) {break} (tok (BREAK)) {break}"--"{break}+ (tok (END)) {char_space}+ (tok (SPACE ,(string-length yytext))) {char_tab}+ (tok (SPACE ,(fx* 7 (string-length yytext)))) {word} (tok (WORD ,yytext)) 0(x|X)({hex})+ (tok (NAT ,(string->number (substring yytext 2 (string-length yytext)) 16))) 0(o|O)({octal})+ (tok (NAT ,(string->number (substring yytext 2 (string-length yytext)) 8))) 0(b|B)({binary})+ (tok (NAT ,(string->number (substring yytext 2 (string-length yytext)) 2))) 0(d|D)({decimal})+ (tok (NAT ,(string->number (substring yytext 2 (string-length yytext)) 10))) ({decimal})+ (tok (NAT ,(string->number yytext 10))) -?(({decimal}+(\.{decimal}+)?)|(\.{decimal}+))([eE]([-+])?{decimal}+)? (tok (REAL ,(string->number yytext))) {decimal}+(\.{decimal}+)({word}?) (tok (WORD ,yytext)) "#"({word}|({char_space}+))* (yycontinue) "(" (tok (LPAREN)) ")" (tok (RPAREN)) "," (tok (COMMA)) <> '*eoi* <> (lexer-error (conc yyline ": illegal character") (yygetc))