Programming Languages – Lecture 1 Review
Learning Outcomes
- LO1: Identify use of programming languages
- LO2: Discuss generations of computer languages
- LO3: Explain role of translators
- LO4: Compare language levels / generations
Programming Language Definition
- Vocabulary + grammatical rules used to instruct a computer to perform specific tasks
Core Components
- Vocabulary (Alphabet)
- Syntax (structure)
- Semantics (meaning)
Syntax vs Semantics Example
- "Snake is a reptile." – correct syntax & semantics
- "Snake is a mammal." – correct syntax, wrong semantics
- "Snake not mammal is." – wrong syntax
Language Generations & Levels
- 1^{st} Gen / Low-level – Machine language
- 2^{nd} Gen / Low-level – Assembly (mnemonics)
- 3^{rd} Gen / High-level – Procedural languages (C, COBOL, Java)
- 4^{th} Gen / Very high-level – Non-procedural & query languages (SQL, PostScript)
- 5^{th} Gen / Very high-level – AI & constraint-based (Prolog, Mercury)
Key Characteristics
- Machine Lang.: binary, hardware-dependent, fastest execution
- Assembly: mnemonics, 1-to-1 with machine code, needs Assembler
- Procedural (3GL): English-like, portable, programmer specifies "what" & "how", needs Compiler/Interpreter
- Non-Procedural (4GL): focus on "what", often DB & visual tools
- 5GL: problem solving via constraints, AI, visual development
Translators
- Assembler – Assembly \rightarrow Machine
- Compiler – Whole high-level source \rightarrow Object code before run
- Interpreter – Statement-by-statement translation & execution during run
Translator contrasts
- Compilation: longer translation, faster run, full error report after pass
- Interpretation: quick translation, slower run, stops at first error
- Assembler: fastest (between two low-level codes)
Compiler duties
- Syntax checking
- Error listing
- Object code generation
Debugging & Error Types
- Syntax errors – violate language rules; found at compile/run time
- Logical errors – program runs but wrong output (wrong operators, reused vars)
- Run-time errors – occur during execution (array bounds, division by 0, infinite loops)