資源簡介
Python 語言寫的 C 語言的詞法分析器。是實驗報告的一個實驗。實驗內容詳見:https://blog.csdn.net/yuxin1100/article/details/80360837
代碼片段和文件信息
import?re
#?關鍵字列表
key_ws?=?[‘char‘?‘short‘?‘int‘?‘unsigned‘?‘long‘?‘float‘?‘double‘?‘struct‘?‘union‘?‘void‘?‘enum‘?‘signed‘
??????????‘const‘?‘volatile‘?‘typedef‘?‘auto‘?‘register‘?‘static‘?‘extem‘?‘break‘?‘case‘?‘continue‘
??????????‘default‘?‘do‘?‘else‘?‘for‘?‘goto‘?‘if‘?‘return‘?‘switch‘?‘while‘?‘sizeof‘?‘txt‘?‘FILE‘
??????????‘fopen‘?‘NULL‘?‘fclose‘?‘exit‘?‘r‘?‘read‘?‘close‘?‘w‘?‘fprintf‘]
#?變量名
ID?=?r‘[a-zA-Z\_][0-9a-zA-Z\_]*‘
#?分隔符
SEPARATOR?=?r‘[:{};)(<>]#‘
#?操作碼
OP?=?[‘+‘?‘-‘?‘*‘?‘/‘?‘%‘?‘>‘?‘<‘?‘=‘?‘!‘?‘|‘?‘&‘?‘~‘?‘^‘]
#?常數
NUM?=?r‘[0-9\.][0-9]*‘
KEY_List?=?[]
ID_List?=?[]
OP_List?=?[]
SEPARATOR_list?=?[]
STRING_List?=?[]
NUM_List?=?[]
print_List?=?[]
content_List?=?[]
def?main():
????global?ws
????cflag?=?0??#?控制多行注釋
????oflag?=?0
????op_first?=?‘‘
????line?=?read_file(‘/Users/Desktop/test.c‘)
????#?行號
????line_num?=?0
????#?多行注釋起始行號
????line_comment_start?=?0
????comment_start1?=?‘//‘
????comment_start2?=?‘/*‘
??
- 上一篇:簡易電子琴設計(匯編源碼+設計報告)
- 下一篇:一種基于膚色和臉部特征的人臉檢測方法
評論
共有 條評論