> To begin, let me make it explicit that this post is about the concept
> of syntax and semantics in computer languages. For example, are
> computer languages defined by syntax and semantics? Does syntax and
> semantics comprise the whole of a computer language? What is a
> computer language? What is syntax, what is semantics? etc.
>
> First, lets note few facts:
>
> • there is no formal and universally accepted definition of what is
> meant by “semantics”. There may be some, if so defined, they are
> typically based on “models” over idealized, abstract hardware (i.e.
> operations on values in storage; as in finite state machine).
I think that something along the lines of "the results of evaluating an
expression or statement written in the language" would be a suitable
working definition. No, I don't have a citation for that. But in my
experience, people don't tend to be too confused as to what "semantics"
means.
> • semantics is tied to syntax. There cannot be semantics without
> syntax. We could conceptualize a semantic without any syntax, but this
> is basically not done.
I think you have this backwards. Syntax is meaningless without
semantics. The same set of semantics can have multiple syntactic
expressions (this was the original intent behind Lisp's [lack of]
syntax, so far as I know). Further, similar syntaxes (sp?) can have
very different semantics. See the plethora of rather diverse languages
with C-based syntax for examples.
Semantics can exist without syntax. It's just difficult to talk about.
> • a computer language, is typically mathematically defined as a set of
> operations on a set of chars. This typical definition, covers
> effectively just the syntax. (See
>
http://en.wikipedia.org/wiki/Formal_language)
>
> in general, the study of design of computer languages as languages for
> practical use, does not have much formal background. Typically, some
> computer scientists (the real ones are properly known as
> Mathematicians), create a lang that is LOSELY based on their idea of
> some mathematical theory (such as lambda calculus, or other sub
> branches of logic.) Lisp, prolog, haskell, apl are such examples. For
> vast majority of langs, such as pascal, logo, C, C++, Java, perl, awk,
> sh, python, php, ruby, tcl, basic, fortran,... etc, basically their
> design, creation, are far removed from any mathematics. It is pretty
> much a so-called “art”. Any dummy, can conceive and create a computer
> language from scratch based on basically just his personal experiences
> in using lang and intuition. This does not mean the lang will be
> “bad”. In fact, most successful or widely used langs, results from
> such personal creativity.
Many successful and widely used languages are built from such personal
creativity. Perl and Python come to mind.
There are exceptions, however: Standard ML has a complete mathematical
definition of its semantics for at least the core language (see "The
Definition of Standard ML"). Haskell also has a lot of formalism about
it, but I am not sure how thoroughly its semantics are defined.
> One of the question we want to ask is, what is a computer language? As
> we know, formal methods, such as those based on automata, has nothing
> to do with actual langs and is basically just the study of syntax. A
> formal languages, of course does also have semantics, but that
> semantics basically means transformation of strings.
Patently false. Formal languages, such as definitions of Turing
machines, are typically dealt with without any particular syntax. You
can express them in a variety of ways (an annotated state diagram, a
table, a list of functions), and they are semantically equivalent.
Lambda calculii probably have a more consistent syntax, but the syntax
remains just a representation of the abstract concepts.
> This sense is far different from what mean by “semantics” in pop books
> that deal with real langs (such as the the text book “Programming
> Languages: Application and Interpretation”", by Shriram Krishnamurth).
> The other question we want to ask, related to the above, is “what
> exactly is a computer language?”. There is a popular, unconcious
> belief, that a computer language is made up of syntax and semantics.
> However, as we know from above, there are no formal definition on what
> exactly is semantics that can be applied to computer languages in
> daily use.
The graduate level programming languages course I took in my
undergraduate years had a pretty good definition, I thought: "a language
capable of expressing every computable function."
> So, what is then, a computer language? Is there a formal definition
> that makes Java, C, perl, lisp, as computer languages? The answer is
> just no in our current state of mathematics.
Using the definition above, all that is necessary to show that they are
programming languages is to demonstrate that is possible to reduce a
Turing machine (the definition of computability) to them. That they are
computer languages is self-evident -- they are languages processable by
or controlling computers.
They may not be well-defined languages, but they certainly are
programming languages.
> Why is syntax far more important than whatever we intuitively
> understood as “semantics”? Because, it is syntax that we actually see
> and use in a computer lang, and it is syntax that drives the
> development of semantics. When you design a language, you start with
> syntax, coupled with some vague idea of what u want to happen, then,
> once you wrote a compiler, then is semantics born.
Again, not necessarily true. It may be true in some languages (perhaps
Perl), but not in others. As stated above, Standard ML has a complete
semantic definition. In the Python community, when adding new language
features, there have been times when they new most of what they wanted
semantically but it took some time to nail down what the syntax would
be.
I would argue that development goes in exactly the opposite description
you describe: one first thinks of what one wants to tell the computer to
do, and then figures out how to write it down.
> another reason syntax is far more important can be seen from the
> history of math notations. Tech geekers might think, notation doesn't
> mean much except some convenience aspects. But if you are acquainted
> in history of math notation, you'll know that notation largely drove
> many development and directions of mathematics. Examples include
> arabic numeral with decimal positional notation, symbols for variables
> → abstract algebra, matrix notation → linear algebra, some notations →
> calculus. (notations, is somewhat like terminology, in that sometimes
> the existance of a notation/terminology have huge impact from
> awareness of the concept to major influence on thought of a subject.)
Sure, syntax and notations are nice. But that does not make them more
important than semantics. It simply means that syntax makes it easier
to discuss semantics coherently.
- Michael
--
mouse, n: A device for pointing at the xterm in which you want to type.