Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext C grammar
Xtext C grammar [message #878524] Tue, 29 May 2012 13:30 Go to next message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
Hello, is there any xtext grammar for C language?
Re: Xtext C grammar [message #878579 is a reply to message #878524] Tue, 29 May 2012 14:53 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
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 #878599 is a reply to message #878579] Tue, 29 May 2012 15:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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 #878606 is a reply to message #878524] Tue, 29 May 2012 15:44 Go to previous messageGo to next message
Oleg Bolshakov is currently offline Oleg BolshakovFriend
Messages: 36
Registered: August 2010
Member
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++.
Re: Xtext C grammar [message #878615 is a reply to message #878579] Tue, 29 May 2012 15:52 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-29-05 16: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

BTW, an implementation suitable to act as a compiler is easier to
achieve than one that supports editing - simply apply the c preprocessor
(cpp) to the input stream before giving it to the lexer/parser.

The result is probably not what you want to see in an editor but it can
be parsed.

Regards
- henrik
Re: Xtext C grammar [message #878619 is a reply to message #878606] Tue, 29 May 2012 15:58 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
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
Previous Topic:Manually Maintained Metamodel
Next Topic:Special signs in parser pules
Goto Forum:
  


Current Time: Fri Apr 19 11:08:30 GMT 2024

Powered by FUDForum. Page generated in 0.02152 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top