Skip to content
LAM
Read Home Blog
Make Projects HTML Tools Games
Touch grass Notes Resume Links
Home Blog HTML Projects
Tools Games Notes Resume Links
Back Module 1: Programming Language Principles Programming
Download Open
Show description 2,401 chars · Programming

Module 1: Programming Language Principles

Module 1: Programming Language Principles





MODULE 1

Programming Language Principles & Foundations





Module Contents


Programming Paradigms
Language Structures
BNF & Syntax
Pre-processing
Macros
Error Types





Programming Paradigms



What is a Programming Paradigm?

A programming paradigm is a fundamental style or approach to programming that provides a conceptual framework for solving problems and structuring code. It defines how you think about and organize your program.






⚙️
Imperative

Step-by-step instructionsHow to do somethingExamples: C, Pascal




🏗️
Object-Oriented

Objects and classesData + methods togetherExamples: Java, C++




🧮
Functional

Mathematical functionsNo side effectsExamples: Scheme, Haskell




🧠
Logic

Facts and rulesWhat is trueExamples: Prolog, Datalog






Language Evaluation Criteria



Readability

How easy is it to understand the code?



Simple syntax and semantics

Good control structures

Meaningful data types

Clear naming conventions








Writability

How easy is it to write programs?



Expressiveness of language

Abstraction capabilities

Support for common patterns

Conciseness without cryptic syntax








Reliability

Does the program behave as expected?



Type checking (static vs dynamic)

Exception handling mechanisms

Memory safety features

Aliasing restrictions








Cost Factors

What are the economic implications?



Training programmers

Development time

Compilation time

Execution efficiency

Maintenance costs









Language Features vs Performance


The Trade-off Spectrum




Feature

Benefit

Performance Cost

Example






Automatic Memory Management

Programmer productivity, safety

GC overhead, unpredictable pauses

Java, Python




Dynamic Typing

Flexibility, rapid prototyping

Runtime type checks

Python, JavaScript




Virtual Method Calls

Polymorphism, extensibility

Indirect function calls

C++, Java




Bounds Checking

Memory safety

Array access overhead

Java, C#








Historical Influences on Language Development



Computer Architecture: Von Neumann architecture influenced imperative languages

Mathematical Foundations: Lambda calculus led to functional languages

Problem Domains: Business (COBOL), Scientific…

Module 1: Programming Language Principles

