Reputation: 41
I want to do a static code analysis on a bunch of scripts written in a not very common programming language (C like syntax). Frequent problems are:
The language interpreter/compiler itself does not provide aid for these problems.
Is there any lint like tool that is flexible enough to adapt it easily to new programming languages? Or does someone know another good starting point? (Lex/Yacc ???)
Thanks in advance
Upvotes: 4
Views: 293
Reputation: 569
After spending a few hours playing with PHP_CodeSniffer and some others suggested in another thread here ... I have concluded that PHPlint is the way to go for me. If for no other reason it can correctly detect code that calls a function with the wrong number of arguments.
Upvotes: 0
Reputation: 17981
Consider the Vera Community Edition or Google's cpplint providing code you can customise.
Upvotes: 0
Reputation: 80355
The commercially available DMS Software Reengineering Toolkit allows to write such consistency checks and is flexible enough to be adapted to many languages.
Upvotes: 2
Reputation: 2612
I doubt you're going to find an all-purpose tool.
Much of static analysis depends on far more than lexical and grammatical compliance.
A good static analyzer is going to have extra-contextual knowledge of the language and its implementation. It may also include a simulator that keeps track of state and multiple execution paths. Additionally, it may be aware of patterns and practices, as well as certain libraries and calls.
For instance, in C, this code if ( x = 3 ) { /*Do something*/ }
is perfectly legal, although the programmer may have intended ==
. Or, one might do printf("%s", longVal);
, and while arbitrary values can be shoved on the stack, that specific call may have other expectations based on initial values passed to it.
Bottom line, there'd be so much for a generic lint application to know, not to mention that languages and libraries are a moving target, that if such a beast did exist it'd be either way too complicated or way too underpowered for practical application than a cheaper tool that did a language-specific job better.
Upvotes: 2