KRun.externalParse StackOverflowError
leavens opened this issue · comments
The files I refer to are found in the attached zip file. I am using:
K framework version 4.0.0
Git revision: d310c7a
Git branch: v4.0.0
Build date: Wed Jul 27 22:10:26 EDT 2016
When I kompile the module model.k (in the zip file), everything seems fine. But when I do krun --debug model1.mod, I get a StackOverflowError with the following output.
org.kframework.utils.errorsystem.ParseFailedException: [Error] Critical: Parser returned a non-zero exit code: 1
Stdout:
Stderr:
[Error] Internal: Uncaught exception thrown of type StackOverflowError.
Please rerun your program with the --debug flag to generate a stack trace, and
file a bug report at https://github.com/kframework/k/issues
at org.kframework.krun.KRun.externalParse(KRun.java:372)
at org.kframework.krun.KRun.parseConfigVars(KRun.java:298)
at org.kframework.krun.KRun.run(KRun.java:77)
at org.kframework.krun.KRunFrontEnd.run(KRunFrontEnd.java:97)
at org.kframework.main.FrontEnd.main(FrontEnd.java:52)
at org.kframework.main.Main.runApplication(Main.java:110)
at org.kframework.main.Main.runApplication(Main.java:100)
at org.kframework.main.Main.main(Main.java:52)
[Error] Critical: Parser returned a non-zero exit code: 1
Stdout:
Stderr:
[Error] Internal: Uncaught exception thrown of type StackOverflowError.
Please rerun your program with the --debug flag to generate a stack trace, and
file a bug report at https://github.com/kframework/k/issues
The zip file is not part of the output I receive. The output starts after that with "org.kframework..."
I thought perhaps the stack overflow was due to the left recursion in the grammar, but even changing it to right recursion
syntax MBElems ::= MBElem
| MBElem MBElems
doesn't help, as the same error occurs.
However, if I take out the recursion completely and use
module MODEL-SYNTAX
syntax Model ::= "model" Id "{" MBElems "}"
syntax MBElems ::= MBElem
syntax MBElem ::= "use" "module" Id
endmodule
then I don't get the error when I use krun on model1.mod.
You get the stack overflow because the parser gets into a loop. MBElem
and MBElems
can be nullable.
I changed your example into:
syntax MBElems ::= List{MBElem, ""}
syntax MBElem ::= NeList{Import,";"}
and I managed to get a result.
Note that K has a complete context-free parser, you don't have to worry about left recursion, but you do have to worry about infinite cycles.
Let us know if this solves your problem and if we can close the issue.
Yes, that does solve the problem. Perhaps K should check for such infinite cycles, or the error message about StackOverflowError should be changed to point out the possibility of such infinite cycles, but now that I know what to do I can make progress. Thanks!