Lecture 3 Flashcards

(42 cards)

1
Q

Layered View of Computer

A

(inside )

Bare Machine.

Macro Instruction Interpreter.

Operating System.

Compiler level, such as C++, FORTRAN, Operating System Command Interpreter (CMD).

Then Virtual Compiler.

(outside)

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

Computer & Languages

Primitive Operations.

A

Processor circuits provide a realisation of a set of primitive operations, or machine instructions for arithmetic and logic
operations.

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

Computer & Languages

Macroinstructions

A

Some of machine instructions are called macroinstructions, because they are put together with a set of instructions of even lower level called microinstructions.

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

Computer & Languages

Set of instructions

A

Machine Language of a computer is its set of instructions. In the absence of any other supporting software, its own machine language is the only language a computer can understand.

A computer could be designed and built with particular high-level languages as its machine languages, but it would be very complex, expensive, difficult or impossible to use other high-level languages.

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

Computer and Languages Continued

A

On top of the machine language, is the Operating System.

Large Collection of programs that supplies higher-primitive than those of the machine language, e.g primitives for device and file system management, I/O operations, text/program editor and etc.

Rested on the operating system are various language
implementations.
* A particular language implementation and the operating system form
a virtual computer of that language, e.g., the operating system and C compiler provide a virtual C computer.

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

Language Implementation Methods

Compilation

A

Programs are translated into machine language, includes Just-In-Time systems.

Use: large scientific or commercial applications.

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

Language Implementation Methods

Pure Interpretation

A

Programs are interpreted by another program known as an interpreter.

Use: Small programs or when efficiency is not a big issue, web programs.

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

Language Implementation Methods

Hybrid Implementation Systems

A

A compromise between compilers and pure interpreters.

Use: Small and Medium systems when efficiency is not the first priority.

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

Compilation

A

Translates high-level program (source language) into machine code (machine language).

Slow translation, fast execution.

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

Compilation process

A

Lexical Analysis:
Converts characters in the source program into lexical units.

Syntax Analysis:
Transforms lexical units into parse trees which represent the syntactic structure of program.

Semantics Analysis:
Generate intermediate code.

Code Generation:
Machine code is generated.

Work is done by a compiler.

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

Compiler

A

Computer Program that translates a program in a source language into a equivalent program in a target language.

Compiler can give error messages.

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

Compiler Source Language

A

Source language is a high-level language. The target language is a low level language.

  • A machine or assembly language.
  • A language executable by a virtual machine.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Structure of a Compiler

A
  • Source Program -

Lexical Analyser
Semantic Analyser
Code optimiser
Code generations
(all have a symbol table)

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

Structure of a compiler details

A

The source program is read by the first phase. (Lexical Analyser)

The target program is output by the final phase (code gen.)

Phases interact with a data structure called a symbol table.

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

Lexical Analysis

A

Reads the source program text ( one character at a time ) and returns sequence of tokens to send to next phase.

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

Lexical Analysis Tokens

A

Tokens are symbolic names for lexical elements of the source language, in a Pascal compiler.

  • IF might be the token for the Paschal keyword if.
  • IDENT stands for any identifier (e,g. foo, n12)

Each token is associated with a pattern
- IF is an associated with the pattern “i followed by f”
-IDENT is associated with the pattern “ a sequence of letters, digits and ‘_’ that begin with a letter.”

scanner matches patterns against sequences of input chars

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

Symbol Table

A

Is a data structure containing all identifiers (with attributes) of a source program.

18
Q

Symbol Table Attributes

A

For variables, typical attributes include type size, scope.

For methods, procedures or functions:

  • Number of arguments and their types and passing mechanisims.
  • the return type (if any)

The symbol table provides access to identifier attributes throughout the compilation process.

19
Q

Syntax Analysis (Parsing)

A

Syntax analyser (parser) analyses the syntactic structure of the source program.

Input to a parser is the sequence of output tokens from the lexical analyser.

Attempts to apply rules that define syntax of language on the sequence of tokens.

