Programming languages questions from the book

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is a just-in-time compiler?

A compiler that translates byte code into machine language immediately before each execution of the program.

What is a frame pointer? What is it used for?

A frame pointer points to the current location within the frame. Allows us to access aforementioned data.

What does it mean for a context-free grammar to be ambiguous?

A grammar that allows the construction of more than one parse tree for some string of terminals is said to be ambiguous.

What is bootstrapping?

A method in which a simple implementation of an interpreter evolves to build more complex versions until the compiler has been built.

What is the difference between a compiler and a preprocessor?

A preprocessor is an initial translator that removes comments and white space, and groups characters together into tokens such as keywords, identifiers, numbers, and symbols, as well as simple analysis of syntactic structures. A compiler employs thorough analysisand nontrivial transformation.

What is a referencing environment?

A set of active bindings.

What are forward references? Why are they prohibited or restricted in many programming languages?

A static semantic error. The use of a name before its declaration. It's forward referencing. Attempting to refer to a name before it is declared Simplify the compiler

What is the advantage of binding things as early as possible? What is the advantage of delaying bindings?

Advantage: faster by binding early Advantage of delaying: dynamic type checking, allocating objects of unknown size. Higher expressiveness. Most scripting languages are an example.

What is the purpose of a scope resolution operator?

Allows you to access the outer meaning of a name that is outside your scope. So like my_proc.x, accessing the X of that even though you have an X already within your scope.

List the objects and information commonly found in a stack frame

Arguments to called routines, Temporaries (intermediate values produced in complex calculations), Local variables, Miscellaneous bookkeeping, Return address

What are associativity and precedence? Why are they significant in parse trees?

Associativity tells us that operators group left to right. Or right-associativity is the other way. Precedence is which operator to go first. Significant in evaluating parse trees correctly.

what was the immediate form employed by the original AT&T C++ compiler

C++ implementations based on the early AT&T compiler actually generated an intermediate program in C, instead of in assembly language

Name three von Neumann languages

C, Ada, Fortran

Why does the use of dynamic scoping imply the need for runtime type checking?

Cannot be checked at compile time; behavior of program determine the bindings

Explain the distinction between interpretation and compilation. What are the comparative advantages and disadvantages of the two approaches?

Compiler translates high level source program into a equivalent target program (machine language). An interpreter implements a virtual machine whose "machine language" is the high-level programming language. The interpreter reads statements in that language more or less one at a time, executing them as it goes along.

What are the three basic operations that can be used to build complex regular expressions from simpler regular expressions?

Concatenation, Alternation and Kleene Closure

What is garbage collection?

De allocating memory from objects

Explain the difference between a declaration and a definition. Why is the distinction important?

Declaration is when you introduce a name and its scope but omits its implementation details. Definition describes the object in sufficient detail to determine its implementation.

What distinguishes declarative languages from imperative languages?

Declarative languages hide implementation details. Imperative embraces them.

When discussing context-free languages, what is a derivation? What is a sentential form?

Derivation: a series of replacement operations that shows how to derive a string of terminals from the start symbol. Sentential Form: Each string of symbols along the way is called a sentential form.

Describe the difference between static and dynamic scoping.

Dynamic scoping is when the bindings are dependent on runtime paths taken. Static scoping is when the binding is the same no matter what the runtime path is.

Why are there so many programming languages?

Evolution, Special Purposes, Personal Preference

What is an opaque export?

Exported variables that may be declared, passed as arguments to the module's subroutines, and possibly compared or assigned to one another, but not manipulated in any other way. Read-only variables

What makes a programming language successful?

Expressive Power, Ease of Use for Novice, Ease of Implementation, Standardization, Open Source, Excellent Compilers, Economics, Patronage, Inertia

What are internal and external fragmentation?

External fragmentation: data storage in heap. When you have gaps between data. Internal fragmentation: gaps inside the object. From allocating to much memory to an object. Internal fragmentation occurs when a storage-management algorithm allocates a block that is larger than required to hold a given object; the extra space is then unused. External fragmentation occurs when the blocks that have been assigned to active objects are scattered through the heap in such a way that the remaining, unused space is composed of multiple blocks: there may be quite a lot of free space, but no one piece of it may be large enough to satisfy some future request

