Are there two senses of "grammar"?

Is it correct that

  • in linguistics, semantics (and maybe also pragmatics) belongs to and is specified in grammar? (My impression from limited reading of a linguistic book)

  • in formal logic and programming languages, semantics (and pragmatics) is not? (I encountered the concept of "grammar" for the first time when reading about formal languages, and thought that the concept is strictly syntactic.)

  • 1
    Sure. There's also grammar schools. Most words have different senses in different contexts!
    – curiousdannii
    Commented Jul 24, 2023 at 2:36

3 Answers 3


You could say that there are myriad senses of grammar. For example, even here, some people speak of "grammar" as referring to syntax. Since syntax has connections to morphology, it can also be used to refer to "morphosyntax". Broadly and non-linguistically, it refers to "proper language", however determined, which could be about syntax, pronunciation, spelling, or whatever. Generative grammar uses it to refer to a specific cognitive faculty enabling language. However, current minimalism has pretty much changed the concept to "construction of constituency relations", so it is only a subset of syntax. Right now, I am working on writing a "grammar" (a descriptive account of a language). Oddly (or not), the original Greek concept was much broader, encompassing literature and writing, and the narrowing to prescriptive grammar in the sense of "grammar school" is a 16th century and later development.

I don't know how programmers use "semantics" w.r.t. programming languages, but generally speaking, "formal" approaches presuppose that we have a formalism for talking about the object (e.g. categories of words and the fact that A precedes B), but what you do with those "formal" objects is out of the reach of formal approaches, until someone devises an equally formal theory of semantics, as indeed has been done for natural language. In the 60's and 70's, it was largely believed that semantics was beyond the scope of scientific study, though that has proven not to be true.

  • Semantics for programming languages are typically either described informally or formally specified as (possible – even programming languages can have ambiguities) executions on a (usually abstract) machine. Full formal specifications are pretty rare though as they require a lot of labour to create in the first place, and even more to keep up to date as languages change over time.
    – Cubic
    Commented Jul 24, 2023 at 10:51
  • @Cubic: Practically the same things can be said about "formal linguistics" of any sort. And for practically the same reason -- they're all built for idealized, nonexistent contexts.
    – jlawler
    Commented Jul 24, 2023 at 16:41

There are indeed different senses of "grammar". In the scientific (linguistic) sense, it has a broader meaning than in everyday language. Grammar in the broader sense is any system of rules for combining items into larger items, or for analysing larger chunks into their constituent parts. This can be done in syntax and morphology, but also in phonology (e.g. syllable structure). In this sense, combining the meanings of words into a meaning for the whole sentence would also fall under grammar (especially as it goes hand in hand with syntax). I would say that certain parts of semantics would not be called grammar, though, like many aspects of word meaning and categorisation, as in prototype theory etc.

Cf. the handbook definition of grammar: "systematic description of a language’s structure." (is that good English, I wonder?; it's from a German source :) https://www.degruyter.com/database/WSK/entry/wsk_id_wsk_artikel_artikel_8254/html )

PS: I don't see pragmatics as a part of grammar. Grammar is about linguistic items and expressions, pragmatic is about their use.

  • 1
    I would say the everyday meaning is broader than the linguistic one, not the other way around. The often-heard colloquial meaning of grammar is essentially ‘anything to do with language, especially if it involves rules’. You often see people claiming that things like malapropisms, misquoted sayings, alternative pronunciations, colloquial contractions, etc., are ‘grammatically incorrect’, when in the linguistic sense they are nothing of the sort. Commented Jul 24, 2023 at 12:08
  • Perhaps it is a broader meaning, but perhaps it is also just a mistake?
    – Alazon
    Commented Jul 24, 2023 at 12:47
  • I would agree that it’s a mistake – the way many people use it is so vague it’s pretty much meaningless. But it is a very common everyday meaning of the word, and I don’t think ‘grammar’ has another everyday meaning that is narrower than the linguistic meaning. Commented Jul 24, 2023 at 13:25

From a programmer's perspective, there are languages with a clear split between "grammar" and "semantics", and languages where that distinction becomes murky.

For example, a calculator that allows assigning names to intermediate results could be defined with a grammar like

    input calculation
|   empty


    NAME "=" expression
|   expression

    expression "+" product
|   expression "-" product
|   product

    product "*" factor
|   product "/" factor
|   factor

|   NAME
|   "(" expression ")"

This allows input like

a = 1
b = a * 3
c = b + d

The "semantics" of that language are what should happen after the syntax has been analyzed.

The token stream begins with a NAME, which can be either input(1)->calculation(1)->NAME or input(1)->calculation(2)->expression(3)->product(3)->factor(2)->NAME. The equals sign determines this to be the former, so in order to be syntactically correct, the following token must be NUMBER, NAME or (, because that is how an expression can start.

It is a NUMBER, and the next token after that is b, which is none of +, -, * or /, so the calculation ends here, and a new one begins. In the end, we are left with a tree like


This program is syntactically correct, as it matches the grammar rules we were given. Now for this to be useful, we also need to add interpretation rules:

  1. NAME "=" expression calculates the result of expression and associates it with NAME
  2. expression "+" product calculates the result of both expression and product and uses the sum as result
  3. likewise, for "-"
  4. likewise, for "*"
  5. likewise, for "/"
  6. NUMBER is interpreted as a number
  7. NAME as part of an expression is replaced with the result that was previously associated with NAME.

The latter rule imposes additional constraints on what constitutes valid input: every NAME that appears on the right hand side of an equals sign or in a computation with no equals sign must also exist on the left hand side of an equals sign in a different computation, and that occurrence must be earlier in the token stream.

Violating these constraints means that the input is still syntactically correct, but semantically incorrect.

In the c = b + d case, it is also obvious (to us) that there is no valid interpretation for that input, because we don't know what d is.

If we extend the input by d = 2 + 4 / 2, this remains semantically incorrect as the requirement was for NAMEs to be introduced before their use, even if we could argue that the meaning of the input is well-defined now. There is an easy counterexample a = b + 2 b = a + 2, which is still syntactically valid but would be troublesome to evaluate with the ruleset above, so the word "previously" is doing a lot of heavy lifting here.

There are other programming languages where this distinction is less clear, and the translation phases for syntax and semantic analysis merge -- for example, the C programming language allows introducing names for data types into the same namespace, and the grammar rules depend on being able to distinguish between type and object names -- so there is a lookup table of type names introduced so far, and at least that part of semantic processing must be performed as part of syntax analysis.

The word "semantics", in a programming context, encompasses both validity and interpretation rules, because these are typically intertwined.

In a natural language context, there are also sentences that have correct grammar, but express concepts that do not fit together. A classic example is "colorless green ideas sleep furiously".

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.