AI Glossary / Natural language and speech / Intermediate

Terminal symbol

Definition

A terminal symbol is a symbol that appears in the completed strings generated by a formal grammar. In a context-free grammar, terminal symbols are not expanded by production rules, while nonterminal symbols represent categories that can be expanded. A natural-language grammar may treat words as terminals, whereas another grammar may use characters or other tokens.

What it means

The distinction is about a symbol’s role in a particular grammar. Terminals are the vocabulary of the final output; nonterminals help describe how that output is structured.
For example, a grammar might use Noun as a nonterminal and “sensor” as a terminal. A rule can replace Noun with sensor, but the grammar does not continue expanding sensor into another grammatical category.
Terminal does not mean the last symbol in a sentence. Every symbol in a fully derived string is terminal, including the first and middle ones. It also has no connection here with a command-line terminal or a computer display device.

How it works

Define separate sets of terminal and nonterminal symbols together with production rules and a start symbol. In a context-free grammar, a production rewrites a nonterminal on its left-hand side.
The right-hand side may contain terminals, nonterminals, or an empty sequence where the grammar permits it. Derivation continues by expanding remaining nonterminals.
When the result contains only terminals, it is a completed string derivable from the chosen starting point. In a parse tree for such a derivation, the terminal sequence can be read from the leaves in order, apart from notation conventions for empty productions.
Choose the terminal granularity appropriate to the task. Word-level terminals make sense for some linguistic grammars, while a programming-language grammar may operate on tokens produced by a separate lexical analyzer.

Three practical examples

  • A small command grammar treats action words and device names as terminals in the accepted command strings.
  • A sentence grammar uses phrase categories as nonterminals and actual word tokens as terminal leaves.
  • A parser for structured expressions distinguishes grammar categories from punctuation and literal tokens that appear in the input.

Think of it this way

Think of nonterminals as labeled assembly instructions and terminals as the pieces remaining in the completed symbolic product. The analogy is limited because terminals need not be physically indivisible or single characters; they are final only with respect to the grammar’s chosen representation.

Worked example

Consider an invented grammar: Command → Verb Item, Verb → inspect, and Item → sensor. Declare Command as the start symbol, with terminal set {inspect, sensor} and nonterminal set {Command, Verb, Item}.
The derivation Command → Verb Item → inspect Item → inspect sensor ends with two terminal symbols. The first terminal, inspect, is not the last word, showing that terminal is not a positional label.
The intermediate sequence “inspect Item” is not a completed terminal string because Item still needs expansion. It is a sentential form produced during the derivation.
Now imagine a different character-level grammar whose terminals are individual letters. The word sensor would then be represented by several terminals rather than one. That change would concern the grammar’s granularity, not the ordinary meaning of the word. A symbol’s terminal status must therefore be read from the grammar definition.

Illustrative case study

In a fictional project, Moss Commands builds a validator for a small text interface. A developer confuses grammar category names with literal input tokens and accidentally accepts the word Item where a device name should appear.
The team makes the terminal and nonterminal sets explicit and checks completed derivations from the start symbol. Test cases include both valid commands and intermediate-looking strings containing category labels.
The imagined correction clarifies the representation. It does not imply that every category name must be forbidden as ordinary text in all grammars; a different grammar could intentionally include the same spelling as a terminal with a distinct role.

Common misconceptions and mistakes

Terminal does not mean the final position in the input.
It does not necessarily mean a single character or an indivisible linguistic unit.
An uppercase spelling does not automatically make a symbol nonterminal, nor does lowercase automatically make it terminal; those are notation conventions at most.
Finally, the empty string is not an ordinary terminal that appears as a visible character in the output. Grammars allowing empty productions need to distinguish that absence of symbols from a literal token.

Business use

The terminal/nonterminal distinction helps teams design parsers, validators, and structured language interfaces. It prevents confusion between the actual input vocabulary and the categories used to describe its organization.
Document the lexical layer and grammar layer separately when both are present. A tokenizer may produce one token for a number, while the grammar treats that token as a terminal without needing to parse its individual digits again.
Test whether accepted inputs are fully derived from the intended start symbol. Recognizing a mixture of literal tokens and unresolved category symbols should not be mistaken for a completed valid input unless the application explicitly defines such a partial representation.

People also ask

Are terminals always words?

No. They can be characters, tokens, words, or other symbols chosen by the grammar.

Can a terminal occur at the beginning of a string?

Yes. Terminal status is not determined by position.

How do I know which symbols are terminals?

Consult the grammar’s declared symbol sets and rules rather than guessing from typography.

Check your understanding

In a grammar where NP is a nonterminal and “robot” is a terminal, is the intermediate sequence “the NP” necessarily a completed terminal string?

Answer: No. NP remains a nonterminal requiring expansion, assuming “the” is terminal and the sequence is otherwise derivable.

Related terms

  • Start symbol
  • Context-free grammar
  • Parse tree
  • Formal language
  • nonterminal symbol
  • production rule
  • derivation
  • lexical analysis

Learn next

Mark terminals and nonterminals in a tiny grammar, then trace a derivation until no nonterminals remain. Compare character-level and token-level grammars to see why the same written text can have different terminal representations.

More in Natural language and speech

  • Temporal annotation - Temporal annotation is the addition of structured labels describing time-related information in language.
  • Temporal expressions - Temporal expressions are words, numbers or phrases that refer to time.
  • Term weight - A term weight is a numerical value assigned to a term in a text representation or retrieval model to control its contribution to a score.
  • Text corpus - A text corpus is an organized collection of texts assembled for a defined purpose, such as studying language, training a model or evaluating a...
  • Text graph - A text graph is a graph representation built from language material.
  • Text mining - Text mining is the computational analysis of text collections to identify useful patterns, relationships or information.

Sources

Source: Jurafsky and Martin, Speech and Language Processing, terminal and nonterminal symbols in context-free grammars: https://web.stanford.edu/~jurafsky/slp3/19.pdf . Independently consulted sections 19.2 and 19.2.1 defining the terminal/nonterminal sets, production rules, derivations and terminal strings.

Previous: Terminal states Next: Terminal test

  • 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