资源简介
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 = ‘/*‘
- 上一篇:简易电子琴设计(汇编源码+设计报告)
- 下一篇:一种基于肤色和脸部特征的人脸检测方法
相关资源
- 李晓峰通信原理.zip
- 图解西门子S71200PLC入门到实践(清晰
- AI拓客商家联盟V2.1.3前端+后端.rar
- echarts大数据领导仓demo.rar
- [C51单片机开发工具Keil.UV4].Keil.C51.V9
- Deep_Learning_2016.pdf
- zw_Classification1.zip
- Griffiths-IntroductiontoElectrodynamics4thEdit
- ParaViewTutorial.pdf
- xyisv_10236804.zip
- 计算机图形学第4版高清电子书.pdf
- 《多粒度知识获取与不确定性度量》
- 华成英模电课件.zip
- 70d0cd041f738f12db575d3b46e97582.pdf
- OfficeTabEnterprise13.1.zip
- wxu998.rar
- PowerDesigner16.5汉化文件.rar
- jsgis.zip
- PinyinIME(关键代码写了注释).zip
- 锁相环设计、仿真与应用第5版中.pd
- novelOnLine.zip
- SingleSensorImagingMethodsandApplicationsforDi
- ControlSystemsEngineering7th(NormanS.Nise)
- ModernControlSystems13th(RichardC.Dorf).ra
- VectorMagic_1.15pojie.rar
- complexityoflattice__problems.pdf
- xnby_883749.zip
- TOGAF培训讲义-周金根.pdf
- OS12.2驱动,手机虚拟定位软件,Loca
- 大话系列-大话数据结构(pdf高清版)
评论
共有 条评论