cis Flashcards
(35 cards)
What should a store do?
map program variables into locations
map locations into values
map program variables into values
map locations into values
To interpret an assignment L = R, we must
evaluate L to a
evaluate R to a
Location
value
What should an environment do?
map program variables into values
map program variables into locations
map locations into values
map program variables into locations
What is needed to evaluate a command (check all that applies)
a store
an environment
a store
an environment
What is the result of interpreting a command?
an updated environment
an updated store
a value
an updated store
Interpreting an expression must return a value; when must it also return a changed store?
never
when the expression is not pure
always
when the expression is not pure
For a given program, how often is each part of its abstract syntax tree examined by
an interpreter?
a compiler?
possibly many times?
only once
What does a lexical analysis
BOTH HAVE ANSWER
produce?
consume?
a list of tokens
a string of characters
What does a parser
produce?
consume?
a syntax tree
a list of tokens
Consider the lexical analysis presented in the lecture notes. Assume it is in state NumberState 62, and that the next character is 4. What will then happen?
it will transition to NumberState 624, with no output
it will transition to InitState, and output the token NumT 624
it will transition to InitState, and output the token NumT 62
it will transition to NumberState 462, with no output
it will transition to NumberState 624, with no output
Consider the lexical analysis presented in the lecture notes. Assume it is in state NumberState 62, and that the next character is +. What will then happen?
it will transition to InitState, output the token NumT 62, and advance the input pointer (skipping the + symbol)
it will stay in NumberState 62, and advance the input pointer (skipping the + symbol)
it will transition to InitState, output the token NumT 62, but not move the input pointer
it will transition to InitState, output the token NumT 62, but not move the input pointer
Consider, as in the lecture notes, the grammar
::= NumT num
| OpenParenT CloseParenT
| PlusT
| MinusT
| TimesT
Which of the following token lists have at least two different parse trees?
[NumT 7, PlusT, NumT 3, PlusT, NumT 4]
[NumT 7, TimesT, NumT 3]
[NumT 7, PlusT, NumT 3]
[NumT 7, TimesT, NumT 3, PlusT, NumT 4]
[NumT 7, PlusT, NumT 3, PlusT, NumT 4]
[NumT 7, TimesT, NumT 3, PlusT, NumT 4]
For a given (arbitrary) grammar, what can we say about the number of syntax trees for a given list of tokens?
perhaps zero, perhaps one, perhaps more than one
at least one, perhaps more
exactly one
at most one, perhaps zero
perhaps zero, perhaps one, perhaps more than one
For a given unambiguous grammar, what can we say about the number of syntax trees for a given list of tokens?
at most one, perhaps zero
exactly one
at least one, perhaps more
perhaps zero, perhaps one,
perhaps more than one
at most one, perhaps zero
Consider the (renamed) grammar from the notes: ::=
| E PlusT T | E MinusT T ::= F | T TimesT F (*) F ::= NumT nums | OpenParenT E CloseParenT and assume we replace the line marked (*). For which replacement(s) will the resulting grammar still be unambiguous?
F TimesT T
T TimesT T
F TimesT F
F TimesT F
F TimesT T
Consider the (renamed) grammar from the notes: ::=
| TimesT (*) ::= NumT | OpenParenT CloseParenT and assume we replace the line marked (*). For which replacement(s) will the resulting grammar allow syntax trees for all token lists for which there is a syntax tree in the original grammar?
F TimesT T
T TimesT T
F TimesT F
PlusT
| MinusT
::=
F TimesT F
T TimesT T
Consider the grammar
::=
| PlusT | MinusT | TimesT ::= NumT | OpenParenT CloseParenT Which properties does it have (check all that apply)
allows a syntax tree for all token lists for which there is a syntax tree
in the grammar from the notes
addition and subtraction are both left-associative
multiplication has precedence over addition and subtraction
multiplication is left-associative
unambiguous
allows a syntax tree for all token lists for which there is a syntax tree
addition and subtraction are both left-associative
multiplication is left-associative
unambiguous
What does a (top-down) parsing function expect as input (check all that apply)
a list of tokens
a string of characters
a syntax tree
a list of tokens
What does a (top-down) parsing function return as output (check all that apply)
a list of tokens
a string of characters
a syntax tree
a list of tokens
a syntax tree
For the top-down parser listed in the notes, which functions (check all that apply) may need to report an error (by raising an exception)?
parFact (for parsing a factor)
parse (for parsing at top-level)
parExp (for parsing an expression)
parTerm (for parsing a term)
parFact (for parsing a factor)
parse (for parsing at top-level)
What is true (check all that apply) about grammars that make arithmetic operators left associative?
they adhere to standard rules of arithmetic
they can be implemented by a bottom-up parser
they can be easily implemented by a top-down parser
they adhere to standard rules of arithmetic
they can be implemented by a bottom-up parser
What is true (check all that apply) about grammars that make arithmetic operators right associative?
they adhere to standard rules of arithmetic
they can be implemented by a bottom-up parser
they can be easily implemented by a top-down parser
they can be implemented by a bottom-up parser
they can be easily implemented by a top-down parser
Consider the first-order program h z = 5 * z; g y = 2 + y; h (g 7) With the substitution approach to evaluation, what will h (g 7) rewrite to in the first step, using
Call-By-Value
Call-By-Name
h (2 +7 )
5 * (g 7)
Consider the first-order program f z = z * 4; g y = y + 3; f (g 5) With Call-By-Name evaluation, the first step is f (g 5) => (g 5) * 4 What is the result of the second step?
8 * 4
5 + 3 * 4
(5 + 3) * 4
(5 + 3) * 4