top of page

Week 1 Practice

EBNF

Practice Set 1

Write an EBNF rule for the lecture room "ML D 28" in which you attend the lecture. It is your choice how many subrules you may choose. Try out different ways to write the EBNF rule and see what you prefer. The main rule should be called <room>.

<building_ml> <= M L
<floor_d> <= D
<twenty_eight> <= 2 8
<room> <= <building_ml>  <floor_d>  <twenty_eight>

Hover to reveal answer

EBNF

Practice Set 1

Write an EBNF rule that displays the time at which the Eprog lecture starts on Tuesday morning. Use the format hh:mm. The rule should be called <start_time>.

<hour_10> <= 1 0
<minute_15> <= 1 5
<colon> <= :
<start_time> <= <hour_10>  <colon>  <minute_15>

Hover to reveal answer

EBNF

Practice Set 1

You have seen that EBNF describes the syntax of a language. Another word that appears in this context is the "semantics" of a language. Briefly explain the difference between the two.

Syntax: The symbolic representation of a language and the rules how to combine the symbols.
Semantics: The meaning of a combination of such symbols.

Hover to reveal answer

EBNF

Practice Set 2

Is the following statement true or false? Reason why or why not.

"The selection control form allows us to select one or none of the symbols."

False: The selection control form requires one symbol to be selected and no more than one.

Hover to reveal answer

EBNF

Practice Set 2

Write an EBNF rule <even_digit> which allows all even digits (including 0) and rejects all odd digits. Do the same for the odd digits and call the rule <odd_digit>.

<even_digit> <= 0 | 2 | 4 | 6 | 8
<odd_digit> <= 1 | 3 | 5 | 7 | 9

Hover to reveal answer

EBNF

Practice Set 2

Write an EBNF rule which allows all even natural numbers including zero. Make sure that no additional preceding zeroes are allowed, but the number 0 itself is allowed. Call the rule <even_number>. You may make use of any EBNF rule seen in the theory part.

<even_digit> <= 0 | 2 | 4 | 6 | 8
<even_number> <= 0 |  (<digit_no_zero> <numbers> <even_digit>)

Hover to reveal answer

That is it.

Practice makes perfect! Keep practising what you learnt in the lecture and you will be a great programmer in no time.

bottom of page