Programming Languages - Detailed
Notes
1. Syntactic and Semantic Rules of a Programming Language
Syntactic Rules:
- Define the grammar or structure of a programming language.
- Govern how statements, expressions, and components must be written.
- Based on formal grammar (like BNF).
Semantic Rules:
- Define the meaning or behavior of syntactically valid programs.
- Concerned with type correctness, variable usage, scope, etc.
2. Characteristics of a Good Programming Language
- Simplicity: Easy syntax and small number of constructs.
- Readability: Code should be easy to read.
- Writability: Easy to write programs.
- Orthogonality: Consistent design with few constructs.
- Efficiency: Fast execution and low memory use.
- Portability: Runs on multiple platforms.
- Modularity: Support functions, procedures, classes.
- Error Handling: Effective detection/reporting.
- Security: Prevent illegal operations.
- Tool Support: IDEs, compilers, debuggers, etc.
3. Programming Language Translators
Compiler:
- Translates whole code to machine code before execution.
- Faster after compilation.
Interpreter:
- Executes code line-by-line.
- Easier debugging, slower execution.
Assembler:
- Converts assembly code to machine code.
Hybrid (e.g., Java):
- Uses both compiler (to bytecode) and interpreter (JVM).
4. Elementary Data Types
- Data Objects: Represent program values.
- Variables: Named memory locations.
- Constants: Fixed values.
- Primitive Data Types: int, float, char, bool, void.
5. Specification & Implementation of Elementary Data Types
Specification:
- Abstract definition of what a type represents and operations.
Implementation:
- How the data type is stored in memory.
- Example: int as 2 or 4 bytes depending on architecture.
6. Declarations, Type Checking & Type Conversions
Declarations:
- Declaring variable types and names.
Type Checking:
- Ensures correct operations between compatible types.
Type Conversions:
- Implicit (automatic) and Explicit (casting).
7. Assignment & Initialization
Assignment:
- Storing a value in a variable.
Initialization:
- Assigning value at the time of declaration.
8. Numeric Data Types
Integer Types:
- int, short, long, unsigned, etc.
Floating-Point Types:
- float, double, long double.
9. Enumerations
- User-defined type with fixed set of constants.
- Example: enum Days { MON, TUE, WED };
10. Booleans & Characters
Booleans:
- true or false.
Characters:
- Stored as ASCII/Unicode.
- Example: char ch = 'A';