I am reading "Less is exponentially more" and there is a list of advantages of Go, first of them, quote "regular syntax (don't need a symbol table to parse)".
What does it mean "regular syntax"? What properties define "language X does (not) have a regular syntax"?
2 Answers 2
Languages like C++ require a symbol table to parse properly, because some constructs are syntactically ambiguous if you don't know whether a given token represents a type, a function or a variable.
The main concrete example that I'm aware of is that declaring functions and constructing values both use parentheses:
int foo(3); // creates an integer called foo with value 3
int bar(int); // creates a function called bar that takes an int and returns an int
To parse this, you have to know that int
is the name of a type and 3
is not. Because of user-defined types, in general you cannot know whether a given token is a type name unless you have a symbol table containing all types the parser has seen up to this point. Note that the infamous "Most Vexing Parse" is closely related to this particular ambiguity.
The author you've quoted is most likely claiming that the Go language has no ambiguities like this, and thus can be parsed correctly without a symbol table. If you look at the official Go language specification, you'll notice pretty much everything about the syntax comes with an EBNF definition. I haven't read through it thoroughly, but it seems likely that Go's syntax is an actual context-free grammar, not merely approximated by one, which is pretty nice compared to C++.
-
Thank you very much! For the record -- en.wikipedia.org/wiki/Most_vexing_parsegreenoldman– greenoldman01/02/2016 14:00:27Commented Jan 2, 2016 at 14:00
-
"The author you've quoted is most likely claiming that the Go language has no ambiguities like this, and thus can be parsed correctly without a symbol table.": This means that the syntax of the language can be described by a context-free grammar, whereas C++ is context-sensitive.Giorgio– Giorgio01/03/2016 10:30:30Commented Jan 3, 2016 at 10:30
A look at the definition of Regular Language on Wikipedia could give you some pointers. Note that this goes into language theory and the Wikipedia article is not all that easy to read.
Basically, a regular language is a language that can be expressed by regular expressions.
I'm sure someone can manage to get into more details and still have the answer understandable by normal human beings, but that someone isn't me...
-
3I asked about regular syntax, not regular language. Go is not regular language.greenoldman– greenoldman01/02/2016 13:43:59Commented Jan 2, 2016 at 13:43
>>
) and for that purpose parser builds symbol table on fly? Something along those lines?