When processing large grammars, getAlphabet() throws a StackOverflowError due to deep recursion. Even increasing the JVM stack size to 12 MB (-Xss12m) does not resolve the issue.
Steps to Reproduce
- Download the attached files
parenthesesList.txt and bracketsList.txt with symbol IDs.
- Use the following grammar definition:
import java.io.File
fun dyckGrammar(
): Grammar {
val parenthesesIds = File("parenthesesList.txt").readLines()
val bracketsIds = File("bracketsList.txt").readLines()
return object : Grammar() {
val S by Nt().asStart()
init {
var alternatives: Regexp = Epsilon or (Term("normal") * S)
for (id in parenthesesIds) {
val open = "op--$id"
val close = "cp--$id"
alternatives = alternatives or ((Term(open) * S * Term(close)) * S)
}
for (id in bracketsIds) {
val open = "ob--$id"
val close = "cb--$id"
alternatives = alternatives or ((Term(open) * S * Term(close)) * S)
}
S /= alternatives
}
}
}
- Call the grammar and trigger the error:
val grammar = dyckGrammar()
grammar.rsm
Exception:
Exception in thread "main" java.lang.StackOverflowError
at org.ucfs.grammar.combinator.regexp.Regexp$DefaultImpls.getAlphabet(Regexp.kt:30)
at org.ucfs.grammar.combinator.regexp.Alternative.getAlphabet(Alternative.kt:6)
...
Attached Files
parenthesesList.txt
bracketsList.txt
When processing large grammars,
getAlphabet()throws aStackOverflowErrordue to deep recursion. Even increasing the JVM stack size to 12 MB (-Xss12m) does not resolve the issue.Steps to Reproduce
parenthesesList.txtandbracketsList.txtwith symbol IDs.Exception:
Attached Files
parenthesesList.txt
bracketsList.txt