Programming Languages Ch. 1

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

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

1. Assemblers: used to convert mnemonics into machine language 2. Debuggers: used to detect errors in program 3. Preprocessors: tools which read program before compilation and removes comments and white spaces 4. Linkers: used to combine library routines to various parts of a program 5. Style Checkers: tools used to provide syntactic or semantic constraints, which compiler does not provide 6. Configuration Management Tools: keep the various compiled components intact

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

1. IDE provides facility to execute programs in various languages. It has the feature of interoperability 2. IDE provides more user interaction than command line tools by providing user interface 3. Possible to add various automation tools in IDE, which makes program compilation and execution easier and more efficient 4. Modifying control structure in IDEs is relative easy and less time consuming

List the phases that are also executed as part of interpretation.

1. Lexical Analysis 2. Syntax Analysis 3. Semantic Analysis 4. Direct Execution

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

1. Scanner/Lexical Analysis: Reads program left to right and groups elements into legal tokens (constants, operators, keywords, seperators, punctuation) 2. Parser/Syntax Analysis: generates parse tree (structure of program) and constructs statements, expressions, and subroutines 3. Semantic Analysis: makes sure the variables and other semantics are consistent 4. Intermediate Code Generation: intermediate code generated, usually in form of register operations 5. Code Optimization: intermediate code optimized to minimize space and time requirements 6. Code Generation: final code for target program generated

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

Both - Java programs are first compiled in intermediate form know as byte code; later versions starting using just-in-time compiler to provide faster execution of programs by translating byte code into machine language immediately before every execution

What distinguishes declarative languages from imperative languages?

Declarative - hides implementation details Imperative - embraces implementation details

Why are there so many programming languages?

Evolution, special purposes, personal preference

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

Fortran

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

Front end is the first three phases, which determine the meaning of the source program. Back end is the last three phases which translate the source program into assembly or machine language.

In what way(s) are high-level languages an improvement on assembly language? In what circumstances does 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 P-code?

Intermediate output which is produced as output in bootstrapping process of Pascal compiler

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

Interpretation - interpreter has complete control of execution of programs and reads lines one by one and continues execution simultaneously Compilation - compiler changes input language to machine language, user executes machine language program 1. As interpretation scans program line by line, it provides better error detection 2. Interpretation does not convert input program into any intermediate form, so it provides better and early debugging 3. Some languages are impossible to be implemented without interpretation because they utilize "late binding" (ability to assign values to variable late during execution phase) 4. Compilation is faster, saves result in cache (instead of scanning program every time a variable is requested) 5. Compilation more efficient

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

It is a data structure (maintained by the semantic analyzer) that contains information about the indentifiers in a program such as the data type, size of the element, scope, etc. Semantic analyzers uses table to generate rules which constitute structure of program in terms of expressions, statements, and subroutines.

What was the first functional language?

Lisp

What is the difference between machine language and assembly language?

Machine language - bits readable by machines Assembly language - symbols readable by people

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

No, due to the fact that concurrent execution of instructions is not possible and assembly and the compiler's access to advanced microprocessor architectures and superscalar implementations, a programmer cannot generate better code.

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

Phase is a step that determines information useful to the next phase. Pass is a set of inter-related phases in such a manner that the next step cannot start until the completion of the previous phase. Multiple passes is useful when the front end may be shared by compilers for more than one target program and the back end may be shared for more than one source program.

What is bootstrapping?

Process of compilation in same language in which it was developed; used to implement self-hosting features of compilers

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

Program passed to scanner in form of sequence of characters which is scanned one by one to group into tokens. Tokens passed to parser to generate parse tree, which determines structure of program and expressions. Semantic analyzer then assigns meaning to constructed program and checks for static and dynamic errors. Semantic analysis generate abstract syntax tree, which is used to generate intermediate code.

What is the difference between static and dynamic semantics?

Static checks: 1. Whether each indentifier is declared before being used 2. No indentifier should be called in an illegal context 3. Subroutine call with correct number and type of arguments 4. In the switch constructs all cases must be associated to distinct constant 5. Any function defined as non-void must return an explicit value Dynamic checks: 1. Unassigned variable not used in expression 2. If pointer foes not refer to a valid object then it cannot be dereferenced 3. Array should be assigned values within bounds of array 4. Arithmetic operations must be within defined limit

What is a just-in-time compiler?

Translation of byte code into machine language before every execution


Kaugnay na mga set ng pag-aaral

Motivation and Social Psychology

View Set

The Aegean Cycladic, Minoan and Mycenaean Art

View Set

Chapter 4 Multiple Choice Questions

View Set

GENBA 110 - Business Foundations

View Set

Edmentum Mastery Test: Inscribed and Circumscribed Circles (100%)

View Set

Direct Social Work Ch. 5 Responding with Reciprocal Empathy and Constructing Reciprocal Responses, the leads list

View Set