cis Flashcards
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