You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
951 B
Racket
23 lines
951 B
Racket
9 years ago
|
#lang br
|
||
|
(require parser-tools/lex parser-tools/lex-sre
|
||
9 years ago
|
brag/support
|
||
9 years ago
|
racket/string)
|
||
|
|
||
|
(provide tokenize)
|
||
|
(define (tokenize input-port)
|
||
|
(define (next-token)
|
||
|
(define get-token
|
||
9 years ago
|
(lexer-src-pos
|
||
9 years ago
|
[(eof) eof]
|
||
9 years ago
|
[(union
|
||
|
(seq "/*" (complement (seq any-string "*/" any-string)) "*/")
|
||
|
(seq "//" (repetition 1 +inf.0 (char-complement #\newline)) #\newline))
|
||
9 years ago
|
(token 'COMMENT lexeme #:skip? #t)]
|
||
|
[(union #\tab #\space #\newline) (get-token input-port)]
|
||
9 years ago
|
[(union "load" "output-list" "output-file" "compare-to" "set" "eval" "output" (char-set ",;")) lexeme]
|
||
|
[(seq "%" (repetition 1 +inf.0 (union alphabetic numeric (char-set ".")))) (token 'FORMAT-STRING lexeme)]
|
||
9 years ago
|
[(repetition 1 +inf.0 numeric) (token 'VAL (string->number lexeme))]
|
||
9 years ago
|
[(repetition 1 +inf.0 (union alphabetic numeric (char-set "-."))) (token 'ID lexeme)]))
|
||
9 years ago
|
(get-token input-port))
|
||
|
next-token)
|