Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Include C++ blocks in Xtext
Include C++ blocks in Xtext [message #1838525] Sat, 27 February 2021 09:46 Go to next message
Eclipse UserFriend
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] Sat, 27 February 2021 22:02 Go to previous message
Eclipse UserFriend
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: Mon Jul 07 16:35:43 EDT 2025

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

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

Back to the top