|
|
Re: Xtext C grammar [message #878599 is a reply to message #878579] |
Tue, 29 May 2012 11:28   |
Eclipse User |
|
|
|
Hi
IMHO C/C++ is two languages, a preprocessor language with #directives
and non-trivial recursive properties, and a real language thereafter.
Attempting to process both languages at once is an almost guarantee of
failure on corner cases.
If you preprocess, or borrow an existing preprocessor, #line directives
are conventionally implanted to allow the context of errors from the
second language to be reported in the line numbers of the first.
Regards
Ed Willink
On 29/05/2012 15:53, Henrik Lindberg wrote:
> On 2012-29-05 15:30, Oleg Bolshakov wrote:
>> Hello, is there any xtext grammar for C language?
>
> Don't think so, at least not a complete implementation. C is a
> language that is known to be difficult to parse due to macros,
> includes etc. (And by "difficult" I mean "you have to be an expert and
> be willing to add support for macros and includes to Xtext").
>
> If you want to link to elements defined in C, maybe there is some way
> to link to a model maintained by something like CDT (don't know if it
> is backed by a model though).
>
> Regards
> - henrik
|
|
|
|
|
Re: Xtext C grammar [message #878619 is a reply to message #878606] |
Tue, 29 May 2012 11:58  |
Eclipse User |
|
|
|
On 2012-29-05 17:45, Oleg Bolshakov wrote:
> I understand that Xtext can't cover preprocessing tasks. So I mean
> grammar without prepocessing keywords. I hope to find some ready
> preprocessor or make it by myself. All it's about C, not C++.
I just posted on that topic - you can use cpp to evaluate all the macros
- it also resolves all includes etc. The resulting text has directives
about contributions from files/lines etc. You can certainly parse that
and makes sense of it, but if you show the result in an editor the user
will be surprised. You will need to allow the user to edit the original
file, while keeping track of the underlying representation and map error
markers in the macro processed content to the source view.
You also have to implement resource descriptions that define how files
depend on each other in order to trigger re-parsing/validation as
included files/inclusions change.
This is one starting point: http://gcc.gnu.org/onlinedocs/cpp/
Regards
- henrik
|
|
|
Powered by
FUDForum. Page generated in 0.05535 seconds