20
Q

Syntax Analysis (Parsing) rules

A

Suppose that part of the source language is described by the rules:

<assign> -> <ident> := <exp>
<exp> -> <ident> | <ident> + <ident>

The lexical analyser, on reading the input fragment x: = y + z, returns the following token sequence:

IDENT(x) ASSIGN IDENT(y) PLUS IDENT(z)
</ident></ident></ident></exp></exp></ident></assign>

21
Q

Parse Trees

A

The parser uses these rules to derive the sequence of tokens; such a derivation would relate to the parse trees on the left:

check slides!

22
Q

Parser Abstract Syntax Trees

A

Represent the source program syntax, but is simpler that the corresponding parse tree.

23
Q

Semantic Analysis

A

Checks whether the program is syntactically correct, but not that it is completely valid or semantically correct.

24
Q

Semantic Analysis Expression example

A

Expression such as y + z is syntactically valid.
But if y is declared as a float, and z as a string, it is
semantically meaningless.

An example, a procedure call, such as doit (12, x, y, z) , is syntactically ok, but semantically meaningless if doit is declared to take 3 arguments.

Semantic analyser determines if the source program is semantically valid.

25
Code Optimisation
Code optimisation phase attempt to improve the time and space requirements of a program. Example optimisations include: -Constant folding (e.g replacing 3+7 with 10) - Eliminating unreachable code - Follow-of-control optimisation, and etc
26
Code Generation
Final task of the compiler is to generate code for a specific machine. In this phase we need to consider: -Instruction selection: -Instruction scheduling -Register Allocation -Debug data.
27
Code Generation Instruction Selection:
Which (machine language) instructions to use.
28
Code Generation Instruction scheduling
in which order to put those instructions.
29
Code Generation Register allocation
the allocation of variables to processor registers
30
Code Generation Debug data generation
if required so the code can be debugged.
31
Code Generation output phase
Is usually programs in machine language or assembly language or code for a virtual machine. Code generation could be found in compiler design texts
32
Pure Interpretation
A program is interpreted by another program called interpreter that directly executes the programs written in a high-level programming language without previously batch-compiling them into machine language.
33
Pure Interpretation Parse
The source code and execute it directly, e.g html, JavaScript, and early versions of LISP and BASIC.
34
Interpreter Diagram
Source Program gives input data to Interpreter then outputs results.
35
Pure Interpretation Slower Execution than compiled programs
-Decoding high-level languages statements is slower than decoding machine language instructions. - Regardless how many times a statement is executed, it must be decoded every time.
36
Pure Interpretation Often requires more space
The source code and the symbol table must be present during the interpretation.
37
Pure Interpretation and Compilation
Have more methods at the opposite ends, they are not mutually exclusive, as most interpreting systems also preform translation work just like compilers do.
38
Hybrid Implementation Systems difference between pure.
Compromise between compilers and pure interpreters (not as fast as compiled languages, but faster than interpreted languages). A high-level language program is translated/compiled to an intermediate code that will be interpreted during execution.
39
Hybrid Implementation Systems Compilation
very similar to that of a compiled language, except that the intermediate code is never further translated/compiled to machine language instructions.
40
Hybrid Implementation Systems
virtual machine is supplied that takes the intermediate language as its machine language, and interpret the intermediate code (much faster than it would be able to interpret a high-level language) E.g., Perl, Python, and MATLAB, JDK1.0.
41
Hybrid Implementation Systems flowchart
Source Program -> Lexical Analyzer -> Lexical Units -> Syntax Analyzer -> Intermediate Code Generator -> Interpreter -> which takes input data and gives results.
42
Just-in-Time Implementation Systems
Initially compile programs to an intermediate language. The program in intermediate language is loaded into memory and segments of the program are translated into machine code just before its execution. The machine code version is kept for subsequent calls. JIT systems is used for Java Programs and is largely responsible for making Java competitive with fully compiled languages at runtime. .NET languages are implemented with a JIT system.