Is a programming language a set of programs or a set of instructions

programming-languagesterminology

From Structured Computer Organization by Tanenbum

A program is a sequence of instructions describing how to perform a
certain task.

  • When trying to see a programming language as a formal languages added with semantics, I heard that a programming language is a set of valid programs (valid according to the syntax and other aspects of the language).

  • When reading Structured Computer Organization by Tanenbum, I understood that a programming languages is a set of instructions, from

    Each machine has a machine language, consisting of all the instructions that the machine can execute.

So I wonder if a programming language is a set of programs or a set of instructions? Thanks.

Best Answer

From the perspective of programming language theory

I would say neither. A programming language is 3 things

  1. A set of rules for constructing programs: the grammar of the language.
  2. A set of rules for determining whether a particular program is a valid program without running it: the static semantics of the language*
  3. A set of rules for actually evaluating a program to a value: the dynamic semantics (this is what most people call "semantics")

You can't just call the set of programs a programming language because we, as programmers, care very deeply about how you interpret that program. If I told you I constructed a new language called Nothyp which had the same syntax as Python (accepted the same set of programs) but ran everything backwards (different dynamic semantics) it'd be characterized as the same language if we just looked at the programs they accept!

Plus, in this form proving something like type safety, termination guarantees, or the canonical values lemma is actually reasonably pleasant.

*The static semantics capture the essence of type checking and all the other things a compiler will catch before runtime