diff options
author | David Beazley <dave@dabeaz.com> | 2022-10-27 13:44:12 -0500 |
---|---|---|
committer | David Beazley <dave@dabeaz.com> | 2022-10-27 13:44:12 -0500 |
commit | af80858e888c5f36979da88fcb1080de7b848967 (patch) | |
tree | 2f2fb95414baee83e489eac1b936602599ea9eba /test/lex_object.py | |
parent | 818ab0684e33f5f513fc839673ff56ea330b6380 (diff) | |
download | ply-af80858e888c5f36979da88fcb1080de7b848967.tar.gz |
Reorganization. Added makefile
Diffstat (limited to 'test/lex_object.py')
-rw-r--r-- | test/lex_object.py | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/test/lex_object.py b/test/lex_object.py deleted file mode 100644 index 7e9f389..0000000 --- a/test/lex_object.py +++ /dev/null @@ -1,55 +0,0 @@ -# ----------------------------------------------------------------------------- -# lex_object.py -# ----------------------------------------------------------------------------- -import sys - -if ".." not in sys.path: sys.path.insert(0,"..") -import ply.lex as lex - -class CalcLexer: - tokens = ( - 'NAME','NUMBER', - 'PLUS','MINUS','TIMES','DIVIDE','EQUALS', - 'LPAREN','RPAREN', - ) - - # Tokens - - t_PLUS = r'\+' - t_MINUS = r'-' - t_TIMES = r'\*' - t_DIVIDE = r'/' - t_EQUALS = r'=' - t_LPAREN = r'\(' - t_RPAREN = r'\)' - t_NAME = r'[a-zA-Z_][a-zA-Z0-9_]*' - - def t_NUMBER(self,t): - r'\d+' - try: - t.value = int(t.value) - except ValueError: - print("Integer value too large %s" % t.value) - t.value = 0 - return t - - t_ignore = " \t" - - def t_newline(self,t): - r'\n+' - t.lineno += t.value.count("\n") - - def t_error(self,t): - print("Illegal character '%s'" % t.value[0]) - t.lexer.skip(1) - - -calc = CalcLexer() - -# Build the lexer -lex.lex(object=calc) -lex.runmain(data="3+4") - - - - |