Nepedia
Back to Discover
Fluent Reader
🔢

Formal grammar

math Maturity 11-13 Next article →

Imagine you are playing a game with symbols. You start with one special symbol called a start symbol. You follow a set of rules to change these symbols into new ones. These are called production rules. Each rule has a left side and a right side. You find what is on the left and swap it for the right side.

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

This process is like a language generator. It creates strings of symbols following a specific pattern. A formal grammar does not care about what the symbols mean. It only cares about the form or the shape of the string. This is why it is used in math and computer science.

To understand how this works, you must know about two types of symbols. Terminal symbols are the final parts of a string. They are the end of the line and cannot be changed further. Nonterminal symbols are different because they act as tools for rewriting. You use the production rules to replace nonterminal symbols with new things. You keep doing this until only terminal symbols are left. When a string has no more nonterminal symbols, it is called a sentence. If there are many ways to make the same sentence, the grammar is called ambiguous.

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

In the 1950s, a thinker named Noam Chomsky changed how we look at these rules. He proposed a way to organize them called generative grammars. In 1956, he created the Chomsky hierarchy to group different types of grammars. He found that some rules are stricter than others. Some grammars are very powerful and can express many things. Other grammars have very simple rules and can only express a few things. This hierarchy helps scientists understand the limits of different systems. It shows us which languages can be built and which cannot.

There are several important levels in this hierarchy. Regular grammars are at one level and have very simple rules. They can be understood by a machine called a finite-state machine. Context-free grammars are another important type. In these, the left side of a rule has only one nonterminal symbol. These are often used to build parsers in computers. A parser is a tool that checks if a string follows the rules. Some languages are so complex that a machine cannot even recognize them. This is part of a study called automata theory.

You can see these ideas in the technology you use every day. Computer scientists use formal grammar to help machines understand code. They also use it in linguistics to study how sentences are built. Some people use a method called compositional semantics to find meaning. This involves breaking a string down into parts to see its deep structure. This structure is often shown as a parse tree. By looking at the form, we can understand how the parts fit together. It is a way to turn a messy string into a clear pattern.

483 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.