Program Construction Flashcards
What happens when an overflow error occurs?
We change (flip) all the values to the right of the most significant bit (MSB) to it’s opposite.
What are the 3 types of translators and what do they do?
Compilers- translates the whole program into machine code.
Interpreters- translate the program line by line into machine code
Assemblers- Translates assembly language into machine code using mnemonics.
What is the purpose of a translator?
To convert source code (higher level languages) to object code (aka machine code).
What are the advantages and disadvantages of using compilers?
Advantages
- It’s very fast as all source code is executed at once
- It produces an executable file that doesn’t need to be compiled each time when run.
- Library files are packages with the executable code.
Disadvantages
- Error messages are only displayed after the code has been compiled, making it difficult to debug individual lines of code.
- It’s therefore more difficult to debug
What are the advantages and disadvantages of using interpreters?
Advantages
- It’s easy to identify bugs as code is translated instruction by instruction.
- Code can be run on any machine with the interpreter
-If a single error is found, you can fix it and continue to compile (no need to recompile the whole program)
Disadvantages
- An executable file is not produced meaning it needs to be interpreted each time the program is run.
- It can be slower to compile
- The library files must be present for the program to be run (Separately)
What programming languages use compilers?
Java and C++
What programming languages use interpreters?
JavaScript, Python and Ruby
What are the 4 stages of the compilation process? (With what they do)
- Lexical Analysis- spaces, functions → tokens, table
- Syntax Analysis- grammar, rules
- Semantic Analysis- Unused variables, data types
- Code Generation- optimisation
Lexy Sang Semi Calm???
What happens in Lexical Analysis?
1) Unnecessary Spaces and comments are removed
2) Constants, keywords (e.ge print) and identifiers (names for variables/ functions) are replaces with ‘tokens’ that represent their function
3) A table is creates to store these tokens
What happens in Syntax Analysis?
1) Checks the grammar and spelling of the tokens in the table
2) They are also checked against the rules to determine if they are the correct syntax.
3) If the syntax, spelling or grammar is incorrect an error message is produced
What happens in Semantic Analysis?
1) Variables are checked to ensure they are declared and used
2) They are check to see if they have the correct data type (e.g. Strings, Integers, and real).
What happens in Code Generation?
1) Code is optimised to make generating machine code more efficient by removing redundant instructions and replacing inefficient code.
What are the 6 types of syntax errors?
- Runtime Execution Error
- Linking Error
- Logical Error
- Rounding Error
- Syntax Error
- Truncation Error
Rabbits like licking really sweat Treats
What is the description of a Runtime Execution Error and example?
The program stops due to an invalid operation during execution. For example trying to divide by 0 or attempting to read past the end of a file.
What is the description of a Linking Error and example?
The compiler can’t find a sub-procedure as the programmer has not declared it properly. E.g. A procedure (code) carrying out mathematical calculations but the maths library has not been called.