AI Glossary / Natural language and speech / Intermediate

Non-terminal symbols

Definition

Non-terminal symbols are grammar symbols that represent categories or intermediate structures and can be expanded by production rules. In a context-free grammar, they organize how terminal symbols combine. Terminals form the final strings; non-terminals describe the structure used to derive or parse them.

What it means

A grammar might use NP for noun phrase, VP for verb phrase, and S for sentence. These labels stand for classes of structures, not literal words that must appear in the output. A rule such as S → NP VP describes one permitted arrangement of those categories.

The distinction is defined by the grammar, not by capitalization or the everyday meaning of a name. Uppercase labels are a convention. In a programming-language grammar, a non-terminal might be called expression or statement; a quoted keyword can be a terminal even if it looks like an ordinary word.

This entry uses the context-free grammar setting common in introductory NLP. Non-terminals occur in other grammar formalisms too, but the allowed production shapes depend on the formalism.

How it works

A context-free grammar specifies non-terminals, terminals, production rules, and a designated start symbol. Each production has a single non-terminal on its left side. Its right side can contain terminals, non-terminals, or, where permitted, the empty string.

Generation begins with the start symbol and repeatedly replaces a non-terminal using an applicable production. A completed derivation contains only terminals. Parsing works from an observed terminal sequence to one or more structures licensed by the grammar.

A non-terminal can expand recursively, allowing a finite grammar to describe arbitrarily long strings. Recursion does not ensure every expansion path terminates. A useful grammar also needs reachable productive structures: a label with no route to terminals cannot contribute a completed string along that route.

Three practical examples

  • Language parsing: label a span as a noun phrase so a parser can represent its role within a larger sentence structure.
  • Command validation: define categories such as ACTION and ITEM to specify which simple command forms an application accepts.
  • Structured generation: constrain an output format with grammar rules, while separately checking that its content is meaningful and appropriate.

Think of it this way

Think of a non-terminal as a labeled space in a construction plan that must be filled according to a rule. A completed structure contains the actual materials, while the labels explain how it was assembled. The analogy is limited because recursive grammars can reuse the same category at many depths and can assign several structures to the same final string.

Worked example

Define a tiny command grammar with non-terminals S, ACTION, and ITEM. Its rules are S → ACTION ITEM; ACTION → “open” | “close”; ITEM → “file” | “folder”. The four terminals are open, close, file, and folder.

One derivation is S ⇒ ACTION ITEM ⇒ open ITEM ⇒ open folder. There are three rule applications, and the final string contains two terminal symbols. Under these rules, the grammar generates exactly four strings: open file, open folder, close file, and close folder. The count is two action choices multiplied by two item choices.

The string “open ACTION” is not a completed command in this grammar because ACTION is a category label, not an allowed terminal there. The grammar also says nothing about whether a particular folder exists or whether opening it is authorized. Syntactic membership does not establish operational validity.

Illustrative case study

Fictional case: Alder Forms uses a grammar to generate concise status commands. A developer accidentally places the label ITEM in a quoted terminal position, so generated text contains the word “ITEM” instead of an actual object category.

The team reviews the distinction between grammar notation and emitted text, then tests every output of the small grammar. It keeps a separate validation step for available objects and permitted actions. This illustrates a modeling correction, not an instruction to execute any generated command.

Common misconceptions and mistakes

A non-terminal is not an unfinished word and need not correspond to a single token. One NP can cover several words, while a lexical category can expand to a single terminal. Terminals themselves need not always be words; a grammar can use characters or other defined units.

Do not assume every non-terminal eventually terminates on every expansion path. Also, not every grammatically permitted string has exactly one parse. Ambiguity means that a terminal string has more than one distinct parse tree (equivalently, more than one leftmost derivation); changing only the order of independent expansions does not create ambiguity.

Business use

When using grammars in a business system, document category meanings and the start symbol. Test that intended inputs are reachable, invalid arrangements are rejected, and recursive rules behave as intended. Keep the grammar's tokenization aligned with the actual parser.

For structured AI output, a grammar can enforce a shape but cannot by itself verify factual accuracy or business permissions. Evaluate those separately. When a parser rejects ordinary user language, check the grammar's coverage before concluding that the user's wording is wrong; a small formal grammar is only a model of the accepted input language.

People also ask

Is S always the start symbol?

No. S is conventional in many examples, but the grammar explicitly chooses its start symbol.

Can a rule contain only terminals on the right?

Yes. A non-terminal may expand directly to terminal material.

Can non-terminals disappear?

A production to the empty string can remove a non-terminal where the grammar permits it. Empty-string behavior must be handled correctly by the parsing algorithm.

Check your understanding

In NP → Det Noun and Det → “the,” which symbols are non-terminals and which is terminal?

Answer: NP, Det, and Noun are category symbols in these rules; “the” is terminal material. Noun still needs an appropriate expansion before that branch yields a completed phrase.

Related terms

  • Context-free grammar
  • Terminal symbol
  • Start symbol
  • Parse tree
  • Syntactic parsing (computational linguistics)
  • production rule
  • derivation
  • recursion
  • syntactic parsing

Learn next

write a grammar with two categories and enumerate its finite outputs before adding recursion. Draw one derivation tree, then compare the leaves with the internal labels. Finally test a deliberately ambiguous grammar to see why a terminal string may admit more than one structure.

More in Natural language and speech

  • Noisy text analytics - Noisy text analytics is the analysis of text whose spelling, formatting, segmentation, or other characteristics differ from the conventions expected by a...
  • Non-capturing group - A non-capturing group is a regular-expression group that organizes part of a pattern without assigning that group a captured substring.
  • Non-native speech database - A non-native speech database is an organized collection of recordings from people speaking a language they acquired beyond their first-language background...
  • Noun - A noun is a grammatical word class whose members commonly refer to people, places, objects, events, substances, or abstract concepts.
  • Noun phrase - A noun phrase is a grammatical constituent that behaves as a nominal unit, often built around a noun with optional determiners, modifiers, or complements.
  • Nyquist frequency - Definition: The Nyquist frequency is half a signal's sampling rate. For a recording sampled 16,000 times per second, it is 8,000 hertz.

Sources

Sources: Jurafsky and Martin, Speech and Language Processing, Chapter 19, formal grammar symbols and derivations: https://web.stanford.edu/~jurafsky/slp3/19.pdf . NLTK, nltk.grammar module, implementation reference for grammar objects: https://www.nltk.org/api/nltk.grammar.html . The four-command grammar and Alder Forms scenario are original examples; no real command execution is involved.

Previous: Non-sampling error Next: Non-uniform memory access

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer