Chapter Four Lexical Analysis
Article Directory
- (1) Word description tool
- 1. Contains: ①Formal grammar ②Formal
- 2. Function
- (2) Formal grammar (type 3 grammar)
- 1. Definition:
- 2. Example: (just take a look)
- (3) Regular expression (regular expression) and regular set
- 1. Definition:
- 2. The relationship and difference between normal form and normal set** (the fourth point below has an example)**
- 3. Operator precedence
- 4. Example: (important!)
- 5. Formula (note number seven, push right to left)
- 6. Identifiers and alphanumeric examples
- (3) Conversion between regular grammar and regular expression
- 1. The equivalence of the two
- 2. Regular to regular grammar rules
- 3. Examples of formal to formal grammar
- 4. Regular grammar to regular rules
- 5. Examples of converting regular grammar to regular form
(1) Word description tool
1. Contains: ①Formal grammar ②Formal
2. Function
Describe the composition rules of words, establish lexical analysis technology based on this kind of description tools, and then realize the automatic construction of lexical analysis programs.
(2) Formal grammar (type 3 grammar)
1. Definition:
(The first character on the right of the production must be a terminator)
2. Example: (just take a look)
(3) Regular expression (regular expression) and regular set
1. Definition:
Regular expressions are a convenient tool for describing normal sets
. There are some special character sets in the alphabet Σ——normal sets
2. The relationship and difference between normal form and normal set (the fourth point below has an example)
(The normal form is a formula, and the normal set is a collection of sentences)
3. Operator precedence
'*'> '.'> '|'
'.' And '|' are left associative
('* 'is star closure,' | 'is or,'. 'Is connection)
4. Example: (important!)
5. Formula (note number seven, push right to left)
6. Identifiers and alphanumeric examples
(Regular expressions are easier to understand than regular grammars, and the recognition program can be automatically constructed from a regular expression)
(3) Conversion between regular grammar and regular expression
1. The equivalence of the two
① For any regular grammar, there is a regular form that defines the same language.
② For any regular form, there is a regular grammar that defines the same language.
③ps: As mentioned in the previous chapters, a language can be expressed by multiple regular expressions or multiple regular grammars.