欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

lex_state_try.py

M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作为模拟平台
PY
字号:
# lex_state2.py## Declaration of a state for which no rules are definedimport syssys.path.insert(0,"..")import ply.lex as lextokens = [    "PLUS",    "MINUS",    "NUMBER",    ]comment = 1states = (('comment', 'exclusive'),)t_PLUS = r'\+'t_MINUS = r'-'t_NUMBER = r'\d+'t_ignore = " \t"# Commentsdef t_comment(t):    r'/\*'    t.lexer.begin('comment')    print "Entering comment state"def t_comment_body_part(t):    r'(.|\n)*\*/'    print "comment body", t    t.lexer.begin('INITIAL')def t_error(t):    passt_comment_error = t_errort_comment_ignore = t_ignoreimport syslex.lex()data = "3 + 4 /* This is a comment */ + 10"lex.runmain(data=data)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -