PL Review Questions Flashcards

(130 cards)

1
Q

Why is it useful for a programmer to have some background in language design, even though he or she may never actually design a programming language?

A

Because it will increase the ability to express ideas and choose the most suitable language to create some program. Also, it will make it easier to learn another programming language because we already know key concepts.

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

What programming language has dominated scientific computing over the past 60 years?

A

FORTRAN (short for FORmula TRANslation).

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

What programming language has dominated business applications over the past 60 years?

A

COBOL (short for COmmon Business Oriented Language).

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

What programming language has dominated artificial intelligence over the past 60 years?

A

LISP (short for LISt Processor).

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

In what language is most of UNIX written?

A

C

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

What language used orthogonality as a primary design criterion?

A

ALGOL 68

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

What construct of a programming language provides process abstraction?

A

Subprograms

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

What does it mean for a program to be reliable?

A

A program is said to be reliable if it performs to its specifications under all conditions.

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

How can knowledge of programming language characteristics benefit the whole computing community?

A

By knowing the characteristics of programming languages, it would make the learning of a new language easier and get more people involved in programming. Easier learning process and involving more people would result in many new programming languages ​​which are easier to understand and run things better.

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

What is the disadvantage of having too many features in a language?

A

Some of the features may be out of scope for the language, as this will increase memory requirements, and thin out performance efforts.

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

How can user-defined operator overloading harm the readability of a program?

A

User-defined operators can harm the readability of a program because the built in operator has the precision and the compiler knows all the precision between the operators, and it works on that precision. User can also create its own operator but the compiler does not know how to make precision of this operator. This will be the cause of the overloading harm.

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

What is one example of a lack of orthogonality in the design of C?

A

The use of the asterisk (*) symbol in C for both multiplication and dereferencing pointers is a clear example of a lack of orthogonality. This overlapping functionality leads to potential confusion and can result in programming errors.

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

What primitive control statement is used to build more complicated control statements in languages that lack them?

A

The selection statement plus GOTO is used to build more complicated control statements such as FOR loop.

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

Why is type checking the parameters of a subprogram important?

A

Type checking is an important factor in language reliability because it tests for type errors in a given program, either by the compiler or during the execution of a program.

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

What is aliasing?

A

Aliasing is two or more distinct names that can be used to access the same memory cell.

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

What is exception handling?

A

Exception handling is the ability of a program to intercept run-time errors and other unusual conditions detectable by the program and take corrective measures then continue which is an obvious aid to reliability.

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

Why is readability important to writability?

A

Readability is important to writability because if a programming language is difficult to read and understand then it can be difficult for a programmer to create new code that might need to interact or use other code.

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

How is the cost of compilers for a given language related to the design of that language?

A

The cost of compilers for a given language is related to the design of it because a language that requires many run-time type checks will prohibit fast code execution, regardless of the quality of the compiler.

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

What have been the strongest influences on programming language design over the past 50 years?

A

The basic architecture of computers (von Neumann).

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

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

A

Imperative languages

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

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

A

Incompleteness of type checking and inadequacy of control statements

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

What are the three fundamental features of an object-oriented programming language?

A

Data abstraction, inheritance and (run-time) method.
or
Encapsulation, Inheritance and Polymorphism

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

What language was the first to support the three fundamental features of object-oriented programming?

A

Smalltalk

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

What is an example of two language design criteria that are in direct conflict with each other?

A

