Compilation Principle Answers After Class

1. Judgment questions

1. A syntax tree represents all the different derivation processes of a sentence pattern, including rightmost derivation and leftmost derivation.

2. There may be two different grammars G1 and G2, one is ambiguous and the other is unambiguous, but L(G1)=L(G2).

3. Variables hold both lvalues ​​and rvalues, while constants and expressions with operators are generally considered to hold only rvalues.

4. The language defined by grammar G: S→bA, A→aA|a is the set of all strings starting with b followed by at least one a.

5. Suppose grammar G: S→S*S | S+S | (S) | a This grammar is ambiguous.

6. Regular grammar must not be ambiguous.

7. Context-free grammar can produce language: L={ anbnci| i>=1, n>=1 }.

8. There is no formal grammar that can produce language: L={anbn| n>=1}.

9. For every left linear grammar G1, there exists a right linear grammar G2 such that L(G1)=L(G2).

10. Languages ​​produced by regular grammars can be described by context-free grammars.

11. Context-free grammar has stronger descriptive power than regular grammar.

12. Grammatical ambiguity and language ambiguity are conceptually the same, that is to say, for a language, there cannot be more than two grammars to describe it.

13. Ambiguity can be determined, that is to say, such a program can be compiled. After inputting the grammar, the program can give an exact answer whether the grammar is ambiguous.

14. The descriptive statement is intended to define the nature of the name. The compiler registers these properties in the symbol table and checks whether the references and descriptions of the names in the program are consistent. In fact, many description statements cannot be translated into corresponding object code.

15.C language is a language that allows nested definition of subprograms.

2. Multiple choice questions

1. Chomsky divided grammar into four types, type 0, type 1, type 2 and type 3. Type 3 grammar is also called ( ), and type 2 grammar is also called ( ).

A. Context-free grammar B. Context-sensitive grammar     C. Regular grammar      D. Phrase grammar

2. Many widely used languages, such as Fortran, C, Pascal, etc., belong to ().

A. Mandatory language      B. Application language C. Rule-based language D. Object-oriented language

3. Let G be a grammar and S be the start symbol. If S⇒*α, α∈(VT∪VN)*, then α is said to be a ( ).

A. Sentence             B. Sentence pattern           C. Derivation D. Language

4. Among the three elements usually included in a data type, there is no () below.

A. Attributes used to distinguish data objects of this type

B. The values ​​that a data object of this type can have

C. Memory allocation for data objects of this type

D. Operations that can be performed on data objects of this type

5. Chomsky divided grammar into four types, among which ( ) is also called regular grammar

A. Type 0 B. Type 1 C. Type 2             D. Type 3

6. The lexical rules of a language are generally described by Chomsky’s ( ) type grammar:

A. 0              B. 1             C. 2           D. 3

7. In the grammar G[S]: S→(L)|a L→L,S|S, the following are the terminal symbols in this grammar.

A. S              B. ,            C. L           D. |

8. The language described by grammar G is the set of ( ).

A. The symbol string consisting of all the symbols in the alphabet of grammar G

B. All symbol strings in the closure * of the alphabet of grammar G

C. All symbol strings derived from the identification symbols of grammar G

D. All terminal symbol strings derived from the identification symbols of grammar G 

9. Language L={αcα| α∈(a|b)*}, this language is ( ) language.

A. Type 3 language B. Type 2 language C. Type 1 language         D. Type 0 language

10. Let there be a grammar G[L]: L→L1 | L0 |La | Lc | a | b | c |

The sentences in the following string of symbols that are not part of this grammar are:

A. ab0         B. a0c01         C. aaa            D. bc10

11. Given the grammar G[A]: A→bA|cc, in the following symbol string, the sentence of this grammar is ().

A. bcbc          B. bbbcc        C. bcbcc         D. bccbcc

12. Among the four formal language grammars defined by Chomsky, Type 2 grammar can be identified by ( ).

A. Turing machine; B. Deterministic finite automaton;

C. Pushdown automaton;          D. Nondeterministic finite automaton;

13. If the language defined by grammar G is an infinite set, then the grammar must be ().

A. Context-free      B. Recursive           C. Ambiguous D. Unambiguous

14. The language defined by grammar G[S]: S→aaS|abc is ().

A. {a2kbc|k>0}       B. {akbc|k>0}<br>     C. {a2k-1bc|k>0}      D. {akakbc|k>0}

15. Grammar: G[S]: S→xSx | The language recognized by y is ().

A. xyx B. (xyx)* C. x*yx*             D. x n yx n (n≥0)

3. Fill in the blanks

1. Assume that G is a grammar, α is a string composed of terminal symbols and non-terminal symbols, and S is the start symbol of the grammar. If S=>*α, then α is said to be a [sentence pattern ] .

2. In the assignment statement, the variable names on the left and right sides of the assignment symbol ':=' play two different roles. In order to distinguish these two characteristics of a name, we call the [unit address] represented by a name as The lvalue of the name refers to the [ value ] of a name as the rvalue of the name.

3. For Grammar G, a sentence pattern containing only terminal symbols is called a [ sentence ].

4. Suppose there is a grammar G[E], some of its productions:   

E→E+T   E→T   T→T*F   T→F    F→(E)   F→a   则VN={E,T,F},VT={ +,*,(,),a}。

5. The set of [ sentences ] produced by grammar is the language produced by grammar.

6. Type 3 grammar defined by Chomsky grammar can be divided into [ right linear grammar ] and [ left linear grammar ].

7. The four components of a context grammar G are: start symbol, [ production set ], [ terminal set ], and non-terminal set.

8. Known language: {anbnambm|n, m≥0}, its grammar is defined as:

G=({a, b}, {S, A, B}, S, P), where P is: [ S-> AB ]; [ A->aAb| ε ]; [ B->aBb| ε ] .

9. It is known that the grammar of a certain language is defined as: G=({1, 0}, {S, A}, S, P),

And P: S→1A0|A|ε; A→0A1| ε, then the language is [ a n | n>=0 ].

10. It is known that a certain language is {wcwR|w∈{a, b}*}, and its grammar is defined as G=({a, b, c}, {S}, S, P), where P is: { S ->aSa|bSb| ε }.

11. The so-called rightmost derivation means that any step α→β is a replacement for [ any step α→β is a 1 replacement for the rightmost non-terminal symbol in α ].

12. Grammar G[S]: S→aA|a, A→aS is a [ 3 ] type grammar, and its determined language is: [ a 2 n+ 1 | n>=0 ].

13. We say that G=(VT, VN, S, P) is a type 0 grammar, if each of its productions α → β is such a structure: α∈[ (V T U V N ) * ] and Contains at least one non-terminal symbol, and β∈[ (V T U V N ) * ].    

14. If a sentence in a grammar corresponds to two or more different grammar trees, the grammar is called an " ambiguous grammar ".

15. Suppose A→α is a production, and α, β∈(VT∪VN)*, if αAβ=>αγβ, then αAβ directly deduces αγβ; or, αγβ is a [direct derivation] of αAβ .

If α1=>α2=>…=>αn, then this sequence is said to be a [ sentence pattern ] from α1 to αn .

Guess you like

Origin blog.csdn.net/m0_70711364/article/details/131747111