On modern machines, do assembly language programmers still tend to write better code than a good compiler can? Why or why not?

For modern microprocessor architectures, particularly those with so-called super scalar implementations (ones in which separate functional units can execute instructions simultaneously), compilers can usually generate better code than can human assembly language programmers.

What is generally considered the first high-level programming language?

Fortran

In what way(s) are high-level languages an improvement on a assembly language? Are there circumstances in which it still make sense to program in assembler?

High level languages economizes the programmer effort in the construction and maintenance of programs.For performance centered tasks, assembly allows direct control for optimization.

What is a dangling reference?

If an object is de-allocated too soon, the program may follow a dangling reference, accessing memory now used by another object.

What is the purpose of the compiler's symbol table?

It is a data structure that maps each identifier to the information known about it including the identifiers type, internal structure , and scope. The symbol table serves throughout compilation as a repository for information about identifiers.

Name two widely used concurrent languages.

Java and C# have concurrent features

Is Java compiled or interpreted (or both)? How do you know?

Java could be considered either. It is possible for a compiler (complicated translator) to produce code that is then executed by a complicated virtual machine (interpreter)

What is the difference between a right-most derivation and a left-most derivation?

Left most derivation expands leftmost non terminal first. Right most derivation expands rightmost non terminal first.

Explain the distinction between the lifetime of a name-to-object binding and its visibility.

Lifetime: time between the creation and destruction of the thing Visibility: when you can see the thing

What do we mean by the scope of a name-to-object binding?

Lines in program where the binding is active.

What was the first functional language?

Lisp

Name two languages in which a program can write new pieces of itself "on the fly."

Lisp and Prolog

Name three functional languages

Lisp, ML, Haskell

What is the difference between machine language and assembly language?

Machine Language is a sequence of bits which directs the processor to perform the desired mathematical operations. It can be written in either Binary, Octal or Hexadecimal. For large and complicated programs this notation seemed to be more error prone so assembly language was developed. Assembly language was based on the mnemonics (abbreviations of the instructions), which was quite easier to understand and implement. Programs written in Assembly languages are required to be translated in machine language with the help of Assembler, to perform any operation.

Explain the importance of information hiding.

Makes objects and algorithms invisible, whenever possible, to portions of the system that do not need them. Allows for modularization

