Organization of Programming Languages - Exam 1

Ace your homework & exams now with Quizwiz!

What are the two distinct goals of syntax analysis?

"First, the syntax analyzer must check the input program to determine whether it is syntactically correct. When an error is found, the analyzer must produce a diagnostic message and recover. In this case, recovery means it must get back to a normal state and continue its analysis of the input program. This step is required so that the compiler finds as many errors as possible during a single analysis of the input program. If it is not done well, error recovery may create more errors, or at least more error messages. "The second goal of syntax analysis is to produce a complete parse tree, or at least trace the structure of the complete parse tree, for syntactically correct input. The parse tree (or its trace) is used as the basis for translation."

A ________________ is a program that processes a program immediately before the program is compiled.

Preprocessor

Give three advantages of LR parsers.

1) They can be built for all programming languages. 2) They can detect syntax errors as soon as it is possible in a left-to-right scan. 3) The LR class of grammars is a proper superset of the class parsable by LL parsers (for example, many left recursive grammars are LR, but none are LL).

Using the grammar in Example 3.4 [p.120]*, show a sentential form leftmost derivation: A = B + C + A

<assign> => <id> = <expr> => A = <expr> => A = <expr> + <term> => A = <expr> + <term> + <term> => A = <term> + <term> + <term> => A = <factor> + <term> + <term> => A = <id> + <term> + <term> => A = B + <term> + <term> => A = B + <factor> + <term> => A = B + <id> + <term> => A = B + C + <term> => A = B + C + <factor> => A = B + C + <id> => A = B + C + A

In what language is most of UNIX written?

C

The first successful high-level language for business was ________________.

COBOL

What are the three general methods of implementing a programming language?

Compilation, Pure interpretation, Hybrid implementation

The process of placing a memory cell that has been unbound from a variable back into the pool of available memory.

Deallocation

PHP's array data structure is a combination of what two data structures from other languages?

Perl hashes, Javascript arrays

Select all that are examples of dynamic type binding. a. Perl: $x = 4; b. Java: int x = (int)4.0; c. Python: x = int(4.0) d. C++: int x = 4;

Perl: $x = 4; Python: x = int(4.0)

Which one of the following features was NOT a feature of Fortran 77?

Dynamic arrays

Perform the pairwise disjointness test for each of the following grammar rules. Your answer should show the FIRST() function for each RHS, and then state whether the LHS rule passes or fails pairwise disjointness. A → b{aB} | a

FIRST(b{aB}) = {b} FIRST(a) = {a} FIRST(b{aB}) ∩ FIRST(a) = Ø {b} ∩ {a} = Ø Passes

The first successful high-level language for scientific applications was _____________.

Fortran

What is the name of the category of programming languages whose structure is dictated by the von Neumann computer architecture?

Imperative programming languages

Variables bound to heap storage only when they are assigned values.

Implicit heap-dynamic variables

What are the three general methods of implementing a programming language?

Interpreted, compiled, Hybrid (compiled-interpreted)

A word of a programming language that is special only in certain contexts.

Keywords

The time during which the variable is bound to a specific memory location.

Lifetime

On what branch of mathematics is denotational semantics based?

Recursive Function Theory

Convert the following EBNF rules to BNF: S → A{bA} A → a[b]A

S → A | AB B → bA | bAB A → aA | abA

Variables whose storage bindings are created when their declaration statements are elaborated, but whose types are statically bound.

Stack-dynamic variables

Variables that are bound to memory cells before program execution begins and remain bound to those same memory cells until program execution terminates.

Static variables

What data structure(s) does Python use in place of arrays?

Tuples, dictionaries, lists

What is the primary use of attribute grammars?

Type Compatibility

An abstraction of a computer memory cell or collection of cells.

Variable

Consider the following grammar: <S> → <A> a <B> b <A> → <A> b | b <B> → a <B> | a Which of the following sentences are in the language generated by this grammar? a) bbaab b) bbbab c) baab d) bbaaaaa

bbaab baab

Initial implementations of Java were all hybrid. Its intermediate form, called ______________, provides portability to any machine that has an interpreter and an associated runtime system.

