Random grammar question: Why are there two start s...
# compiler
s
Random grammar question: Why are there two start symbols
kotlinFile
and
script
? `kotlinFile`'s
topLevelObject
seems to only contain declarations. What is this used for? 🙂 (https://kotlinlang.org/docs/reference/grammar.html#syntax-grammar)
m
Well, Kotlin script files (being scripts) can contain arbitrary statements at top level (e.g., loops, function calls, etc.). Regular Kotlin files allow only declarations at top level. Hence, the difference you encountered )))
s
Oh, of course! Somehow I totally missed that you actually cannot have top level statements in regular Kotlin files. Now it is obvious. Thank you!
👍 1