2.1 The Elements of Java Programs | 43
Metalanguages
Metalanguageis the word languagewith the prefix meta, which means “beyond” or “more compre-
hensive.” In other words, a metalanguage is a language that goes beyond a normal language by
allowing us to speak precisely about that language. It is a language for talking about languages.
One of the oldest computer-oriented metalanguages is the Backus-Naur Form(BNF), which is
named for John Backus and Peter Naur, who developed it in 1960. BNF syntax definitions are
written out using letters, numbers, and special symbols. For example, an identifier(a name for
something) in Java must be at least one letter, underscore, or dollar sign, which may or may not
be followed by additional letters, underscores, dollar signs, or digits. The BNF definition of an
identifier in Java is
< letter-digit-sequence > ::=
| a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z
where the symbol ::= is read “is defined as,” the symbol | means “or,” and the symbols < and > are
used to enclose words called nonterminal symbols(symbols that still need to be defined).
Everything else is called a terminal symbol.
The first line of the definition reads as follows: “An identifier is defined as a letter or a letter
followed by a letter-digit-sequence.” This line contains nonterminal symbols that must be
defined. In the second line, the nonterminal symbol
ter-or-digit> or as a
ence in the definition is a roundabout way of saying that a
series of one or more letters or digits. In the third line, a
fine
BNF is an extremely simple language, but that simplicity leads to syntax definitions that can
be long and difficult to read. An alternative metalanguage, the syntax diagram, is easier to follow.
It uses arrows to indicate how symbols can be combined. The following syntax diagrams define
an identifier in Java: