Backus Naur Form Flashcards

1
Q

what does the following symbol mean

<>

A

encloses a synctatic item

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what does the following symbol mean

::=

A

consists of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what does the following symbol mean

|

A

or choice between two items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what does the following symbol mean

{}

A

zero or more repetitions of the content

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

write a BNF definition for a digit assignment

A

?digit? :: = 0|1|2|3|4|5|6|7|8|9
* question marks supposed to be < and >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write a BNF definition for a simple variable assignment like this:

x = 5

A

<assignment> ::= <identifier> "=" <value>
<identifier> ::= "x" | "y" | "z"
<value> ::= <digit> | <digit> <value>
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
</digit></value></digit></digit></value></identifier></value></identifier></assignment>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why can BNF represent some languages that regular expressions cannot?

A

BNF can define context-free grammars, which can handle nested or recursive structures (like parentheses or nested conditionals). Regular expressions can’t handle recursion.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the following BNF define?

<letter> ::= "a" | "b" | "c" | "d"
<identifier> ::= <letter> | <letter> <identifier>
</identifier></letter></letter></identifier></letter>

A

<letter> is a terminal: either a, b, c, or d.

<identifier> is a recursive rule — it allows a single letter or a letter followed by another identifier.
➡ So <identifier> defines a sequence of one or more letters, using only a–d.
</identifier></identifier></letter>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Given the BNF:

<digit> ::= "0" | "1"
<number> ::= <digit> | <digit> <number>

Which of the following are valid <number>s?

A) 10

B) 01

C) 12

D) 110
</number></number></digit></digit></number></digit>

A

✅A) 10 → valid
✅ B) 01 → valid
❌ C) 12 → invalid (2 not allowed)
✅ D) 110 → valid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does this syntax diagram represent?

–>──(a)──>──(b)──>──(c)──>──>

A

This syntax diagram represents the string “abc” — it must be made up of:

the character “a”

followed by “b”

followed by “c”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly