Nepedia
Back to Discover
Advanced Reader
🔢

Formal grammar

math Maturity 11-13 Next article →

A formal grammar is a mathematical system used to generate strings of symbols. It acts as a set of rules for rewriting specific symbols into every possible combination allowed by a language. Importantly, a formal grammar describes only the form or syntax of these strings. It does not describe what the strings actually mean. In applied mathematics, the study of these systems is called formal language theory. This field is essential to theoretical computer science, mathematical logic, and theoretical linguistics.

To understand the mechanism, you must look at the components of a grammar. A grammar consists of a set of nonterminal symbols and a set of terminal symbols. Nonterminal symbols are placeholders that can be replaced. Terminal symbols are the final characters that cannot be changed further. The system also includes a designated start symbol, often called the sentence symbol. The core of the system is a set of production rules. Each rule has a left-hand side and a right-hand side. To use a rule, you find the left-hand side in a string and replace it with the right-hand side.

Terminal and non-terminal symbols example
Terminal and non-terminal symbols example

This process creates a sequence of transformations. You begin with the single start symbol and apply rules repeatedly. If a rule replaces a string with an empty string, it is called an erasing rule. The process continues until the string contains only terminal symbols. Once all nonterminal symbols are gone, the result is called a sentence. If there are multiple different ways to generate the exact same sentence, the grammar is described as ambiguous. This ambiguity can make a grammar more complex to analyze or use in computing.

In 1956, Noam Chomsky proposed a formalization known as generative grammars. He organized these grammars into a system called the Chomsky hierarchy. This hierarchy classifies grammars based on how strict their production rules are. The more restrictions a rule has, the fewer languages that grammar can express. This classification helps scientists understand the expressive power of different systems. It allows researchers to group languages by their mathematical complexity.

One level in the hierarchy is the regular grammar, also known as Type 3. These are the most restricted grammars. In a regular grammar, the left-hand side must be a single nonterminal symbol. The right-hand side is also limited to a terminal, an empty string, or a terminal followed by a nonterminal. All languages created by regular grammars can be recognized by a finite-state machine. Another important type is the context-free grammar, or Type 2. In these, the left-hand side must be a single nonterminal symbol, but the right-hand side can be more complex. Context-free languages are widely used because parsers for them can be implemented efficiently.

Formal grammar is also used to build parsers. A parser is a computing function that determines if a string belongs to a specific language. If the string follows the rules, the parser accepts it. If not, the parser identifies it as grammatically incorrect. To describe these parsers, scientists use automata theory. This study has shown that it is impossible to design a recognizer for certain formal languages. This discovery is linked to the concept of undecidable problems in mathematics.

Grammars are also connected to how we understand meaning through compositional semantics. This practice suggests that the meaning of a string is structured by its syntax. To find the meaning, one can break a string into parts to find its analyzed form. In computer science, this is called a parse tree. In generative grammar, it is known as the deep structure. By analyzing these structures, researchers can move from the form of a string to its actual meaning. This connection links the rigid rules of math to the complex patterns of human language.

626 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (1)
File:Terminal and non-terminal symbols example.png
Terminal and non-terminal symbols example.png
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.