Regex and BNF Flashcards

1
Q

What is BNF

A

a notation used to define the grammar of a language. It describes how valid statements are structured using production rules.

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

Why do we need to use bnf

A
  • some expressions cant be expressed with regEx or FSMs
  • this class of languages called context free languages are more expressive than regular langs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

::=

A

equals to

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

<>

A

surrounds category names and non terminal elements

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

what are terminal symbols
what are non terminal symbols

A
  • terminal elements can be broken down
  • non terminal cant be broken down
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is parsing

A

checking an input string against the set of BNF rules to see if its valid

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

parts of a syntax diagram and what are they used for

A

elipse - represents a terminal symbol
rectangle - a non terminal symbol
arrow above rectangle/circle(loop back) - non terminal element that may be used more than once

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

what is syntax

A

strict rules a program must follow regarding their structure

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

what does bnf consist of

A
  • set of terminal symbols
  • set of non terminal symbols
  • set of production rules
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what type of language is BNF

A

meta language

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

what are production rules

A

rules that define the syntax of a language by specifying how symbols can be expanded into other symbols or terminal values.

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

what is a subset

A

A set A is a subset of B (A ⊆ B) if every element in A is also in B.

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

what is a proper subset

A

A set A is a proper subset of B (A ⊂ B) if A ⊆ B and A ≠ B (A has fewer elements than B).

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

What is a countable set?

A

A set is countable if it has the same number of elements as some subset of the natural numbers ℕ.

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

What does ⊂ mean?

A

It means “proper subset” – A ⊂ B means A is contained in B, but B has extra elements not in A.

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

What is membership in set theory

A

If an element x belongs to a set A, we write x ∈ A.

16
Q

What does ⊆ mean?

A

“subset” – A ⊆ B means A is contained in B, but A could be equal to B.

17
Q

What is union (A ∪ B)

A

The union of A and B is a set containing all elements from both A and B.

18
Q

What is intersection (A ∩ B)

A

The intersection of A and B is a set containing only elements that are in both A and B.

19
Q

What is the difference between two sets (A \ B)?

A

A \ B (or A - B) is the set of elements that are in A but not in B.

20
Q

what do these mean:
[01]
{2,4}

A
  • (only 0 or 1 allowed)
  • (length must be between 2 and 4)
21
Q

Explain what this regex means: [a-zA-Z][a-zA-Z0-9]{5,9}

A
  • First character must be a letter (uppercase or lowercase).
  • The next 5 to 9 characters can be letters or numbers
22
Q

Why can’t regular expressions describe nested structures like (()())

A
  • Regular expressions lack recursion.
  • They can’t track nested structures like parentheses, which require context-free grammar (BNF).
23
Q

Why can FSMs recognize regular languages but not context-free ones?

A

FSMs lack memory (they can’t track nested structures), but context-free languages require a stack to keep track of recursion

24
what is a regular language
A regular language is any language that can be recognized by an FSM and described using a regular expression
25
^ and $ meanings
^ - start $ - end