Learning Objectives
By the end of this chapter, you will be able to:
- Define syntax and semantics and spot why a program fails.
- Compare low level and high level languages by readability, speed, portability, and use.
- Order generations 1GL to 5GL by abstraction and example.
- Contrast compiler, interpreter, and assembler by input, output, and error timing.
- Choose a language by task, performance, and hiring constraints.
What a programming language is
A programming language is a formal set of instructions that tells a computer what to do. Every language has syntax, the grammar that must be correct for the program to run, and semantics, the meaning that decides whether the result is correct. A syntax error stops execution. A logic error executes but answers wrong.
Human code cannot run as written. It must be translated to machine code, the binary that the CPU executes.
Low level versus high level: group by distance from hardware
Distance from hardware predicts who reads it, how fast it runs, and where it fits.
A. Low level: close to the machine
- Machine language (1GL): binary such as
10110000 00000101. The CPU runs it directly. No human reads it for long. - Assembly language (2GL): mnemonics such as
MOV AL, 5andADD AL, 3. Readable to a trained engineer, still tied to one CPU family. Translated by an assembler.
Use where control and cycle count matter: device drivers, embedded controllers, firmware.
B. High level: close to the human
English like statements such as total = 5 + 3 or SELECT Name FROM Customers WHERE City = 'Pokhara';. Portable across machines, slower by a small overhead that rarely decides a business choice.
Group high level by intent, not just name:
| Group | Intent | Examples | Typical place in business |
|---|---|---|---|
| 3GL procedural | Tell how to do it step by step | C, Java, Python, C++ | Back ends, Android, data scripts |
| 4GL declarative | Say what you want, not how | SQL, report builders | Queries, reports, dashboards |
| 5GL constraint and AI | State constraints, let solver infer | Prolog | Logic and AI prototypes |
The same addition at three distances:
| Level | Code | Who reads it |
|---|---|---|
| Machine | 10110000 00000101 |
CPU only |
| Assembly | MOV AL, 5 |
Engineer with manual |
| High level Python | total = 5 + 3 |
Any trained developer |
| Aspect | Low level | High level |
|---|---|---|
| Readability | Hard, needs manual | Easy, English like |
| Execution speed | Fastest per task | Slightly slower, translator overhead |
| Portability | Tied to one CPU | Runs on many platforms |
| Build time | Long, error prone | Short, easier to maintain |
| Best use | Drivers, embedded | Apps, web, analysis |
flowchart TB
HL[High level: Python Java C++] --> TR[Translator]
ASM[Assembly: MOV ADD] --> ASMB[Assembler]
TR --> ML[Machine code: binary]
ASMB --> ML
How translation happens
Since hardware only runs binary, every non binary language needs a translator. The translator decides workflow, error timing, and artefact.
| Translator | Translates when | Produces | Error seen | Examples |
|---|---|---|---|---|
| Compiler | Whole program before run | Executable file | After full scan, list of errors | C, C++ |
| Interpreter | Line by line during run | No separate file, runs directly | At first offending line | Python, JavaScript |
| Assembler | Assembly to binary before run | Binary object | On failing mnemonic | Assembly |
| Hybrid | Compile to bytecode then run | Bytecode on virtual machine | Both phases | Java JVM bytecode |
A common flow:
flowchart LR
SRC[Source code] --> C[Compiler]
C --> EXE[Executable]
EXE --> RUN[Run]
SRC --> I[Interpreter]
I --> OUT[Execute line by line]
Faster after compile is true. Faster to change and test after interpret is also true. Business trade off is build time versus run time, not only speed.
Popular languages and where they fit by task
Group by the task that pays for them, not alphabetically.
| Task | First look | Why |
|---|---|---|
| Data analysis and AI | Python | Libraries, notebooks, hiring pool |
| Enterprise and Android | Java, Kotlin | JVM stability, tooling, scale |
| Web interactivity | JavaScript | Runs in every browser |
| Systems and games | C, C++ | Control and speed |
| Windows apps and Unity | C# | Platform tooling |
| Web content sites | PHP | WordPress ecosystem |
| Data storage | SQL | Standard for queries |
| iOS apps | Swift | Apple platform |
Language choice is a staffing and maintenance decision as much as a technical one. A Pokhara firm building a bank mobile app might use Kotlin and Swift for the handsets, Java for the application server, and SQL for queries, because that mix matches the hiring market and the audit trail.
Self-check
Nepal worked example: build or buy a barcode billing script on 2081-10-03 (NPR)
A stationery shop in Pokhara needs a small billing aid for 400 bills a day. On 2081-10-03 it prices two options for a 3 year horizon.
Option A: a Python script written by a freelancer. Build cost Rs 60,000 on 2081-10-03, maintenance Rs 8,000 per year, a part time Python assistant at Rs 25,000 per year to run reports, and a laptop already owned. No licence. Errors are caught by the interpreter at run time line by line, so fixes can be tested the same day.
Option B: a C based billing utility sold locally as compiled executable. Licence Rs 45,000, annual support Rs 12,000, plus one day of training Rs 5,000. Errors are caught at compile time by the vendor before release, but any change needs a new build from the vendor.
3 year cost:
- A: 60,000 plus 8,000 times 3 plus 25,000 times 3 = Rs 159,000.
- B: 45,000 plus 5,000 plus 12,000 times 3 = Rs 86,000.
B is cheaper on cash. A is cheaper on control. Because the shop wants to add QR e-invoice fields next year under IRD changes, it picks A despite the higher three year cash, since interpreter based change does not wait for a vendor release. If no IRD change were expected, B would be the better TCO.
Example 1: On 2081-10-03 a business decision is whether interpreter speed of change matters more than cash TCO. Ask: if IRD changes the invoice schema, can the shop ship the fix before month end without waiting for a vendor build? If not, the cheaper licence is the costlier compliance risk.
Example 2: On 2081-10-03 a business decision is throughput at the till. Ask: for 400 bills a day, does the chosen language let a junior hire add a discount rule in hours and test it live, or does it need a compile and redeploy window that stops sales? Measure hours to rule change, not only licence NPR.
Summary
- Syntax decides whether a program runs. Semantics decides whether it answers correctly.
- Low level is close to hardware and fast per cycle. High level is close to humans and fast to build.
- 1GL and 2GL are machine and assembly. 3GL states steps, 4GL states wanted results, 5GL states constraints.
- Translators decide workflow: compiler for whole program executables, interpreter for line by line execution, assembler for assembly, hybrid for bytecode.
- Language choice follows task, performance need, and who you can hire to maintain it.
Key Takeaways
- No high level program runs without translation to binary.
- Compiler versus interpreter is when translation happens and when errors appear, not only speed.
- 4GL SQL asks what, 3GL code describes how.
- Pick by task and maintenance market, not by popularity alone.
Discussion Questions
- Why does a high level program need a translator even though it looks correct?
- When is a compiled language worth its slower change cycle?
- Give one business case for SQL instead of procedural code for the same report.
Exercises
Short answer
- Define syntax and semantics with an example of each error.
- Differentiate 1GL, 2GL, and 3GL with one example each.
- Contrast compiler and interpreter on translation time, artefact, and error reporting.
Long answer
- Compare low level and high level languages on readability, speed, portability, build time, and use, with a table and a Nepali business example.
- Explain generations 1GL to 5GL and the role of compiler, interpreter, assembler, and JVM bytecode, with the Pokhara billing choice on 2081-10-03 and its three year NPR math.


