PROGRAMMING LANGUAGE CONCEPTS
PROGRAMMING LANGUAGE CONCEPTS
Programming Language என்பது computer-க்கு ஒரு task எப்படி செய்ய வேண்டும் என்பதை instructions மூலம் தெரிவிக்கப் பயன்படும் ஒரு formal language. Simple-a சொன்னால்: Programmer-ன் idea-வை computer புரிந்துகொள்ளக்கூடிய instructions-ஆக எழுத உதவும…
Programming Language என்பது computer-க்கு ஒரு task எப்படி செய்ய வேண்டும் என்பதை instructions மூலம் தெரிவிக்கப் பயன்படும் ஒரு formal language.
Programmer-ன் idea-வை computer புரிந்துகொள்ளக்கூடிய instructions-ஆக எழுத உதவும் language தான் Programming Language.
- C
- C++
- Java
- Python
- C#
- JavaScript
1. WHY DO WE NEED A PROGRAMMING LANGUAGE?
Computer அடிப்படையில் binary instructions-ஐ மட்டுமே execute செய்கிறது.
ஆனால் மனிதர்கள் நேரடியாக binary-ல் பெரிய programs எழுதுவது மிகவும் கடினம்.
- Human Problem
- Programming Language
- Translator
- Machine Language
- Computer Execution
int a = 10; int b = 20; cout << a + b;
30
Programmer simple code எழுதுகிறார்.
Computer அந்த code-ஐ நேரடியாக புரிந்து கொள்ளாது.
Compiler போன்ற translator அதனை machine instructions-ஆக மாற்றுகிறது.
BASIC ELEMENTS OF A PROGRAMMING LANGUAGE
- Programming Language
- +-- Syntax
- +-- Semantics
- +-- Variables
- +-- Constants
- +-- Data Types
- +-- Operators
- +-- Expressions
- +-- Statements
- +-- Control Structures
- +-- Functions
- +-- Scope
- +-- Data Structures
- +-- Memory Managementஇவற்றை ஒவ்வொன்றாக பார்க்கலாம்.
SYNTAX
Syntax என்பது ஒரு programming language-ல் code எழுத வேண்டிய grammatical rules.
ஒரு program எப்படி எழுதப்பட வேண்டும் என்பதற்கான விதிகள் தான் Syntax.
int x = 10;
Correct.
int x = 10
இங்கு semicolon ; இல்லை.
அதனால் syntax error ஏற்படலாம்.
English language-க்கு grammar இருப்பது போல programming language-க்கு syntax இருக்கும்.
English → Grammar
Programming Language → Syntax
- if (x > 10)
- {
- cout << x;
- }
- if x > 10
- {
- cout << x;
- }
- C++-ல் condition parentheses-ல் எழுதப்பட வேண்டும்.
Syntax = Structure
அதாவது:
எப்படி எழுதுவது?
SEMANTICS
Semantics என்பது program statement-ன் meaning.
Syntax code-ன் structure பற்றி பேசும்.
Semantics code என்ன செய்கிறது என்பதைப் பற்றி பேசும்.
1x = x + 1;
If:
- Current x value
- Add 1
- Store result again in x
1x = 5
1x = x + 1
1x = 5 + 1
1x = 6
SYNTAX VS SEMANTICS
| Syntax | Semantics |
|---|---|
| Code structure | Code meaning |
| Grammar rules | Meaning of instructions |
| எப்படி எழுதுவது | என்ன செய்கிறது |
| Example: ; required | Example: x=x+1 meaning |
| Structural correctness | Meaning correctness |
Frequently asked:
Syntax specifies the form of a program, while semantics specifies its meaning.
TOKENS
Programming language-ல் உள்ள smallest meaningful units-ஐ Tokens என்று அழைக்கிறோம்.
int total = 100;
- int → keyword
- total → identifier
- = → operator
- 100 → constant
- ; → punctuation/special symbol
இவை அனைத்தும் tokens.
KEYWORDS
Language-ல் predefined meaning கொண்ட reserved words-ஐ Keywords என்று அழைக்கிறோம்.
- int
- float
- if
- else
- while
- for
- return
- class
- public
- private
- virtual
- Keyword-ஐ variable name ஆக பயன்படுத்த முடியாது.
int while = 10;
while already keyword.
IDENTIFIERS
Programmer variables, functions, classes போன்றவற்றிற்கு கொடுக்கும் names-ஐ Identifiers என்று அழைக்கிறோம்.
int studentAge;
Here:
1studentAge = identifier
add function identifier.
int add(int a, int b)
VARIABLE
Variable என்பது program execution போது value store செய்ய பயன்படும் named memory location.
int age = 25;
- Variable name : age
- Data type : int
- Value : 25
- +---------+
- | 25 |
- +---------+
- age
Later:
1age = 30;
Value change செய்யலாம்.
அதனால் இது variable.
CONSTANT
Program execution போது value change செய்யக்கூடாத fixed value-ஐ Constant என்று அழைக்கிறோம்.
const int MAX = 100;
Now:
1MAX = 200;
செய்ய முடியாது.
VARIABLE VS CONSTANT
| Variable | Constant |
|---|---|
| Value change செய்யலாம் | Value normally change செய்ய முடியாது |
| Mutable storage | Fixed value |
| int x=10; | const int x=10; |
DATA TYPE
Variable எந்த வகையான value store செய்யும் என்பதை குறிப்பிடுவது Data Type.
int age = 25;
age integer value store செய்கிறது.
float salary = 25000.50;
Decimal value.
char grade = 'A';
Single character.
- BASIC DATA TYPESData Types
- +-- int+-- char+-- float+-- double+-- bool
int age = 25;
char grade = 'A';
float mark = 89.5;
double amount = 12345.6789;
bool pass = true;
DATA OBJECT
ஒரு data type-க்கு உட்பட்ட value store செய்யும் memory entity-ஐ Data Object என்று கூறலாம்.
int x = 10;
x என்பது integer type object.
Type → int
Object → x
Value → 10
OPERATOR
Values அல்லது variables மீது operations செய்ய பயன்படும் symbol = Operator.
1c = a + b;
- = arithmetic operator
- = = assignment operatorOPERATOR TYPESOperators
- +-- Arithmetic+-- Relational+-- Logical+-- Assignment+-- Increment / Decrement+-- Bitwise+-- Conditional
ARITHMETIC OPERATORS
- Addition
- Subtraction
- Multiplication
/ Division
% Modulus
int a = 10; int b = 3;
1cout << a + b;
13
13
RELATIONAL OPERATORS
Two values compare செய்ய பயன்படும்.
Greater than
< Less than
= Greater than or equal
<= Less than or equal
== Equal
!= Not equal
10 > 5
true
LOGICAL OPERATORS
Multiple conditions combine செய்ய பயன்படும்.
- &&
- AND
- ||
- OR
- !
- NOT
1if (age >= 18 && citizen == true)
இரண்டு conditions-மும் true ஆக இருந்தால் block execute ஆகும்.
EXPRESSION
Variables, constants மற்றும் operators சேர்ந்து ஒரு value produce செய்யும் combination-ஐ Expression என்று அழைக்கிறோம்.
a + b
இது expression.
a + b * c
இதுவும் expression.
STATEMENT
Program-ல் ஒரு complete instruction-ஐ Statement என்று அழைக்கிறோம்.
1x = 10;
ஒரு statement.
1cout << x;
ஒரு statement.
EXPRESSION VS STATEMENT
1x = a + b;
Expression.
a + b
முழுவதும்:
1x = a + b;
Statement.
DECLARATION
ஒரு variable அல்லது function-ன் name மற்றும் type-ஐ compiler-க்கு அறிமுகப்படுத்துவது declaration.
int x;
x என்ற integer variable இருக்கிறது.
என்று தெரிவிக்கப்படுகிறது.
INITIALIZATION
Variable create செய்யும் நேரத்திலேயே initial value கொடுப்பது Initialization.
Declaration + Initialization
ASSIGNMENT
Variable already இருக்கும்போது value கொடுப்பது assignment.
Declaration.
DECLARATION VS INITIALIZATION VS ASSIGNMENT
int x;
Declaration.
int y = 20;
Declaration + Initialization.
x = 30;
MCQ IMPORTANT
= means:
Assignment Operator
== means:
Equality Comparison
CONTROL STRUCTURES
Program execution எந்த order-ல் நடைபெற வேண்டும் என்பதை control செய்வது Control Structure.
Sequence
Selection
- 1. Iteration
- 2. SEQUENCE
Statements one after another execute ஆகும்.
1int a = 10; 2int b = 20; 3int c = a + b; 4cout << c;
- Statement 1
- Statement 2
- Statement 3
- Statement 4
SELECTION
Condition அடிப்படையில் ஒரு path select செய்வது.
if
if-else
switch
1if (mark >= 50) 2{ 3 cout << "Pass"; 4} 5else 6{ 7 cout << "Fail"; 8}
- Condition
- / \
- True False
- | |
- Pass Fail
ITERATION
Same statements repeated execute செய்யப்படுவது Iteration.
for
while
do-while
1for (int i = 1; i <= 5; i++) 2{ 3 cout << i; 4}
12345
12345
FUNCTION
ஒரு specific task perform செய்யும் reusable block of code = Function.
int add(int a, int b)
{
return a + b;
}
Calling:
1cout << add(10,20);
30 WHY FUNCTIONS?
30 WHY FUNCTIONS?
Same code repeatedly எழுத வேண்டிய நிலை ஏற்படலாம்.
- Code Reuse
- Modularity
- Easy Testing
- Easy Debugging
- Easy Maintenance
PARAMETER AND ARGUMENT
int add(int a, int b)
a and b = parameters.
add(10,20); 10 and 20 = arguments.
- Definition
- Parameters
- Calling
- Arguments
SCOPE
ஒரு variable program-ல் எந்த பகுதிகளில் accessible ஆகும் என்பதை Scope தீர்மானிக்கிறது.
- Local Scope
- Global Scope
LOCAL VARIABLE
Function/block உள்ளே declare செய்யப்படும் variable.
void test()
{
int x = 10;
}x local variable.
test() வெளியே அதை access செய்ய முடியாது.
GLOBAL VARIABLE
Functions வெளியே declare செய்யப்படும் variable.
- void test()
- {
- cout << x;
- }
x global variable.
Program-ன் multiple functions access செய்ய முடியும்.
| Local | Global |
|---|---|
| Function/block உள்ளே | Functions வெளியே |
| Limited scope | Wider scope |
| Block முடிந்ததும் normally lifetime முடியும் | Program execution முழுவதும் இருக்கலாம் |
TYPE SYSTEM
Programming language values-ஐ different types-ஆக classify செய்து அவற்றின் operations-ஐ control செய்யும் mechanism = Type System.
int x = 10;
x integer.
string name = "Raja";
name string.
Type system தவறான operations-ஐ detect செய்ய உதவும்.
STATIC TYPING
Variable-ன் type compile time-ல் தெரியும்.
- C
- C++
- Java
int x = 10;
x type explicitly integer.
DYNAMIC TYPING
Variable type runtime-ல் determine செய்யப்படும் languages.
Python:
1x = 10
Python இதை allow செய்கிறது.
x = "Hello"
STATIC VS DYNAMIC TYPING
| Static Typing | Dynamic Typing |
|---|---|
| Type compile time-ல் determined | Runtime-ல் determined |
| C++, Java | Python, JavaScript |
| More compile-time checking | More runtime flexibility |
ABSTRACTION
Unnecessary implementation details-ஐ hide செய்து essential information மட்டும் காட்டுவது Abstraction.
Accelerator
Brake
Steering
பயன்படுத்த தெரிந்தால் போதும்.
Engine உள்ளே combustion எப்படி நடக்கிறது என்பது driver-க்கு அவசியமில்லை.
Programming-லும் அதே concept.
sort(data);
User sort algorithm implementation முழுவதையும் அறிய வேண்டியதில்லை.
MODULARITY
ஒரு பெரிய program-ஐ small independent modules-ஆக divide செய்வது.
Student Management System
- +-- Login Module
- +-- Student Module
- +-- Marks Module
- +-- Report Module
Easy development
Easy testing
Easy maintenance
Code reuse
DATA ABSTRACTION
Data எப்படி internally represented ஆகிறது என்பதை hide செய்து operations மட்டும் provide செய்வது.
1class BankAccount 2{ 3private: 4 double balance;
5
public:
void deposit(double amount);
};User balance memory-ல் எப்படி handled ஆகிறது என்பதை directly பார்க்க வேண்டியதில்லை.
PROCEDURAL ABSTRACTION
ஒரு task எப்படி internally செய்யப்படுகிறது என்பதை hide செய்து function interface மட்டும் பயன்படுத்துவது.
sqrt(25);
5
sqrt() internally எப்படி calculate செய்கிறது என்பதை programmer அறிய வேண்டிய அவசியமில்லை.
PROGRAM STATE
ஒரு குறிப்பிட்ட நேரத்தில் program-ல் உள்ள variables மற்றும் memory values அனைத்தும் சேர்ந்து program-ன் state எனப்படும்.
int x = 10; int y = 20;
Current state:
1x = 10
1y = 20
New state:
x++;
1x = 11
1y = 20
Statement execution program state-ஐ மாற்றலாம்.
BINDING
இது Programming Language Concepts-ல் மிகவும் முக்கியமான term.
ஒரு program entity மற்றும் அதன் property இடையே association உருவாவதை Binding என்று அழைக்கிறோம்.
int x;
x → int
என்ற association உருவாகிறது.
Name-to-type binding
என்று பார்க்கலாம்.
x → Memory Location
இதுவும் binding.
DIFFERENT BINDINGS
Variable ↔ Memory location
Variable name ↔ Data type
Function call ↔ Function definition
Operator ↔ Operation
Object ↔ Class
BINDING TIME
Binding எப்போது நிகழ்கிறது என்பதை Binding Time என்று அழைக்கிறோம்.
Language Design Time
Language Implementation Time
Compile Time
Link Time
Load Time
Runtime
இந்த topic உங்கள் Unit VI-ல் தனியாகவும் முக்கியமானது.
PROGRAMMING LANGUAGE IMPLEMENTATION
Programmer எழுதும் source code-ஐ computer execute செய்ய மூன்று common implementation approaches உள்ளன:
Compilation
Interpretation
Hybrid Implementation
COMPILATION
Entire source program-ஐ machine/object code-ஆக translate செய்வது compiler.
- Source Program
- Compiler
- Machine/Object Code
- Execution
C
C++
INTERPRETATION
Interpreter source code-ஐ statement-by-statement translate செய்து execute செய்கிறது.
- Source Code
- Interpreter
- Immediate Execution
Python implementations
JavaScript engines
Actual modern implementations compiler + interpreter/JIT combinations பயன்படுத்தலாம்; exam concept-ல் interpreter model இவ்வாறு கற்பிக்கப்படுகிறது.
COMPILER VS INTERPRETER
| Compiler | Interpreter |
|---|---|
| Whole program translation | Usually instruction-by-instruction execution model |
| Object/executable may be generated | Direct execution model |
| Compiled program execution generally fast | Translation may happen during execution |
| C/C++ classic examples | Python classic example |
SOURCE PROGRAM
Programmer high-level programming language-ல் எழுதும் original program = Source Program.
1#include <iostream> 2using namespace std;
1int main() 2{ 3 cout << "Hello"; 4}
இது source code.
OBJECT PROGRAM
Compiler source code-ஐ translate செய்த பிறகு கிடைக்கும் lower-level representation = object code/object program.
- Source Code
- Compiler
- Object Code
EXECUTABLE PROGRAM
Object code + required libraries linking செய்யப்பட்ட பிறகு execute செய்யக்கூடிய program உருவாகும்.
- Source Code
- Compiler
- Object Code
- Linker
- Executable
PROGRAMMING LANGUAGE LEVELS
Assembly Language
Machine Language
High-Level Language
MACHINE LANGUAGE
Computer processor நேரடியாக execute செய்யக்கூடிய binary instructions.
10110000 01100001
Direct execution
Very difficult for humans
Machine dependent
Hard to debug
ASSEMBLY LANGUAGE
Binary-க்கு பதிலாக mnemonic instructions பயன்படுத்துகிறது.
MOV A, B
ADD A, C
Assembler
- Assembly Program
- Assembler
- Machine Code
HIGH-LEVEL LANGUAGE
Human-readable statements கொண்ட programming language.
- C
- C++
- Java
- Python
1total = a + b;
Machine language-ஐ விட மிகவும் easy.
LOW-LEVEL VS HIGH-LEVEL LANGUAGE
| Low-Level | High-Level |
|---|---|
| Hardware close | Human language close |
| Machine dependent | More portable |
| Harder to program | Easier to program |
| Machine/Assembly | C++, Java, Python |
PORTABILITY
ஒரு program-ஐ different machines/platforms-ல் minimal changes-உடன் பயன்படுத்த முடிந்தால் அது portable.
High-level languages portability improve செய்கின்றன.
READABILITY
Program மற்ற programmers எளிதாகப் புரிந்து கொள்ளக்கூடிய தன்மை = readability.
int studentCount;
int x;
விட meaningful.
WRITABILITY
Programmer ஒரு solution-ஐ language-ல் எவ்வளவு easy-ஆக express செய்ய முடிகிறது என்பதே Writability.
Simple language features writability improve செய்யும்.
RELIABILITY
ஒரு program specification படி correct output produce செய்யும் திறன் = reliability.
Strong type checking
Exception handling
Restricted pointers
Clear syntax
MAINTAINABILITY
Existing program-ஐ understand, modify, debug மற்றும் extend செய்வது எவ்வளவு easy என்பதே maintainability.
Functions
Classes
Modules
Meaningful names
Comments
maintainability improve செய்கின்றன.
PROGRAMMING LANGUAGE DESIGN CRITERIA
Writability
Readability
Reliability
Portability
Efficiency
Maintainability
Simplicity
- Exam-ல்
Four important programming language evaluation criteria
- என்று கேட்டால் பொதுவாக
Readability
Writability
Reliability
Cost
என்று language design textbooks குறிப்பிடுகின்றன.
PROGRAMMING PARADIGM - CONNECTION
- Programming Language Concept புரிந்த பிறகு next முக்கிய concept
Programming Paradigm.
- Paradigm என்பது
Program எப்படி organize செய்து problem solve செய்ய வேண்டும் என்பதற்கான programming style/model.
- Major paradigms
Imperative
Procedural
Object-Oriented
Functional
Logic / Declarative
C++ ஒரு multi-paradigm language.
- C++ support செய்கிறது
Procedural Programming
Object-Oriented Programming
Generic Programming
- Problem
- Algorithm
- Programming Language
- Tokens
- Syntax
- Statements / Expressions
- Variables + Data Types
- Operators
- Control Structures
- Functions / Classes
- Compiler / Interpreter
- Machine Instructions
- Execution
- Output
TRB / NET / SET examination-க்கு இந்த definitions மிகவும் முக்கியம்:
= Structure of a program.
1Semantics 2 = Meaning of a program.
1Identifier 2 = Programmer-defined name.
1Variable 2 = Named storage whose value may change.
1Constant 2 = Fixed value.
Data Type
= Specifies the kind of data.
1Expression 2 = Combination producing a value.
1Statement 2 = Complete executable instruction.
1Binding 2 = Association between an entity and an attribute.
Binding Time
= Time at which a binding takes place.
1Abstraction 2 = Hiding unnecessary implementation details.
1Modularity 2 = Dividing a program into manageable modules.
- Syntax ≠ Semantics
- Variable ≠ Identifier
- Parameter ≠ Argument
- Expression ≠ Statement
- Declaration ≠ Initialization
- Compiler ≠ Interpreter
- Data Type ≠ Data Value
1.
- Programming language syntax defines
Answer: Form/Structure of programs
2.
- Programming language semantics defines
Answer: Meaning of programs
3.
- Smallest meaningful unit of a program
Answer: Token
4.
- Association of an attribute with an entity
Answer: Binding
5.
- When an association occurs
Answer: Binding Time
6.
- Breaking a large system into smaller components
Answer: Modularity
7.
- Hiding implementation details
Answer: Abstraction
8.
- C++ is primarily
Answer: Multi-paradigm programming language
Programming Language Concepts என்பது C++ programming-க்கு foundation.
- Programming Language
- Syntax + Semantics
- Tokens
- Identifiers
- Variables + Constants
- Data Types
- Operators
- Expressions
- Statements
- Control Structures
- Functions
- Scope
- Binding
- Abstraction
- Translation
இந்த foundation strong ஆக இருந்தால் அடுத்த topics ஆன Programming Paradigms and Models, Programming Environments, Virtual Computers, Binding Times, Syntax and Stages in Translation மிகவும் எளிதாக புரியும்.