01 defined schema compiler technology (Chapter IV parsing) grammar and syntax
1, the basic concept
1) lexical rules: what is legal or illegal
Alphabet: language allows the use of a set of characters
Glossary: finite strings of characters (string)
Identifier: function name, variable names, etc.
2) the rules of grammar:
Sentence: a "lexical sequence"
To determine the legality of the sentence in the form of
Providing structure of the sentence: if (expression) statement else statement
3) grammar, said:
(1) natural language description
(2) Formal Description (BNF)
(3) transition diagram (FIG syntax)
2, formal description
Terminator, nonterminal production
1) the definition of
2 represents the production)
3) production conventions
(1) Non-terminal symbols, represented by capital letters
(2) start symbol, only one, the first symbol on the left of the production
4) representation of grammar
5) Classification of grammar
(1) Type 0 grammars (unrestricted grammar)
(2) Type 1 grammars (context-sensitive grammar)
(3) Type 2 grammars (context-free grammar)
(4) type 3 grammar (regular grammar, the grammar of Linear)
6) Derivation and protocols
(1) from the sentence to sentence, to replace the production left to the right, from abstract to concrete
(2) from the sentence to sentence, to replace the production left to the right, from the concrete to the abstract
7) sentence and sentences
Sentence: derived from the start symbol any symbol string
Sentence: a sentence consisting only of terminator, terminator with only sentence
Language 8) generated by the grammar G
G of the set of all sentences, denoted L (G)
3, derivation tree (the syntax tree)
Fig display a sentence (sentence) derivation
Inverted tree
- On the roots, leaves next
- Start symbol for the "root"
Derivation Tree summary