Concrete additive news and tec > Concrete additive news > General knowledge of JavaScript language - re learning JavaScript

General knowledge of JavaScript language - re learning JavaScript

Concrete additive news 2021-07-29 13:52 69

I'm% 26nbsp; Triple drill% 26nbsp;, In% nbsp《

praise is strength, attention is recognition, and comments are love! See you next time

this note is based on the summary of Mr. winter's \

in this relearning series, it will be assumed that you have a certain understanding of JavaScript, CSS and HTML. The process of re learning is actually to help us establish a new order in these past knowledge, that is, the process of establishing knowledge system. In the process of re learning JavaScript, we will take the syntax of JavaScript as a clue and learn the language knowledge of JavaScript from fine to coarse

Languages are classified according to grammar

first, let's talk about the taxonomy of universal languages. We usually speak Chinese. When we go abroad to study or travel, we all need to speak English. I don't know if you have this experience. When you are abroad, because English is not very good, we will put together the key words, and then the grammar is wrong, but foreigners also understand. For example, if we say \ A characteristic of languages like

is that its syntax does not have a strict definition, so we call it \

in the computer, most languages are \

is also classified in formal language. Here, I'll tell you one of them is \

Chomsky pedigree% 26nbsp;: It is a taxonomic pedigree describing the expression ability of formal grammar in computer science. It was proposed by norm Chomsky in 1956. It consists of four levels.

Informal language Chinese, English Formal language (Chomsky pedigree) Type 0: unrestricted grammar -% 26nbsp; As long as you define what language is like Type 1: context sensitive grammar -% 26nbsp; The same combination of words and sentences, its above, below and content are related Type 2: context free grammar -% 26nbsp; The same expression means the same no matter where it is put Type 3: regular grammar -% 26nbsp; A grammar that can be described by regular expressions

in the Chomsky pedigree, 0123 is an inclusive relationship, that is, a context sensitive grammar, which must also belong to type 0, but the reverse is not necessarily

