Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Reusing and Building CPP Parser

Hi Amr,

> I need to add an extension for C++ language with some new
> grammar rules and keywords,
> My language syntax looks like C/C++ code, so I think about reusing 
> Eclipse CDT source code and adapting it to parse my language.
>
> [...]
>
> My question is how can I add new grammar rules to CPP parser 

Eclipse CDT has a hand-written recursive descent parser for C++ code. You would need to modify this parser to support your language extension's grammar rules.

The parser's code is contained in GNUCPPSourceParser.java (and base/helper classes referenced from that file).

> and how can I build it with these new grammar rules?

You would need to rebuild CDT as a whole (or, at least, the org.eclipse.cdt feature). Instructions for doing so can be found here [1].

> And after that, what should I do to support auto completion and
> highlighting for my language keywords?

If your language extensions involve new keywords, the parser changes would start with adding new token types for the keywords in IToken.java and Keywords.java.

Highlighting and code completion for the keywords is accomplished by additionally adding the keywords to KeywordSets.java; no further changes should be required. (Note, however, that only keywords that are at least 5 characters are long as provided as completion proposals; see bug 397296 for details).

Hope that helps,
Nate

[1] https://wiki.eclipse.org/Getting_started_with_CDT_development

Back to the top