Legal derivation

from Wikipedia, the free encyclopedia

A legal derivation (also legal canonical derivation , English rightmost derivation ) is in theoretical computer science a sequence of derivation steps in which the rightmost so-called non - terminal symbol is always replaced by the application of a production rule. It is important for the compiler construction because with it the syntax tree for a certain class of programming languages ​​( LR (k) languages ) can be calculated easily.

In order to generate formal languages such as programming languages, formal grammars are set up with which words can be derived and generated according to their production rules . The legal derivation is a series of steps which, starting from a start symbol, generates a word in formal language. In formal grammars, the so-called non-terminal symbols of derived words are used to describe the internal structure of the language. These non-terminals could (in context-free grammars ) at every point of a word replaced are. In the case of the right derivative, you commit yourself to always replacing the rightmost non-terminal. Whenever the one furthest to the left is replaced, it is called a left derivative .

example

Let it be a grammar with the non-terminal symbols , the terminal symbols , the start symbol and the following production rules :

There are two legal derivatives for the word , which shows that the grammar is ambiguous. Therefore it should not be used to describe formal language .

Legal derivative 1:

Legal derivative 2:

If there is no grammar for a language that has only one legal derivative for each word in the language described, it is called an inherently ambiguous language . With a clear grammar, the syntax tree that matches the derivation can be generated with an LR parser .

See also

swell

Web links