GCSE · Computer Science · Eduqas · Spec C500QS
Semantic analysis
"The sandwich signed the mortgage." Perfect spelling, perfect grammar, zero meaning. Compilers meet the same problem with code, and they refuse to finish the job.
Computer Science · Compilers
Compile it. Read it. Fix it.
Every line of this program is written correctly. Press Run to compile it, read what the compiler reports, then choose a fix. Keep going until the compiler produces the finished program.
- public class Main {
- public static void main(String[] args) {
- int score = 10;
- String points = "20";
- int total = score + bonus;
- int lives = "three";
- int doubled = points * 2;
- }
- }
The error wording is what javac (Java 21) reports, shortened: its copy of the code line and its pointer are left out. In this lesson, Run means compile. The "finished program" line is added by the lesson.
Eduqas GCSE Computer Science (C500QS): semantic analysis is listed in Component 1, Understanding Computer Science, in the Program construction section on translators.
Computer Science · Compilers
Which fault is it?
Sort each statement by the fault it contains. Some have none.
Still to sort
Variable not declared (0)
A variable is used but never declared.
Where the line is: The name appears with no declaration before it. A declared variable that holds the wrong kind of value is a different fault.
Value does not match declared type (0)
The value given is not the type the variable was declared to hold.
Where the line is: This is about assigning a value to a variable. Combining two values in arithmetic is a different fault.
Operation on incompatible types (0)
An operation is applied to values whose data types cannot be used together.
Where the line is: The operation itself is the problem, such as arithmetic on a string and an integer. Assigning to a variable is a different fault.
Form error, not semantic (0)
The statement is not written in a valid form.
Where the line is: A form error is about how the statement is written. The three semantic faults are about meaning, in statements that are written correctly.
No fault (0)
Passes all three meaning checks.
Where the line is: Everything it uses is declared, its types match and its operation is compatible.
Commit to a category for each statement, then read why.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Code can look perfect and still be refused. Find out why.
What you need to know
- A compiler translates a high-level language program, and it does the job in stages. Semantic analysis is one of those stages.
- At this stage the compiler checks the meaning of the program: do the statements make sense, and can they be carried out?
- Meaning goes beyond form. Form is only whether a statement is written in the correct way.
Have a goPriya says: "Every line of my program is written correctly, so the compiler has to accept it." Is that safe reasoning?
No. Correct form does not guarantee valid meaning.
Semantic analysis checks the meaning of the program as well as its form, so a correctly written statement can still fail that check.
- Check one: every variable used in the program must have been declared before it is used.
- Check two, type checking: data types must be used consistently, so a value assigned to a variable matches its declared type.
- Check three: operations need compatible data types, so no arithmetic on a string and an integer as if both were numbers.
Have a goYour friend writes 5 * "apples". Which of the three checks should stop it: declared, types consistent, or compatible operations?
Compatible operations: arithmetic on an integer and a string.
A string like "apples" cannot be treated as a number, so the operation is applied to incompatible data types.
- So a statement can be correctly formed, or grammatically valid, and still fail semantic analysis because its meaning is invalid.
- Where the meaning is invalid, the compiler reports it to the programmer.
- It does not produce a finished executable program until the problem has been corrected.
Have a goA friend says: "The compiler told me about the problem but built the program anyway, so I will fix it later." What does not add up?
No finished executable is produced until the problem is corrected.
When the meaning is invalid, the compiler reports it to the programmer and does not produce a finished executable until it is corrected.
The big picture
Semantic analysis is the stage of compilation where the compiler checks that a program's meaning is valid: variables declared, data types consistent and operations on compatible types. If it is not, the compiler reports it and produces no finished executable until it is corrected.
Key points
Worked example
Problem
The compiler meets these three statements, and all three are written correctly: int price = 4; int cost = price * quantity; String name = 7; Decide whether each one passes semantic analysis and, if it fails, which check it fails.
⚠ Watch out
Believing a program is safe from the compiler as long as every statement is written correctly. Correct form only answers the form question. Semantic analysis still asks whether the statement makes sense: variables declared, data types consistent, operations compatible.
Memory hook
Spelled right is not the same as makes sense. Put three questions to every statement: Is it declared? Do the types match? Can these values be used together?
Check yourself
Cover the page. Name the three things semantic analysis checks. Then make up a statement that is written correctly but would still be refused, and say which check it fails.
Flashcards
(10)What is semantic analysis?
What is compilation?
Form or meaning: which does semantic analysis check?
Semantic check 1: variables
What is type checking?
Semantic check 3: operations
Can a grammatically valid statement fail semantic analysis?
What happens when semantic analysis finds invalid meaning?
boolean ready = "yes"; Which check fails?
A variable is used on line 5 but never declared. Where does the fix go?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Eduqas GCSE Computer Science topics
How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 16 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.