[Analysis of Soft Exam Test Site] Software Designer--Formal and Formal Collection

1. Concept

Normal form and normal set are concepts in the principle of compilation.

The normal form is used to describe a class of words.

A normal set is a collection of words described in a normal form.

Note that the word here is actually a string of symbols, which can be a combination of numbers, letters or other characters.

2. Method

If we have two characters a and b, then there are the following common formal writing methods.

  1. The normal form arepresents a single character a, the corresponding normal set {a}.
  2. Normal form a|b, representing a single character a or b, corresponding to a normal set of 2 elements {a,b}.
  3. Normal form ab, which means that the elements of two characters ab correspond to the normal set with only one element {ab}.
  4. Normal form ab(a|b), ab is the certain part, and then add a or b, corresponding to the normal set {aba,abb}.
  5. Normal form a*, * means any number, corresponding to the normal set {Φ,a,aa,aaa,...}.
  6. The normal form (a|b)*can represent any set of strings composed of a and b, corresponding to the normal set {Φ,a,b,ab,aa,bb...}.

3. Rewriting questions

Problem : A set of strings constructed from a and b and containing only an even number of a, expressed as () in a normal form.
A: (a*a)*b*
B: (b*(ab*a)*)*
C: (a*(ba*)*b)*
D:(a|b)*(aa)*

Analysis :
For A, if the first asterisk is executed 0 times, the second asterisk is executed once, and the third asterisk is executed once, the result is: ab, a is not an even number, an error.
For B, since the two aa in the middle brackets must appear in pairs, there is an even number of as, correct!
For C, the first asterisk is executed once, the second and third asterisks are executed 0 times, and the fourth asterisk is executed once. The result is: ab, a is not an even number, an error.
For D, if the (a|b)execution is a, and the first asterisk is executed once, and the second asterisk is executed once, the result is: aaa, a is not an even number, an error.

Guess you like

Origin blog.csdn.net/woshisangsang/article/details/108052122