Context Free Grammars: Grammar Components & Derivations and Parse Trees Flashcards

1
Q

context-free frammars are written in some variation of ____ ____.

A

backus-Naur Form

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

What is Backus-Naur Form

A

a metalanguage to describe the syntax of other languages especially programming languages

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

The statements of BNF are called ___.

A

productions

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

a context-free grammar consists of a collection of ___.

A

productions

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

what is the input and output of compiler parsers?

A

input: grammar of languages defined in some variation of BNF
output: the actual parser

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

Parsers verify that the … is correct.

A

syntax of a candidate program

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

list the 3 kinds of symbols or tokens of BNF production

A

terminal symbols or tokens
nonterminals
punctuation symbols

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

what are terminal symbols or tokens?

A

the actual lexemes, or words of the programming language

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

what are nonterminal symbols?

A

intermediate symbols that typically correspond to a sequence of tokens

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

T/F: Every different kind of statement in a programming language would have a nonterminal that would be used to define its syntax.

A

True

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

What technique did BNF originally use to distinguish terminal from nonterminal symbols?

A

enclose nonterminals in corner brackets

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

how does the UNIX parser “yacc” differentiate between terminals and non-terminals? What about for single-letter symbols?

A

terminals: all upper case
nonterminals: all lower case
same rule applies

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

T/F: The technique used is unimportant as long as it is clear which symbols are terminals and which are nonterminals.

A

True

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

what does the symbol “::=” mean? what can it be read ass?

A

separates the left and right-hand sides of every production.
“defines” or “can be replaced by”

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

what can variations of BNF use instead of “::=”? (2)

A

right-pointing arrow

single colon

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

T/F: The left side of every production must always be a single terminal symbol.

A

False, nonterminal

17
Q

T/F: The right-hand sides consists of a sequence of nonterminal symbols only

A

False, terminal and nonterminal

18
Q

T/F: productions can have multiple right-hand sides.

A

True

19
Q

What separates the various right-hand sides in a production?

A

vertical bar “|”

20
Q

How do we know when symbols are optional?

A

when they are enclosed in square brackets “[]”

21
Q

how do we know when symbols can be repeated 0 or more times?

A

when they are enclosed in curly braces “{}”

22
Q

In every grammar, one of the nonterminal symbols must be the ____ ____

A

start symbol

23
Q

T/F: It is customary to make the production defining the start symbol, the first production of the grammar.

A

True

24
Q

In order for the grammar to be well-defined, every ____ used on the right-hand side of a production must appear on the ____ ____ of some other production that defines it.

A

nonterminal

left-hand side

25
Q

example of a well-defined grammar

A

S –> {a} b T [c]

T –> d | e

26
Q

what is the rule for sentences of this language grammar?

S –> {a} b T [c]
T –> d | e

A

The sentences or strings of this language start with zero or more a’s followed by one b, then either a d or e followed by an optional c

27
Q

why does the below language allow for an infinite number of possibilities?

A

there is no limit to the number of a’s

28
Q

what makes a production recursive? give an example

A

nonterminal symbol on the left-hand side is also one of the symbols on the right-hand side

Ex: T –> T b

29
Q

what does a grammar need for a recursive production to be well-defined?

A

there must be another right-hand side that does not have the nonterminal

30
Q

List the two kinds of recursive productions that are especially important.

A

left or head recursive

right or tail recursive

31
Q

describe the “left or head recursive”

A

the nonterminal on the left is the leftmost symbol on the right-hand side

32
Q

describe the “right or tail recursive”

A

the nonterminal defined on the left is the rightmost symbol on the right-hand side.

33
Q

give an example of a regular recursive production. explain what makes it well-defined.

A

S –> a S a | b

“| b” which gives you an alternative to “a S a”

34
Q

What language does the grammar below define? (2)

S –> a S a | b

A

strings that begin with n a’s follow by one b and then n a’s again.
n represents any nonnegative integer. So there are the same number of a’s before the b as after the b.

35
Q

What makes the grammar below left recursive?

S –> S a | b

A

the nonterminal S is the left-most symbol on the right-hand side.