-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaLexer.py
More file actions
57 lines (42 loc) · 868 Bytes
/
LambdaLexer.py
File metadata and controls
57 lines (42 loc) · 868 Bytes
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
53
54
55
56
57
import ply.lex as lex;
tokens = [
'NUM', 'LP', 'RP', 'LB','RB','OP','EQ','COMA','LAM','ALPH','FV','ID','SEMI'
]
t_LP = r'\('
t_RP = r'\)'
t_LB = r'\['
t_RB = r'\]'
t_OP = r'[+\-/*]'
t_EQ = r'='
t_COMA = r','
t_ID = r"[a-zA-Z][a-zA-Z0-9']*"
t_SEMI = r';'
def t_LAM(t):
r'[Ll][Aa][Mm][Bb][Dd][Aa]'
t.type = "LAM"
return t
def t_ALPH(t):
r'[Aa][Ll][Pp][Hh][Aa]'
t.type = "ALPH"
return t
def t_FV(t):
r'[Ff][Vv]'
t.type = "FV"
return t
def t_NUM(t):
r'-?[0-9]+'
t.value = float(t.value)
return t
# Ignored characters
t_ignore = " \r\n\t"
t_ignore_COMMENT = r'\#.*'
def t_error(t):
print(f"Illegal character '{t.value[0]}'")
raise Exception('Lexer Error')
lex.lex()
# lex.input("(lambda x (x y))[y = (u v)];")
# while True:
# tok = lex.token()
# if not tok:
# break
# print(tok)