byte code

Consider the following grammar: S → aScB | A | b A → cA | c B → d | A Which of the following sentences are in the language generated/recognized by this grammar? a) cd b) acccbd c) acd d) acccbcc e) abcd f) accc

cd abcd accc

The binding of more than one variable to the same memory cell.

Aliasing

With respect to language evaluation critieria, select all language characteristics that affect reliability: a. Syntax design b. Orthogonality c. Type checking d. Support for abstraction e. Restricted aliasing f. Simplicity g. Data types h. Exception handling i. Expressivity

All answers are correct

The process of taking a memory cell from a pool of available memory and binding it to a variable.

Allocation

One of the greatest single advances in computing came with the introduction of the IBM [a] in 1954, in large measure because its capabilities prompted the development of [b].

a) 704 b) fortran

Using the algorithm described in Section 4.4.2, remove direct left recursion form the following grammar rules. A → Aa | Abc | bc | d

A → bcA' | dA' A' → aA' | bcA' | ε

At which possible binding time is a C or C++ static variable bound to a memory location?

Load time

On what branch of mathematics is axiomatic semantics based?

Logic

What characteristic does Ruby share with Smalltalk?

Pure-object oriented language

Using the algorithm described in Section 4.4.2, remove direct left recursion form the following grammar rules. X → Xyy | Xz | Yx | w Y → Yy | Yw | zy | x

X → YxX' | wX' X' → yyX' | zX' | ε Y -> zyY' | xY' Y' → yY' | wY' | ε

Using the grammar in Example 3.4 [p.120]*, show a sentential form leftmost derivation: A = ( A + B ) * C

<assign> => <id> = <expr> => A = <expr> => A = <term> => A = <term> * <factor> => A = <factor> * <factor> => A = (<expr>) * <factor> => A = (<expr> + <term>) * <factor> => A = (<term> + <term>) * <factor> => A = (<factor> + <term>) * <factor> => A = (<id> + <term>) * <factor> => A = (A + <term>) * <factor> => A = (A + <factor>) * <factor> => A = (A + <id>) * <factor> => A = (A + B) * <factor> => A = (A + B) * <id> => A = (A + B) * C

Using the grammar in Example 3.4 [p.120]*, show a sentential form leftmost derivation: A = A * (B + C)

<assign> => <id> = <expr> => A = <expr> => A = <term> => A = <term> * <factor> => A = <factor> * <factor> => A = <id> * <factor> => A = A * <factor> => A = A * (<expr>) => A = A * (<expr> + <term>) => A = A * (<term> + <term>) => A = A * (<factor> + <term>) => A = A * (<id> + <term>) => A = A * (B + <term>) => A = A * (B + <factor>) => A = A * (B + <id>) => A = A * (B + C)

Using the grammar in Example 3.4 [p.120]*, show a sentential form leftmost derivation: A = B * (C * (A + B))