What is production( BNF) Production: in the computer, it refers to a series of statements conforming to grammar rules (BNF) obtained by Tiger compiler after lexical analysis and syntax analysis of the source program Bakonor paradigm% 26nbsp;: That is, Backus normal form (BNF) is a language used to represent context free grammar, which describes a kind of formal language. It is a set of symbols first introduced by John Backus and Peter Naur to describe the syntax of computer language. Terminator: the character that finally appears in the code (% 26nbsp; Terminator and non Terminator (% 26nbsp;) Use angle brackets (% 26nbsp;% 26lt;% 26nbsp;,% 26nbsp;% 26gt;% 26nbsp;) Grammatical structures are divided into basic structures and composite structures that need to be defined with other grammatical structures Infrastructure Terminator Compound structure is called non terminator Quotation marks and characters in the middle represent terminators Can have parentheses *  Indicates multiple repetitions |  Means \ +  Indicates at least once Case:

let's use BNF to express the four familiar operations

The four are far: 1 + 2 * 3 The summation symbol: Number + 、% 26nbsp;-% 26nbsp;、% 26nbsp;*% 26nbsp;、 Non Terminator MultiplicativeExpression AdditiveExpression

when we were young, the four operations we learned were addition, subtraction, multiplication and division. In fact, it has a priority relationship. We can understand it as a% 26nbsp; 1+2x3  Can be split into one% 26nbsp; 1 and% 26nbsp; 2x3  Composed of. Then% 26nbsp; 2x3  Is its substructure, and then% 26nbsp; 2  And% 26nbsp; 3 , This is% 26nbsp; in this structure; Number , Then in the middle is the operator% 26nbsp; *% 26nbsp;。

so when using BNF to describe this remote calculation, we will first define a% 26nbsp; Addition expression% 26nbsp;, The format is:

List of multiplication expressions% 26nbsp; or Addition expression% 26nbsp; +% 26nbsp; Multiplication expression% 26nbsp; or Addition expression% 26nbsp; -% 26nbsp; Multiplication expression

because BNF is recursive, you can use your own expression when defining an expression

then multiplication is similar, except that the expression of multiplication in addition is changed to% 26nbsp; Number  That's it:

Number  or Multiplication expression% 26nbsp; *% 26nbsp; Number  or Multiplication expression% 26nbsp; /% 26nbsp; Number

finally, let's see how it is written in Code:

                     < MultiplicativeExpression>::=% 26lt; Number> |
< MultiplicativeExpression> * % 26lt; Number> |
< MultiplicativeExpression> / % 26lt; Number> |
< AddtiveExpression>::=% 26lt; MultiplicativeExpression> |
< AddtiveExpression> + % 26lt; MultiplicativeExpression> |
< AddtiveExpression> - % 26lt; MultiplicativeExpression> |  

Deep understanding of production

let's try to understand the Chomsky pedigree through production

Terminator: the last character to appear in the code (% 26nbsp; Terminator and non Terminator (% 26nbsp;)

0-type: unrestricted grammar Production:% 26nbsp;?% 26nbsp;::=% 26nbsp;? In unrestricted grammar, multiple non terminators can be generated So you can write freely in unrestricted grammar Type 1: context sensitive grammar Generation:% 26sp;?% 26nbsp;% 26lt; A>% 26nbsp;?% 26nbsp;::=% 26nbsp;?% 26nbsp;% 26lt; B>% 26nbsp;? There are certain restrictions on the writing produced You can% 26nbsp;?% on the left and right 26nbsp; Write multiple non terminators in But what can be changed can only be the front and the back, and it is related And there must be a fixed part in the middle So% 26nbsp;% 26lt; A>% 26nbsp; Previous% 26nbsp;?% 26nbsp; This is% 26nbsp;?% above 26nbsp; That's what follows Type 2: context free grammar Production:% 26nbsp;% 26lt; A>% 26nbsp;::=% 26nbsp;? % 26nbsp;% on the left 26lt; A>% 26nbsp; It must be a non terminator % 26nbsp;?% on the right 26nbsp; It can be written at will. It can be a lot of terminators or a mixture of terminators and non terminators 3-type: regular grammar Production:% 26nbsp;% 26lt; A>% 26nbsp;::=% 26nbsp;% 26lt; A>% 26nbsp;?% 26nbsp; ✅,% 26nbsp;% 26lt; A>% 26nbsp;::=?% 26nbsp;% 26lt; A>% 26nbsp; ❌ Regular grammar requires If the regular grammar is recursively defined, then it does not allow you to have this definition a on the tail If the symbol on the left is% 26nbsp;% 26lt; A>% 26nbsp;, According to this rule, all regular grammars can be represented by regular expressions

that JavaScript is% 26nbsp; Context sensitive grammar% 26nbsp;,% 26nbsp; Context free grammar% 26nbsp; Or% 26nbsp; Regular independent grammar% 26nbsp

JavaScript generally belongs to context free grammar, and most of its expressions belong to regular grammar, but there are two special cases:

A new% 26nbsp; * *% is added to the JavaScript expression 26nbsp; Operator,% 26nbsp; * *% 26nbsp; Represents the power The power operator is actually a right combination. For example, 2 * * 1 * * 2 results in 2 Here, because 1 * * 2 is calculated first, the second power of 1 is 1, and then the first power of 2 is 2, so the final result is 2 instead of 4 So because it's right associative, it's not a regular grammar If these judgments are added, it will not be a regular grammar For example,% 26nbsp; get If we are writing% 26nbsp; get a {return 1}  Then get is something like a keyword But if we're at% 26nbsp; get  Add% 26nbsp;:% 26nbsp;,

so if we understand it strictly according to the Chomsky pedigree, then% 26nbsp; JavaScript belongs to context sensitive grammar% 26nbsp;. In the implementation of JavaScript engine, IELTS zero foundation can be understood as the structure of multi-body programming, which is aimed at context free grammar. Once encountered, such as% 26nbsp; get  Where such context is relevant, some special cases will be handled separately with code. Therefore, generally speaking, JavaScript will not be classified as context sensitive grammar

Other production

in addition to the Chomsky lineage, which can be defined by BNF, there are actually many different types of production. For example, EBNF and ABNF, which appeared later, were grammatical extensions based on BNF. Therefore, generally speaking, each language standard will customize a production writing method

for example, in javascript:

AdditiveExpression +
AdditiveExpression -

it starts with% 26nbsp; Indent% 26nbsp; Is equivalent to% 26nbsp; Non terminator% 26nbsp; to the left of production;, The non terminator is followed by a colon, followed by an indentation of two spaces. Then, in the standard of JavaScript, its non terminator, plus sign and minus sign are represented by bold black font 26nbsp; Therefore, there are many kinds of production on the Internet. You can't understand all languages by learning only one BNF.% 26nbsp;. Although they all have different standards and writing methods, their meanings are basically the same 26nbsp; Therefore, we need to understand the ideas and principles behind production, so we can ignore the differences in expressions

Classification of modern languages Special cases of modern language

C++  % 26nbsp; *% in 26nbsp; It may express a multiplier sign or pointer, which depends on whether the identifier in front of the asterisk is declared as a type

VB  % 26nbsp;% in 26lt;% 26nbsp; It may be the less than sign or the beginning of the XML direct quantity, depending on whether the current location can accept the XML direct quantity

Python  % 26nbsp; at the beginning of the line; tab