Compilation, Interpretation & Subroutines Flashcards
What is the main difference between compilation and interpretation?
Compilation changes high-level code into machine code before running it. Interpretation runs code line by line without changing it into machine code.
What are the levels of programming languages?
High-Level Languages (e.g., Java, C++)
Low-Level Languages (e.g., Machine Code)
Assembly Language (between high and low level)
What are the main steps in the compilation process?
Lexical Analysis
Syntax Analysis
Semantic Analysis
Optimization
Code Generation
Linking
What are the advantages of compilation?
Runs faster after compiling, better machine code, and works well on specific platforms
What are the disadvantages of compilation?
Takes longer to compile and needs recompilation for different hardware
What is cross compilation?
Compiling code on one platform to run on a different one
What is an interpreter?
A program that reads and runs code line by line.
What are the advantages of using an interpreter?
Easier to debug and test, works on any platform, and runs while modifying in real-time
What are the disadvantages of using an interpreter?
Interpreted code runs slower because it’s handled line by line, adding extra work during execution
How does combined compilation and interpretation work?
High-level code is compiled into bytecode, then either interpreted or JIT compiled
What is a Virtual Machine (VM)?
A software that acts like a physical computer to run intermediate code.
What is the most common virtual machine in programming?
The Java Virtual Machine (JVM), which executes Java bytecode.
What is JIT compilation?
Bytecode is compiled to machine code right before running to improve performance
What are subroutines?
Reusable code blocks that do a task and can be used anywhere in a program
What are the advantages of using subroutines?
Reuse code, keep it organized, and reduce repetition
What is a stack used for in subroutine management?
To store return addresses, parameters, and local variables.
What are the primary operations performed on a stack?
Push (add to top) and Pop (remove from top).
What are the call and return instructions used for?
Call saves the return address and jumps to the subroutine. Ret gets the address back from the stack
What is Reverse Polish Notation?
A way of writing math where operators come after numbers (e.g., 3 4 + instead of 3 + 4).
Why is Reverse Polish Notation useful?
No parentheses needed, so stack calculations are easier
How would you express 3 + 4 * 2 in RPN?
3 4 2 * +
What is an operand stack?
A data structure that holds numbers and results during calculations
What are stack machines?
Computers that use stacks, not registers, to do operations
What is the difference between unconditional and conditional jumps?
Unconditional Jump: Always goes to a set address.
Conditional Jump: Goes to a new address only if a condition is true (like if x == 0).
What is the Shunting-Yard Algorithm used for?
Converting infix expressions (e.g., 3 + 4 * 2) to postfix (RPN) expressions.
What type of architecture does JVM follow?
An architecture that uses a stack to push and pop values while doing operations
Why is Java considered portable?
Java code becomes bytecode, so it can run on any computer with a JVM
Why do subroutines save registers?
Saves the caller’s register values during execution.
Why are stacks efficient for temporary storage?
They follow the LIFO (Last In, First Out) rule, making push and pop quick