$30.00
Description

Finite State Automaton (FSA)


Specify a DFA using a transition diagram and a formal FSA speci cation <S, s, F, T> (see lecture 2) that recognizes the following language: \All strings of 0’s and 1’s that, when interpreted as a binary number, are divisible by 4. In other words, value(binary number) modulo 4 = 0.”



Specify a DFA using a transition diagram and a formal FSA speci cation <S, s, F, T> (see lecture 2) that recognizes the following language: \All strings of 0’s and 1’s that, when interpreted as a binary number, its value modulo 4 = 1. “


ContextFree Languages
Are the following languages contextfree or not? If yes, specify a contextfree grammar in BNF notation that generates the language. If not, give an informal argument.

f a^{m}b^{n}c^{o} j m > n 0, o > 0g , with alphabet = fa, b, cg

f a^{n}b^{3n} j n 0 g, with alphabet = fa, bg

f ww^{R} j w 2 and w^{R} is w in reverse g, with alphabet =fa, bg

f a^{n}b^{n}c^{n}d^{m} j n 0, m 0 g, with alphabet = fa, b, c, dg

f w j w has no more than 3 symbolsg, with alphabet =fa, bg

Derivation, Parse Tree, Ambiguity, Precedence & Associativity
A language that is a subset of the language of propositional logic may be de ned as follows:
1
<start> ::= <expr>
<expr> :: = <expr> _ <expr> j
<expr> ^ <expr> j
<expr> ! <expr> j
<const> j <var>
<const> :: = true j false
<var> :: = a j b j c j . . . j z

Give a leftmost and a rightmost derivation for the sentence a _ false ^ b ! false .

Give the corresponding parse trees for the derivations.

Give the corresponding abstract syntax tree (AST).

Show that the above grammar is ambiguous.

Give an unambiguous grammar for the same language that enforces the following precedence and associativity:
^ has highest precedence (binds strongest), followed by _, and then !
^ and _ are left associative, and ! is right associative

Give the parse tree and AST for your new, unambiguous grammar for the sentence
a _ true ^ b ! false _ true .

Extracredit Problem  Fix the grammar for dangling ifthenelse statement (10% more points)
Recall the simple statement grammar we discussed in class:
2
<start> ::= <stmt>
<stmt> ::= <ifstmt> j <assgn>
<ifstmt> ::= if <expr> then <stmt> j
if <expr> then <stmt> else <stmt>
<assgn> ::= <id> := <d>
<expr> ::= <id> = 0
<d> ::= 0 j 1 j 2 j 3 j 4 j 5 j 6 j 7 j 8 j 9
<id> ::= a j b j c j . . . j z
The above grammar will cause ambiguity for parsing the following compound statement:
if x = 0 then if y = 0 then z := 1 else z := 2
Is it possible to change the grammar without changing the language to parse the above statement unambiguously? If not, please give an informal argument. If yes, please provide your solution. Note that you are not supposed to add new terminals (tokens), i.e., delimiters, as it will change the language.
3