📚
CMS 705
Programming Languages
Complete Exam Cheat Sheet
Rivers State University
Lecturer: the lecturer | Session: 2024/2025
Topics Covered
Language Structure · Data Types · Data Structures
Control Structures · Data Flow · Runtime
Interpretive Languages · Lexical Analysis & Parsing
💡
A language is a formal system of symbols and rules to communicate with a computer. Every instruction must have a precise, single meaning.
| Component | What it studies | CS / C++ analogy |
| Phonology | Sound patterns · smallest units (phonemes) | int, <<, age · tokens |
| Morphology | How words/tokens are formed | Walk + ed → Walked; identifiers |
| Syntax | Rules for arranging words → sentences | for(int i=0;i<10;i++){} |
| Semantics | Meaning of words / sentences | What the code actually does |
| Pragmatics | Language in social / usage context | Readability, writability, reliability |
🎯
3 Key Questions a Language Must Answer:
1. What programs look like → Syntax
2. What programs mean → Semantics
3. How programs are used in practice → Pragmatics
CMS 705
1 / 13
CMS 705
2
Static vs Dynamic Semantics
⚙️ Static Semantics
- Checked at compile time
- Type compatibility
- Variable declared before use
- Prevents execution errors
▶️ Dynamic Semantics
- Checked at runtime
- How expressions are evaluated
- How values change during execution
- What actually happens when code runs
int x;
x = "hello";
int c = 0;
if (flag) c = 1;
cout << c;
⚠️
Exam tip: Static = compile time (type errors, undeclared vars). Dynamic = runtime (actual behaviour, value changes).
2 / 13
CMS 705
3
Types of Language · Levels of Abstraction
| Level | Type | Example | Notes |
| Lowest |
Machine Language |
01001010 |
Binary; CPU executes directly; no translation; machine-dependent |
| Low |
Assembly Language |
MOV A, B |
Mnemonics; needs assembler; full hardware control |
| Middle |
C Language |
int sum = a+b; |
Hardware access + structured; used in OS, compilers |
| High |
Python, Java, C++ |
English-like syntax |
Needs compiler/interpreter; machine-independent; easy to use |
Middle-level (C)
- Moderate portability
- Faster execution
- Manual memory management
- Systems / embedded use
High-level (C++, Python)
- High portability
- Slower (compilation overhead)
- Automatic memory
- Application / end-user focus
3 / 13
CMS 705
🔧
Assembly
Translates assembly language → machine code via assembler
📦
Compilation
Entire program translated at once → .exe (C, C++)
▶️
Interpretation
Code translated & executed line by line at runtime (Python, JS)
⚡
JIT (Just-in-Time)
Bytecode compiled to machine code on demand at runtime · Java / JVM
| Compiled | Interpreted | JIT |
| Speed | Fast | Slower | Near-compiled |
| Output | .exe | None | Native (runtime) |
| Errors found | Before run | During run | Mix |
| Examples | C, C++ | Python, JS | Java (JVM) |
4 / 13
CMS 705
📌
Built-in, fixed size, stored directly in memory (CPU-level). Cannot be null. No built-in functions.
| Type | Size | Example | Use |
| int | 4 bytes | int count = 10; | Counting, indexing, loops |
| short int | 2 bytes | short x = 5; | Smaller integers |
| long int | 4–8 bytes | long big = 99999; | Large integers |
| unsigned int | 4 bytes | unsigned int u = 10; | Non-negative only |
| float | 4 bytes | float t = 36.5; | Single precision (7 digits) |
| double | 8 bytes | double pi = 3.14159; | Double precision (15–16 digits) |
| char | 1 byte | char g = 'A'; | Single character (ASCII) |
| bool | 1 byte | bool ok = true; | Decision / conditions |
| void | - | void display(){} | Functions with no return value |
🧠
int range: −2,147,483,648 to 2,147,483,647 | char uses single quotes 'A' | string uses double quotes "Alex"
5 / 13
CMS 705
6
Non-Primitive Data Types
📌
Also called reference / derived types. Complex, dynamic size, have built-in functions. Built from primitive types.
String
string name = "Alex Johnson";
cout << name.length();
Array
int nums[] = {10,20,30,40};
cout << nums[0];
Struct
struct Student {
string name; int age;
};
Pointer
int c = 10;
int* ptr = &c;
Enum
enum Day {Mon,Tue,Wed,Thu};
Day today = Wed;
cout << today;
Class (OOP)
class Car {
public:
string model; int year;
void display();
};
| Primitive | Non-Primitive |
| Created by | Language itself | Programmer / library |
| Size | Fixed | Dynamic |
| Functions | None | Many built-in |
6 / 13
CMS 705
7
Data Structures · Overview
💡
A method of organising, storing, and managing data in a computer so it can be accessed and manipulated efficiently.
Linear
- Sequential arrangement
- Single level
- Simple to traverse
- Array, Linked List, Stack, Queue
Non-Linear
- Hierarchical / graph-like
- Multiple levels
- Complex to traverse
- Tree, Graph, Heap, Hash Table, Trie
| Operation | Description |
| Insertion | Add element (beginning, end, or position) |
| Deletion | Remove element + free memory |
| Traversal | Visit ALL elements once · "go through everything" |
| Searching | Find specific element · "stop when found" (Linear or Binary) |
| Updating | Change value of existing element |
| Sorting | Arrange ascending/descending (Bubble, Selection, Insertion) |
| Merging | Combine two data structures into one |
⚠️
Traversal vs Searching: Traversal visits every element. Searching stops as soon as it finds the target.
7 / 13
CMS 705
8
Linear & Non-Linear Structures
Stack · LIFO
Push (insert) | Pop (remove)
Function callsUndo/redoBrowser back
Queue · FIFO
Enqueue (rear) | Dequeue (front)
Printer queueCPU scheduling
Array
Contiguous memory, fixed size, O(1) access by index
Binary Tree
Each node ≤ 2 children. Left < Parent < Right (BST)
Hash Table
key → hash function → index. O(1) avg. lookup/insert/delete
Heap
Max Heap: Parent ≥ Children
Min Heap: Parent ≤ Children
struct Node { int data; Node* next; };
Node* head = NULL;
void insertEnd(int value) {
Node* newNode = new Node();
newNode->data = value; newNode->next = NULL;
if (head == NULL) { head = newNode; return; }
Node* temp = head;
while (temp->next != NULL) temp = temp->next;
temp->next = newNode;
}
8 / 13
CMS 705
💡
Determine the order of execution · which statement runs, when, and how many times.
| # | Type | Purpose | Keywords |
| 1 | Sequential | Default top-to-bottom | (none · default) |
| 2 | Selection | Branch on condition | if, else, else if, switch |
| 3 | Iteration | Repeat a block | for, while, do-while, for-each |
| 4 | Jump | Transfer control unconditionally | break, continue, return, goto |
for (int i=1; i<=5; i++)
cout << i;
int i = 1;
while (i <= 5) { cout << i; i++; }
do { cout << i; i++; }
while (i <= 5);
int nums[] = {1,2,3,4,5};
for (int n : nums) cout << n;
if (i==5) break;
if (i==6) continue;
switch(day){
case 1: cout<<"Mon"; break;
default: cout<<"Other";
}
9 / 13
CMS 705
💡
The movement, transformation, and usage of data within a program: Input → Storage → Processing → Output
Input
→
Storage
→
Processing
→
Output
| By Program Execution |
| Sequential | Line by line: A→B→C→D |
| Conditional | Branches on condition (if/else) |
| Iterative | Data flows repeatedly through loops |
| Procedural | Data moves between functions via parameters/return |
Explicit Flow
- Clearly written in code
- Passed as parameters
- Returned from functions
- Easy to trace & debug
Implicit Flow
- Through global variables
- Hidden / indirect
- Harder to trace
- Can cause side effects
10 / 13
CMS 705
11
Runtime Considerations
💡
Runtime = the phase when a compiled/interpreted program is actually executing on the CPU.
📦 Stack
Local variables, function calls | LIFO, auto-freed when function ends
🌐 Heap
Dynamic allocations via new | Must manually free with delete
🌍 Global
Global / static variables | Lives for entire program lifetime
📜 Code
Compiled instructions (text segment) · read-only
int globalCounter = 100;
int processData(int value) {
int localVar = value * 2;
int* heapVar = new int(5);
int result = *heapVar;
delete heapVar;
return result;
}
| Compile Time | Runtime |
| When | Before execution | During execution |
| Errors | Syntax, type errors | Logic, null pointer, division by zero |
| Semantics | Static | Dynamic |
11 / 13
CMS 705
12
Interpretive Languages
| Compiled | Interpreted | JIT |
| Translation | Whole program at once | Line by line at runtime | Bytecode → machine code on demand |
| Output file | .exe produced | No output file | Native code at runtime |
| Speed | Fast (pre-translated) | Slower | Near-compiled |
| Portability | Lower (platform-specific) | High | High (via JVM) |
| Examples | C, C++ | Python, JavaScript | Java (JVM) |
How Interpretation Works
📄 Source Code (.py)
↓
🔍 Read line 1 → Translate → Execute
↓
🔍 Read line 2 → Translate → Execute
↓
❌ Error on line 3 → Stop
How JIT Works (Java)
📄 Java Source (.java)
↓ javac compiler
⚙️ Bytecode (.class)
↓ JVM
⚡ JIT → Machine Code
↓
🚀 Fast Execution
⚠️
Interpreter never produces a saved executable. JIT produces machine code but only at runtime · not saved to disk.
12 / 13
CMS 705
13
Lexical Analysis & Parsing
📖
Source Code
Raw text written by programmer
🔡
Lexical Analysis
Groups characters → TOKENS (keywords, identifiers, operators, literals)
🌳
Parsing
Checks grammar rules → builds Parse Tree / AST
🧠
Semantic Analysis
Checks meaning · types, declarations, compatibility
⚙️
Code Generation
Produces machine code / bytecode
int @age = 5;
int = age 5;
int age = "hello";
| Linguistics | Programming Language | Compiler Stage |
| Phonology | Characters, symbols | Character scanning |
| Morphology | Tokens · keywords, identifiers | Lexical Analysis |
| Syntax | Valid statements & expressions | Parsing |
| Semantics | Meaning of code | Semantic Analysis |
13 / 13
CMS 705
| Key Definitions |
| Syntax | Rules for valid code structure |
| Semantics | What the code means |
| Pragmatics | Readability, writability, reliability |
| Data Type | What a variable holds + ops allowed |
| Parameter | Variable declared in function definition |
| Argument | Value passed when calling a function |
| Stack | LIFO · local vars, auto-freed |
| Heap | Dynamic alloc, manual delete |
| Traversal | Visit every element once |
| Searching | Stop when element found |
🎯
Exam Tips
• Know Singly Linked List C++ code
• Know Binary Tree C++ code
• Know Grade Calculator (procedural data flow)
• break = exits loop; continue = skips iteration
• Static = compile time; Dynamic = runtime
• do-while runs at least ONCE
• JIT: bytecode → machine code at runtime
• Phonology→Morphology→Syntax = Lexer→Parser
📋
5 Course Topics
1. Language Definition Structure
2. Data Types & Structures
3. Runtime Considerations
4. Interpretive Languages
5. Lexical Analysis & Parsing
Rivers State University | CMS 705 · Programming Languages | the lecturer | 2024/2025
✦
CMS 705