Nepedia
Back to Discover
Advanced Reader
💻

Metasyntax

technology Maturity 11-13 Next article →

Metasyntax is a specialized system of rules used to define the structure of other languages. These other languages can be natural human languages or formal computer programming languages. To describe these languages, scientists use a "metalanguage," which is a language used to describe another language. A metasyntax acts as the blueprint for this metalanguage. It explains how phrases and sentences must be built to be considered correct. Without a clear metasyntax, it would be difficult to define the exact composition of a programming language.

A formal metasyntax is typically composed of three distinct elements: terminals, nonterminals, and metasymbols. Terminal symbols are the simplest building blocks, such as a single word or a specific token. They are stand-alone structures that do not change. Nonterminal symbols represent larger syntactic categories. These categories define a set of valid structures made from a subset of other elements. Finally, metasymbols provide essential syntactic information. They act as the glue or the instructions that show how terminals and nonterminals interact within the rules.

These three elements do not appear in every type of metalanguage. For example, regular languages are used for token-level descriptions. These languages typically do not use nonterminals because they do not require nesting. In contrast, recursive languages, also known as context-free languages, require all three elements. English can serve as a metalanguage to describe other languages, but it does not use formal metasymbols. Instead, it uses standard English expressions to explain how words should be used.

Several formal metasyntaxes have been developed to describe computer languages. Backus–Naur form, or BNF, is a standard convention. In BNF, nonterminal symbols are denoted by angle brackets, like <category>. Terminal symbols are shown using double quotes, like "word". EBNF, or extended Backus–Naur form, includes everything in BNF but adds more features. It uses square brackets to show an optional phrase and curly brackets to show a phrase that repeats zero or more times. Wirth syntax notation, or WSN, is another version. WSN does not always require angle brackets for nonterminals and does not require every nonterminal to be explicitly defined.

Augmented Backus–Naur form, or ABNF, offers even more specific ways to define structure. In ABNF, nonterminals are identified by starting a one-word name with an alphabet character. Angle brackets are not required here. Terminals can be shown with double quotes or through a numeric structure. This numeric structure uses a comma followed by a range of values to define a set. ABNF also has several ways to handle repetition. For instance, a single numeric value before an element means that element repeats a specific number of times. It can also show a range, such as repeating an element at least a certain number of times but no more than a certain limit.

Because these conventions are not yet fully formalized, many variations exist in programming manuals. Some systems move away from using symbols like brackets or quotes. Instead, they use different font types to distinguish between categories. For example, the Ada language uses a lower case sans-serif font to denote syntactic categories. Its terminal symbols consist of characters within a specific code position defined by the ISO/IEC 10646:2003 standard. In the C and Java languages, programmers use italic fonts for categories and gothic fonts for terminals. The J language takes a different path entirely. It uses a metalanguage called Dictionary, which is very similar to English, to explain its syntax.

There are clear advantages to using these extended metasyntaxes rather than the original BNF. The primary goals are to increase simplicity and reduce ambiguity. BNF can become very difficult to read because it uses many opening and closing symbols. It also becomes confusing when the language being described uses marks like apostrophes or quotation marks as actual symbols. By using properties like font style, character case, or specific code positions, newer metasyntaxes make the rules much clearer. These extensions allow for more complex layouts and help programmers understand the rules without unnecessary confusion.

666 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

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.