Skip to content

StackOverflowError in getAlphabet() on large grammars #47

@RodionovMaxim05

Description

@RodionovMaxim05

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

  1. Download the attached files parenthesesList.txt and bracketsList.txt with symbol IDs.
  2. 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
		}
	}
}
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions