Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Antlr4 to xtext(Convert antlr4 grammar to xtext grammar.)
icon7.gif  Antlr4 to xtext [message #1755183] Tue, 28 February 2017 17:52 Go to next message
Vihanga Liyanage is currently offline Vihanga LiyanageFriend
Messages: 3
Registered: February 2017
Junior Member
Hi all,
My objective is to create an eclipse plugin for a DSL which maintains an antlr4 grammar file. I know that xtext is the easiest way to create such language plugin, but the owners of the DSL doesn't want to maintain a separate xtext grammar file as well for that language.
Is there a way to get the relevant xtext grammar from antlr4 grammar?
If not, what is the best approach I should use?

  • Write some kind of a converter between two grammars?
  • Write a plugin from scratch without using xtext at all?
  • Something else?


Thanks in advance...
Re: Antlr4 to xtext [message #1755200 is a reply to message #1755183] Wed, 01 March 2017 04:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
Since Xtext uses antlr 3 and a subset only this might be not as easy as you think.
I'd write an external tool


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Antlr4 to xtext [message #1755202 is a reply to message #1755200] Wed, 01 March 2017 04:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
Ps what about deriving the antlr grammar from the Xtext grammar (there is already a flag in the workflow that gives you a pure antlr v3 grammar

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 01 March 2017 05:15]

Report message to a moderator

Re: Antlr4 to xtext [message #1755203 is a reply to message #1755183] Wed, 01 March 2017 07:01 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 614
Registered: July 2009
Location: Dortmund, Germany
Senior Member

hint for the flag:
		language = StandardLanguage {
...
			parserGenerator = {
				debugGrammar = true
			}
...
		}



But I also think this is not what you want. What you actually want is not really possible with Xtext.

Writing such a plugin your own is the right way to do, but this is really huge effort. That's why it isoften a good idea to use Xtext, this is already done for you by the framework.

Good luck.
Re: Antlr4 to xtext [message #1755214 is a reply to message #1755183] Wed, 01 March 2017 08:43 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

If you want to write an Xtext2Antlr transformation, you might find my initial work on an Xtext2LPG transformation helpful.

'initial'. It was developed to use conventional LALR analysis to detect hidden shift-reduce hazards in the Xtext LL-ish grammars for OCL. I think that the grammar conversion works, The action code to make the generated LPG execute (incrementally) is one of many jobs on my stack.

Regards

Ed Willink
Re: Antlr4 to xtext [message #1755216 is a reply to message #1755214] Wed, 01 March 2017 08:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

Oops. Forgot the reference:

GIT\org.eclipse.ocl\examples\org.eclipse.ocl.examples.xtext2lpg in http://git.eclipse.org/c/ocl/org.eclipse.ocl.git

Regards

Ed Willink
Re: Antlr4 to xtext [message #1755408 is a reply to message #1755216] Fri, 03 March 2017 06:10 Go to previous messageGo to next message
Vihanga Liyanage is currently offline Vihanga LiyanageFriend
Messages: 3
Registered: February 2017
Junior Member
Hi all,

Thank you for you replies. As I understand it, it's better to write a separate plugin from scratch. Well in that case, do any one of you know any easy methods you found to do that. I haven't developed a plugin before, so any help would be much appreciated.
Thanks again.

Vihanga.
Re: Antlr4 to xtext [message #1755549 is a reply to message #1755183] Sun, 05 March 2017 15:29 Go to previous messageGo to next message
Vihanga Liyanage is currently offline Vihanga LiyanageFriend
Messages: 3
Registered: February 2017
Junior Member
Hi all,

Thank you for you replies. As I understand it, it's better to write a separate plugin from scratch. Well in that case, do any one of you know any easy methods you found to do that. I haven't developed a plugin before, so any help would be much appreciated.
Thanks again.

Vihanga.
Re: Antlr4 to xtext [message #1767964 is a reply to message #1755183] Wed, 12 July 2017 12:38 Go to previous messageGo to next message
Hong-Thai Nguyen is currently offline Hong-Thai NguyenFriend
Messages: 6
Registered: April 2016
Junior Member
Any new evolution about switching to ANTLR 4 ? New generation ANTLR 4 is available for 5, 6 years, many systems use ANTLR4, and migrated already from ANTLR 3.
Re: Antlr4 to xtext [message #1767965 is a reply to message #1767964] Wed, 12 July 2017 12:43 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 614
Registered: July 2009
Location: Dortmund, Germany
Senior Member

We have discussed this topic at Xtext Summit 2017 and it was decided that we do not take action here. One of the reasons is that Xtext has high requirements on performance which ANTLR 4 cannot guarantee, another is development effort and further that there is no actual benefit for users besides left recursion, which can be avoided with left-factoring.
Re: Antlr4 to xtext [message #1783618 is a reply to message #1767965] Wed, 14 March 2018 15:44 Go to previous messageGo to next message
Christopher Barber is currently offline Christopher BarberFriend
Messages: 1
Registered: March 2018
Junior Member
There are a lot more benefits to ANTLR4 than simply left recursion. Please read through https://github.com/antlr/antlr4/releases and tell me that there are no other significant differences. The fact is that most people working with ANTLR will be using ANTLR 4. I know that for my DSL project, it is simply not worth the effort of back-porting my grammar to work with XText, if it is even possible.
Re: Antlr4 to xtext [message #1783622 is a reply to message #1783618] Wed, 14 March 2018 16:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
Hi, how much work or money would you spend to do this.

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Antlr4 to xtext [message #1783643 is a reply to message #1783622] Wed, 14 March 2018 20:19 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 614
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Or in other words: The relation between effort and benefit is not to argue the invest. We have decided not to take action here. The effort here is easily underestimated.
If your need is urgent and you are willing to invest here, we can get into talk.
Re: Antlr4 to xtext [message #1790140 is a reply to message #1783643] Tue, 05 June 2018 20:37 Go to previous messageGo to next message
Michael Hoffer is currently offline Michael HofferFriend
Messages: 9
Registered: August 2014
Junior Member

As part of our research we have developed a ANTLR4 based "parser/unparser" + modeling technology. It doesn't give you an eclipse editor. But it is well suited for transforming text&code. We have working ANTLR4 grammars for Java8, JSON, Mini-C, Mini-Java and many inhouse DSLs. We use it for building JavaFX-based visual programming editors for our VRL-Studio IDE.

Anyone interested, let me know.


Re: Antlr4 to xtext [message #1790302 is a reply to message #1790140] Fri, 08 June 2018 07:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6040
Registered: July 2009
Senior Member
Hi

As part of the wider Eclipse community, I would be very interested if your ANTLR4 experience is able to support the migration of Xtext from ANTLR3 to ANTLR4.

Regards

Ed Willink
Re: Antlr4 to xtext [message #1790353 is a reply to message #1790302] Fri, 08 June 2018 13:52 Go to previous message
Michael Hoffer is currently offline Michael HofferFriend
Messages: 9
Registered: August 2014
Junior Member

Hi Ed,

I don't think I can. I work in an academic environment and we don't have a large customer base that we'd have to migrate etc. And the Xtext developers are certainly aware of the potential benefits of ANTLR4. I am not sure if those benefits are enough to justify a migration.

That being said, ANTLR4 certainly has huge benefits. One of many reasons to develop our ANTLR4 based modeling infrastructure is that ANTLR4 simplifies grammar development a lot. We tested with several grammars from the https://github.com/antlr/grammars-v4 repository. I had a basic Java8 language infrastructure up and running in about 2-3 hours (we basically just added labels to the ANTLR4 grammar). While ANTLR3 is often faster, new grammars are more likely to be developed for ANTLR4.

Regards
Michael


Previous Topic:Generate code with Xtend of ReqIF model
Next Topic:Xtext Serialization: how to benchmark?
Goto Forum:
  


Current Time: Sat Sep 22 00:58:45 GMT 2018

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

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

Back to the top