42,826 bytes · HTML source
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Module 1: Programming Language Principles</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', 'Source Code Pro', Consolas, monospace;
            background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
            color: #ffffff;
            line-height: 1.6;
            min-height: 100vh;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 50px;
            padding: 50px 20px;
            background: linear-gradient(45deg, #1e3a8a 0%, #3b82f6 50%, #60a5fa 100%);
            border-radius: 20px;
            box-shadow: 0 15px 40px rgba(59, 130, 246, 0.3);
            color: #ffffff;
        }

        .header h1 {
            font-size: 3.5em;
            margin-bottom: 15px;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
            font-weight: 900;
        }

        .header p {
            font-size: 1.3em;
            opacity: 0.95;
            font-weight: 500;
        }

        .module-nav {
            position: sticky;
            top: 20px;
            background: rgba(45, 45, 45, 0.95);
            border: 2px solid #3b82f6;
            border-radius: 15px;
            padding: 20px;
            margin-bottom: 30px;
            backdrop-filter: blur(10px);
            z-index: 100;
        }

        .module-nav h3 {
            color: #60a5fa;
            margin-bottom: 15px;
            text-align: center;
            font-size: 1.4em;
        }

        .nav-links {
            display: flex;
            flex-wrap: wrap;
            gap: 12px;
            justify-content: center;
        }

        .nav-links a {
            color: #e5e7eb;
            text-decoration: none;
            padding: 10px 18px;
            border: 1px solid #3b82f6;
            border-radius: 25px;
            transition: all 0.3s ease;
            font-weight: 500;
            font-size: 0.9em;
        }

        .nav-links a:hover {
            background: #3b82f6;
            color: #ffffff;
            transform: scale(1.05);
            box-shadow: 0 5px 15px rgba(59, 130, 246, 0.4);
        }

        .section {
            background: linear-gradient(145deg, #2d2d2d, #404040);
            border-radius: 18px;
            padding: 40px;
            margin-bottom: 40px;
            border: 2px solid #4b5563;
            box-shadow: 0 10px 30px rgba(0,0,0,0.4);
        }

        .section h2 {
            color: #60a5fa;
            font-size: 2.4em;
            margin-bottom: 25px;
            border-bottom: 3px solid #3b82f6;
            padding-bottom: 12px;
        }

        .section h3 {
            color: #93c5fd;
            font-size: 1.8em;
            margin: 30px 0 18px 0;
        }

        .section h4 {
            color: #bfdbfe;
            font-size: 1.4em;
            margin: 20px 0 12px 0;
        }

        .concept-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
            gap: 25px;
            margin: 25px 0;
        }

        .concept-card {
            background: rgba(59, 130, 246, 0.1);
            border: 1px solid #3b82f6;
            border-radius: 12px;
            padding: 25px;
            transition: all 0.3s ease;
        }

        .concept-card:hover {
            background: rgba(59, 130, 246, 0.15);
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(59, 130, 246, 0.2);
        }

        .concept-card h4 {
            color: #60a5fa;
            font-size: 1.3em;
            margin-bottom: 15px;
        }

        .concept-card p {
            color: #e5e7eb;
            margin-bottom: 12px;
        }

        .code-block {
            background: #111827;
            border: 2px solid #374151;
            border-radius: 12px;
            padding: 20px;
            margin: 20px 0;
            font-family: 'Consolas', 'Source Code Pro', monospace;
            font-size: 0.95em;
            overflow-x: auto;
            position: relative;
        }

        .code-block::before {
            content: attr(data-lang);
            position: absolute;
            top: -1px;
            right: 15px;
            background: #3b82f6;
            color: #ffffff;
            padding: 3px 10px;
            font-size: 0.8em;
            border-radius: 0 0 6px 6px;
            font-weight: bold;
        }

        .keyword { color: #f59e0b; }
        .type { color: #60a5fa; }
        .string { color: #10b981; }
        .comment { color: #9ca3af; font-style: italic; }
        .function { color: #a78bfa; }
        .number { color: #f87171; }
        .operator { color: #fbbf24; }

        .paradigm-showcase {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin: 30px 0;
        }

        .paradigm-item {
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid #4b5563;
            border-radius: 12px;
            padding: 25px;
            text-align: center;
        }

        .paradigm-item h4 {
            color: #3b82f6;
            font-size: 1.4em;
            margin-bottom: 15px;
        }

        .paradigm-item .icon {
            font-size: 3em;
            margin-bottom: 15px;
            display: block;
        }

        .highlight-box {
            background: linear-gradient(45deg, rgba(59, 130, 246, 0.2), rgba(147, 197, 253, 0.1));
            border: 2px solid #3b82f6;
            border-radius: 15px;
            padding: 25px;
            margin: 25px 0;
        }

        .highlight-box h4 {
            color: #60a5fa;
            font-size: 1.5em;
            margin-bottom: 15px;
        }

        .key-points {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 10px;
            padding: 20px;
            margin: 20px 0;
        }

        .key-points ul {
            list-style: none;
            padding-left: 0;
        }

        .key-points li {
            padding: 8px 0;
            padding-left: 25px;
            position: relative;
            color: #e5e7eb;
        }

        .key-points li::before {
            content: "▶";
            position: absolute;
            left: 0;
            color: #3b82f6;
            font-weight: bold;
        }

        .bnf-example {
            background: #1f2937;
            border: 1px solid #4b5563;
            border-radius: 8px;
            padding: 15px;
            margin: 15px 0;
            font-family: monospace;
        }

        .bnf-rule {
            color: #60a5fa;
            font-weight: bold;
        }

        .bnf-or {
            color: #fbbf24;
        }

        .bnf-terminal {
            color: #10b981;
        }

        .comparison-table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 8px;
            overflow: hidden;
        }

        .comparison-table th {
            background: #3b82f6;
            color: #ffffff;
            padding: 15px;
            text-align: left;
            font-weight: bold;
        }

        .comparison-table td {
            padding: 12px 15px;
            border-bottom: 1px solid #4b5563;
            color: #e5e7eb;
        }

        .comparison-table tr:hover {
            background: rgba(59, 130, 246, 0.1);
        }

        .error-types {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin: 25px 0;
        }

        .error-type {
            background: rgba(239, 68, 68, 0.1);
            border: 1px solid #ef4444;
            border-radius: 10px;
            padding: 20px;
        }

        .error-type h5 {
            color: #fca5a5;
            font-size: 1.2em;
            margin-bottom: 10px;
        }

        @media (max-width: 768px) {
            .header h1 {
                font-size: 2.5em;
            }
            
            .concept-grid {
                grid-template-columns: 1fr;
            }
            
            .nav-links {
                flex-direction: column;
                align-items: center;
            }
            
            .container {
                padding: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>MODULE 1</h1>
            <p>Programming Language Principles & Foundations</p>
        </div>

        <nav class="module-nav">
            <h3>Module Contents</h3>
            <div class="nav-links">
                <a href="#paradigms">Programming Paradigms</a>
                <a href="#structures">Language Structures</a>
                <a href="#bnf">BNF & Syntax</a>
                <a href="#preprocessing">Pre-processing</a>
                <a href="#macros">Macros</a>
                <a href="#errors">Error Types</a>
            </div>
        </nav>

        <section id="paradigms" class="section">
            <h2>Programming Paradigms</h2>
            
            <div class="highlight-box">
                <h4>What is a Programming Paradigm?</h4>
                <p>A programming paradigm is a fundamental style or approach to programming that provides a conceptual framework for solving problems and structuring code. It defines how you think about and organize your program.</p>
            </div>

            <div class="paradigm-showcase">
                <div class="paradigm-item">
                    <span class="icon">⚙️</span>
                    <h4>Imperative</h4>
                    <p>Step-by-step instructions<br>How to do something<br><strong>Examples:</strong> C, Pascal</p>
                </div>
                <div class="paradigm-item">
                    <span class="icon">🏗️</span>
                    <h4>Object-Oriented</h4>
                    <p>Objects and classes<br>Data + methods together<br><strong>Examples:</strong> Java, C++</p>
                </div>
                <div class="paradigm-item">
                    <span class="icon">🧮</span>
                    <h4>Functional</h4>
                    <p>Mathematical functions<br>No side effects<br><strong>Examples:</strong> Scheme, Haskell</p>
                </div>
                <div class="paradigm-item">
                    <span class="icon">🧠</span>
                    <h4>Logic</h4>
                    <p>Facts and rules<br>What is true<br><strong>Examples:</strong> Prolog, Datalog</p>
                </div>
            </div>

            <h3>Language Evaluation Criteria</h3>
            <div class="concept-grid">
                <div class="concept-card">
                    <h4>Readability</h4>
                    <p>How easy is it to understand the code?</p>
                    <div class="key-points">
                        <ul>
                            <li>Simple syntax and semantics</li>
                            <li>Good control structures</li>
                            <li>Meaningful data types</li>
                            <li>Clear naming conventions</li>
                        </ul>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>Writability</h4>
                    <p>How easy is it to write programs?</p>
                    <div class="key-points">
                        <ul>
                            <li>Expressiveness of language</li>
                            <li>Abstraction capabilities</li>
                            <li>Support for common patterns</li>
                            <li>Conciseness without cryptic syntax</li>
                        </ul>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>Reliability</h4>
                    <p>Does the program behave as expected?</p>
                    <div class="key-points">
                        <ul>
                            <li>Type checking (static vs dynamic)</li>
                            <li>Exception handling mechanisms</li>
                            <li>Memory safety features</li>
                            <li>Aliasing restrictions</li>
                        </ul>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>Cost Factors</h4>
                    <p>What are the economic implications?</p>
                    <div class="key-points">
                        <ul>
                            <li>Training programmers</li>
                            <li>Development time</li>
                            <li>Compilation time</li>
                            <li>Execution efficiency</li>
                            <li>Maintenance costs</li>
                        </ul>
                    </div>
                </div>
            </div>

            <h3>Language Features vs Performance</h3>
            <div class="highlight-box">
                <h4>The Trade-off Spectrum</h4>
                <table class="comparison-table">
                    <thead>
                        <tr>
                            <th>Feature</th>
                            <th>Benefit</th>
                            <th>Performance Cost</th>
                            <th>Example</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Automatic Memory Management</td>
                            <td>Programmer productivity, safety</td>
                            <td>GC overhead, unpredictable pauses</td>
                            <td>Java, Python</td>
                        </tr>
                        <tr>
                            <td>Dynamic Typing</td>
                            <td>Flexibility, rapid prototyping</td>
                            <td>Runtime type checks</td>
                            <td>Python, JavaScript</td>
                        </tr>
                        <tr>
                            <td>Virtual Method Calls</td>
                            <td>Polymorphism, extensibility</td>
                            <td>Indirect function calls</td>
                            <td>C++, Java</td>
                        </tr>
                        <tr>
                            <td>Bounds Checking</td>
                            <td>Memory safety</td>
                            <td>Array access overhead</td>
                            <td>Java, C#</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h3>Historical Influences on Language Development</h3>
            <div class="key-points">
                <ul>
                    <li><strong>Computer Architecture:</strong> Von Neumann architecture influenced imperative languages</li>
                    <li><strong>Mathematical Foundations:</strong> Lambda calculus led to functional languages</li>
                    <li><strong>Problem Domains:</strong> Business (COBOL), Scientific (FORTRAN), AI (Lisp, Prolog)</li>
                    <li><strong>Software Engineering Needs:</strong> Modularity, reusability, maintainability</li>
                    <li><strong>Hardware Evolution:</strong> Multicore → parallel programming languages</li>
                    <li><strong>Internet Era:</strong> Web development → JavaScript, PHP, etc.</li>
                </ul>
            </div>
        </section>

        <section id="structures" class="section">
            <h2>Language Structure Levels</h2>
            
            <div class="concept-grid">
                <div class="concept-card">
                    <h4>1. Lexical Structure</h4>
                    <p>The vocabulary of the language - individual tokens</p>
                    <div class="code-block" data-lang="Tokens">
<span class="comment">// Examples of lexical tokens:</span>
<span class="keyword">int</span>         <span class="comment">// keyword</span>
<span class="function">variable</span>    <span class="comment">// identifier</span>
<span class="number">42</span>          <span class="comment">// integer literal</span>
<span class="string">"hello"</span>     <span class="comment">// string literal</span>
<span class="operator">+</span>           <span class="comment">// operator</span>
<span class="operator">;</span>           <span class="comment">// delimiter</span>
                    </div>
                    <div class="key-points">
                        <ul>
                            <li>Keywords (reserved words)</li>
                            <li>Identifiers (variable names)</li>
                            <li>Literals (constants)</li>
                            <li>Operators (+, -, *, /)</li>
                            <li>Separators/Delimiters (;, {, })</li>
                        </ul>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>2. Syntactic Structure</h4>
                    <p>How tokens combine to form valid statements</p>
                    <div class="code-block" data-lang="Grammar">
<span class="comment">// Syntax rules define valid combinations:</span>
assignment_stmt ::= identifier <span class="operator">=</span> expression <span class="operator">;</span>
expression ::= term (<span class="operator">+</span> <span class="operator">|</span> <span class="operator">-</span>) expression <span class="operator">|</span> term
term ::= factor (<span class="operator">*</span> <span class="operator">|</span> <span class="operator">/</span>) term <span class="operator">|</span> factor
factor ::= identifier <span class="operator">|</span> number <span class="operator">|</span> <span class="operator">(</span> expression <span class="operator">)</span>
                    </div>
                    <div class="key-points">
                        <ul>
                            <li>Grammar rules (production rules)</li>
                            <li>Parse trees and derivations</li>
                            <li>Precedence and associativity</li>
                            <li>Ambiguity resolution</li>
                        </ul>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>3. Contextual Structure</h4>
                    <p>Context-sensitive constraints and scoping rules</p>
                    <div class="code-block" data-lang="Context">
<span class="keyword">int</span> x = <span class="number">10</span>;        <span class="comment">// x declared as int</span>
x = <span class="string">"hello"</span>;     <span class="comment">// ERROR: type mismatch</span>

<span class="keyword">void</span> <span class="function">func</span>() {
    <span class="keyword">int</span> y = <span class="number">5</span>;    <span class="comment">// y has local scope</span>
}
<span class="function">print</span>(y);        <span class="comment">// ERROR: y not in scope</span>
                    </div>
                    <div class="key-points">
                        <ul>
                            <li>Variable declarations before use</li>
                            <li>Type compatibility checking</li>
                            <li>Scope rules (lexical/dynamic)</li>
                            <li>Function signature matching</li>
                        </ul>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>4. Semantic Structure</h4>
                    <p>The meaning and behavior of valid programs</p>
                    <div class="code-block" data-lang="Semantics">
<span class="keyword">int</span> a = <span class="number">5</span>, b = <span class="number">0</span>;
<span class="keyword">int</span> result = a / b;  <span class="comment">// Syntactically correct</span>
                     <span class="comment">// Semantically: division by zero!</span>

<span class="keyword">while</span> (<span class="keyword">true</span>) {    <span class="comment">// Infinite loop</span>
    <span class="comment">// semantic issue: never terminates</span>
}
                    </div>
                    <div class="key-points">
                        <ul>
                            <li>Runtime behavior</li>
                            <li>Memory allocation/deallocation</li>
                            <li>Control flow execution</li>
                            <li>Side effects and state changes</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <section id="bnf" class="section">
            <h2>BNF & Syntax Representation</h2>
            
            <h3>Backus-Naur Form (BNF)</h3>
            <div class="highlight-box">
                <h4>BNF Notation Rules</h4>
                <div class="bnf-example">
<span class="bnf-rule">&lt;non-terminal&gt;</span> ::= <span class="bnf-terminal">production rule</span>
<span class="bnf-or">|</span> means "or" (alternative)
<span class="bnf-terminal">terminal</span> symbols are in quotes or plain text
<span class="bnf-rule">&lt;non-terminal&gt;</span> symbols need further definition
                </div>
            </div>

            <div class="concept-grid">
                <div class="concept-card">
                    <h4>Simple Expression Grammar</h4>
                    <div class="bnf-example">
<span class="bnf-rule">&lt;expression&gt;</span> ::= <span class="bnf-rule">&lt;term&gt;</span>
                <span class="bnf-or">|</span> <span class="bnf-rule">&lt;expression&gt;</span> <span class="bnf-terminal">+</span> <span class="bnf-rule">&lt;term&gt;</span>
                <span class="bnf-or">|</span> <span class="bnf-rule">&lt;expression&gt;</span> <span class="bnf-terminal">-</span> <span class="bnf-rule">&lt;term&gt;</span>

<span class="bnf-rule">&lt;term&gt;</span> ::= <span class="bnf-rule">&lt;factor&gt;</span>
        <span class="bnf-or">|</span> <span class="bnf-rule">&lt;term&gt;</span> <span class="bnf-terminal">*</span> <span class="bnf-rule">&lt;factor&gt;</span>
        <span class="bnf-or">|</span> <span class="bnf-rule">&lt;term&gt;</span> <span class="bnf-terminal">/</span> <span class="bnf-rule">&lt;factor&gt;</span>

<span class="bnf-rule">&lt;factor&gt;</span> ::= <span class="bnf-rule">&lt;number&gt;</span>
          <span class="bnf-or">|</span> <span class="bnf-rule">&lt;identifier&gt;</span>
          <span class="bnf-or">|</span> <span class="bnf-terminal">(</span> <span class="bnf-rule">&lt;expression&gt;</span> <span class="bnf-terminal">)</span>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>If-Statement Grammar</h4>
                    <div class="bnf-example">
<span class="bnf-rule">&lt;if-stmt&gt;</span> ::= <span class="bnf-terminal">if</span> <span class="bnf-terminal">(</span> <span class="bnf-rule">&lt;condition&gt;</span> <span class="bnf-terminal">)</span> <span class="bnf-rule">&lt;statement&gt;</span>
             <span class="bnf-or">|</span> <span class="bnf-terminal">if</span> <span class="bnf-terminal">(</span> <span class="bnf-rule">&lt;condition&gt;</span> <span class="bnf-terminal">)</span> <span class="bnf-rule">&lt;statement&gt;</span> 
               <span class="bnf-terminal">else</span> <span class="bnf-rule">&lt;statement&gt;</span>

<span class="bnf-rule">&lt;condition&gt;</span> ::= <span class="bnf-rule">&lt;expression&gt;</span> <span class="bnf-rule">&lt;relop&gt;</span> <span class="bnf-rule">&lt;expression&gt;</span>

<span class="bnf-rule">&lt;relop&gt;</span> ::= <span class="bnf-terminal">==</span> <span class="bnf-or">|</span> <span class="bnf-terminal">!=</span> <span class="bnf-or">|</span> <span class="bnf-terminal">&lt;</span> <span class="bnf-or">|</span> <span class="bnf-terminal">&gt;</span> <span class="bnf-or">|</span> <span class="bnf-terminal">&lt;=</span> <span class="bnf-or">|</span> <span class="bnf-terminal">&gt;=</span>
                    </div>
                </div>
            </div>

            <h3>Extended BNF (EBNF)</h3>
            <div class="highlight-box">
                <h4>EBNF Additional Notation</h4>
                <div class="bnf-example">
{ } means zero or more repetitions
[ ] means optional (zero or one)
( ) means grouping
                </div>
                
                <div class="bnf-example">
<span class="comment">// Regular BNF:</span>
<span class="bnf-rule">&lt;var-list&gt;</span> ::= <span class="bnf-rule">&lt;variable&gt;</span> <span class="bnf-or">|</span> <span class="bnf-rule">&lt;var-list&gt;</span> <span class="bnf-terminal">,</span> <span class="bnf-rule">&lt;variable&gt;</span>

<span class="comment">// EBNF equivalent:</span>
<span class="bnf-rule">&lt;var-list&gt;</span> ::= <span class="bnf-rule">&lt;variable&gt;</span> { <span class="bnf-terminal">,</span> <span class="bnf-rule">&lt;variable&gt;</span> }
                </div>
            </div>

            <h3>Syntax Graphs (Railroad Diagrams)</h3>
            <div class="key-points">
                <ul>
                    <li>Visual representation of grammar rules</li>
                    <li>Rectangles = non-terminals</li>
                    <li>Circles/Ovals = terminals</li>
                    <li>Arrows show possible paths</li>
                    <li>Loops represent repetition</li>
                    <li>Branches represent alternatives</li>
                </ul>
            </div>
        </section>

        <section id="preprocessing" class="section">
            <h2>Processing Methodologies</h2>
            
            <div class="concept-grid">
                <div class="concept-card">
                    <h4>Interpretation</h4>
                    <p>Execute source code directly without creating machine code</p>
                    <div class="key-points">
                        <ul>
                            <li><strong>Examples:</strong> Python, JavaScript, Shell scripts</li>
                            <li><strong>Pros:</strong> Interactive, immediate execution, platform independent</li>
                            <li><strong>Cons:</strong> Slower runtime, requires interpreter</li>
                            <li><strong>Process:</strong> Source → Parse → Execute</li>
                        </ul>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>Compilation</h4>
                    <p>Translate source code to machine code before execution</p>
                    <div class="key-points">
                        <ul>
                            <li><strong>Examples:</strong> C, C++, Rust, Go</li>
                            <li><strong>Pros:</strong> Fast execution, optimized code, no runtime dependency</li>
                            <li><strong>Cons:</strong> Longer build times, platform specific</li>
                            <li><strong>Process:</strong> Source → Compile → Machine Code → Execute</li>
                        </ul>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>Intermediate/Hybrid</h4>
                    <p>Compile to intermediate code, then interpret or JIT compile</p>
                    <div class="key-points">
                        <ul>
                            <li><strong>Examples:</strong> Java (bytecode), C# (IL), Python (.pyc)</li>
                            <li><strong>Pros:</strong> Portable, some optimization, faster than pure interpretation</li>
                            <li><strong>Cons:</strong> Requires runtime environment (JVM, CLR)</li>
                            <li><strong>Process:</strong> Source → Bytecode → VM/Runtime → Execute</li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="highlight-box">
                <h4>Compilation Process Steps</h4>
                <div class="code-block" data-lang="Process">
<span class="comment">1. Preprocessing</span>    → Handle #include, #define, etc.
<span class="comment">2. Lexical Analysis</span>  → Break into tokens
<span class="comment">3. Syntax Analysis</span>   → Build parse tree
<span class="comment">4. Semantic Analysis</span> → Type checking, scope resolution  
<span class="comment">5. Optimization</span>      → Improve code efficiency
<span class="comment">6. Code Generation</span>  → Produce target code
<span class="comment">7. Linking</span>           → Combine object files
                </div>
            </div>
        </section>

        <section id="macros" class="section">
            <h2>Macro Processing</h2>
            
            <h3>What are Macros?</h3>
            <div class="highlight-box">
                <h4>Macro Definition</h4>
                <p>Macros are text substitution mechanisms that are processed <strong>before</strong> compilation. The preprocessor literally replaces macro calls with their definitions.</p>
            </div>

            <div class="concept-grid">
                <div class="concept-card">
                    <h4>Simple Macros</h4>
                    <div class="code-block" data-lang="C">
<span class="keyword">#define</span> <span class="function">PI</span> <span class="number">3.14159</span>
<span class="keyword">#define</span> <span class="function">MAX_SIZE</span> <span class="number">100</span>

<span class="comment">// Usage:</span>
<span class="keyword">double</span> area = <span class="function">PI</span> * radius * radius;
<span class="keyword">int</span> buffer[<span class="function">MAX_SIZE</span>];

<span class="comment">// After preprocessing:</span>
<span class="keyword">double</span> area = <span class="number">3.14159</span> * radius * radius;
<span class="keyword">int</span> buffer[<span class="number">100</span>];
                    </div>
                </div>

                <div class="concept-card">
                    <h4>Function-like Macros</h4>
                    <div class="code-block" data-lang="C">
<span class="keyword">#define</span> <span class="function">MAX</span>(a, b) ((a) > (b) ? (a) : (b))
<span class="keyword">#define</span> <span class="function">SQUARE</span>(x) ((x) * (x))

<span class="comment">// Usage:</span>
<span class="keyword">int</span> bigger = <span class="function">MAX</span>(<span class="number">10</span>, <span class="number">20</span>);
<span class="keyword">int</span> result = <span class="function">SQUARE</span>(side);

<span class="comment">// After preprocessing:</span>
<span class="keyword">int</span> bigger = ((<span class="number">10</span>) > (<span class="number">20</span>) ? (<span class="number">10</span>) : (<span class="number">20</span>));
<span class="keyword">int</span> result = ((side) * (side));
                    </div>
                </div>
            </div>

            <h3>Macros vs Functions</h3>
            <div class="highlight-box">
                <h4>Key Differences</h4>
                <table class="comparison-table">
                    <thead>
                        <tr>
                            <th>Aspect</th>
                            <th>Macros</th>
                            <th>Functions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Processing Time</td>
                            <td>Compile-time (preprocessing)</td>
                            <td>Runtime</td>
                        </tr>
                        <tr>
                            <td>Type Checking</td>
                            <td>No type checking</td>
                            <td>Strong type checking</td>
                        </tr>
                        <tr>
                            <td>Performance</td>
                            <td>No function call overhead</td>
                            <td>Function call overhead</td>
                        </tr>
                        <tr>
                            <td>Code Size</td>
                            <td>Code bloat (inlined everywhere)</td>
                            <td>One copy in memory</td>
                        </tr>
                        <tr>
                            <td>Debugging</td>
                            <td>Harder to debug</td>
                            <td>Easier to debug</td>
                        </tr>
                        <tr>
                            <td>Side Effects</td>
                            <td>Can cause multiple evaluations</td>
                            <td>Arguments evaluated once</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h3>Macro Pitfalls</h3>
            <div class="concept-card">
                <h4>Side Effect Problems</h4>
                <div class="code-block" data-lang="C">
<span class="keyword">#define</span> <span class="function">MAX</span>(a, b) ((a) > (b) ? (a) : (b))

<span class="keyword">int</span> x = <span class="number">5</span>, y = <span class="number">10</span>;
<span class="keyword">int</span> bigger = <span class="function">MAX</span>(++x, ++y);

<span class="comment">// Expands to:</span>
<span class="keyword">int</span> bigger = ((++x) > (++y) ? (++x) : (++y));
<span class="comment">// Problem: x or y gets incremented twice!</span>
                </div>
            </div>

            <h3>Macros vs Inline Functions</h3>
            <div class="concept-grid">
                <div class="concept-card">
                    <h4>Inline Functions (C++)</h4>
                    <div class="code-block" data-lang="C++">
<span class="keyword">inline</span> <span class="keyword">int</span> <span class="function">max</span>(<span class="keyword">int</span> a, <span class="keyword">int</span> b) {
    <span class="keyword">return</span> (a > b) ? a : b;
}

<span class="comment">// Benefits of inline over macros:</span>
<span class="comment">// - Type checking</span>
<span class="comment">// - No side effect issues</span>
<span class="comment">// - Scope respecting</span>
<span class="comment">// - Debugger friendly</span>
                    </div>
                </div>

                <div class="concept-card">
                    <h4>When to Use Each</h4>
                    <div class="key-points">
                        <ul>
                            <li><strong>Use Macros for:</strong>
                                <ul style="margin-left: 20px;">
                                    <li>Constants</li>
                                    <li>Conditional compilation</li>
                                    <li>Code generation</li>
                                    <li>Language features not available</li>
                                </ul>
                            </li>
                            <li><strong>Use Inline Functions for:</strong>
                                <ul style="margin-left: 20px;">
                                    <li>Type-safe operations</li>
                                    <li>Complex logic</li>
                                    <li>Avoiding side effects</li>
                                    <li>Modern C++ code</li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <h3>Macro Processing Examples</h3>
            <div class="highlight-box">
                <h4>Step-by-Step Expansion</h4>
                <div class="code-block" data-lang="C">
<span class="keyword">#define</span> <span class="function">PRINT_VAR</span>(var) <span class="function">printf</span>(<span class="string">#var " = %d\n"</span>, var)
<span class="keyword">#define</span> <span class="function">SWAP</span>(a, b) { <span class="keyword">int</span> temp = a; a = b; b = temp; }

<span class="keyword">int</span> x = <span class="number">10</span>, y = <span class="number">20</span>;
<span class="function">PRINT_VAR</span>(x);
<span class="function">SWAP</span>(x, y);
<span class="function">PRINT_VAR</span>(x);

<span class="comment">// After preprocessing:</span>
<span class="keyword">int</span> x = <span class="number">10</span>, y = <span class="number">20</span>;
<span class="function">printf</span>(<span class="string">"x" " = %d\n"</span>, x);
{ <span class="keyword">int</span> temp = x; x = y; y = temp; };
<span class="function">printf</span>(<span class="string">"x" " = %d\n"</span>, x);
                </div>
            </div>
        </section>

        <section id="errors" class="section">
            <h2>Error Classification by Structure Level</h2>
            
            <div class="error-types">
                <div class="error-type">
                    <h5>Lexical Errors</h5>
                    <p>Invalid characters or tokens</p>
                    <div class="code-block" data-lang="Examples">
<span class="comment">// Illegal characters</span>
<span class="keyword">int</span> x@ = <span class="number">5</span>;        <span class="comment">// @ not allowed</span>
<span class="keyword">float</span> $price;     <span class="comment">// $ not valid in identifiers</span>
<span class="string">"unterminated string</span>
                    </div>
                </div>

                <div class="error-type">
                    <h5>Syntax Errors</h5>
                    <p>Grammar rule violations</p>
                    <div class="code-block" data-lang="Examples">
<span class="comment">// Missing semicolons, brackets</span>
<span class="keyword">int</span> x = <span class="number">5</span>         <span class="comment">// missing ;</span>
<span class="keyword">if</span> (x > <span class="number">0</span> {       <span class="comment">// missing )</span>
    <span class="function">print</span>(x)
                    </div>
                </div>

                <div class="error-type">
                    <h5>Contextual Errors</h5>
                    <p>Context-sensitive rule violations</p>
                    <div class="code-block" data-lang="Examples">
<span class="comment">// Type mismatches, scope errors</span>
<span class="keyword">int</span> x;
x = <span class="string">"hello"</span>;      <span class="comment">// type error</span>
<span class="function">print</span>(undeclared); <span class="comment">// undeclared variable</span>
                    </div>
                </div>

                <div class="error-type">
                    <h5>Semantic Errors</h5>
                    <p>Logical errors in program meaning</p>
                    <div class="code-block" data-lang="Examples">
<span class="comment">// Runtime errors, logic errors</span>
<span class="keyword">int</span> x = <span class="number">10</span> / <span class="number">0</span>;    <span class="comment">// division by zero</span>
<span class="keyword">while</span> (<span class="keyword">true</span>) { } <span class="comment">// infinite loop</span>
<span class="keyword">int</span> arr[<span class="number">5</span>];
arr[<span class="number">10</span>] = <span class="number">0</span>;      <span class="comment">// array bounds error</span>
                    </div>
                </div>
            </div>

            <div class="highlight-box">
                <h4>Error Detection Timeline</h4>
                <div class="key-points">
                    <ul>
                        <li><strong>Lexical:</strong> Caught by lexer during tokenization</li>
                        <li><strong>Syntax:</strong> Caught by parser during syntax analysis</li>
                        <li><strong>Contextual:</strong> Caught during semantic analysis (compile-time)</li>
                        <li><strong>Semantic:</strong> Often caught only at runtime</li>
                    </ul>
                </div>
            </div>
        </section>

        <div class="section">
            <h2>Key Takeaways for Module 1</h2>
            <div class="key-points">
                <ul>
                    <li><strong>Programming paradigms</strong> provide different mental models for problem-solving</li>
                    <li><strong>Language design</strong> involves trade-offs between readability, writability, reliability, and performance</li>
                    <li><strong>Four structure levels</strong> (lexical, syntax, contextual, semantic) each catch different error types</li>
                    <li><strong>BNF and EBNF</strong> provide formal ways to specify language syntax</li>
                    <li><strong>Processing methodologies</strong> (interpretation, compilation, hybrid) have different performance characteristics</li>
                    <li><strong>Macros</strong> are powerful but dangerous - prefer inline functions when possible</li>
                    <li><strong>Understanding language implementation</strong> helps you write better code and debug issues</li>
                </ul>
            </div>
        </div>
    </div>
</body>
</html>