Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Cannot set backtrack to false(mwe2)
Cannot set backtrack to false [message #1823357] Wed, 25 March 2020 09:20 Go to next message
Eclipse UserFriend
We have a problem with java.lang.IllegalStateException when auto formating a distinct dsl file.
I have read in some forum that this might be because of the use of backtracking, respectively left recursion grammar.
As we actually don't have such, I wanted to disable it with the statement
			parserGenerator = {
				options = {
					ignoreCase = true 	// Case Insensitive Keywords
					backtrack = false
				}
			}

just to be sure in the mwe2 file.
It seems that it doe not work properly because we still have the entry
backtrack=true

in the InternalTabsParser.g file.
How comes? And how to check whether the backtrack option is switched off?

Thanks for help
Christian
Re: Cannot set backtrack to false [message #1823358 is a reply to message #1823357] Wed, 25 March 2020 09:26 Go to previous messageGo to next message
Eclipse UserFriend
Hi, you may debug AbstractAntlrGrammarGenerator
can you please provide a complete example.

[Updated on: Wed, 25 March 2020 09:38] by Moderator

Re: Cannot set backtrack to false [message #1823360 is a reply to message #1823358] Wed, 25 March 2020 10:23 Go to previous messageGo to next message
Eclipse UserFriend
If you mean the grammar, I don't think it makes sense because it has about 870 lines of code.
I already debugged the application and found the spot where it crashes. Now I want to set the left recursion to off to be sure there is none ( I suppose the parser genarator should throw an error then), but the entry in the mwe2 file did not lead to anything new and after searching for backtrack I still found it set to true in the InternalTabsParser.g file (whatever this file is)
So my actual problem is maybe to set the left recursion to off.
Re: Cannot set backtrack to false [message #1823361 is a reply to message #1823360] Wed, 25 March 2020 10:38 Go to previous messageGo to next message
Eclipse UserFriend
but the code backtrack=true must be done somewhere in the generator.
and the only place in the code of the (new) generator that creates backtrack=true is
AbstractAntlrGrammarGenerator

=> if you debug the workflow it should stop there.
or do you use the old deprecated workflow/generator
Re: Cannot set backtrack to false [message #1823362 is a reply to message #1823361] Wed, 25 March 2020 10:50 Go to previous messageGo to next message
Eclipse UserFriend
Well the entry in the mwe2 file should do the trick, right?
I use the new workflow/generator (it's mwe"2") at least as far as I know.
Well I will try to debug this thing...
Re: Cannot set backtrack to false [message #1823367 is a reply to message #1823362] Wed, 25 March 2020 11:26 Go to previous messageGo to next message
Eclipse UserFriend
the workflow is mwe2 for both old and new

parserGenerator = {

indicates you use the new one
(overlooked that at the first glance)

=> please debug where the backtrack=true comes from in AbstractAntlrGrammarGenerator
Re: Cannot set backtrack to false [message #1823370 is a reply to message #1823362] Wed, 25 March 2020 11:30 Go to previous messageGo to next message
Eclipse UserFriend
Uhh. This looks like an xtend bug to me! I experienced this before but not with templates.
Bad I cannot include snapshots here, but here is the code sniplet from AbstractAntlrGrammarGenerator (sorry for the bad characters):
	protected def compileParserOptions(Grammar it, AntlrOptions options) '''

		options {
			�IF !isCombinedGrammar�
				tokenVocab=�grammarNaming.getLexerGrammar(it).simpleName�;
			�ENDIF�
			�IF grammarNaming.getInternalParserSuperClass(it) !== null�
				superClass=�grammarNaming.getInternalParserSuperClass(it).simpleName�;
			�ENDIF�
			�IF isParserBackTracking(options) || options.memoize || options.k >= 0�
				�IF isParserBackTracking(options)�
					backtrack=true;
				�ENDIF�
				�IF options.memoize�
					memoize=true;
				�ENDIF�
				�IF options.k >= 0�
					memoize=�options.k�;
				�ENDIF�
>>>>		�ENDIF�
		}
	'''
	
	protected def isParserBackTracking(Grammar it, AntlrOptions options) {
		options.backtrack
	}
	

When you come to the point marked with ">>>>" the output is (copied from variable _builder.segments[]:
[
, options {, 
, 	, tokenVocab=, InternalTabsLexer, ;, 
, 	, superClass=, AbstractInternalContentAssistParser, ;, 
, 	, backtrack=true;,  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
]

Which is an error according to debugged variable options.backtrack which is false
so isParserBackTracking(options) should never return true!

Had this xtend error before in normal xtend code with nested ifs. If you insert "{}" after the condition everything is fine, if not sometimes it goes into the nested if, even if the condition is false.
But you cannot do this here with template syntax!

So I am really stuck :-(

PS: uploaded the screenshots
Re: Cannot set backtrack to false [message #1823375 is a reply to message #1823370] Wed, 25 March 2020 12:42 Go to previous messageGo to next message
Eclipse UserFriend
if you debug you can click on the stackframe with the xtend file and select show source -> java from the context menu
then you should be able to see who adds the backtrace=true to the _builder/StringConcatenation
you can also debug the getter and setter in org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions
(rightklick, open generated file to see the java code)
to see who calls setBacktrack with true
Re: Cannot set backtrack to false [message #1823376 is a reply to message #1823375] Wed, 25 March 2020 12:44 Go to previous messageGo to next message
Eclipse UserFriend
then i debug with a hello world dsl i see

options {
superClass=AbstractInternalAntlrParser;

and


options {
superClass=AbstractInternalContentAssistParser;

no tokenVocab

in the _builder
Re: Cannot set backtrack to false [message #1823377 is a reply to message #1823376] Wed, 25 March 2020 12:47 Go to previous messageGo to next message
Eclipse UserFriend
please also have a look at the subclass that customizeses

org.eclipse.xtext.xtext.generator.parser.antlr.AntlrContentAssistGrammarGenerator.isParserBackTracking(Grammar, AntlrOptions)

override protected isParserBackTracking(Grammar it, AntlrOptions options) {
super.isParserBackTracking(it, options) || !allPredicatedElements.isEmpty
}

=> i assume you have allPredicatedElements

and the content assist grammar uses that as criteria
to enable backtracking.

[Updated on: Wed, 25 March 2020 12:48] by Moderator

Re: Cannot set backtrack to false [message #1823407 is a reply to message #1823377] Thu, 26 March 2020 04:37 Go to previous messageGo to next message
Eclipse UserFriend
Well yes you are right. In the subclass the value is set according to !allPredicatedElements.isEmpty. Does that mean the program does not care what I set in the options and overwrites it accordingly to the current situation?!
What for is the option then?
Re: Cannot set backtrack to false [message #1823409 is a reply to message #1823407] Thu, 26 March 2020 04:48 Go to previous messageGo to next message
Eclipse UserFriend
there is none. if you use -> or => the ca parser needs backtracking (please note: this is the content assist parser, not the build parser)
Re: Cannot set backtrack to false [message #1823414 is a reply to message #1823409] Thu, 26 March 2020 05:07 Go to previous message
Eclipse UserFriend
Well actually I just wanted to check our rather complicated grammar for left recursive. I have learned that this is not possible by just switching the parser generator via options to this state (backtrack=false), because this might be overwritten.
But if it is overwritten, then the grammar is left recursive.

[Updated on: Thu, 26 March 2020 05:30] by Moderator

Previous Topic:Maven dependencies
Next Topic:how to create an external cross-reference in the AST
Goto Forum:
  


Current Time: Tue Jul 08 17:24:33 EDT 2025

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

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

Back to the top