Consequence of a syntax error

spatch performs syntax error recovery using various heuristics.

If a syntax error occurs while processing a function definition no matching is attempted on the contents of that definition.

The following:

spatch -parse_c foo.c

provides information about the parsing of the C file, foo.c. Lines annotated with BAD contain parse errors. A summary is provided at the end of the reasons for the most common parsing problems. Often parsing problems are due to macro uses. The summary of parsing problems can be useful in determining how to update standard.h according to the macros used in the given C file.

Implicit declarations

If an undeclared variable is encountered various heuristics are used to provide the appropriate declaration. If the heuristic used is incorrect a syntax error may occur, for instance in:

void f_1(void)
{
 void *ptr = (tree)0;  // tree not declared and assumed to be a typedef
}
 void f_2(void)
 {
  int x = tree;  // tree treated as a typedef, resulting in a syntax error
 }
 

C variants

Coccinelle primarily targets ANSI C, and supports some GCC extensions. It has only partial support for K&R C. K&R function declarations are only recognized if the parameter declarations are indented. Furthermore, the parameter names are subsequently considered to be type names, due to confusion with function prototypes, in which a name by itself is indeed the name of a type.

 
c_syntax_errors.txt · Last modified: 2010/05/22 07:16 by jll
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki