What Is Syntax

Does anybody want to posit a clear-cut definition of "syntax"? It seems like it would be easy, but it turns out not to be.

[What do you mean by "clear-cut"? Easy to understand? Rigorous and formal? The two are in opposition. Syntax/grammar can be defined as power series in a division algebra (almost always nonabelian) on semigroups, as John Baez explains fairly clearly on http://math.ucr.edu/home/baez/twf_ascii/week108, with some comments added by me at the end.]

[If you want something less mathematical and therefore less rigorous and more ambiguous, don't expect to get anywhere splitting hairs on the less formal definition.]

[It is worth noting, however, that syntax/grammar is in fact formally equivalent to computation. That's not to say that Java syntax is the same thing as computations performed by Java code; 5 and 37 are formally equivalent in several ways: they're both integers, they're both odd, they're both prime, etc -- but they're not the same number. So there exist grammars that are equivalent to any given computation, but it depends on the grammar and the domain of the grammar. Syntax and code are different.]

[Lastly, this whole thing about basically wanting to claim that words like "syntax" and "code" are ill-defined is rather ill-advised; these things can be pinned down as firmly (and mathematically) as you like -- but you will not be pleased with the resulting rigor. I advise a rapid course change. -- DougMerritt]

See http://en.wikipedia.org/wiki/Syntax#In_computer_science.

That mostly gives examples, not a definition.

"The set of allowed reserved words and their parameters and the correct word order in the expression is called the syntax of the language" is a definition.

For example, is something still "syntax" after it is put into a AbstractSyntaxTree?

You're confusing levels. Some text may obey or conform to a specific syntax. An AST representation of that text may make that conformance explicit. Things are not "syntax" before or after they are put into ASTs. "Syntax" is the set of rules.

Are all set of rules "syntax"?

No.

What distinquishes syntax rules from non-syntax rules?

In computer science, a syntax is the set of rules that define a programming language. If rules define something else, they aren't a syntax.

But in issues such as DataAndCodeAreTheSameThing and "Type" definitions, this is still not specific enough.

Sure it is.

Oh sh8t. It looks like that first we need to agree on "what is code".

Nope. Syntax does that for us. Anything that conforms to syntax is code.

This appears to be a circular definition. Above it was stated that "syntax is the set of rules that define [code]". Now you are defining code as something that has syntax.

All definitions are circular. All words are defined by other words. A "syntax" defines what is "code" for any given programming language. "Code" is anything that satisfies a "syntax".

[That's what happens when you're informal. Syntax defines legal sequences of symbols. Code defines a computation. As you know. If you want to split hairs, by all means, let's go straight for the mathematics of it.]

The precision wasn't an issue until the "types" definition debacle.


See also:


CategoryDefinition


EditText of this page (last edited August 14, 2010) or FindPage with title or text search