Program Construction Flashcards
(19 cards)
Describe an assembler
A simple translation program
- converts low level assembly language into machine code
- 1 instruction = 1 machine code instruction
-no extra unnecessary lines of code
-used for maximum efficiency
Describe a compiler
- converts high level language into machine code
- can be run over and over once compiled
- shows list of errors
Describe an interpreter
-runs a high level language program
-doesn’t convert into a binary executable
-interprets one line, executes one line
Give As and Ds for a compiler
- takes a while but can be run over and over
- end user doesn’t need a compiler
-shows a list of errors
-can be slow
-software needs to be recompiled
Give As and Ds for an assembler
+quicker bc AL is closer to machine code, doesn’t require additional steps
-difficult to write and read
-machine dependant, can only be run on a specific type of computer
Give As and Ds for an interpreter
+ as lines are run, can debug easily
+test code immediately
- end user needs access to code, security risk
Assuming a compiler and interpreter both exist for the language…
Interpreter for development
- quick testing
Compile for distribution
- int security risk
What is meant by intermediate language?
Similar to machine code
H
Not processor specific
Allows code to be created to run on multiple architectures
Code runs very quickly, conversion is straightforward
Eg. Bytecode for Java and CIL for .Net
What are translation errors?
Errors spotted by the compiler
Syntax, structure
Semantic, spotted in semantic stage
Linking, linking code
What are execution errors?
Run time errors
Occur when a program is running, cause program to crash
What are the stages of compilation?
Source Code
Lexical analysis
Syntax analysis
Semantic analysis
Code generation
Optimisation
Object code
Describe lexical analysis
-Removes comments and spaces
- tokenisation: source code to tokens, refer to symbol table
- add entries to symbol table for names
- basic error checking
-program now set of token
Describe syntax analysis
Checks structure of program is correct,
Follows grammar rules of language
List of syntax errors
Compilation may stop
Describe semantic analysis
Check for types of error:
- variables declared
-values are assigned to data type
-no illegal mixed code arithmetic
Describe code generation and optimisation
Generates machine code
Each HLL line becomes many lines of machine code
Optimisation-
Improve efficiency, make program smaller
Compare the translation process carried out by a compiler with the translation process carried out by an interpreter
Compiler-
Takes entire program as input, produces machine code version
Compiled program can be re-run without more translation
Interpreter-
Single source code instruction. Translate, execute.
Interpreter needs to be repeated each time program is run
Describe a diagram of a compiler
Source code- compile- object code- run any number of times
Describe a diagram of an interpreter
Source code- interpret line- execute line LOOP