This repository was archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexer.x
More file actions
52 lines (47 loc) · 2.01 KB
/
Copy pathLexer.x
File metadata and controls
52 lines (47 loc) · 2.01 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
52
{
module Lexer where
}
%wrapper "basic"
$white = [\ \t\n\r\b\v\f\a\\\'\"]
$alpha = [_A-Za-z]
$digit = [0-9]
tokens :-
$white+ ;
"(" { \_ -> LPAREN }
")" { \_ -> RPAREN }
"+" { \_ -> PLUS }
"-" { \_ -> MINUS }
"*" { \_ -> MULT }
"<=" { \_ -> LESS_EQUAL }
"=" { \_ -> EQUAL }
"skip" { \_ -> SKIP }
":=" { \_ -> ASSIGN }
";" { \_ -> SEMICOLON }
"not" { \_ -> NOT }
"and" { \_ -> AND }
"true" { \_ -> TRUE }
"false" { \_ -> FALSE }
"if" { \_ -> IF }
"then" { \_ -> THEN }
"else" { \_ -> ELSE }
"while" { \_ -> WHILE }
"do" { \_ -> DO }
"or" { \_ -> OR }
$alpha($alpha|$digit)* { \s -> ID s }
$digit+ { \s -> NUM (read s) }
{
data Token = ID String
| NUM Int
| LESS_EQUAL
| EQUAL
| LPAREN | RPAREN
| ASSIGN | SKIP
| IF | THEN | ELSE
| WHILE | DO
| OR
| PLUS | MINUS | MULT
| SEMICOLON
| NOT | AND
| TRUE | FALSE
deriving (Eq, Show)
}