Reliability and cost of execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What are the three general methods of implementing a programming language?
Compilation, pure interpretation, hybrid implementation systems
26
Which produces faster program execution, a compiler or a pure interpreter?
Compiler
27
What role does the symbol table play in a compiler?
Serves as a database for the compilation process in a compiler. Answer: The compiler converts each user-defined line into a machine readable code then back to user readable language. The symbol table shows the process and how the user-defined code is translated to lexical and syntax analysis then is generated to semantics analysis and code generation. The Symbol table basically shows the load module, linking, and loading process.
28
What does a linker do?
Takes one or more object files (generated by a compiler or an assembler) and combines them into a single executable file, library file, or another "object" file.
29
Why is the von Neumann bottleneck important?
It limits the speed of a von Neumann architecture computer
30
What are the advantages in implementing a language with a pure Interpreter?
The main advantage of implementing a language with a pure interpreter is that a pure interpreter allows for implementation of many source level debugging operations, because many run-time error messages can refer to source level units.
31
In what year was Plankalkül designed? In what year was that design published?
Designed in 1945, published in 1972.
32
What two common data structures were included in Plankalkül?
Array and Record.
33
How were the pseudocodes of the early 1950s implemented?
The pseudocodes of the early 1950s was implemented with a pure interpreter.
34
Speedcoding was invented to overcome two significant shortcomings of the computer hardware of the early 1950s. What were they?
The first hardware shortcoming was the lack of floating point hardware. The second was the lack of automatic incrementing address registers.
35
Why was the slowness of interpretation of programs acceptable in the early 1950s?
The slowness of interpretation of programs acceptable in the early 1950s because of the lack of floating-point hardware in the available computers.
36
In what year was the Fortran design project begun?
1953
37
What was the primary application area of computers at the time Fortran was designed?
Mathematics
38
What was the source of all of the control flow statements of Fortran I?
They were based on 704 instructions
39
What was the most significant feature added to Fortran I to get Fortran II?
Independent-compilation capability
40
What control flow statements were added to Fortran IV to get Fortran 77?
logical loop statements and IF with an optional ELSE
41
Which version of Fortran was the first to have any sort of dynamic variables?
Fortran 90
42
Which version of Fortran was the first to have character string handling?
Fortran 77
43
Why were linguists interested in artificial intelligence in the late 1950s?
Because linguists were concerned with natural language processing
44
Where was LISP developed? By whom?
It was developed at MIT by John McCarthy
45
In what way are Scheme and Common LISP opposites of each other?
Common LISP allows for static scoping and dynamic scoping Scheme only uses static scoping. Scheme is relatively small while Common LISP is large and complex.
46
What dialect of LISP is used for introductory programming courses at some universities?
Scheme
47
What two professional organizations together designed ALGOL 60?
ACM and GAMM
48
In what version of ALGOL did block structure appear?
ALGOL 60
49
What missing language element of ALGOL 60 damaged its chances for widespread use?
The lack of input and output statements with formatting
50
What language was COBOL based?
FLOW-MATIC
51
In what year did the COBOL design process begin?
1959
52
What data structure that appeared in COBOL originated with Plankalkül?
Hierarchical data structures (records)
53
What organization was most responsible for the early success of COBOL (in terms of extent of use)?
Department of Defense
54
What user group was the target of the first version of BASIC?
Non-science students
55
PL/I was designed to replace what two languages?
Fortran and COBOL
56
For what new line of computers was PL/I designed?
IBM System/360 line of computers.
57
What features of SIMULA 67 are now important parts of some object oriented languages?
The concept of a class and data abstraction
58
What innovation of data structuring was introduced in ALGOL 68 but is often credited to Pascal?
User defined data types
59
What design criterion was used extensively in ALGOL 68?
orthogonality
60
What language introduced the case statement?
ALGOL-W
61
What are the two kinds of statements that populate a Prolog database?
fact and rule
62
What are the concurrent program units of Ada called?
Tasks
63
What Ada construct provides support for abstract data types?
Packages
64
What three concepts are the basis for object-oriented programming?
Classes, objects and methods
65
From what language does Objective-C borrow its syntax for method calls?
Smalltalk
66
What was the first application for Java?
A programming language for embedded consumer electronic devices
67
What characteristic of Java is most evident in JavaScript?
Format of syntax
68
How does the typing system of PHP and JavaScript differ from that of Java?
Java is a strongly typed language while JavaScript and PHP are dynamically typed.
69
What array structure is included in C# but not in C, C++, or Java?
Jagged arrays
70
For what application area is JavaScript most widely used?
Web applications
71
What is the relationship between JavaScript and PHP, in terms of their use?
JavaScript and PHP are both scripting languages used for web programming, Js used in the browser while PHP is used on the server.
72
What data structure does Python use in place of arrays?
List
73
What characteristic does Ruby share with Smalltalk?
They are both purely object oriented
74
What characteristic of Ruby’s arithmetic operators makes them unique among those of other languages?
Arithmetic operators can be re-defined
75
Define syntax and semantics.
Syntax – is the form or structure of the expressions, statements and program units. Semantics – is the meaning of expressions, statements and program units.
76
Describe the operation of a general language generator.
Device that can be used to generate the sentences of the language. It generates predictable sentences which makes a generator to be a device of limited usefulness as language descriptor
77
Describe the operation of a general language recognizer.
Recognition device capable of reading strings of characters from the alphabet. Would analyze a given string and either accept or reject based on the language given. Devices like filters separating correct sentences from incorrect
78
What is the difference between a sentence and a sentential form?
A sentence is a valid string according to the language syntax, while a sentential form may contain non-terminal symbols and is a step in the derivation process.
79
Define a left-recursive grammar rule.
A left-recursive grammar rule is one where the leftmost symbol in the rule is also the non-terminal being defined.
80
Distinguish between static and dynamic semantics.
Static Semantics: Concerned with properties that can be determined at compile-time. Dynamic Semantics: Deals with the behavior of programs at runtime
81
What purpose do predicates serve in an attribute grammar?
Predicates in attribute grammars are conditions associated with attributes, guiding the evaluation of attributes based on certain properties or constraints.
82
What is the difference between a synthesized and an inherited attribute?
A synthesized attribute is computed at a node and depends only on attributes of its children. An inherited attribute depends on attributes of its parent and siblings.
83
How is the order of evaluation of attributes determined for the trees of a given attribute grammar?
The parse tree is evaluated based on its underlying BNF grammar, with a possibility of having an empty set of attributes values attached to each node.
84
What is the primary use of attribute grammars?
Device used to describe more of the structure of a programming language than can be described with a context-free grammar.
85
Explain the primary uses of a methodology and notation for describing the semantics of programming languages.
A methodology and notation for describing semantics provide a formal, precise way to define the meaning of programming constructs. This helps in language specification, compiler design, and proving program correctness. It ensures consistency and eliminates ambiguity in understanding language behavior.
86
Describe the two levels of uses of operational semantics.
Language implementation – Used by compiler writers to define how language constructs are executed on a machine. Program verification – Helps prove properties of programs by simulating their execution behavior in a formal way.
87
Which part of an inference rule is the antecedent?
The top part of an inference rule is called the antecedent.
88
What is the problem with using a software pure interpreter for operational semantics?
The detailed characteristics of the particular computer would make actions difficult to understand. Such a semantic definition would be machine-dependent.
89
Explain what the preconditions and postconditions of a given statement mean in axiomatic semantics.
An assertion before a statement (a precondition) states the relationships and constraints among variables that are true at that point in execution. An assertion following a statement is a postcondition.
90
What are the design issues for names?
The following are the primary design issues for names: - Are names case sensitive? - Are the special words of the language reserved words or keywords?
91
What is the potential danger of case-sensitive names?
the problems are about writability and readability. For readability, because names that look very similar in fact denote different entities. For writability, many of the predefined names including both uppercase and lowercase letters.
92
In what way are reserved words better than keywords?
As a language design choice, reserved words are better than keywords because the ability to redefine keywords can be confusing.
93
What is an alias?
Aliases are the variables when more than one variable name can be used to access the same memory location.
94
Which category of C++ reference variables is always aliases?
union
95
What is the l-value of a variable? What is the r-value?
l-value of a variable is the address of a variable, while r-value of a variable is a variable's value itself.
96
Define binding and binding time.
Binding is an association between an attribute and an entity, such as between a variable and its type or value, or between a variable and its type or value, or between an operation and a symbol. Binding time is the time at which a binding takes place.
97
After language design and implementation what are the four times bindings can take place in a program?
Compile time, load time, link time, or run time
98
Define static binding and dynamic binding.
Static binding: if it first occurs before run time and remains unchanged throughout program execution. Dynamic binding: if it first occurs during execution or can change during execution of the program.
99
What are the advantages and disadvantages of implicit declarations?
Implicit declarations offer the advantage of making code more concise and quicker to write by allowing programmers to skip explicitly stating a variable's data type, but the downside is that it can lead to confusion, potential errors, and reduced code readability, especially in larger projects where understanding variable types becomes crucial for maintenance and collaboration.
100
What are the advantages and disadvantages of dynamic type binding?
Advantages: flexibility and no definite types declared(PHP, JavaScript). Disadvantages: adds to the cost of implementation and type error detection by the compiler is difficult
101
Define lifetime, scope, static scope, and dynamic scope.
Lifetime of variable is time during which the variable is bound to a specific men location. Scope of variable is the range of statements over which it is visible. Static scope is binding names to non-local variables. Dynamic scope is based on the calling sequence of subprograms, not on their spatial relationship to each other. Thus the scope can be determined only at run time.
102
How is a reference to a nonlocal variable in a static-scoped program connected to its definition?
A reference to a nonlocal variable in a static-scoped program is resolved by searching the enclosing scopes (lexical ancestors) at compile time until the variable's definition is found. This follows the static (lexical) scope rule, meaning the program structure determines the variable’s scope.
103
What is the general problem with static scoping?
Programmer could mistakenly call a subprogram that should not have been callable, which would not be detected as an error by the compiler. Too much data access and verifications. Encourages the use of more global than are necessary and not preferable to programming
104
What is the referencing environment of a statement?
the collection of all variables that are visible in the statement
105
What is a static ancestor of a subprogram? What is a dynamic ancestor of a subprogram?
Static ancestor: A subprogram that encloses another subprogram in terms of lexical (static) scope. It is determined at compile time. Dynamic ancestor: A subprogram that calls another subprogram at runtime, forming part of the call stack.
106
What is a block?
Section of code to have its own local variables whose scope is minimized. Such variables are typically stack dynamic, so their storage is allocated when the section is entered and deallocated when the section is exited. Such a section of code is called a block.
107
What is the purpose of the let construct in functional languages?
The let construct in functional languages allows for local variable bindings within an expression. It helps define temporary variables in a structured way and prevents pollution of the global namespace.
108
What is the difference between the names defined in an ML let construct from the variables declared in a C block?
In ML's let construct, names are immutable by default, meaning they cannot be reassigned after initialization. In C blocks, variables are mutable, allowing reassignment within their scope.
109
What are the advantages and disadvantages of dynamic scoping?
Dynamic scoping allows a variable to be resolved by searching the call stack for the most recent binding. Its advantages include flexibility, as functions can use variables without explicitly passing them as parameters, and reduced code complexity in certain cases. However, its disadvantages include difficulty in debugging due to unpredictable variable values, reduced readability, and potential unintended side effects, as changes to variables affect all functions in the call chain. This makes maintaining and reasoning about code more challenging compared to static (lexical) scoping.
110
What are the advantages of named constants?
They enhance readability by replacing hardcoded values with meaningful names, making the code easier to understand (e.g., using PI instead of 3.14159265).
111
_____________, in which a single operator symbol has more than one meaning.
operator overloading
112
means that a relatively small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structures of the language
Orthogonality
113
Perhaps the most orthogonal programming language
ALGOL 68
114
is a measure of how easily a language can be used to create programs for a chosen problem domain.
Writability
115
means the ability to define and then use complicated structures or operations in ways that allow many of the details to be ignored
abstraction
116
simply testing for type errors in a given program, either by the compiler or during program execution
Type checking
117
The ability of a program to intercept run-time errors
exception handling.
118
having two or more distinct names that can be used to access the same memory cell
aliasing
119
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
120
The execution of a machine code program on a von Neumann architecture computer occurs in a process called the ____________
fetch-execute cycle
121
programs can be translated into machine language, which can be executed directly on the computer. This method is called
compiler implementation
122
The language that a compiler translates is called the ___
source language
123
The process of collecting system programs and linking them to user programs is called ____________
linking and loading,
124
A ____________is a program that processes a program immediately before the program is compiled.
preprocessor
125
what is a descriptor?
the collection of the attributes of a variable
126
advantages and disadvantages of decimal data types?
advantage: - accuracy. decimal types are able to precisely store decimal values, at leat those within a restricted range, which cannot be done by floating-point disadvantage: - the range of values id restricted because no exponents are allowed - their representation in memory is mildly wasteful
127
what are the design issues for character string types?
1. should strings be simply a special kind of character array or primitive type? 2. should strings have static or dynamic length?
128
describe the three string length options
1. static length string: the length can be static and set when the string is created 2. limited dynamic string: allow strings to have varying length up to a declared and fixed maximum set by a variable's definition 3. dynamic length string: allow string to have varying length with no maximum
129
define ordinal, enumeration, and subrange types
ordinal type: range of possible values can be easily associated with the set of positive integers. enumeration type: all of the possible values, which are named constants, are enumerated in the definition subrange type: a contiguous subsequence of an ordinal type
130
what are the advantages of user-defined enumeration types?
aid to readability: named values are easily recognized, whereas coded values are not aid to reliability: 1. no arithmetic operations are legal 2. no enumeration variable can be assigned a value outside its defined range