选择正确的解析器来解析C头 [英] Choosing the right parser for parsing C headers

查看:64
本文介绍了选择正确的解析器来解析C头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我需要解析C的一个子集(头文件),并为其中列出的函数生成一些单元

测试。因此我需要解析代码,

然后用错误的参数重写函数调用。我称之为晃动

破树 :)

我选择在Python 2.4中制作我的UT生成器。但是,我现在

在为工作选择正确的解析器时遇到问题。我在b
中选择不合适的,过时的,

alpha,或者太大的任务......


到目前为止,我已经识别了9个(!)潜在候选人(大部分来自

http://www.python.org/moin/LanguageParsing 页面):


- Plex:

据我所知,只有一个词法分析器。有点RE ++,没有语法

处理

- ply:

Lex / Yacc for python!解决野兽!语法处理看起来好像是b $ b复杂..

- Pyggy:

Lex / Yacc-styled也是如此。最近,但0.4版本会好吗

足够吗?

- PyLR:

快速解析器,核心功能在C ... hasn自''97移动'

- Pyparsing:

快速简单的解析器...但我认为它不仅仅是词汇

分析

- spark:

这里有一些木头。现在建造你的房子。

- yapps2:

yapps2 +(我毫不犹豫地称之为yapps3):

http://www.python.org/sigs/parser-si ... -standard.html

选择是最新的吗?

但它会解析C吗?

- TPG(玩具分析器生成器):

看起来很酷
- ANTLR(1月28日的最新版本生成Python代码):

看起来很强大有很多支持,但我不想要使用外部Java工具来获得
。此外,它能让我轻松控制每个阶段发生的事情吗?或者它只是让我成为编译器吗?


我省略了这些: shlex,kwparsing(网页?),PyBison,Trap

(网页?),DParser和SimpleParse(我不想要额外的

依赖)。 />

我希望能有一个快速简单的选择,但是被抓到了焦油坑里。
太多的信息。解析是一个庞大而复杂的领域。作为一个

增加了障碍,我是解析者黑暗雷区的新手......我已经有了一些Lex / Yacc的经验,并且有一些经验解析器的知识

理论,通过关于编译器的课程。因此我习惯了EBNF风格的

语法。

我很失望地看到Parser-SIG已经消失了。

你有没有关于哪个解析器最适合该任务的任何想法?


John

Hi,

I need to parse a subset of C (a header file), and generate some unit
tests for the functions listed in it. I thus need to parse the code,
then rewrite function calls with wrong parameters. What I call "shaking
the broken tree" :)
I chose to make my UT-generator in Python 2.4. However, I am now
encountering problems in choosing the right parser for the job. I
struggle in choosing between the inappropriate, the out-of-date, the
alpha, or the too-big-for-the task...

So far I''ve indentified 9(!) potential candidates (Mostly taken from
the http://www.python.org/moin/LanguageParsing page) :

- Plex:
Only a lexical analyser as far as I understand. Kinda RE++, no syntax
processing
- ply:
Lex / Yacc for python! Tackle the Beast! Syntax processing looks
complex..
- Pyggy:
Lex / Yacc -styled too. More recent, but will a 0.4 version be good
enough?
- PyLR:
fast parser with core functions in C... hasn''t moved since ''97
- Pyparsing:
quick and easy parser... but I don''t think it does more than lexical
analysis
- spark:
Here''s some wood. Now build your house.
- yapps2 :
yapps2+ (I hesitate to call it yapps3):
chosen by http://www.python.org/sigs/parser-si...-standard.html.
Is the choice up-to-date?
But will it do for parsing C?
- TPG (Toy Parser Generator):
looks cool
- ANTLR (latest version from Jan 28 produces Python code) :
Seems powerful and has a lot of support, but I don''t want to have to
use an exterior Java tool. Furthermore, does it let me control what
happens at each stage easily, or does it just make me a compiler?

I''ve omitted these: shlex, kwparsing (webpage?), PyBison, Trap
(webpage?), DParser, and SimpleParse (I don''t want the extra
dependancy).

I was hoping for a quick and easy choice, but got caught in the tar pit
of Too Much Information. Parsing is a large and complex field. As an
added handicap, I''m new to the dark minefield of parsers... I''ve had
some experience with Lex/Yacc, and have some knowledge of parser
theory, through a course on compilators. I am thus used to EBNF-style
grammar.
I was disappointed to see that Parser-SIG has died out.
Would you have any ideas on which parser is best suited for the task?

John

推荐答案

Jean de Largentaye < JL ********* @ gmail.com>写道:
"Jean de Largentaye" <jl*********@gmail.com> writes:


我需要解析C的一个子集(一个头文件),并为函数生成一些单元
测试列在其中。因此我需要解析代码,然后用错误的参数重写函数调用。我称之为震动破碎的树 :)
Hi,

I need to parse a subset of C (a header file), and generate some unit
tests for the functions listed in it. I thus need to parse the code,
then rewrite function calls with wrong parameters. What I call "shaking
the broken tree" :)




IMO,对于解析真实世界的C头文件,没有什么可以击败gccxml。


Thomas



IMO, for parsing ''real-world'' C header files, nothing can beat gccxml.

Thomas


Jean de Largentaye写道:
Jean de Largentaye wrote:
我需要解析C的一个子集(一个头文件),然后生成一些单元
测试其中列出的功能。因此我需要解析代码,然后用错误的参数重写函数调用。我称之为震动破碎的树 :)

我选择在Python 2.4中制作我的UT生成器。但是,我现在在为工作选择正确的解析器时遇到了问题。我在选择不合适的,过时的,
alpha或太大的任务之间挣扎......
I need to parse a subset of C (a header file), and generate some unit
tests for the functions listed in it. I thus need to parse the code,
then rewrite function calls with wrong parameters. What I call "shaking
the broken tree" :)

I chose to make my UT-generator in Python 2.4. However, I am now
encountering problems in choosing the right parser for the job. I
struggle in choosing between the inappropriate, the out-of-date, the
alpha, or the too-big-for-the task...



为什么不使用真正的编译器?

http://www.boost.org/libs/python/pyste/
http://www.gccxml.org/HTML/Index.html


< / F>



why not use a real compiler?

http://www.boost.org/libs/python/pyste/
http://www.gccxml.org/HTML/Index.html

</F>


Hello Jean,
Hello Jean,
- ply:
Lex / Yacc for python!解决野兽!语法处理外观
- ply:
Lex / Yacc for python! Tackle the Beast! Syntax processing looks



mini_c是使用ply编写的C编译器。您可以按原样使用它。
http:// people.cs.uchicago.edu/~varmaa/mini_c/


HTH。

-

- -------------------------------------------------- ---------------------

Miki Tebeka< mi ********* @ zoran.com>
http://tebeka.bizhat.com

儿童和成人之间的区别仅在于玩具的价格


mini_c is a C compiler written using ply. You can just use it as is.
http://people.cs.uchicago.edu/~varmaa/mini_c/

HTH.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zoran.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys


这篇关于选择正确的解析器来解析C头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