Learning Module: Basic Syntax and Semantics
Overview
This module introduces Basic Syntax and Semantics in computer programming. It explains how
programming languages are written (syntax) and how instructions are interpreted and executed by the
computer (semantics). This module is ideal for beginners learning their first programming language.
Learning Objectives
By the end of this module, learners should be able to: - Define syntax and semantics - Differentiate between
syntax and semantics - Identify common syntax rules in programming languages - Understand how
semantics affects program behavior
Lesson 1: What is Syntax?
Definition
Syntax refers to the rules and structure that define how statements and commands must be written in a
programming language.
Importance of Syntax
• Ensures programs are written correctly
• Allows the compiler or interpreter to understand instructions
• Prevents syntax errors
Examples of Syntax Rules
• Proper use of keywords
• Correct punctuation (parentheses, braces, semicolons)
• Proper indentation (in some languages like Python)
Lesson 2: What is Semantics?
Definition
Semantics refers to the meaning of the statements written in a programming language. It determines what
the program actually does when it runs.
1
Importance of Semantics
• Ensures the program produces correct results
• Helps avoid logical errors
• Defines how instructions are executed
Lesson 3: Syntax Errors vs Semantic Errors
Syntax Errors
• Occur when code violates language rules
• Program will not run
• Example: missing parentheses or incorrect keywords
Semantic Errors
• Code runs but produces incorrect results
• Caused by wrong logic or meaning
• Example: using the wrong formula in a calculation
Lesson 4: Basic Programming Syntax Elements
• Keywords – Reserved words with special meaning
• Identifiers – Names of variables and functions
• Operators – Symbols used to perform operations (+, -, *, /)
• Statements – Instructions executed by the program
• Comments – Notes added to explain code (not executed)
Lesson 5: Why Syntax and Semantics Matter
• Help programmers write correct and readable code
• Reduce errors and bugs
• Improve program reliability and performance
• Essential for understanding and debugging programs
Learning Activities
Activity 1: Identify whether the error is syntax or semantic.
Activity 2: Write a simple program statement and explain its meaning.
2
Assessment (Short Quiz)
1. What is syntax?
2. What is semantics?
3. What is the difference between syntax and semantic errors?
Summary
• Syntax defines how code is written
• Semantics defines what the code means and does
• Syntax errors stop programs from running
• Semantic errors cause incorrect results
• Both are essential concepts in programming
References
• Programming Fundamentals textbooks
• Computer Science introductory materials