5

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
  • 2
    Does stackoverflow.com/questions/69112/what-is-a-symbol-table help you? Commented Jan 2, 2016 at 13:29
  • @JamesSnell, thank you for that link, but I am not closer to the answer :-) I could only guess that maybe it is a reference to the way C++ is parsed, that some constructs are context dependent (like >>) and for that purpose parser builds symbol table on fly? Something along those lines? Commented Jan 2, 2016 at 13:41

2 Answers 2

10

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++.

2
  • Thank you very much! For the record -- en.wikipedia.org/wiki/Most_vexing_parse Commented 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
    Commented Jan 3, 2016 at 10:30
-4

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...

1
  • 3
    I asked about regular syntax, not regular language. Go is not regular language. Commented Jan 2, 2016 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.