fbpx
Wikipedia

Terminal and nonterminal symbols

In formal languages, terminal and nonterminal symbols are the lexical elements used in specifying the production rules constituting a formal grammar. Terminal symbols are the elementary symbols of the language defined as part of a formal grammar. Nonterminal symbols (or syntactic variables) are replaced by groups of terminal symbols according to the production rules.

The string "the dog ate the bone" was created using production rules that replaced non-terminal with terminal symbols.[1]

The terminals and nonterminals of a particular grammar are in two completely separate sets.

Terminal symbols edit

Terminal symbols are symbols that may appear in the outputs of the production rules of a formal grammar and which cannot be changed using the rules of the grammar. Applying the rules recursively to a source string of symbols will usually terminate in a final output string consisting only of terminal symbols.

Consider a grammar defined by two rules. In this grammar, the symbol Б is a terminal symbol and Ψ is both a non-terminal symbol and the start symbol. The production rules for creating strings are as follows:

  1. The symbol Ψ can become БΨ
  2. The symbol Ψ can become Б

Here Б is a terminal symbol because no rule exists which would change it into something else. On the other hand, Ψ has two rules that can change it, thus it is nonterminal. A formal language defined or generated by a particular grammar is the set of strings that can be produced by the grammar and that consist only of terminal symbols. Diagram 1 illustrates a string that can be produced with this grammar.

 
Diagram 1. The string Б Б Б Б was formed by the grammar defined by the given production rules. This grammar can create strings with any number of the symbol Б

Nonterminal symbols edit

Nonterminal symbols are those symbols that can be replaced. They may also be called simply syntactic variables. A formal grammar includes a start symbol, a designated member of the set of nonterminals from which all the strings in the language may be derived by successive applications of the production rules. In fact, the language defined by a grammar is precisely the set of terminal strings that can be so derived.

Context-free grammars are those grammars in which the left-hand side of each production rule consists of only a single nonterminal symbol. This restriction is non-trivial; not all languages can be generated by context-free grammars. Those that can are called context-free languages. These are exactly the languages that can be recognized by a non-deterministic push down automaton. Context-free languages are the theoretical basis for the syntax of most programming languages.

Production rules edit

A grammar is defined by production rules (or just 'productions') that specify which symbols may replace which other symbols; these rules may be used to generate strings, or to parse them. Each such rule has a head, or left-hand side, which consists of the string that may be replaced, and a body, or right-hand side, which consists of a string that may replace it. Rules are often written in the form headbody; e.g., the rule ab specifies that a can be replaced by b.

In the classic formalization of generative grammars first proposed by Noam Chomsky in the 1950s,[2][3] a grammar G consists of the following components:

  • A finite set N of nonterminal symbols.
  • A finite set Σ of terminal symbols that is disjoint from N.
  • A finite set P of production rules, each rule of the form
 
where   is the Kleene star operator and denotes set union, so   represents zero or more symbols, and N means one nonterminal symbol. That is, each production rule maps from one string of symbols to another, where the first string contains at least one nonterminal symbol. In the case that the body consists solely of the empty string[note 1], it may be denoted with a special notation (often Λ, e or ε) in order to avoid confusion.
  • A distinguished symbol   that is the start symbol.

A grammar is formally defined as the ordered quadruple  . Such a formal grammar is often called a rewriting system or a phrase structure grammar in the literature.[4][5]

Example edit

Backus–Naur form is a notation for expressing certain grammars. For instance, the following production rules in Backus-Naur form are used to represent an integer (which may be signed):

<digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' <integer> ::= ['-'] <digit> {<digit>} 

In this example, the symbols (-,0,1,2,3,4,5,6,7,8,9) are terminal symbols and <digit> and <integer> are nonterminal symbols. [note 2]

Another example is:

 
 

In this example, the symbols a,b,c,d are terminal symbols and S,A are nonterminal symbols.

See also edit

Notes edit

  1. ^ It contains no symbols at all.
  2. ^ This example supports strings with leading zeroes like "0056" or "0000", as well as negative zero strings like "-0" and "-00000".


References edit

  1. ^ Rosen, K. H. (2012). Discrete mathematics and its applications. McGraw-Hill. pages 847-851
  2. ^ Chomsky, Noam (1956). "Three Models for the Description of Language". IRE Transactions on Information Theory. 2 (3): 113–123. doi:10.1109/TIT.1956.1056813. S2CID 19519474.
  3. ^ Chomsky, Noam (1957). Syntactic Structures. The Hague: Mouton.
  4. ^ Ginsburg, Seymour (1975). Algebraic and automata theoretic properties of formal languages. North-Holland. pp. 8–9. ISBN 0-7204-2506-9.
  5. ^ Harrison, Michael A. (1978). Introduction to Formal Language Theory. Reading, Mass.: Addison-Wesley Publishing Company. pp. 13. ISBN 0-201-02955-3.

