|
April 2002
Regular Expressions: Syntax Checking the Scripting Way
by Cameron Laird and Kathryn Soraiz
The static syntax validation of pychecker and similar utilities can improve the quality of your programs.
That's not the only way, of course. There are all sorts of tools and techniques to help you manage the correctness of the code you write. Our last "Regular Expressions" column, for example, presented Erlang as a language designed to make it easier to write correct programs.
Static syntax analysis, though, is a particularly low-cost way to improve your programs. It fits the "scripting mentality" this column regularly advertises in that you can try out syntax checkers for yourself with little effort and make your own quick judgment about whether they fit your needs.
What "Syntax Analysis" Means
"Static syntax analysis" is what lint does for C programmers, or validators for HTML coders. These programs report on constructions that generally can be compiled or browsed respectively, but are still hazardous. Typical lint warnings include implicit casts and suspicious assignments: did programmers really intend:
if (counter = limit) return;
or was it:
if (counter == limit) return;
they wanted? Both of these are syntactically valid. Experience has shown, however, that the former often appears as a misspelling of the latter. Syntax analyzers draw attention to source that has this sort of potential for mistake.
Comparison with "spelling checkers" is apt, in fact. The "feel" of a syntax analyzer is much like that of a spelling checker. Different people make different uses for each; some engineers run lint every time they compile, others never, and most seem to do it only for "final drafts."
|