3 ms·
I'm a bit confused about Go's grammar. I thought I read somewhere that Go could be parsed by a CFG. But when I looked into it just now, the introduction to th
by jlarocco 14y ago
I'm a bit confused about Go's grammar. I thought I read somewhere that Go could be parsed by a CFG.
But when I looked into it just now, the introduction to the language spec [1] says "The grammar is compact and regular ...". But how can the grammar be regular? According to Wikipedia "regular grammars" describe languages that can be expressed using regular expressions. [2][3] Wouldn't matching parenthesis and braces require at least a context free language instead of regular?
[1] http://golang.org/ref/spec#Introduction http://golang.org/ref/spec#Introduction
[2] https://en.wikipedia.org/wiki/Regular_grammar https://en.wikipedia.org/wiki/Regular_grammar
[3] https://en.wikipedia.org/wiki/Regular_language https://en.wikipedia.org/wiki/Regular_language
- gchpaco 14y agoRegular here does not mean regular in the technical sense, it means there aren't any weird special case constructs that break the rest of the parsing (for a particularly egregious example, consider the Perl report sublanguage, which is nothing like the rest of the language).