Lecture 3 Flashcards
(17 cards)
Layered View of Computer
Bare Machine.
Macro Instruction Interpreter.
Operating System.
Compiler level, such as C++, FORTRAN, Operating System Command Interpreter (CMD).
Then Virtual Compiler.
Computer & Languages
Primitive Operations.
The processor circuits provide a realisation of a set of primitive operations, or machine instructions for arithmetic and logic
operations.
Computer & Languages
Macroinstructions
Some of machine instructions are called macroinstructions, because they are put together with a set of instructions of even lower level called microinstructions.
Computer & Languages
Set of instructions
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.
Computer and Languages Continued
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.
Language Implementation Methods
Compilation
Programs are translated into machine language, includes Just-In-Time systems.
Use: large scientific or commercial applications.
Language Implementation Methods
Pure Interpretation
Programs are interpreted by another program known as an interpreter.
Use: Small programs or when efficiency is not a big issue, web programs.
Language Implementation Methods
Hybrid Implementation Systems
A compromise between compilers and pure interpreters.
Use: Small and Medium systems when efficiency is not the first priority.
Compilation
Translates high-level program (source language) into machine code (machine language).
Slow translation, fast execution.
Compilation process
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.
Compiler
Computer Program that translates a program in a source language into a equivalent program in a target language.
Compiler can give error messages.
Compiler Source Language
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.
Structure of a Compiler
- Source Program -
Lexical Analyser
Semantic Analyser
Code optimiser
Code generations
(all have a symbol table)
- Target Programs -
Structure of a compiler details
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.
Lexical Analysis
Reads the source program text ( one character at a time ) and returns sequence of tokens to send to next phase.
Lexical Analysis Tokens
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.”