Program construction Flashcards
assembler
translates code from low level assembly language to machine code
once assembled program file can be re-used without assembly
interpreter
reads, translates and executes one line at a time from high level language program
interpreter pros
will stop when comes across a line with an error which makes debugging easier
interpreter cons
doesn’t produce executable file so must be re-translated each run - slower overall
relevant interpreter to source code must be installed
compiler
translates code from high level to machine all at once then executes used by C++
compiler pros
slow for first run though due to translation but produces executable file that means only needs to be translated once
compiler cons
can produce multiple errors at same time so hard to debug
if needs to run on diff platform it will need to be recompiled to be targeted at required platformst
stages of the compilation process
lexical analysis
syntax analysis
semantic analysis
code generation and optimiser
lexical analysis
comments and unneeded spaces are removed
converts source code into token stream and puts them into the symbol table
keywords, constants and identifiers become tokens (usually hex numbers) in the table
syntax analysis
the tokens are checked to see if they match the expected spelling and grammar
done by parsing each token to determine if it uses the correct syntax for the language
produces error message if syntax error found
semantic analysis
variables checked to ensure:
they have been properly declared and used + they are of the correct data type
operations checked to ensure they are legal for data type being used
code generation
code specific to target machine is generated
several lines of machine code for each high level instruction
code optimisation
replacement of inefficient code done by compilers to increase speed of the program, decrease demand on resources while still achieving desired output and not delaying overall compilation process