terminal, nonterminal, symbols, formal, languages, terminal, nonterminal, symbols, lexical, elements, used, specifying, production, rules, constituting, formal, grammar, terminal, symbols, elementary, symbols, language, defined, part, formal, grammar, nontermi. In formal languages terminal and nonterminal symbols are the lexical elements used in specifying the production rules constituting a formal grammar Terminal symbols are the elementary symbols of the language defined as part of a formal grammar Nonterminal symbols or syntactic variables are replaced by groups of terminal symbols according to the production rules The string the dog ate the bone was created using production rules that replaced non terminal with terminal symbols 1 The terminals and nonterminals of a particular grammar are in two completely separate sets Contents 1 Terminal symbols 2 Nonterminal symbols 3 Production rules 4 Example 5 See also 6 Notes 7 ReferencesTerminal symbols editTerminal symbols are symbols that may appear in the outputs of the production rules of a formal grammar and which cannot be changed using the rules of the grammar Applying the rules recursively to a source string of symbols will usually terminate in a final output string consisting only of terminal symbols Consider a grammar defined by two rules In this grammar the symbol B is a terminal symbol and PS is both a non terminal symbol and the start symbol The production rules for creating strings are as follows The symbol PS can become BPS The symbol PS can become B Here B is a terminal symbol because no rule exists which would change it into something else On the other hand PS has two rules that can change it thus it is nonterminal A formal language defined or generated by a particular grammar is the set of strings that can be produced by the grammar and that consist only of terminal symbols Diagram 1 illustrates a string that can be produced with this grammar nbsp Diagram 1 The string B B B B was formed by the grammar defined by the given production rules This grammar can create strings with any number of the symbol BNonterminal symbols editNonterminal symbols are those symbols that can be replaced They may also be called simply syntactic variables A formal grammar includes a start symbol a designated member of the set of nonterminals from which all the strings in the language may be derived by successive applications of the production rules In fact the language defined by a grammar is precisely the set of terminal strings that can be so derived Context free grammars are those grammars in which the left hand side of each production rule consists of only a single nonterminal symbol This restriction is non trivial not all languages can be generated by context free grammars Those that can are called context free languages These are exactly the languages that can be recognized by a non deterministic push down automaton Context free languages are the theoretical basis for the syntax of most programming languages Production rules editA grammar is defined by production rules or just productions that specify which symbols may replace which other symbols these rules may be used to generate strings or to parse them Each such rule has a head or left hand side which consists of the string that may be replaced and a body or right hand side which consists of a string that may replace it Rules are often written in the form head body e g the rule a b specifies that a can be replaced by b In the classic formalization of generative grammars first proposed by Noam Chomsky in the 1950s 2 3 a grammar G consists of the following components A finite set N of nonterminal symbols A finite set S of terminal symbols that is disjoint from N A finite set P of production rules each rule of the form S N N S N S N displaystyle Sigma cup N N Sigma cup N rightarrow Sigma cup N nbsp dd where displaystyle nbsp is the Kleene star operator and denotes set union so S N displaystyle Sigma cup N nbsp represents zero or more symbols and N means one nonterminal symbol That is each production rule maps from one string of symbols to another where the first string contains at least one nonterminal symbol In the case that the body consists solely of the empty string note 1 it may be denoted with a special notation often L e or e in order to avoid confusion A distinguished symbol S N displaystyle S in N nbsp that is the start symbol A grammar is formally defined as the ordered quadruple N S P S displaystyle langle N Sigma P S rangle nbsp Such a formal grammar is often called a rewriting system or a phrase structure grammar in the literature 4 5 Example editBackus Naur form is a notation for expressing certain grammars For instance the following production rules in Backus Naur form are used to represent an integer which may be signed lt digit gt 0 1 2 3 4 5 6 7 8 9 lt integer gt lt digit gt lt digit gt In this example the symbols 0 1 2 3 4 5 6 7 8 9 are terminal symbols and lt digit gt and lt integer gt are nonterminal symbols note 2 Another example is S cAd displaystyle ce S gt cAd nbsp A a ab displaystyle ce A gt a ab nbsp In this example the symbols a b c d are terminal symbols and S A are nonterminal symbols See also editAlphabet formal languages Chomsky Hierarchy Recursive grammarNotes edit It contains no symbols at all This example supports strings with leading zeroes like 0056 or 0000 as well as negative zero strings like 0 and 00000 References edit Rosen K H 2012 Discrete mathematics and its applications McGraw Hill pages 847 851 Chomsky Noam 1956 Three Models for the Description of Language IRE Transactions on Information Theory 2 3 113 123 doi 10 1109 TIT 1956 1056813 S2CID 19519474 Chomsky Noam 1957 Syntactic Structures The Hague Mouton Ginsburg Seymour 1975 Algebraic and automata theoretic properties of formal languages North Holland pp 8 9 ISBN 0 7204 2506 9 Harrison Michael A 1978 Introduction to Formal Language Theory Reading Mass Addison Wesley Publishing Company pp 13 ISBN 0 201 02955 3 Retrieved from https en wikipedia org w index php title Terminal and nonterminal symbols amp oldid 1192129092 Terminal symbols, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.