Compilation Principles Chapter 4 part1 (normal form, normal grammar, operator precedence)

Chapter Four Lexical Analysis

(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:

Insert picture description here
(The first character on the right of the production must be a terminator)

2. Example: (just take a look)

Insert picture description here

(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)

Insert picture description here
(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!)

Insert picture description here

5. Formula (note number seven, push right to left)

Insert picture description here

6. Identifiers and alphanumeric examples

Insert picture description here
(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.

2. Regular to regular grammar rules

Insert picture description here

3. Examples of formal to formal grammar

Insert picture description here

4. Regular grammar to regular rules

Insert picture description here

5. Examples of converting regular grammar to regular form

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44575911/article/details/107112846