Regarding finding constants, our SD Source Code Search Engine (SCSE) can do this off the shelf. SCSE provides GUI interface for search across large sets of mixed programming langauge files, using a query language that understands the lexical syntax of each language accurately.
A typical query:
'for' ... I=index* '=' N<10
will find for keywords near an Identifier whose name must start with the sequence index followed immediately by an = operator followed by a Number whose value is less than 10. Because SCSE understands the language structure, it isn't bothered by whitespace or formatting constraints. It will also match hexadecimal values for N; it understands the different format for literals and offers queries in terms of the actual value of the number, rather than as a string.
Given such a query, the GUI will find all matches across all your files, and show a set of hits; a click on a hit takes to you the source code with the hit line highlighted.
To find all constants that aren't zero, you write the following very simple query:
N>0
What you really want are all constants that aren't defined in some kind of constant definition. So you want to remove any constant-definitions from the hit list, which
is accomplished by using the "query subtract" operator:
N>0 - 'const' 'int' I '=' N
This finds nonzero constants, and removes any that are also matched by the const declaration.
Your other dreams require a much more sophisticated engine. In essence, you want to analyze C++ code (your rule of three) or extend the C++ language with some new features, and then implement those features using standard C++ capabilities. You can accomplish this using a program transformation system
that can manipulate C++.
Our DMS Software Reengineering Tookit can do this. It has a full C++ front end that parses C++ to internal compiler data structures and builds complete symbol tables (and can regenerate C++ source code with all details from its internal structures). Using that front end and DMS's built in pattern matching capabilities, you could implement your rule-of-three check.
For language extensions, you can modify the DMS C++ front end by modifying its grammar to include the extra constructs you think ideal. Then, you can write program transformations that look for such constructs, and transform them into the desired code. (This idea was called intentional programming by Charles Simyoni of MS fame, but is just a special case of program transformation.)
DMS has been used to carry out massive automated transformations on real C++ applications. It could do your task fairly easily from a technical point of view.
However, understanding the definition of C++ and how everything fits together, and how DMS supports transformations, requires considerable compiler-style sophistication. What you suggest to do isn't an afternoon or a week's worth of work. It would take a significant investment in education and effort.
But a lot less than trying to do with starting with just YACC.