PLY

Ahmad Yoosofan

Compiler course

University of Kashan

https://yoosofan.github.io/course/compiler.html

Lexical Analyser

1 tokens = ('NUMBER','PLUS')
2 t_PLUS    = r'\+'
3 def t_NUMBER(t):
4   r'[0-9]+'
5   t.value = int(t.value)
6   return t
7 t_ignore = " \t,"
8 import ply.lex as lex
9 lex.lex()
10 lex.input("5434+2882 + ,,,,,  45")
11 while True:
12   tok = lex.token()
13   if not tok: 
14     break
15   print(tok)

END

1