When describing the syntax of a given programming language the words "expression" and "term" are often used to seemingly describe the same things. Are these words interchangeable in the context of programming languages?
Asked By : tibbe
Answered By : Gilles
The two words expression and term have largely the same sets of possible meaning, but in a specific presentation, they may not be synonyms.
In rewriting theory, a term is something that conforms to a certain syntax, and for which a notion of computation (rewriting) is defined. In programming language theory, term can mean specifically one of the two aspects. And so can expression. Which means which depends on the author, and not all authors use both words in this way.
- One possible meaning of the word is "something that can be computed". In this sense, if the computation terminates, you end up with a value.
- Another possible meaning of the word is "something that conforms to a certain syntax". There is often a computation mechanism defined over this syntax, but not always.
In the theory of a programming language, there are often multiple syntactic objects: the core language, types, kinds, objects, classes, modules, interfaces, … Something like function x : int => x + 1
may be a core term which contains the type term int
, or a core expression which contains the type expression int
. It's common but not universal to use one of the two nouns to mean "core" (and "core" is my choice of terminology), e.g. "function x : int => x + 1
is an expression" or "function x : int => x + 1
is a term". Different authors use different words; communities of a specific language tend to align on terminology, but that isn't systematic.
For example, in the world of ML, "expression" with no qualifier is normally reserved for the core language, and there are additionally "module expressions" in the module language, as well as "type expressions" and "signature expressions". A "term" can be anything conforming to one of the syntactic forms, although many authors (e.g. the SML definition) don't use "term" at all.
But in Coq, a "term" is the most important syntactic form. Due to the nature of the language, the syntax of types is the same as terms. The Coq manual uses "expression" to designate any family of syntactic form.
If you're reading a text on programming languages, the meaning of the words should be explained or (in less formal texts) clear from context. If you're writing a text, try to use the terminology that's common in your community, and always make sure that the definitions you use are clear.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/64699
0 comments:
Post a Comment
Let us know your responses and feedback