In
formal language
In logic, mathematics, computer science, and linguistics, a formal language is a set of strings whose symbols are taken from a set called "alphabet".
The alphabet of a formal language consists of symbols that concatenate into strings (also c ...
theory, a
context-free grammar
In formal language theory, a context-free grammar (CFG) is a formal grammar whose production rules
can be applied to a nonterminal symbol regardless of its context.
In particular, in a context-free grammar, each production rule is of the fo ...
is in Greibach normal form (GNF) if the right-hand sides of all
production rules start with a
terminal symbol
In formal languages, terminal and nonterminal symbols are parts of the ''vocabulary'' under a formal grammar. ''Vocabulary'' is a finite, nonempty set of symbols. ''Terminal symbols'' are symbols that cannot be replaced by other symbols of the v ...
, optionally followed by some non-terminals. A non-strict form allows one exception to this format restriction for allowing the
empty word
In formal language theory, the empty string, or empty word, is the unique string of length zero.
Formal theory
Formally, a string is a finite, ordered sequence of characters such as letters, digits or spaces. The empty string is the special cas ...
(epsilon, ε) to be a member of the described language. The normal form was established by
Sheila Greibach
Sheila Adele Greibach (born 6 October 1939 in New York City) is an American researcher in formal languages in computing, automata, compiler theory and computer science. She is an Emeritus Professor of Computer Science at the University of Calif ...
and it bears her name.
More precisely, a context-free grammar is in Greibach normal form, if all production rules are of the form:
:
where
is a
nonterminal symbol
In formal languages, terminal and nonterminal symbols are parts of the ''vocabulary'' under a formal grammar. ''Vocabulary'' is a finite, nonempty set of symbols. ''Terminal symbols'' are symbols that cannot be replaced by other symbols of the v ...
,
is a terminal symbol, and
is a (possibly empty) sequence of nonterminal symbols.
Observe that the grammar does not have
left recursions.
Every context-free grammar can be transformed into an equivalent grammar in Greibach normal form. Various constructions exist. Some do not permit the second form of rule and cannot transform context-free grammars that can generate the empty word. For one such construction the size of the constructed grammar is O(
4) in the general case and O(
3) if no derivation of the original grammar consists of a single nonterminal symbol, where is the size of the original grammar.
This conversion can be used to prove that every
context-free language
In formal language theory, a context-free language (CFL), also called a Chomsky type-2 language, is a language generated by a context-free grammar (CFG).
Context-free languages have many applications in programming languages, in particular, mos ...
can be accepted by a real-time (non-deterministic)
pushdown automaton
In the theory of computation, a branch of theoretical computer science, a pushdown automaton (PDA) is
a type of automaton that employs a stack.
Pushdown automata are used in theories about what can be computed by machines. They are more capab ...
, i.e., the automaton reads a letter from its input every step.
Given a grammar in GNF and a derivable string in the grammar with length , any
top-down parser
Top-down parsing in computer science is a parsing strategy where one first looks at the highest level of the parse tree and works down the parse tree by using the rewriting rules of a formal grammar. LL parsers are a type of parser that uses a top- ...
will halt at depth .
See also
*
Backus–Naur form
In computer science, Backus–Naur form (BNF, pronounced ), also known as Backus normal form, is a notation system for defining the Syntax (programming languages), syntax of Programming language, programming languages and other Formal language, for ...
*
Chomsky normal form
*
Kuroda normal form In formal language theory, a noncontracting grammar is in Kuroda normal form if all production rules are of the form:
:''AB'' → ''CD'' or
:''A'' → ''BC'' or
:''A'' → ''B'' or
:''A'' → ''a''
where A, B, C and D are nonterminal symbols and ...
References
*
* {{cite book, author=György E. Révész, title=Introduction to Formal Languages, url=https://books.google.com/books?id=3s7CAgAAQBAJ&q=%22Greibach+normal+form%22, date=17 March 2015, publisher=Courier Corporation, isbn=978-0-486-16937-8
Formal languages