SD05 - Grammars 1 Flashcards

1
Q

What is a language?

A

A sequence of symbols

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

What is a grammar?

A

A formal description of a language - a set of rules which define what a valid sentence looks like

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

What is a parser?

A

A machine which takes a sentence in a language and determines whether or not it adheres to the grammar

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

What is the syntax of a language?

A

How sentences are formed, not what they mean

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

Why are FSAs not desirable for parsing languages?

A

They look at input strings one character at a time which is not a ‘natural’ way to think about languages. We tend to think in terms of words

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

What are the two elements of grammars?

A

Non-terminals (or productions): patterns to match

Terminals (or literals): symbols that actually appear in the input string

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

Is it possible to have a language which contains infinitely many sentences?

A
Yes
The following grammar can be of infinite length if we keep substituting A for 0A1
A → 0 A 1
A → 0 B 0
B → *
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the 4-tuple of a grammar?

A
G = (N, T, P, N0
)
Where:
- N is a set of non-terminals
- T is a set of terminals
- P is a set of productions mapping non-terminals to a sequence of non-terminals and terminals
- N0 is the initial non-terminal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a derivation?

A

A particular sequence of production applications that yields a string in the language (All symbols are terminals)

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

What is a context-free grammar?

A

A grammar where any production can be used regardless of where it is in the string

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

In a grammar, what does the ‘|’ symbol mean?

A

It separates two different expansions for the same non-terminal e.g.:
A -> 0A1 | 1

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

In a grammar, what does the ‘ε’ symbol mean?

A

It is the empty production, producing no output.

0ε1 = 01

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