Tutorial 3: Interpreters and Compilers for Programming Languages
Unit 3 ยท Section 3
Objectives
Trace lexical, syntactic, and semantic processing.
Compare interpretation with compilation.
Explain runtime and portability trade-offs.
A language implementation reads source, identifies tokens, builds structure, checks meaning, and executes or translates it. A compiler produces another form before execution; an interpreter executes from a representation at runtime. Virtual machines and just-in-time compilers combine these strategies.
Classify three errors as lexical, syntax, or semantic.
Compare Java bytecode with native compilation.
Describe one portability benefit of a VM.
Self-check
What is a token?
What does semantic checking do?
Why use a VM?
Self-Check Quiz
1. What does a compiler translate?
AnswerSource code into another executable representation such as bytecode or native machine code.
2. What does syntax describe?
AnswerThe grammatical structure and arrangement of language constructs.
Homework
Trace a program through a language toolchain.
Compare interpreter startup with compiled execution.
Explain one error caught before runtime.
Sample answerA compiler tokenizes and parses source, checks types and meaning, emits bytecode or machine code, and a runtime executes it. Static checking can reject an undeclared variable before the program runs; interpretation may provide faster experimentation but can defer errors.