Grammars 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 set of formal rules that 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

Machines for taking a sentence in a language and deciding whether or not it adheres to the grammar, possibly performing actions on the way

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 languages/code is meant to be formed, not what they mean

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

Why are grammars important?

A

Almost all computer systems need to represent complex structured data, so storing and reading such data is a core task for a huge range of computer systems

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

What characteristics are looked at to check a sentence

A
  • What symbols we can see
  • Their ordering
  • How they can be combined
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does each rule describe?

A

A pattern against which we match the input string, in terms of literals and other patterns

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

What are the two elements of context free grammars?

A
  • Non terminals (patterns to match)

- Terminals (symbols that actually appear in the input string)

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

Describe the 4 tuple of a CFG

A

N - set of non terminals
T - set of terminals
P - set of productions mapping a non terminal to a sequence of non terminals and terminals
N0 - the initial non terminal

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

What is a derivation?

A

A particular sequence of production applications that yields a string in the language

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

What is a parse tree?

A

Each production expands to a small tree, the leaves of which are terminals

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

What is on the LHS and RHS of productions in a CFG?

A

LHS - a single non terminal

RHS - a sequence of terminals and non-terminals

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

What does it refer to by a context free grammar?

A

Refers to the way that we can always replace a non terminal in a string with the RHS of a corresponding production

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

What is an empty production?

A

A production that generates no output

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

What will happen if a grammar is ambiguous?

A

Any valid sentence will have more than one possible parse tree

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

*

A

Any zero or more characters

17
Q

What are the two approaches to allow repetition in grammars?

A

Repeat the same thing multiple times

Repeat a structure

18
Q

+

A

One or more repetitions

19
Q

What do we want in a good grammar?

A

Unambiguous : a single unique parse
Modular : describe individual, identifiable elements
Reusable : only define the same thing once
Readable : by other programmers
Simple : so we can understand how it fits together