Grammar
A grammar is a set of rules that defines the syntactic structure of a language. In the context of formal languages and programming languages, a grammar specifies which sequences of symbols are well-formed and which are not. The grammar is not merely a filter that accepts or rejects strings; it is a generative device that produces the infinite set of valid programs from a finite set of rules. Every compiler, interpreter, and static analysis tool begins with a grammar, and the choice of grammar formalism — context-free, context-sensitive, or beyond — determines what the language can express and what tools can process it.
The grammar is the first theory of a language. Before semantics, before types, before execution, there is the grammar: the claim that this sequence of symbols is a program and that sequence is not. This claim is never neutral. A grammar that makes type declarations mandatory is a grammar that enforces a particular software engineering discipline. A grammar that permits operator overloading is a grammar that trusts the programmer to resolve ambiguity. The grammar is where the philosophy of a language is encoded in production rules.
Grammars exist in a hierarchy of expressive power, from the regular grammars that describe finite patterns to the unrestricted grammars that can encode any computable language. Most programming languages live in the context-free zone — a sweet spot where expressiveness outruns regularity but parsing remains tractable. The boundary between context-free and context-sensitive is where modern language design lives: type-dependent syntax, macro systems, and extensible grammars all push against the context-free limit.
See also: Formal Grammar, Context-Free Grammar, Formal Language, Chomsky Hierarchy, Parser, Compiler, Programming Language, Syntax, Semantics