gpt4 book ai didi

python - 在 Python 中拆分 C 文件?

转载 作者:太空宇宙 更新时间:2023-11-04 06:41:48 24 4
gpt4 key购买 nike

我正在写关于 C 文件的论文。我需要拆分一个 C header 来操作组成它的单字。我必须按所有这些字符拆分行:

  1. 空格和制表符
  2. 新行 ;\n
  3. 单行注释和多行注释///* */
  4. 指针*
  5. 数组括号[][dimension]

例如,如果我有以下几行:

/* This is a
multiline comment.
*/

typedef int rocket;

// This is a single line comment.
typedef double* pi[10];

split 函数应该像这样返回一个列表(或其他所有内容):

["/*","This","is","a","\n","multiline","comment.","\n","*/","\n","\n","typedef","int","rocket",";","\n","\n","//","This","is","a","single","line","comment.","\n","typedef","double","*","pi","[10]",";"]

这应该用 Python 完成!

我试过了,但我对正则表达式的了解很少,这表明我找到了一个糟糕的解决方案!! :)

谢谢,达里奥。

最佳答案

也许你应该考虑玩弄pycparser . (不知道你到底在做什么,我真的不能说更多,抱歉)

关于python - 在 Python 中拆分 C 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6974246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com