-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.py
More file actions
38 lines (34 loc) · 698 Bytes
/
lexer.py
File metadata and controls
38 lines (34 loc) · 698 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
import ply.lex as lex
tokens = (
'SPLITTER', 'ID', 'INT',
'LPAREN', 'RPAREN', 'ARROW', 'COMMA', 'HOLE', 'SEMI',
'LT', 'LE', 'GT', 'GE', 'AND', 'OR', 'NOT', 'EQ', 'NEQ',
'PLUS', 'MINUS', 'TIMES', 'DIV'
)
t_SPLITTER = r'\|'
t_ID = r'[A-Za-z_][A-Za-z0-9_]*'
t_INT = r'\d+'
t_LPAREN = r'\('
t_RPAREN = r'\)'
t_ARROW = r'->'
t_COMMA = r','
t_HOLE = r'\?\?'
t_SEMI = r';'
t_LT = r'<'
t_LE = r'<='
t_GT = r'>'
t_GE = r'>='
t_AND = r'&&'
t_OR = r'\|\|'
t_NOT = r'!'
t_EQ = r'=='
t_NEQ = r'!='
t_PLUS = r'\+'
t_MINUS = r'-'
t_TIMES = r'\*'
t_DIV = r'/'
t_ignore = ' \t\r\n'
def t_error(t):
print("Illegal character %s" % repr(t.value[0]))
t.lexer.skip(1)
lexer = lex.lex(debug=0)