Skip to content

Commit 5bc3d0e

Browse files
Merge pull request seeditsolution#289 from vedang6575/patch-1
class BasicLexer
2 parents 2f0c793 + 6112d9b commit 5bc3d0e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
tokens = { NAME, NUMBER, STRING }
2+
ignore = '\t '
3+
literals = { '=', '+', '-', '/',
4+
'*', '(', ')', ',', ';'}
5+
6+
7+
# Define tokens as regular expressions
8+
# (stored as raw strings)
9+
NAME = r'[a-zA-Z_][a-zA-Z0-9_]*'
10+
STRING = r'\".*?\"'
11+
12+
# Number token
13+
@_(r'\d+')
14+
def NUMBER(self, t):
15+
16+
# convert it into a python integer
17+
t.value = int(t.value) return t
18+
19+
# Comment token
20+
@_(r'//.*')
21+
def COMMENT(self, t):
22+
pass
23+
24+
# Newline token(used only for showing
25+
# errors in new line)
26+
@_(r'\n+')
27+
def newline(self, t):
28+
self.lineno = t.value.count('\n')

0 commit comments

Comments
 (0)