Principles of Programming Languages Midterm

Principles of Programming Languages Midterm

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

When and where are storage bindings created for Stack-Dynamic variables? (A) When: Run-time, when the statement is elaborated Where: On the heap (B) When: Compile time Where: On the heap (C) When: Run-time, when the statement is elaborated Where: On the stack (D) When: Compile time Where: On the stack

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (24)

Section 1

(24 cards)

When and where are storage bindings created for Stack-Dynamic variables? (A) When: Run-time, when the statement is elaborated Where: On the heap (B) When: Compile time Where: On the heap (C) When: Run-time, when the statement is elaborated Where: On the stack (D) When: Compile time Where: On the stack

Front

(C) When: Run-time, when the statement is elaborated Where: On the stack

Back

Chapter 5 Quiz Questions

Front

Back

A grammar can be written in some type of BNF notation. There are two types of symbols in BNF expressions. NON-TERMINAL symbols are typically: (A) The symbols that would appear in a source code file (B) The symbols that would appear in a grammar file (C) Abstract concepts that need to be further defined (D) Metasymbols that are used by BNF grammar types to help describe rules

Front

(C) Abstract concepts that need to be further defined

Back

Chapter 4 Quiz Questions

Front

Back

A Token: (A) is a type of context free grammar. (B) is a group of characters that comprise the smallest unit of a programming language (C) is a recognizer for a grammar (D) is a category or name for a group of characters that comprise the smallest unit of a programming language

Front

(D) is a category or name for a group of characters that comprise the smallest unit of a programming language

Back

A grammar can be written in some type of BNF notation. There are two types of symbols in BNF expressions. TERMINAL symbols are typically: (A) Abstract concepts that need to be further defined (B) Recognizers for legal sentences that can be produced with a grammar (C) The symbols that would appear in a source code file (D) Definitions of abstract concepts

Front

(C) The symbols that would appear in a source code file

Back

How would you remove the direct left-recursion from the following grammar? <A> -> <A>a<B> | <B>a | <C><B><A> <B> -> b<C> | <C> <C> -> c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (A) <A> -> <A'>a<B> | <B>a<A'> | <C><B><A'> <A'> -> a<B> | ε <B> -> b<C> | <C> <C> -> c (B) <A> -> <A>a<B> | <B>a | <C><B><A> <B> -> b<C> | <C> <C> -> c (C) <A> -> <B>a<A'> | <C><B><A><A'> <A'> -> a<B><A'> <B> -> b<C> | <C> <C> -> c (D) <A> -> <B>a<A'> | <C><B><A><A'> <A'> -> a<B><A'> | ε <B> -> b<C> | <C> <C> -> c

Front

(D) <A> -> <B>a<A'> | <C><B><A><A'> <A'> -> a<B><A'> | ε <B> -> b<C> | <C> <C> -> c

Back

