It has always been said that the Knowledge Network is woven and the existing nodes are used to create new nodes, but it is still not doing well. Today we see this example of grammar explanation, we have truly realized the huge benefits brought to us by weaving knowledge networks.
What do grammar give you? Abstract? Obscure? Alibaba Cloud? Shenma Terminator, alphabet, generative form, closure, automatic machine ...... Dizzy
But after reading the example below, you will sigh: It turns out to be a grammar!
Grammar is the formal rule used to describe the syntax structure of a language. Therefore, first of all, there is such an understanding that grammar isSyntax.
Example (from: Software Designer exam ):
Zhang San and Li Si are engineers.
It consists of five words: Zhang San and Li Si are engineers.
Make up a sentence: it consists of a subject and a predicate. We know Chinese grammar:
<Sentence> --> <subject> <predicate>
<Subject> --> <noun phrase>
<Term phrase> --> <term phrase>
<Predicate> --> <verb-bin phrase>
<Verb-object phrase> --> <verb> <Object>
<Object> --> <term>
<Term> --> engineer Zhang Sanwei, Li siyong
<Conjunction> --> and
<Verb> --> Yes
In the preceding example, all the operators used <> include "non-Terminator", and all those directly written are "Terminator". The above rules are "generative ".
Based on the above statement, let's look at the following concepts.
Non-Terminator: it is not a part of the language, but a placeholder in the derivation process. It must be replaced with a Terminator.
Terminator: the language is the final part.
Formula: Use a terminator to replace a non-terminator rule.
Start character: a symbol that can start with a language. In this example, <subject> is the start character.
The obscure concept is much clearer.
Based on the above formula, let's look at how the sentence is derived:
<Sentence >=> <subject> <predicate>
=> <Noun phrase> <predicate>
=> <Term> <conjunction> <term phrase> <predicate>
=> <Term> <conjunction> <term phrase> <verb-bin phrase>
=> <Term and phrase> <verb> <term>
=> Zhang San and Li Si are engineers
We can find that it can also deduce that "Zhang Sanhe and engineer are Li Si". This sentence is in line with the syntax, but there is a semantic problem, therefore, syntax analysis can only identify syntactic errors.
What about lexical analysis? Do you still remember the problems we often analyze?
(0 | 1) * 01 This is a string consisting of 0 and 1 and ends with 01. So it is not difficult to think about how to determine whether the variable name is accurate during program compilation? Create a finite automatic machine that starts with a letter or underline and consists of letters, underscores, and numbers.
Grammar is also easy to understand