Sep 23, 2010

Dealing with the "could not even do k=1 for decision x" error in Xtext

If you have complex Xtext grammars, not the very latest and fastest computer, and are running other CPU intensive applications while kicking off the Xtext generator, you may have come across the following error message:

    error(10): internal error: org.antlr.tool.Grammar.createLookaheadDFA( could not even do k=1 for decision 135

Increasing the amount of memory available to the JVM is the first thing you will have to do when dealing with complex grammars. That however doesn't help in this case. That's because this error is due to a timeout inside the ANTLR generator which by default kicks in after 1000ms. After that ANTLR gives up on creating a DFA for your grammar and you may end up with the error message above.

Fortunately this timeout can be configured by passing ANTLR the -Xconversiontimeout option. In Xtext you do this by adding two antlrParam elements to the ANTLR generator fragment as in the example below (here I use a timeout of 10000ms):

    // The antlr parser generator fragment.
    fragment = parser.antlr.XtextAntlrGeneratorFragment {
        antlrParam = "-Xconversiontimeout" antlrParam = "10000"

Now don't forget to add the same option to the parser.antlr.XtextAntlrUiGeneratorFragment fragment!


  1. Just had this problem, and this post solved it! Thank you very much!

  2. nice tips, it works and helped me
    take care

  3. Much appreesh - this solved my problem as well!

  4. thanks!
    your blog contains interesting stuff about Xtext, I hope you'll post again soon.