Question 1 syntax, semantics, BNF XBNF
a. Define the following terms:
syntax,
semantics,
grammar,
parser,
and
ambiguity.
b. Discussion: Which of the above should you have (or not have) in your Language Reference Manual? Why?
c. Who needs to read language descriptions? List names of types of people.
d. What was BNF used for? What does BNF stand for? Who developed it?
e. What was EBNF used for? What does the E in EBNF stand for?
f. Give an example defining the same simple piece of syntax in BNF and EBNF that shows how they differ.
Question 2
a. Give 4 different examples of syntactically correct examples of
while statements in C/ C++/Java. (Not complete programs, just single
complete while-statements)
b. Give an XBNF definition* of a C/C++/Java while statement in terms of expression and statement.
c. Translate your previous answer into BNF definitions in terms of <expression> and <statement>.
d. Show parse trees for each of your examples using your BNF. If any don't fit, either revise the example of the XBNF and BNF.
Question 3
a. Give 4 examples of a syntactically valid for a C/C++/Java if statement.
Include both if and if-else examples.
b. Give some XBNF definitions that define a C/C++/Java if statements in terms of expression and statement. The definitions must define the syntax of both the if and if-else alternative forms.
c. Translate your previous answer into BNF definitions using <expression> and <statement>.
d. Draw the parse trees for each of your 5 examples using your BNF.
e. If any don't fit, either revise the example of the XBNF and BNF.
Question 4
Express the following informal syntax rules in XBNF:
1*2
1*2+3
1*2+X*Y+4*a*c
2+1*(1+2*3)
4*a*c
4
a
(1+2*3)
(1*2+X*Y+4*a*c)
(2+1*(1+2*3))
Note: this is a very common pattern in syntax descriptions that defines the precedence of operators.
See
[ Answer 4 ]
below.
Question 5
You are designing a new language. In what ways can you define its syntax?
Which do you choose to use? Why?
Question 6
Give an example of how your project team described the syntax of its
language.
(I have put this in previous finals.... however you won't be able to answer it until the end of your project)
1*2
1*2+X*Y+4*a*c
1+2*3
2+1*(1+2*3)
4*a*c
4
a
(1+2*3)
(1*2+X*Y+4*a*c)
(2+1*(1+2*3))