-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.rkt
More file actions
51 lines (47 loc) · 1.51 KB
/
lexer.rkt
File metadata and controls
51 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#lang racket
(require parser-tools/lex
(prefix-in : parser-tools/lex-sre)
parser-tools/yacc)
(define full-lexer (lexer
(whitespace (full-lexer input-port))
((:or (:: (:+ (char-range #\0 #\9))) (:: (:: (:+ (char-range #\0 #\9)) #\. (:+ (char-range #\0 #\9))))) (token-NUM (string->number lexeme)))
((eof) (token-EOF))
(";" (token-SEMICOLON))
("pass" (token-PASS))
("break" (token-BREAK))
("continue" (token-CONTINUE))
("=" (token-ASSIGNMENT))
("return" (token-RETURN))
("global" (token-GLOBAL))
("def" (token-DEF))
("(" (token-OP))
(")" (token-CP))
(":" (token-COLON))
("," (token-COMMA))
("if" (token-IF))
("else" (token-ELSE))
("for" (token-FOR))
("in" (token-IN))
("or" (token-OR))
("and" (token-AND))
("not" (token-NOT))
("==" (token-EQUALS))
("<" (token-LT))
("<=" (token-LET))
(">" (token-GT))
(">=" (token-GET))
("+" (token-PLUS))
("-" (token-MINUS))
("*" (token-TIMES))
("/" (token-DIVIDES))
("**" (token-POWER))
("[" (token-OB))
("]" (token-CB))
("True" (token-TRUE))
("False" (token-FALSE))
("None" (token-NONE))
((:+ (:or (char-range #\0 #\9) (char-range #\a #\z) (char-range #\A #\Z) #\_)) (token-ID lexeme))))
(define-tokens a (NUM ID))
(define-empty-tokens b (EOF SEMICOLON PASS BREAK CONTINUE ASSIGNMENT RETURN GLOBAL DEF OP CP COLON COMMA TRUE FALSE
IF ELSE FOR IN OR AND NOT EQUALS LT LET GT GET PLUS MINUS TIMES DIVIDES POWER OB CB NONE))
(provide (all-defined-out))