Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How can i disable backtracking ?(I thought that using the code mentioned below in mwe2 code the backtracking will be disabled.)
How can i disable backtracking ? [message #1801151] Mon, 14 January 2019 16:52 Go to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
I thought that using the code mentioned below in mwe2 code the backtracking will be disabled.
But after debugging the InternalDSLParser class in antlr.internal package, i found that state.backtrack = 2
And i found this comment in RecognizerSharedState class :

/** If 0, no backtracking is going on. Safe to exec actions etc...
* If >0 then it's the level of backtracking.
*/
public int backtracking = 0;

so backtrack is enabled, right?
how can i disable it?

mew2 file :
fragment = parser.antlr.ex.rt.AntlrGeneratorFragment {
options = {
backtrack = false
classSplitting = true
fieldsPerClass = "500"
ignoreCase = true
//kAsString="1"
memoize=true
}
}


fragment = org.eclipse.xtext.generator.parser.antlr.ex.ca.ContentAssistParserGeneratorFragment {
options ={
backtrack = false
classSplitting = true
fieldsPerClass = "500"
memoize=true
ignoreCase = true
//kAsString="5"
}
}
Re: How can i disable backtracking ? [message #1801153 is a reply to message #1801151] Mon, 14 January 2019 16:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14695
Registered: July 2009
Senior Member
0 = no backtracking

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How can i disable backtracking ? [message #1801158 is a reply to message #1801153] Mon, 14 January 2019 17:17 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
by debugging in InternalDSLParser.java i found that state.backtracking = 2 not zero

so i think there is something i am missing in disabling the backtracking
I know that zero means no backtracking but the value is not equal to zero!!

public final EObject entryRuleprimary() throws RecognitionException {
EObject current = null;
int entryRuleprimary_StartIndex = input.index();
EObject iv_ruleprimary = null;


try {
if ( state.backtracking>0 && alreadyParsedRule(input, 409) ) { return current; }

[Updated on: Mon, 14 January 2019 17:18]

Report message to a moderator

Re: How can i disable backtracking ? [message #1801160 is a reply to message #1801158] Mon, 14 January 2019 17:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14695
Registered: July 2009
Senior Member
Maybe there is something in your grammar

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How can i disable backtracking ? [message #1801162 is a reply to message #1801160] Mon, 14 January 2019 18:11 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
that what i am asking about, is there is something known in xtext that will enable the backtracking and i wrote it by mistake given that i disabled it in mwe2?
are you sure that if "state.backtracing" variable in InternalDSLParser class equals 2 means that backtracking is enabled?
Re: How can i disable backtracking ? [message #1801164 is a reply to message #1801162] Mon, 14 January 2019 18:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14695
Registered: July 2009
Senior Member
yes this means backtracking. but i dont think its related to the global backtracking option for ambiguities.

is there any specific reason you ask?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How can i disable backtracking ? [message #1801170 is a reply to message #1801164] Mon, 14 January 2019 20:02 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
Yes i am suffering from performance problem, and i am really frustrated because i think i am disabling backtracking while its seems its enabled.

the comment in the code is clear,since backtracking variable is not equal zero so it means i am enabling backtracking.

Do you know how to disable it?
Re: How can i disable backtracking ? [message #1801174 is a reply to message #1801170] Mon, 14 January 2019 20:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14695
Registered: July 2009
Senior Member
can you debug where it is set to != 0

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How can i disable backtracking ? [message #1801175 is a reply to message #1801174] Mon, 14 January 2019 20:26 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
it was my next step, but i found that it's used widely in the code so i was looking for hints about the locations where its value got changed, if you have information about that
Re: How can i disable backtracking ? [message #1801176 is a reply to message #1801175] Mon, 14 January 2019 20:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14695
Registered: July 2009
Senior Member
you know you can set a breakpoint on a field and configure it to match modifications

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How can i disable backtracking ? [message #1801177 is a reply to message #1801176] Mon, 14 January 2019 20:39 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
Thanks alot :)
I will check that and return back to this thread with the results

[Updated on: Mon, 14 January 2019 20:39]

Report message to a moderator

Re: How can i disable backtracking ? [message #1801224 is a reply to message #1801177] Tue, 15 January 2019 15:46 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
I found the modification in state.baacktracking happens in functions with this name

public final boolean synpred27_InternalDSLParser() {
state.backtracking++;
int start = input.mark();
try {
synpred27_InternalDSLParser_fragment(); // can never throw exception
} catch (RecognitionException re) {
System.err.println("impossible: "+re);
}
boolean success = !state.failed;
input.rewind(start);
state.backtracking--;
state.failed=false;
return success;
}

also it happens in many functions start with the same prefix "synpred".
Do you know what does it means?

[Updated on: Tue, 15 January 2019 15:50]

Report message to a moderator

Re: How can i disable backtracking ? [message #1801230 is a reply to message #1801224] Tue, 15 January 2019 16:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14695
Registered: July 2009
Senior Member
you you have a predicate in your grammar

=> or ->


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How can i disable backtracking ? [message #1801231 is a reply to message #1801230] Tue, 15 January 2019 16:11 Go to previous messageGo to next message
kimi raikonnan is currently offline kimi raikonnanFriend
Messages: 145
Registered: June 2015
Senior Member
yes, does it enable backtracking?
and if it does, what can i do to avoid that?
Re: How can i disable backtracking ? [message #1801239 is a reply to message #1801231] Tue, 15 January 2019 17:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14695
Registered: July 2009
Senior Member
semantic predicates do local backtracking and you cannot avoid it unless you dont use the predicate

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How can i disable backtracking ? [message #1861604 is a reply to message #1801239] Sat, 21 October 2023 21:18 Go to previous message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 125
Registered: July 2009
Location: New York City, NY
Senior Member
I don't know how this tale turned out in the end, but I just banged my head against a very similar problem where my backtracking setting had no effect.
After hours of debugging I realized that further down in my MWE2 configuration there was another parserGenerator = {debugGrammar=true} entry that overwrote the parser generator configuration that enabled the backtracking.
So keep in mind that there is no checking for duplicate entries, and that entries further down apparently overwrite earlier entries (so there is no merging of configurations either; this is as of Xtext 2.30/MWE2 2.14, not sure if this was fixed in the meantime).
Previous Topic:Large if-then-else results in stack overflow in ANTLR parser
Next Topic: Xtext 2.33.0.M2 is out
Goto Forum:
  


Current Time: Thu Jul 18 08:04:05 GMT 2024

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

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

Back to the top