What is the referencing environment for the block of code within function myf2() (highlighted below) using static scoping? Class RefEnvironment{ private int x = 10; private int y = 20; public RefEnvironment(int x, int y){ this.x = x; this.y = y; } public void myf1(){ int myf1_var = 10; int result = myf1_var + 10; myf2() } public void myf2(){ int myf2_var = 20; int result = myf2_var + 20; } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (A) myf1_var: read/write access result (in function myf1): read/write access x: read/write access y: read/write access (B) myf2_var: read/write access result: read/write access x: read/write access y: read/write access (C) myf1_var: read access result (in function myf1): read access x: read/write access y: read/write access myf2_var: read/write access result (in function myf2): read/write access (D) myf1_var: read access result (in function myf1): read access myf2_var: read/write access result (in function myf2): read/write access

Front

(B) myf2_var: read/write access result: read/write access x: read/write access y: read/write access

Back

A bottom up parser (A) Produces a parse tree that is in the order of a left-most derivation. It examines the input from right-to-left (B) Produces a parse tree that is in the order of a right-most derivation. It examines the input from right-to-left. (C) Produces a parse tree that is in the order of a left-most derivation. It examines the input from left-to-right. (D) Produces a parse tree that is in the order of a right-most derivation. It examines the input from left-to-right

Front

(D) Produces a parse tree that is in the order of a right-most derivation. It examines the input from left-to-right

Back

The key difference between a left-most and a right-most derivation is that: (A) Left-most derivations are generators and right-most derivations are recognizers. (B) Left-most derivations always start with the starting rule (or at the root of the tree) while right-most derivations always start with the input string and work their way up to the starting rule (or start at the leaves and work towards the root) (C) Given a sentential form that contains multiple non-terminals, a left-most derivation always picks the left-most non-terminal to reduce next, while a right-most derivation always picks the right-most non-terminal to reduce next (D) A right-most derivation uses the handle-pruning technique to derive a sentence, while a left-most derivation uses the left-recursive technique to derive a sentence.

Front

(C) Given a sentential form that contains multiple non-terminals, a left-most derivation always picks the left-most non-terminal to reduce next, while a right-most derivation always picks the right-most non-terminal to reduce next

Back

What does it mean to say that a variable attribute is statically bound? (A) The address attribute is bound during compile time and the object refers to the same address for the duration of the program (B) The binding time occurs when the program is compiled and the type is visible to all other instances of the same object (C) The attribute is bound during compile time, and remains bound during the entire execution of the program (D) The binding time occurs when the program is compiled and the type can only be seen inside the current module in which it is created

Front

(C) The attribute is bound during compile time, and remains bound during the entire execution of the program

Back

How would you resolve the pairwise disjointness problem in the grammar below? <X> -> x<Y> | x<Z> | xa<X> | <Y>x | <Z>x<Y> <Y> -> y<Z> | <Z> <Z> -> z ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (A) <X> -> x<Y><new> | x<Z><new> | xa<X> | <Y>x | <Z>x<Y> <new> -> <Y> | <Z> <Y> -> y<Z> | <Z> <Z> -> z (B) <X> -> x <new> | <Y>x | <Z>x<Y> <new> -> <Y> | <Z> | a<X> | ε <Y> -> y<Z> | <Z> <Z> -> z (C) <X> -> x <new> | <Y>x | <Z>x<Y> <new> -> <Y> | <Z> | a<X> <Y> -> y<Z> | <Z> <Z> -> z (D) <X> -> x <new> | <Y>x | <Z>x<Y> <new> -> <Y><new> | <Z><new> | a<X><new> | ε <Y> -> y<Z> | <Z> <Z> -> z

Front

(C) <X> -> x <new> | <Y>x | <Z>x<Y> <new> -> <Y> | <Z> | a<X> <Y> -> y<Z> | <Z> <Z> -> z *Resolving Pairwise Disjointness doesn't require the ε*

Back

Given the following grammar and the following sentential form, what would the next sentential form be if you used left-most derivation? <A> -> a<A> | b<A> | c<B> <B> -> <C><A> | b<C> <C> -> d Input: abcdacbd Current Sentence (derivation step): abc<C><A> (A) abcd<A> (B) abc<C>c<B> (C) abc<C>d<A> (D) abc<C>a<A>

Front

(A) abcd<A>

Back

Given the following grammar and the closure for the starting state, what would the next closure or state be if the next input symbol was " ( " ? E -> E + T | E * T | T T -> ( E ) | id ~~~~~~~~~~ S' -> .E$ E -> .E + T E -> .E * T E -> .T T -> .(E) T -> .id ~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (A) S' -> .E$ E -> .E + T E -> .E * T E -> .T T -> .(E) T -> .id (B) T -> .(E) E -> .E + T E -> .E * T E -> .T T -> .( E ) T -> .id (C) T -> (E.) E -> E. + T E -> E. * T (D) T -> (.E) E -> .E + T E -> .E * T E -> .T

Front

(B) T -> .(E) E -> .E + T E -> .E * T E -> .T T -> .( E ) T -> .id

Back

A Lexeme: (A) is a group of characters that comprise the smallest unit of a programming language. (B) is a type of context free grammar (C) is a category or name for a group of characters that comprise the smallest unit of a programming language. (D) is a recognizer for a grammar

Front

(A) is a group of characters that comprise the smallest unit of a programming language.

Back

A top down parser (A) Produces a parse tree that is in the order of a right-most derivation. It examines the input from left-to-right (B) Produces a parse tree that is in the order of a left-most derivation. It examines the input from left-to-right. (C) Produces a parse tree that is in the order of a right-most derivation. It examines the input from right-to-left. (D) Produces a parse tree that is in the order of a left-most derivation. It examines the input from right-to-left

Front

(B) Produces a parse tree that is in the order of a left-most derivation. It examines the input from left-to-right.

Back

What is the lifetime of any static variable?

Front

The entire life of the program

Back

What is the purpose of a lexer? (A) A lexer produces a parse tree (B) A lexer is responsible for executing a left-most derivation (C) A lexer scans tokens to determine whether the tokens appear in an order that satisfy the grammar rules of a given language (D) A lexer scans an input file and identifies or associates tokens with groups of characters that match a particular token category.

Front

(D) A lexer scans an input file and identifies or associates tokens with groups of characters that match a particular token category.

Back

Chapter 3 Quiz questions

Front

Back

What does it mean to say that a type (data type) binding is dynamic? (A) The type was initially bound before compilation, but can change during execution, usually via an explicit or implicit declaration. (B) The binding occured as a result of an implicit declaration. (C) The type is first bound during executing, and can change during execution of the program, usually via an assignment statement. (D) The binding occured as a result of an explicit declaration.

Front

(C) The type is first bound during executing, and can change during execution of the program, usually via an assignment statement.

Back

How would you remove left-recursion from the following grammar? <A> -> <A>a<B> | <A>bb<A> | <B>a | <C><B><A> <B> -> b<C> | <C> <C> -> c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (A) <A> -> <B>a<A'> | <C><B><A><A'> <A'> -> a<B><A'> | bb<A><A'> <B> -> b<C> | <C> <C> -> c (B) <A> -> <A>a<B> | <A>bb<A> | <B>a | <C><B><A> <B> -> b<C> | <C> <C> -> c (C) <A> -> <B>a<A'> | <C><B><A><A'> <A'> -> a<B><A'> | bb<A><A'> | ε <B> -> b<C> | <C> <C> -> c (D) <A> -> <A'>a<B> | <A'>bb<A> |<B>a<A'> | <C><B><A'> <A'> -> a<B> | bb<A> | ε <B> -> b<C> | <C> <C> -> c

Front

(C) <A> -> <B>a<A'> | <C><B><A><A'> <A'> -> a<B><A'> | bb<A><A'> | ε <B> -> b<C> | <C> <C> -> c

Back

Given the following parser table, state of the stack, and input string, if you were to read in the next symbol, what action would you take? Tip: Recall that when representing how much of an input string we've read, everything BEFORE the . represents what we have already read in, and everything AFTER the . represents what we haven't seen yet. https://auburn.instructure.com/users/3217732/files/145874087/preview?verifier=2Y542Vg2veIbYha0R5e85aYxF2A4gAeOrFnR0AfG input: . id + id $ Stack: 0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (A) add id to the stack, add 1 to the stack, advance the input string so that the . is after the first id symbol, transition to state 1, reduce by rule 3, and pop one pair of symbols off the stack. (B) add id to the stack advance the input string so that the . is after the first id symbol, and reduce by rule 3. (C) add id to the stack, advance the input string so that the . is after the first id symbol, reduce by rule 3, and pop one pair of symbols off the stack. (D) add id to the stack, advance the input string so that the . is after the first id symbol, transition to state 1, and print 3 for your parse trace.

Front

(A) add id to the stack, add 1 to the stack, advance the input string so that the . is after the first id symbol, transition to state 1, reduce by rule 3, and pop one pair of symbols off the stack.

Back

Given the following grammar and the corresponding input string, what would the parse tree look like? <A> -> a<B> | a<A> <B> -> b<B> | b<C> | b<A> <C> -> c Input string: abbbc

Front

Top of the tree: <A> Left side going down next to the right side: a, b, b, b, c Right Side going down: <B>, <B>, <B> <C>

Back

A grammar is considered ambiguous if: (A) It is possible to generate a sentential form that has more than one distinct parse tree. (B) You cannot produce a parse tree from it (C) It is left-recursive or if it contains pairwise disjointness (D) Some of the rules in the grammar have more than one definition

Front

(A) It is possible to generate a sentential form that has more than one distinct parse tree.

Back