Greibach Normal Form
   HOME

TheInfoList



OR:

In
formal language In logic, mathematics, computer science, and linguistics, a formal language consists of words whose letters are taken from an alphabet and are well-formed according to a specific set of rules. The alphabet of a formal language consists of symb ...
theory, a
context-free grammar In formal language theory, a context-free grammar (CFG) is a formal grammar whose production rules are of the form :A\ \to\ \alpha with A a ''single'' nonterminal symbol, and \alpha a string of terminals and/or nonterminals (\alpha can be empt ...
is in Greibach normal form (GNF) if the right-hand sides of all
production Production may refer to: Economics and business * Production (economics) * Production, the act of manufacturing goods * Production, in the outline of industrial organization, the act of making products (goods and services) * Production as a stati ...
rules start with a
terminal symbol In computer science, terminal and nonterminal symbols are the lexical elements used in specifying the production rules constituting a formal grammar. ''Terminal symbols'' are the elementary symbols of the language defined by a formal grammar. ...
, optionally followed by some variables. 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 a researcher in formal languages in computing, automata, compiler theory and computer science. She is an Emeritus Professor of Computer Science at the University of California, Los ...
and it bears her name. More precisely, a context-free grammar is in Greibach normal form, if all production rules are of the form: :A \to a A_1 A_2 \cdots A_n where A is a
nonterminal symbol In computer science, terminal and nonterminal symbols are the lexical elements used in specifying the production rules constituting a formal grammar. ''Terminal symbols'' are the elementary symbols of the language defined by a formal grammar. ...
, a is a terminal symbol, A_1 A_2 \ldots A_n is a (possibly empty) sequence of nonterminal symbols not including the start symbol and S is the start symbol. Observe that the grammar does not have
left recursion In the formal language theory of computer science, left recursion is a special case of recursion where a string is recognized as part of a language by the fact that it decomposes into a string from that same language (on the left) and a suffix (on ...
s. 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) is a language generated by a context-free grammar (CFG). Context-free languages have many applications in programming languages, in particular, most arithmetic expressions are generated by ...
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 capa ...
, 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-d ...
will halt at depth .


See also

*
Backus–Naur form In computer science, Backus–Naur form () or Backus normal form (BNF) is a metasyntax notation for context-free grammars, often used to describe the syntax of languages used in computing, such as computer programming languages, document formats ...
*
Chomsky normal form In formal language theory, a context-free grammar, ''G'', is said to be in Chomsky normal form (first described by Noam Chomsky) if all of its production rules are of the form: : ''A'' → ''BC'',   or : ''A'' → ''a'',   or : ''S'' → ...
*
Kuroda normal form In formal language theory, a context-sensitive 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