Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Left recursion(java and left recursion)
icon9.gif  Left recursion [message #1741725] Sun, 28 August 2016 23:42 Go to next message
Tatiana Silva is currently offline Tatiana SilvaFriend
Messages: 1
Registered: August 2016
Junior Member
Hi, I'm trying to do a lexical analysis at Java grammar (university project). And I have this problem of how to remove left recursion in the package_name rule.

package_name 
      ::= 
      identifier 
      | ( package_name "." identifier ) 


I tried to using something that we learned in class:
imgur.com/a/5LWbV


package_name: 
      identifier 
      | package_name1
;

package_name1:
	"." identifier package_name1 | empty
;


But what would be the empty in xtext?
Re: Left recursion [message #1741791 is a reply to message #1741725] Mon, 29 August 2016 15:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5518
Registered: July 2009
Senior Member
Hi

Xtext is very unusual, unlike anything a traditional grammar course might cover.

Xtext does not support left recursion or epsilon. Major pain.

But Xtext does support EBNF */+/?. Fantastic.

So you must recast your problem into what Xtext supports.

package_name: names+=identifier ('.' names+=identifier)*

Regards

Ed Willink
Re: Left recursion [message #1741850 is a reply to message #1741791] Tue, 30 August 2016 07:41 Go to previous message
Stephane Galland is currently offline Stephane GallandFriend
Messages: 106
Registered: July 2014
Location: Belfort, France
Senior Member
You could also inherit from the Xbase grammar, and define the package definition in your rule as:
'package' package=QualifiedName ';'


Stéphane.


Dr.habil Stéphane Galland.
Belfort-Montbéliard University of Technologie, France.

http://www.multiagent.fr/People:Galland_stephane
http://www.sarl.io
http://www.arakhne.org
Previous Topic:xtext unnamed tree
Next Topic:Xtext grammar ambiguity problem
Goto Forum:
  


Current Time: Mon Dec 11 23:01:04 GMT 2017

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

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