---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 16 Edition"
java_version: 16
chapter: "Chapter 2. Grammars"
section: "2.1"
heading: "2.1. Context-Free Grammars"
parent: "Chapter 2. Grammars"
source: https://docs.oracle.com/javase/specs/jls/se16/html/jls-2.html#jls-2.1
id: "2.1"
url: https://jvm.obfuscated.software/jls/se16/2.1.html
raw: https://jvm.obfuscated.software/jls/se16/2.1.md
---

# 2.1. Context-Free Grammars

A *context-free grammar* consists of a number of *productions*. Each production has an abstract symbol called a *nonterminal* as its *left-hand side*, and a sequence of one or more nonterminal and *terminal* symbols as its *right-hand side*. For each grammar, the terminal symbols are drawn from a specified *alphabet*.

Starting from a sentence consisting of a single distinguished nonterminal, called the *goal symbol*, a given context-free grammar specifies a language, namely, the set of possible sequences of terminal symbols that can result from repeatedly replacing any nonterminal in the sequence with a right-hand side of a production for which the nonterminal is the left-hand side.