<assign> => <id> = <expr> => A = <expr> => A = <term> => A = <term> * <factor> => A = <factor> * <factor> => A = <id> * <factor> => A = B * <factor> => A = B * (<expr>) => A = B * (<term>) => A = B * (<term> * <factor>) => A = B * (<factor> * <factor>) => A = B * (<id> * <factor>) => A = B * (C * <factor>) => A = B * (C * (<expr>)) => A = B * (C * (<expr> + <term>) => A = B * (C * (<term> + <term>)) => A = B * (C * (<factor> + <term>)) => A = B * (C * (<id> + <term>)) => A = B * (C * (A + <term>)) => A = B * (C * (A + <factor>)) => A = B * (C * (A + <id>)) => A = B * (C * (A + B))

Using the grammar in Example 3.2 [p.117]*, show a sentential form leftmost derivation for each of the three following statements: A = A * (B + (C))

<assign> => <id> = <expr> Right side: A = <expr> A = <id> * <expr> A = A * <expr> A = A * (<expr>) A = A * (<id> + <expr>) A = A * (B + <expr>) A = A * (B + (<expr>)) A = A * (B + (<id>)) A = A * (B + (C))

Using the grammar in Example 3.2 [p.117]*, show a sentential form leftmost derivation for each of the three following statements: A = A * (B + (C * A))

<assign> => <id> = <expr> Right side: A = <expr> A = <id> * <expr> A = A * <expr> A = A * (<expr>) A = A * (<id> + <expr>) A = A * (B + <expr>) A = A * (B + (<expr>)) A = A * (B + (<id> * <expr>)) A = A * (B + (C * <expr>)) A = A * (B + (C * <id>)) A = A * (B + (C * A))

Using the grammar in Example 3.2 [p.117]*, show a sentential form leftmost derivation for each of the three following statements: B = C * (A * C + B)

<assign> => <id> = <expr> Right side: B = <expr> B = <id> * <expr> B = C * <expr> B = C * (<expr>) B = C * (<id> * <expr>) B = C * (A * <expr>) B = C * (A * <id> + <expr>) B = C * (A * C + <expr>) B = C * (A * C + <id>) B = C * (A * C + B)

Write EBNF descriptions (i.e. rules) for the a Java class definition header statement. Begin with the start symbol <class_header>. Use the non-terminal <class_name> for the user-defined name of the class You do not have to include a LHS rule which defines valid naming conventions to expand the <class_name> non-terminal

<class_head> → {<modifier>} class <class_name> [extends class_name] [implements <interface_name> {, <interface_name>}] <modifier> → public | abstract | final

Describe, in English, the language defined by the following grammar: S → ABC A → aA | a B → bB | b C → cC | c

All strings that contain one or more a's followed by one or more b's followed by one or more c's. The following strings are all in the language: abc abbbbbbbbbbc aaaaaaaaaabbcc aabcc

Why are named constants used, rather than numbers, for token codes?

Although tokens are usually represented as integer values, for the sake of readability of lexical and syntax analyzers, they are often referenced through named constants.

With respect to language evaluation criteria, select all language characteristics that affect readability: a. Restricted aliasing b. Data types c. Type checking d. Exception handling e. Orthogonality f. Syntax design g. Expressivity h. Support for abstraction i. Simplicity

Data types, Orthogonality, Syntax Design, Simplicity

Variables that are nameless (abstract) memory cells allocated and deallocated by explicit run-time instructions written by the programmer.

Explicit heap-dynamic variables

With respect to language evaluation criteria, select all language characteristics that affect writability: a. Expressivity b. Exception handling c. Orthogonality d. Restricted aliasing e. Type checking f. Simplicity g. Syntax design h. Support for abstraction i. Data types

Expressivity, Orthogonality, Simplicity, Syntax design, Support for abstraction, Data types

Perform the pairwise disjointness test for each of the following grammar rules. Your answer should show the FIRST() function for each RHS, and then state whether the LHS rule passes or fails pairwise disjointness. B → aB | a

FIRST(aB) = {a} FIRST(a) = {a} FIRST(aB) ∩ FIRST(a) = {a} {a} ∩ {a} = {a} Fails

Perform the pairwise disjointness test for each of the following grammar rules. Your answer should show the FIRST() function for each RHS, and then state whether the LHS rule passes or fails pairwise disjointness by examining all pairs of RHS FIRST()'s. To get you started, the first RHS is: FIRST(aB) = {a} A → aB | b | cBB

FIRST(aB) = {a} FIRST(b) = {b} FIRST(cBB) = {c} FIRST(aB) ∩ FIRST(b) ∩ FIRST(cBB) = Ø {a} ∩ {b} ∩ {c} = Ø Passes

Perform the pairwise disjointness test for each of the following grammar rules. Your answer should show the FIRST() function for each RHS, and then state whether the LHS rule passes or fails pairwise disjointness by examining all pairs of RHS FIRST()'s. To get you started, the first RHS is: FIRST(aB) = {a} B → aB | bA | aBb

FIRST(aB) = {a} FIRST(bA) = {b} FIRST(aBb) = {a} FIRST(aB) ∩ FIRST(bA) ∩ FIRST(aBb) = {a} {a} ∩ {b} ∩ {a} = {a} Fails

Perform the pairwise disjointness test for each of the following grammar rules. Your answer should show the FIRST() function for each RHS, and then state whether the LHS rule passes or fails pairwise disjointness. S → aSb | bAA

FIRST(aSb) = {a} FIRST(bAA) = {b} FIRST(aSb) ∩ FIRST(bAA) = Ø {a} ∩ {b} = Ø Passes

Perform the pairwise disjointness test for each of the following grammar rules. Your answer should show the FIRST() function for each RHS, and then state whether the LHS rule passes or fails pairwise disjointness by examining all pairs of RHS FIRST()'s. To get you started, the first RHS is: FIRST(aB) = {a} C → aaA | b | caB

FIRST(aaA) = {a} FIRST(b) = {b} FIRST(caB) = {c} FIRST(aaA) ∩ FIRST(b) ∩ FIRST(caB) = Ø {a} ∩ {b} ∩ {c} = Ø Passes

True or false: In programming languages, the use of keywords is more restrictive than reserved words.

False

True or false: Like the if/else statement in Java and C++, the Racket else statement is optional.

False

True or false: Python data types are declared explicitly.

False

Between 1951 and 1953, a team led by _________________ at UNIVAC developed a series of "compiling" systems named A-0, A-1, and A-2 that expanded a pseudo-code into machine code subprograms in the same way as macros are expanded into assembly language.

Grace Hopper

At which possible binding time is the Java + operator symbol bound to a memory location?

Language design time

Select all that are constructed languages: a. Na'vi b. lojban c. Esperanto d. Klingon e. Mandarin f. Loglan g. English h. Latin

Na'vi, Lojban, Esperanto, Klingon, Loglan

A string of characters used to identify some entity in a program.

Name

Variables can be characterized as a sextuple (6-tuple) of which six attributes?

Name Address Value Type Lifetime Scope

A simple trade-off can be made between compilation cost and execution speed of the compiled code. _______________ is the name given to the collection of techniques that compilers may use to decrease the size and/or increase the execution speed of the code they produce.

Optimization

With respect to compilation, the syntax analyzer takes the lexical units from the lexical analyzer and uses them to construct hierarchical structures called _____________.

Parse trees

A special word of a programming language that can- not be used as a name.

Reserved word

What are three reasons why lexical analysis is separated from syntax analysis?

Simplicity, Efficiency, Portability

What language was the first to fully support object-oriented programming?

Smalltalk

For what application area is JavaScript most widely used?

Web programming

The very first program was written in 1843 by [a], which was designed to execute on the theoretical hardware platform called the Analytical Engine, designed in 1842 by [b].

a) Ada Lovelace b) Charles Babbage

