The following questions are due by the start of class on Tuesday 3 July. The answers to the questions must be typed to be accepted. No late submissions will be accepted. If any outside sources are used they must be cited.
1. Is multiple inheritance supported in Java? Explain your answer.
2. If possible, remove the left recursion from the following grammars, if not explain why you cannot remove the left recursion. (Note : a , b , c , d , and e are terminals )
Z -> T & Z | Z # T | d | e
T -> T ^ F | T # F | F | Z
F - > a | b | c
3. In two or three paragraphs, describe two similarities and five differences between C++ and Java. Be sure to draw upon the material from the video shown in class
4. What role do record variants play in type safety? Illustrate your discussion with an example.
5. If possible, remove the left recursion from the following grammars, if not explain why you cannot remove the left recursion.
Z -> Y % X | Z ( Y ) | 6 | 9
X -> Z * X | X / Y | W
W -> a | b | D
6. Write a method in Java that reverses an array. The code should work for an array of any type except the types that are built into the language (e.g. int, float etc.)
7. Write a program in Java that takes all the strings given as arguments concatenates them and then tokenizes the result using vowels as delimiters. Each token should be printed to the standard output. (Hint: There is a constructor for the StringTokenzer class that takes both the String to be tokenized as well as a string of the characters that act as delimiters.
8. Is it possible to have a language without reserved words?
9. Rewrite the following grammar expressed in EBNF to be in BNF
<g> -> [ <l> ] { a b } <m>
<l> -> z { z }
<m> -> x [ y ] z
10. Given the following BNF:
<exp> -> { <list> } | ( <list> ) | [ <list> ] | <char>
<list> -> <list> , <exp> | <exp>
<char> -> a | b | c | d | e
Show the parse tree (if possible) for
{ ( ( [ a , b, c ] , e ) c, { b } ) }
11. In a couple paragraphs show that any grammar expressed in EBNF may also be expressed in BNF.
12. Under what circumstance is a grammar said to be ambiguous? Illustrate with an example using a specific grammar not from the notes or the book.
13. . Given the grammar below, which has higher precedence “*” or “+”?
LE ::= T { '^' T | '*' T }
T ::= '[' LE ']' | F
F ::= D { '+' D }
D ::= '0' | '1'
14. Translate the following grammar expressed in EBNF into BNF
<goal> -> { a b [ <bar> ] } [<foo>] (<bar> | <baz>)
<bar> -> b [ e ] f
<foo> -> d { d e}
<baz> -> g { g }
14. Give the EBNF and the BNF specification for the language that consists of an odd number of c's followed by either an even number of b's or an even number of a’s.
15. Consider the program below
a) Depict the identifiers accessible from p2 at point {A} if we assume that the language uses static cope rules
b) Depict the identifiers accessible from p1 at point {B} if we assume that the language uses dynamic cope rules. Note that the calling structure is main -> p4 -> p2 -> p3 ->p1
program Question15(input, output) ;
var a,b,c: integer;
procedure p1;
var b: integer;
begin
b := 4;
a := a + b;
{B}
end;
procedure p2;
var b, c : integer;
procedure p3;
var a: integer;
begin
a:= b;
c : = 14;
p1;
end;
begin
b := 10;
c := 20;
{A}
p3;
end;
procedure p4;
begin
p2;
end;
begin { main }
a := 1;
b := 2;
c := 3;
end;
LE ::= T { '*' T | '+' T }
T ::= F { '^' F }
F ::= '[' LE ']' | D
D ::= '0' | '1'