MEG 202 · Basic Software Engineering
Our notes
2 min readLevels of language
- Machine language: binary instructions the CPU executes directly (for example 10110000 01100001). Fast, but hard to write and specific to one processor family.
- Assembly language: short mnemonics for machine instructions (MOV, ADD, JMP) and symbolic addresses. An assembler translates it to machine code. Used for device drivers, embedded systems and speed-critical code.
- High-level languages: close to human language and mathematics, and portable across machines: FORTRAN (1957, scientific computing, still used for engineering simulation), COBOL (business), Pascal (teaching, structured programming), C (1972, systems and embedded programming), C++, Java, Visual Basic (Windows applications), Python and MATLAB (engineering analysis today).
Example: the statement a = b + c in a high-level language may become, in assembly:
LOAD R1, b
ADD R1, c
STORE R1, a
Paradigms
- Procedural (imperative): step-by-step instructions grouped into procedures (FORTRAN, Pascal, C).
- Object-oriented: data and the functions acting on it grouped into objects (C++, Java, Python).
- Functional, logic and event-driven (Visual Basic forms respond to clicks) styles.
Formal languages
A programming language is a formal language: a set of strings built from an alphabet by precise rules (a grammar), unlike natural languages, which are ambiguous.
- Syntax: the rules of form: which sequences of symbols are valid programs. A missing semicolon in C is a syntax error.
- Semantics: the meaning: what a valid program does. x = x + 1 is valid syntax; its meaning is "add one to x and store it".
- Pragmatics: how the language is used in practice (style, conventions).
BNF (Backus-Naur Form)
A notation for grammars (introduced for ALGOL 60). Rules define non-terminals in angle brackets in terms of terminals and other non-terminals, with ::= meaning "is defined as" and the bar meaning "or":
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<integer> ::= <digit> | <integer> <digit>
The second rule is recursive: an integer is a digit, or an integer followed by a digit. So 407 is an integer: 4 is an integer, 40 is integer + digit, 407 is integer + digit. Compilers use such grammars to parse programs.
Translators
- Compiler: translates the whole source program into machine code before running (C, FORTRAN, Pascal). Fast execution; errors are reported for the whole program; the executable can run without the compiler.
- Interpreter: translates and runs one statement at a time (classic BASIC, Python, MATLAB). Easier testing; slower execution.
- Stages of compilation: lexical analysis (split into tokens) → syntax analysis (parse with the grammar) → semantic analysis (type checks) → optimisation → code generation → linking with libraries.
Types of errors
- Syntax errors: found by the compiler.
- Run-time errors: occur while running (division by zero, reading past an array's end).
- Logic errors: the program runs but gives wrong answers (wrong formula); found only by testing.
Exams usually ask
- Compare machine, assembly and high-level languages.
- Distinguish syntax and semantics; write a BNF rule.
- Compare compilers and interpreters.
Common mistake
Thinking a program that compiles is correct. Compilation catches syntax errors only; logic errors need testing.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Best pick Introduction to Computer Science, 7.1 Programming Language Foundations
(opens openstax.org in a new tab)
OpenStax, Introduction to Computer Science, 7.1 Programming Language Foundations, CC BY-NC-SA 4.0 · licence
-
Introduction to Computer Science, 7.4 Programming Language Implementation
(opens openstax.org in a new tab)
OpenStax, Introduction to Computer Science, 7.4 Programming Language Implementation, CC BY-NC-SA 4.0 · licence
-
Programming language
(opens en.wikipedia.org in a new tab)
Wikipedia, Programming language, CC BY-SA 4.0 · licence
-
Compiler
(opens en.wikipedia.org in a new tab)
Wikipedia, Compiler, CC BY-SA 4.0 · licence
-
NOUN CIT 215: Introduction to Programming Language
NOUN course book (PDF, about 6.2 MB: best on Wi-Fi). Syntax, semantics and translation.
(opens nou.edu.ng in a new tab)
-
OpenStax, Introduction to Computer Science (whole free textbook)
The whole book, free to read online or download as a PDF (the PDF is large: Wi-Fi).
(opens openstax.org in a new tab)
OpenStax, OpenStax, Introduction to Computer Science (whole free textbook), CC BY-NC-SA 4.0 · licence
Watch
-
Programming Logic and Languages: Syntax and semantics | | UPV
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
-
PLP 4.1: Program Semantics and Abstract Syntax Trees
8 min · ≈ 36 MB · about ₦20
(opens youtube.com in a new tab)
-
programming language syntax 02
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
-
Syntax Directed Translation | Semantic Analysis | Part 2 (C50)
23 min · ≈ 104 MB · about ₦58
(opens youtube.com in a new tab)
-
Semantic Analysis & Syntax Directed Translation | Unit-03 | Semantic Error with Examples
30 min · ≈ 135 MB · about ₦76
(opens youtube.com in a new tab)
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.