Couple of weeks ago, I re-wrote my CC library (CodeLite), in the following manner:
- ctags is used to create a symbol table
- In addition, and to complete the parser, I wrote 4 yacc grammars to parse the following:
1. scope
2. variables
3. functions
4. expressions
the scope parser:
this parser returns the given scope name at the end of the string, for example:
the above code, given to the scope parser will return a::B
the variable parser:
this parser can locate any member variable in a given scope (needed for the Ctrl+Space functionality), it usuaully used to parse the local scope.
the function parser:
since ctags does not return the function return value, I wrote this parser. It accepts the pattern from ctags (stored in the database) and returns its return value, this in turn can be searched in the symbol table (sqlite based table) for matching tokens.
the expression parser:
the complicated parser of the four, which evaluates expressions.
for example, assuming the following code:
class MyClass {
wxString m_name;
public:
wxString getName(){return m_name;};
}
Now, lets say user type the following:
MyClass cls;
cls.getName().
the last expression, is evaluated into wxString, which now CodeLite can suggest proper completion based on the symbol table, by performing simple SQL query.
these 4 parsers combined with CTAGS & Sqlite are working very nice together.
Eran