• 沒有找到結果。

Scopes of the variables are intercrossed sometimes

N/A
N/A
Protected

Academic year: 2021

Share "Scopes of the variables are intercrossed sometimes"

Copied!
9
0
0

加載中.... (立即查看全文)

全文

(1)

壱、 Mark each statement true or false ( 20 cents )

1. Scopes of the variables are intercrossed sometimes.

2. Yacc can not use ambiguous grammars.

3. Both DFA and NFA can recognize regular set.

4. A grammar is ambiguous if it has two different derivations or two different parse trees for a sentence.

5. Grammars with left recursion eliminated are LL(1).

6. All LL(1) grammars can be parsed by LALR parser.

7.Code generation depends on detailed information about the target architecture, and doesn’t care the characteristics of the source language.

(2)

symbol table is HASH table.

9. An L-value can not occur on the right of an assignment statement.

10.An intermediate representation is a kind of machine language with committing to too much machine-specific detail.

弐、 Single Choice (15 cents)

1. Strings over the alphabet {a,b,c} where the length of the string is even can be generated by regular expression ___:

[A]. ((a | b | c)(a | b | c))*

[B]. (a | b | c)(aa | bb | cc)*(a | b | c) [C]. (aa | bb | cc)*

[D]. (a | b | c)*

2. Which of the following is not only found in a stack frame (activation record)?

[A] static variables [B] return address [C] saved registers [D] parameters

(3)

3. The elements in a LR Parsing table are labeled with the following kinds of actions except___?

[A]. Shift [B]. Goto [C]. Accept [D].

Push

4. In the production B→αAγ, Which would not be in the FOLLOW(A) Set?

[A]. ε [B]. FIRST(γ) [C]. FOLLOW(B) [D]. $

5. Which grammar parser below is the least powerful?

[A]. LL(0) [B]. LR(0) [C]. SLR [D].

LR(1)

6. Here is a grammar:

X→a X→ Y→b Y→X Z→c Z→XYZ W→d W→XY Which symbol is not nullable?

[A]. X [B].Y [C].Z [D].W

(4)

7. Which element would not appear in the stack of LR parser?

[A].terminal [B].nonterminal [C].$

[D].state

8. Normally, we do error recovery with methods except ____?

[A]. add error production [B].

modify the parsing tables

[C]. eliminate the conflict [D].

modify the parsing engine

9.Which of the following is commonly found in a stack frame (activation record)?

[A] fp pointer [B] sp pointer

[C] static variable [D] global variable

10. Many compilers are divided into two

(5)

largely independent passes: a front end, responsible for analyzing source code, and a back end, responsible for

generating target code. (They may also include a third, intermediate phase,

responsible for code improvement.) What is the most important motivation for this division into passes?

[A] to provide portability of compiler [B] to facilitate division of labor when a

compiler is built by a large team of programmers

[C] to minimize memory requirements on modern machines

[D] to facilitate debugging the compiler 参、 Questions ( 65 cents)

1. Please explain the meaning of the leftmost derivation. (5 cents)

2. Convert the following NFA to DFA. You

(6)

need to show the conversion steps. (8 cents)

3. Minimize the following DFA. You need to show the minimization steps. (6 cents)

4. Consider the following grammar: (12 cents)

S→ A B A→ a

(7)

A→ + A→ ( S ) B→ A B B→

Calculate nullable, FIRST and FOLLOW for nonterminals in the grammar.

5. Show that the following grammar is LR(1) but not LALR(1), firstly you should modify this grammar with new start symbol. (15 cents)

S→ a A d S→ b B d S→a B e S→ b A e A→ c B→ c

(8)

6. Consider an example in Tiger language:

(11 cents) 1 let 2

3 function f(a: int, b: int, c: int) = 4 (

5 let var j := a+b;

6 var c := a*a+b*b 7 var a := “hello”

8 in

9 print(a); print(j); print(c)

10 end

11 print(b) 12 )

13

14 in

15 f(10, 20, 30) 16 end

Suppose hash(a)=5, hash(b)=3, hash(c)=8, hash(j)=8, and imperative-style environments are used.

(9)

(1) Show the symbol table when line 8 is compiled

(2) Show the symbol table when line 11 is compiled.

7. Show the activation record of the function ABC that is called. Show the frame pointer and stack pointer. ( the runtime stack grows from higher to lower memory addresses, integer variables require 2 bytes of storage, char variables require 1 byte of storage, double variables require 8 bytes of storage, addresses require 4

(10)

參考文獻

相關文件

好了既然 Z[x] 中的 ideal 不一定是 principle ideal 那麼我們就不能學 Proposition 7.2.11 的方法得到 Z[x] 中的 irreducible element 就是 prime element 了..

Wang, Solving pseudomonotone variational inequalities and pseudocon- vex optimization problems using the projection neural network, IEEE Transactions on Neural Networks 17

volume suppressed mass: (TeV) 2 /M P ∼ 10 −4 eV → mm range can be experimentally tested for any number of extra dimensions - Light U(1) gauge bosons: no derivative couplings. =>

For pedagogical purposes, let us start consideration from a simple one-dimensional (1D) system, where electrons are confined to a chain parallel to the x axis. As it is well known

The observed small neutrino masses strongly suggest the presence of super heavy Majorana neutrinos N. Out-of-thermal equilibrium processes may be easily realized around the

Define instead the imaginary.. potential, magnetic field, lattice…) Dirac-BdG Hamiltonian:. with small, and matrix

incapable to extract any quantities from QCD, nor to tackle the most interesting physics, namely, the spontaneously chiral symmetry breaking and the color confinement.. 

(1) Determine a hypersurface on which matching condition is given.. (2) Determine a