Introduction to Programming Languages
Programming Languages
What Is a Programming Language?
A programming language is a formal language used to communicate instructions to a computer, machine, or other digital device.
Humans communicate using natural languages such as English, Hindi, Spanish, or German. Similarly, computers require specialized languages to receive instructions and perform tasks.
A programming language provides the vocabulary and grammatical rules needed to instruct a computer or computing device to perform a specific task.
Each programming language has:
A unique set of keywords
Specific syntax for organizing instructions
Rules for expressing operations and commands
A way to communicate the intended meaning of instructions to the computer
A computer cannot independently decide how to perform a task. It must receive precise instructions from a programmer through a programming language.
Algorithms, Syntax, and Semantics
Algorithms
An algorithm is a sequence of rules or instructions used to perform a specific task or solve a problem.
For example, an algorithm for preparing a meal might specify:
Collect the ingredients.
Prepare the ingredients.
Cook them in a particular order.
Serve the finished meal.
In programming, algorithms describe the logical steps that a computer must follow. The algorithm represents what needs to be done and in what sequence.
The source material describes a programming language as involving rules or sequences that allow instructions to be communicated to a computer. In practice, the algorithm is the problem-solving procedure, while the programming language is the formal system used to express that procedure.
Syntax
Syntax is the structure or form in which instructions must be written.
In a natural language, syntax includes:
Sentence structure
Word order
Grammar
Spelling and pronunciation
Punctuation
Articles and other grammatical elements
In a programming language, syntax determines:
How commands are written
How variables and expressions are structured
Where symbols or punctuation must be placed
How program statements must be arranged
If a programmer violates the syntax rules, the computer or language translator may report an error.
Semantics
Semantics refers to the meaning produced by a statement or instruction.
A syntactically correct sentence or program may still have an unintended meaning. Therefore, programming requires both:
Correct syntax, or properly formed instructions
Correct semantics, or the intended meaning of those instructions
For example, syntax determines whether a command is written in the correct format, while semantics determines what the command instructs the computer to do.
Computer-Readable Instructions
Electrical Signals and Binary Digits
Computers are electronic devices and fundamentally process electrical signals. These signals can be represented in two basic states:
A high signal, associated with a high voltage
A low signal, associated with a low voltage
Computers represent these two states using binary digits:
High voltage is represented by 1
Low voltage is represented by 0
The digits 0 and 1 are called binary digits, or bits. Combinations of these digits form the instructions that computers can directly understand.
Computers directly understand machine-level instructions represented using combinations of 0 and 1.
The syntax and arrangement of binary digits form a language known as machine language.
Machine Language
Machine language is the lowest-level programming language and the only programming language directly understood by a computer’s processor.
Machine-language programs consist of binary instructions that correspond closely to the operations supported by a particular processor.
Characteristics of machine language include:
Uses only binary digits
Is directly understood by the computer
Does not require a translator before execution
Interacts directly with computer hardware
Is highly dependent on the specific machine or processor
Although machine language can be executed efficiently, it is extremely difficult for humans to write, read, understand, and maintain.
Evolution and Generations of Programming Languages
Programming languages developed through several generations as computers became more advanced and programmers needed easier, more powerful, and more portable ways to write programs.
There are five commonly described generations of programming languages:
First-generation languages
Second-generation languages
Third-generation languages
Fourth-generation languages
Fifth-generation languages
First Generation: Machine-Level Language
The first generation of programming languages, commonly called machine language, was used primarily from approximately 1940 to 1959.
Main Features
Consisted of binary digits, 0 and 1
Was directly understood by the computer
Was used with early vacuum-tube computers and early transistor computers
Did not require a translator
Produced programs that could execute quickly
Because machine language was directly understood by the processor, there was no conversion step between the program and the hardware.
Advantages
Fast execution: The computer could execute the instructions directly.
No translator required: Machine code was already in the form understood by the processor.
Direct hardware interaction: Instructions operated closely with the machine’s hardware.
Disadvantages
Difficult to Write and Understand
Every instruction had to be expressed using binary digits. Even simple operations required long sequences of 0s and 1s.
This made programs:
Very lengthy
Difficult to read
Difficult to debug
Difficult to maintain
High Possibility of Errors
Binary coding is difficult for humans to interpret. A small mistake in a sequence of binary digits could change the intended instruction or cause the program to fail.
Machine Dependence
A machine-language program written for one computer generally could not run on another computer because different machines might use:
Different instruction sets
Different hardware designs
Different binary codes
A programmer therefore had to write separate machine-language programs for different computers.
Lack of Portability
Portability is the ability of a program to run on different computer systems with little or no modification.
Machine-language programs were not portable. The same program had to be rewritten for each different machine.
Time-Consuming Development
Writing long binary sequences required considerable time. Even a simple program, such as one that displays “Hello World,” could require a lengthy and difficult series of binary instructions.
Second Generation: Assembly Language
The second generation of programming languages was developed approximately between 1959 and 1965.
Assembly language was created to make programming easier than writing directly in machine language.
Main Features
Assembly language uses mnemonics, which are symbolic abbreviations representing machine instructions.
Instead of writing a binary pattern, a programmer could use a symbolic instruction associated with an operation. These symbolic representations made programs:
Easier to write
Easier to read
Easier to understand
Less prone to errors
Faster to develop than machine-language programs
Assembly language remained closely connected to the underlying hardware, so it was still considered a low-level language.
Advantages
Symbolic representation: Mnemonics were easier for humans to remember than binary digits.
Improved readability: Programmers could understand the general purpose of instructions more easily.
Reduced errors: The use of symbols lowered the chance of mistakes compared with manually entering binary code.
Faster development: Programs could be written in less time than equivalent machine-language programs.
Direct hardware control: Assembly language allowed close interaction with the computer’s hardware.
Assembler
Computers cannot directly understand assembly-language mnemonics. Therefore, assembly code must be converted into machine language.
An assembler is a translator that converts:
Assembly-language source code into
Machine-language object code
The processor can then execute the resulting object code.
Disadvantages
Translation Required
Unlike machine language, assembly language cannot be executed directly. It must first be processed by an assembler.
This adds a translation step and requires additional time before execution.
Machine Dependence
Assembly language is designed for a particular processor or hardware architecture. Assembly code written for one machine generally cannot run on another machine without changes.
Lack of Portability
Because assembly languages differ across hardware systems, programmers often need to write different versions of a program for different computers.
Low-Level Languages
The first and second generations are collectively known as low-level languages:
First generation: Machine language
Second generation: Assembly language
Low-level languages are closely related to computer hardware and provide direct control over machine resources.
Third Generation: High-Level Languages
The third generation of programming languages emerged around 1965 and continues to be widely used.
Third-generation languages were created to overcome the machine dependence and complexity of machine language and assembly language.
Main Features
Use English-like words and expressions
Are easier for programmers to learn and use
Are generally machine independent
Support structured programming
Are more portable than low-level languages
Can be translated into machine language by a compiler or interpreter
Examples of early third-generation languages include:
FORTRAN
ALGOL
COBOL
Examples of modern third-generation languages include:
C
C++
C#
Java
Machine Independence and Portability
A major benefit of third-generation languages is machine independence.
A program written in a high-level language can generally run on another computer after:
No modification, or
Only minor modifications
This makes high-level programs more portable than machine-language and assembly-language programs.
English-Like Instructions
Third-generation languages use words and structures that are more understandable to humans than binary digits or assembly mnemonics.
This reduces the difficulty of:
Learning programming
Writing programs
Reading source code
Debugging programs
Maintaining software
Because of their ease of use, third-generation languages are often called programmer-friendly languages.
Structured Programming
Third-generation languages support structured programming, in which a large program is divided into smaller sections or modules.
Each section performs a specific task. This makes programs:
Easier to understand
Easier to test
Easier to debug
Easier to modify
More organized
For example, a large application might be divided into separate sections for:
Input
Calculation
Data storage
Output
Error handling
Disadvantage: Translation Required
Computers still understand only machine language. Therefore, high-level source code must be translated before the computer can execute it.
This translation process requires additional time and means that execution is not as direct as it is with machine language.
Fourth Generation: Very High-Level Languages
The fourth generation of programming languages is designed to be even closer to human language than third-generation languages.
These languages are intended to be accessible even to people who do not have extensive formal programming training.
Main Features
Fourth-generation languages:
Use common English-like syntax and phrases
Allow a single command to perform multiple operations
Are highly programmer-friendly
Can process large collections of information
Focus on describing the desired result rather than every implementation step
Are often nonprocedural
Unlike lower-level languages, fourth-generation languages do not require the programmer to specify every step in detail.
Procedural and Nonprocedural Approaches
A procedural language generally requires the programmer to specify how a task should be performed, including the sequence of operations.
A nonprocedural language allows the programmer to specify:
What task should be completed
What conditions must be satisfied
The language or its underlying system determines how to perform the task.
This makes fourth-generation programs easier to write, but it also reduces the programmer’s control over:
Program execution
Hardware resources
The exact method used to complete a task
Typical Applications
Fourth-generation languages are useful for working with large amounts of information and are commonly used in:
Database management
Report generation
Mathematical optimization
Graphical user interface development
Web development
They focus on larger collections of data and information rather than only individual bits and bytes.
Examples
Examples of fourth-generation languages or language systems include:
SQL
NATURAL
M-POWER
LANSA
Disadvantages
Reduced control: The programmer has less direct control over the program and system resources.
Large language packages: Fourth-generation language environments can be lengthy and complex.
Higher resource requirements: They may require more disk space and greater memory capacity.
Fifth Generation: Problem-Solving and Artificial Intelligence Languages
The fifth generation of programming languages was introduced as a concept in Japan during the early 1990s.
The goal of fifth-generation languages is to allow computers to solve problems with minimal direct programming by the user.
Main Features
In a fifth-generation approach, the user specifies:
The problem to be solved
The conditions that must be met
The desired outcome
The user does not need to specify every routine or algorithm required to solve the problem. The system attempts to determine an appropriate solution automatically.
This approach is associated mainly with:
Artificial intelligence research
Automated problem solving
Knowledge-based systems
Systems that use logical or rule-based reasoning
Difference from Fourth-Generation Languages
Fourth-generation languages are generally designed to help programmers build specific applications more easily.
Fifth-generation languages aim to go further by enabling the computer to solve a stated problem without requiring the programmer to describe the complete implementation procedure.
Advantages
Reduces the amount of detailed programming required
Allows users to focus on problems and desired conditions
Supports automated reasoning and problem solving
Is useful in artificial intelligence research
Disadvantages
Automated systems are difficult to develop
Development and maintenance are complicated
The systems require substantial computational resources
The programmer has less direct control over the solution process
Examples
Examples of fifth-generation languages include:
OPS5
MERCURY
Low-Level and High-Level Languages
The five generations can be grouped into two broad categories.
Low-Level Languages
The first and second generations are low-level languages:
Machine language
Assembly language
Characteristics include:
Closely associated with hardware
Machine dependent
Difficult to learn and implement
Use binary digits or symbolic mnemonics
Provide direct interaction with hardware
Are generally not portable
Require detailed knowledge of the computer system
High-Level Languages
The third, fourth, and fifth generations are high-level languages.
Characteristics include:
Use English-like words or phrases
Are easier to learn and implement
Are generally machine independent
Are more portable
Hide many hardware details
Cannot directly interact with hardware in the same way as low-level languages
Require translation into machine code before execution
Key Differences
Hardware Dependence
Low-level languages: Machine dependent and designed for a particular hardware system.
High-level languages: Generally machine independent and usable across different systems with little or no modification.
Form of Instructions
Low-level languages: Use binary digits or mnemonics.
High-level languages: Use English-like words, expressions, and phrases.
Portability
Low-level languages: Programs usually cannot run on different machines without substantial rewriting.
High-level languages: Programs can often run on different machines after little or no modification.
Hardware Interaction
Low-level languages: Can interact directly with hardware.
High-level languages: Usually interact with hardware indirectly through translators and operating-system services.
Ease of Use
Low-level languages: Difficult to learn, write, debug, and maintain.
High-level languages: Easier to learn, write, understand, and implement.
Language Translators
Purpose of Translators
Computers directly understand machine language, but machine language is difficult for humans to write, especially for long and complex programs.
To make programming easier, programmers use assembly or high-level languages. These programs must then be converted into machine language before the computer can execute them.
A language translator is a program that converts source code written in a programming language into machine code, also called object code.
Language translators convert human-oriented source code into instructions that can be executed by the computer’s processor.
Language translators are also called:
Translators
Language processors
Machine language itself does not require translation because it is already written in the form directly understood by the computer.
The three main types of language translators are:
Assembler
Compiler
Interpreter
Assembler
An assembler converts assembly-language source code into machine-language object code.
Process
The programmer writes source code using assembly mnemonics.
The assembler reads the assembly-language instructions.
The assembler converts them into machine-language instructions.
The processor executes the resulting object code.
The assembler is specifically associated with assembly language.
Compiler
A compiler is a language translator that converts a complete source program, generally written in a high-level language, into machine code.
How a Compiler Works
The compiler scans the entire program.
It checks and translates the source code as a whole.
It generates machine code or object code.
The resulting program can then be executed.
Characteristics
Translates the whole program before execution
Reports errors after scanning the program
Generally allows faster execution after compilation
Produces a translated form that can be executed repeatedly
Languages identified in the source as commonly using compilers include:
C
C++
Interpreter
An interpreter also translates source code into machine language, but it does so one statement at a time.
How an Interpreter Works
The interpreter reads one statement.
It translates the statement into machine code.
The computer executes that statement.
The interpreter moves to the next statement.
The process continues until the program ends or an error is encountered.
Characteristics
Translates and executes the program statement by statement
Stops when it encounters the first error
Reports errors during the translation and execution process
Generally takes more total execution time than a compiled program because translation occurs repeatedly
Languages identified in the source as commonly using interpreters include:
Python
Ruby
Compiler and Interpreter Comparison
Translation Method
Compiler: Scans and translates the entire program as a whole.
Interpreter: Translates and executes one statement at a time.
Error Reporting
Compiler: Generally reports errors after scanning the complete program.
Interpreter: Stops and reports an error when the first problematic statement is reached.
Execution Time
Compiler: Usually allows faster execution after the program has been compiled.
Interpreter: Usually takes longer overall because statements are translated during execution.
Typical Language Examples
Compiled languages: C and C++
Interpreted languages: Python and Ruby
The central distinction is that a compiler translates the complete program before execution, whereas an interpreter translates the program progressively during execution.

Ask anything
We've read this whole study set, so questions about it get the best answers.