Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Include C++ blocks in Xtext
Include C++ blocks in Xtext [message #1838525] Sat, 27 February 2021 14:46 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi all,

I am writing an xtext grammar but i have the following issue:

I want to be able to also add C++ blocks as follows:

... when [x==3] then {x++}

where when, then and the brackets are Xtext keywords while x==3 and x++ is C++ code.

Anyone knows how to include these C++ blocks in Xtext?

Thanks,
John
Re: Include C++ blocks in Xtext [message #1838531 is a reply to message #1838525] Sun, 28 February 2021 03:02 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Embedding a language in Xtext is not trivial to not possible. I assume you want the variables (here: x) you are defining in the DSL to be referenced in C++ code. This can't be done easily. The easiest way to embed the C++ code is "as is", i.e. you define the block from { to } to be consumed by the lexer with a single token. This would be done with a terminal rule. You could pass the token to a custom C++ lexer/parser. This is again an advanced topic. "Xtext Custom Lexer" would be the term to google for.
Previous Topic:Concrete to abstract syntax
Next Topic:Xtext 2.25.0 released
Goto Forum:
  


Current Time: Thu Apr 18 16:35:13 GMT 2024

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

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

Back to the top