What two programming language deficiencies were discovered as a result of the research in software development in the 1970s?

a) Incompleteness of type checking b) Inadequacy of control statements

Although never implemented, and not even published until 1972, the first high-level language, [a], was developed in Germany between 1936 and 1945 by [b].

a) Plankalkül b) Zuse

Compute the weakest precondition for each of the following assignment statements and postconditions: a) a = 2 * (b - 1) - 1 {a > 0} b) b = (c + 10) / 3 {b > 6} c) a = a + 2 * b - 1 {a > 1} d) x = 2 * y + x - 1 {x > 11}

a) b > 3/2 b) c > 8 c) b > 1 - a/2 d) y > 6 - x/2

The first widely-used functional programming language (called [a]) was invented to provide language features for list processing, the need for which grew out of the first applications in the area of [b].

a) lisp b) artificial intelligence

Compute the weakest precondition: a = 2 * b + 1; b = a - 3 {b < 0}

b < 1

Computer the weakest precondition: a = 3 * (2 * b + a); b = 2 * a - 1 {b > 5}

b > (1-a)/2 OR b > 1/2-a/2

The execution of a machine code program on a von Neumann architecture computer occurs in a process called the _________________ cycle.

fetch-execute

The primary limiting factor in the speed of von Neumann architecture computers is called the ________________.

von Neumann bottleneck


Related study sets

Principles of Financial Management Chapter 2

View Set

Unit 2 Exam: How does inheritance work?

View Set