Compilers, Interpreters and Grammars Flashcards
Week 11 Stuff
How does a compiler work?
Takes a source program and translates the whole thing into machine code.
The translation and execution are separate
How does an interpreter work?
Takes one instruction at a time from source code and does it.
No binary code is generated.
Source program analysis and execution are interlaced
Which executes code faster, compiler or interpreter?
Compiler
Which is better for keeping source code hidden, compiled or interpreted?
Compiled
Which is better for rapid prototyping (changes are frequently made), compiled or interpreted?
Interpreted
Which is better for moving between platforms, compiled or interpreted?
Interpreted
Why are interpreters sometimes called virtual machines?
Because they take 1 instruction at a time and execute it (similar to a CPU)
Is Java compiled or interpreted?
Both, it’s compiled into machine-independent virtual machine code then interpreted when run.
javac generated virtual bytecode, JVM interprets this.
What is translation?
The act of turning source code into binary (machine) code which the CPU can understand
What kinds of programs do translation?
Compilers (translate HLL into machine code)
Assemblers (translate mnemonics like MOV into binary code)
Sometimes compiling requires a compiler and assembler as 2 steps
What are the steps to making then running a program?
Edit -> Compile -> Link (to external libraries) -> Load/Run
What are the 3 components of a coding language?
Lexical (the tokens)
Syntactical (the structure)
Semantic (the meaning)
What does a lexicon contain?
All the legal words (elementary expressions) in a language together with the information about them.
In Java, these are things like “import”, “public”, “else”, etc.
What does syntax define?
It defines the correct form legal expressions of the language must take.
For example, “double private x” is lexically correct but “private double x” is the syntactically correct version with the tokens in the correct order.
Basically, syntax means tokens are in the correct order
What does the semantic component define?
It defines what an expression actually means.
if (m < n) { doSomething(); } is correct lexically and syntactically but unless we define how if statments work in the semantics, this has no meaning.
Semantics require are statments to have meaning which makes sense