LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   a python suggestion! (https://www.linuxquestions.org/questions/programming-9/a-python-suggestion-332431/)

kapsikum 06-11-2005 06:11 AM

a python suggestion!
 
hi guys,

I need to develop an application in python

which take some .c,.h source file as an input and

analyses the text in them and finally reports ,if there is any kind of

coding violation is there!

CAn any one sugget any site for such a parser kind of utility

or any algorithm to carry out such job.

mishunimi 06-12-2005 06:06 PM

By "coding violation" I assume you mean syntax error (or some other
problem that would cause compilation to fail).

What you need is a full C parser, which is not a trivial task, so put
it mildly.

You could use flax+bison to build such a parser and call it from
your Python code, but that is a pretty large task.

But why not let the C compiler do it for you?
You can run the C compiler from your Python code, pipe its output
back to your code and look for error messages in it. This will save
you a huge amount of time and nothing you do will be as accurate
as this.

If that is not acceptable, and if you don't mind finding only a subset
of the problems, I think I remember seeing somewhere a Python
interface to parsers built using flex+bison (or Lex+Yacc). Go Google
for it.

I will be surprised if anyone anywhere published a parser for C that
you could use as is. It does not make sense to do this outside the
scope of a full compiler or translator.

Hope that helps.

kapsikum 06-14-2005 09:38 AM

thanx mishunimi!

Actuually, i m not to that much level of comlexity!

i need to check for certain kind of coding violations which actually are not syntatical errors!.

Like any binary operatior should have one space around itself.
like a + b but not a +b or a+b

and there is a large set of such kind of violations that can occur !

so i was consdering if i make a generic kind of utility! and keep on adding the rules to check afterwards!, that wud be nice !


i hope u understand!

Crashed_Again 06-14-2005 09:40 AM

Quote:

Originally posted by kapsikum
thanx mishunimi!

Actuually, i m not to that much level of comlexity!

i need to check for certain kind of coding violations which actually are not syntatical errors!.

Like any binary operatior should have one space around itself.
like a + b but not a +b or a+b

and there is a large set of such kind of violations that can occur !

so i was consdering if i make a generic kind of utility! and keep on adding the rules to check afterwards!, that wud be nice !


i hope u understand!

Sounds like you would be using a lot of regular expressions. Fun fun fun!

kapsikum 07-01-2005 04:27 AM

yup!

FUN FUN FUN!


All times are GMT -5. The time now is 03:00 AM.