Explain the distinction between "modules as managers" and "modules as types." [p.143, #25]

Managers: allows for several stacks and requires one module as a manager for instance of stack types which is exported from the module. REquires additional subroutines to create/initialize/destroy stack instances and requires that every subroutine (push/pop/create) accept an additional parameter to specify the stack in question. Types: when a module has a type, the programmer can declare an arbitrary number of similar module objects. In types, the programmer can think of the module's subroutines as "belonging"to the stack in question (A.push(x)), rather than as outside entities to which the stack can be passed as an argument (push(A, x)) (managers).

What is overloading? How does it differ from coercion and polymorphism?

Method overloading is the same name for different functions. Coercion is the process by which a compiler automatically converts a value of one type into a value of another type when that second type is required by the surrounding context. Polymorphism allows a single routine to accept arguments of multiple types, provided that it attempts to use them only in ways that their types support.

How do classes differ from modules?

Modules is a function without access to exterior code Classes are more general?

What does it mean for a scope to be closed?

Modules that must be explicitly imported

What are aliases? Why are they considered a problem in language design and implementation?

Multiple names that refer to the same object; confusing and can prevent compiler from creating optimizations

What is Backus-Naur form? When and why was it devised?

Notation for CFG's BNF is a notation for writing context-free grammars that allows for the use of arbitrary characters, as well as improving readability. It was invented by John Backus and improved by Peter Naur in the late 1950s and early 1960s. BNF, or some variation on it, is used to specify the syntax of many programming languages.

What is the difference between static and dynamic semantics?

Of course, not all semantic rules can be checked at compile time, these are static semantics Those that must be checked at run time are referred to as the dynamic semantics of the language.

Phases that are part of interpretation or compilation

Pg 27 has charts

Name two logic languages.

Prolog, spreadsheets

Name a language in which indentation affects program syntax

Python

What additional operation (beyond the three of regular expressions) is provided in context-free grammars?

Recursion

Explain the value of the restrict qualifier in C.

Restrict qualifier is an assertion that the object the programmer is referring to has no alias

List the principal phases of compilation

Scanner (lexical analysis), Parser (syntax analysis), Semantic analysis and intermediate code generation,Machine-independent code improvement (optional), Target code generation, Machine-specific code improvement (optional)

List the principal phases of compilation, and describe the work performed by each

Scanner: translates characters into tokens removing white space and comments Parser: organizes tokens into a parse tree following a context-free grammar Semantic Analysis: understands parse tree to generate intermediate code and checks constraints with the help of a symbol table Target Code Generation: translates intermediate form into target language (machine language or assembly language)

Explain the purpose of a compiler's symbol table.

Semantic analysis; check if identifiers have been declared, correct types, parameters of functions, keeps track of scope

Why might it be useful to have modules and classes in the same language?

Separate functionalities through modules and multi-instance abstractions

Name three object-oriented languages

Smalltalk, Eiffel, Java

What determines whether an object is allocated statically, on the stack, or in the heap?

Static: Global variables are static. Fixed size and retain values. Heap: objects of variable size Stack: things are local to a subroutine

Explain the distinction between decisions that are bound statically and those that are bound dynamically.

Statically: Things are bound during compile time / before runtime Dynamically: Things are bound at runtime

What is the difference between syntax and semantics?

Syntax is about the structure or the grammar of the language. Semantics is about the meaning of the sentence. Is this sentence valid? If so, what does the sentence mean?

Briefly describe three "unconventional" compilers - compilers whose purpose is not to prepare a high level program for execution on a general purpose processor.

TEX and TROFF are text formatter compilers which convert the high level programs into instructions for laser printers.Query language processors also constitute this type of compiler, which translate the SQL queries into file operations which are used to provide the result of desired query.

What distinguishes the front end of the compiler from the back end?

The first few phases (up through semantic analysis) serve to figure out the meaning of the source program. They are sometimes called the front end of the compiler. The last few phases serve to construct an equivalent target program. They are sometimes called the back end of the compiler. the front end may be shared by compilers for more than one machine (target language), and the back end may be shared by compilers for more than one source language.

What is elaboration?

The process of associating a value to an object including memory allocation, etc.

What is binding time?

Time it takes to bind a thing to what it represents. How long it takes to set A = 5

Why might it be useful to distinguish between the header and the body of a module?

To facilitate separate compilation, modules in many languages (Modula-2 and Oberon among them) can be divided into a declaration part (header) and an implementation part (body), each of which occupies a separate file. Code that uses the exports of a given module can be compiled as soon as the header exists; it is not dependent on the body.

Describe the form in which a program is passed from the scanner to the parser;from the parser to the semantic analyzer; from the semantic analyzer to the intermediate code generator.

Token stream, Parse tree, Abstract syntax tree or other intermediate form

What organization spearheaded the development of Ada?

U.S. Department of Defense

Explain the closest nested scope rule?

When a declaration is known in the scope in which its declared and its nested scopes.

Explain how an integrated development environment (IDE) differs from a collection of command-line tools.

You can write an entire program in an IDE without having to call multiple tools with command-line tools

What is P-code?

a stack-based language similar to the byte code of modern Java compilers ....pre-compiled code

List six kinds of tools that commonly support the work of a compiler within a larger programming environment

assemblers, debuggers, preprocessors, linkers, editors, pretty printers

What is the difference between a phase and a pass of compilation? Under what circumstances does to make sense for a compiler to have multiple passes?

pass:- it is an logical execution of the compilation process. PHASE:- IT IS AN CHRONOLOGICAL PROCESS OF COMPILATION. the reason to have multiple passes is to minimize memory usage. So you can share code between multiple compilers. Each phase discovers information of use to later phases, or transforms the program into a form that is more useful to the subsequent phase. A pass is a phase or set of phases that is serialized with respect to the rest of compilation: it does not start until previous phases have completed, and it finishes before any subsequent phases start.

What is a calling sequence?

the code executed by the caller immediately before and after the call— and of the prologue (code executed at the beginning) and epilogue (code executed at the end) of the subroutine itself


Kaugnay na mga set ng pag-aaral

Respiratory Ch 39 PrepU Fundamentals

View Set

Renal Exam 3 Physiology and Pathology

View Set