Download Quiz 4 - CSE 260 (Fall 2001) - Finite State Machines and Grammar and more Quizzes Discrete Structures and Graph Theory in PDF only on Docsity! CSE 260 (Fall 2001 Sec 1) Quiz 4a 8 Nov Name: 1. (10 pts) Draw the state diagram of a finite machine with output that outputs the exclusive or of the current input symbol and the previous input symbol. The input and output alphabets are both {0, 1}. The machine should always output a 0 after the first symbol is read. 2. (10 pts) Construct a phrase-structured grammer to generate the set of strings {02n1 | n ≥ 0}. You only need to list the productions in the grammar. 1 3. (10 pts) Z Z Z Z Z Z Z Z HHHHHH HH HH H s0 s1 s8 s4 s5 s7 s6 s3 s2 1 0 0 1 s9 1 0 0 1 0 1 0 1 0 1 0 Start 0,1 1 0 1 For each string, indicate if it is accepted by the above finite- state automata. (a) 0101 (b) 11101010 (c) 11111 (d) 10110101 4. (10 pts) Using the grammar below, contruct a complete parse tree (derivation tree) for the expressions on the following page. S −→ E E −→ T // a term in an expression E −→ E + T // addition E −→ E − T // subtraction T −→ F // a factor is a term T −→ T ∗ F // multiplication T −→ T/F // division F −→ I // a variable name, such as (i,j,a,b,etc ) F −→ U // an unsigned number, such as 0 1,2,3,4,5, etc. F −→ (E) // a paranthesized expression F −→ I[E] // an array reference I −→ i // variable names I −→ j I −→ a I −→ b U −→ 2 // integers U −→ 5 // integers 2 CSE 260 (Fall 2001 Sec 1) Quiz 4b 8 Nov Name: 1. (10 pts) Draw the state diagram of a finite machine with output that outputs a 1 if the current input symbol and the previous input symbol are the same, and a 0 otherwise. The input and output alphabets are both {0, 1}. The machine should always output a 0 after the first symbol is read. 2. (10 pts) Construct a phrase-structured grammer to generate the set of strings {13n0 | n ≥ 0}. You only need to list the productions in the grammar. 5 3. (10 pts) Z Z Z Z Z Z Z Z HHHHHH HH HH H s0 s1 s8 s4 s5 s7 s6 s3 s2 1 0 0 1 s9 1 0 0 1 0 1 0 1 0 1 0 Start 0,1 1 0 1 For each string, indicate if it is accepted by the above finite- state automata. (a) 01001 (b) 0000 (c) 011111 (d) 101101111 4. (10 pts) Using the grammar below, contruct a complete parse tree (derivation tree) for the expressions on the following page. S −→ E E −→ T // a term in an expression E −→ E + T // addition E −→ E − T // subtraction T −→ F // a factor is a term T −→ T ∗ F // multiplication T −→ T/F // division F −→ I // a variable name, such as (i,j,a,b,etc ) F −→ U // an unsigned number, such as 0 1,2,3,4,5, etc. F −→ (E) // a paranthesized expression F −→ I[E] // an array reference I −→ i // variable names I −→ j I −→ a I −→ b U −→ 1 // integers U −→ 5 // integers 6 a + b * 5 b [ i - 1 ] * ( i + j ) 7