GCSE · Computer Science · Eduqas · Spec C500QS
Syntax analysis
One missing semicolon and the compiler won't build a single thing. It doesn't guess what you meant. It just says no. So what is it actually checking?
Try it · The compiler says no
Send this program to the compiler
This short program is about to go to the compiler. Press Run and read what comes back. Then choose the fix for the flagged line, run again, and keep going until the compiler is happy.
- public class Main {
- public static void main(String[] args) {
- int score = 10
- System.out.println(score);
- }
- }
The error messages are the real javac 21 messages for these exact programs (each was compiled to check). The sentence about no compiled program is this lesson's own note, not javac output. The page compiles nothing itself.
Now you play the parser
Obeys the grammar rules, or breaks them?
Each line is Java, written inside a main method where int x = 4; is already declared. Decide whether its tokens come in an order and combination the language allows.
Still to sort
Obeys the grammar rules (0)
The tokens form a valid statement.
Where the line is: Allowed order and combination, even if the program would not do what you wanted.
Breaks the grammar rules (syntax error) (0)
The tokens are in an order or combination the language does not allow.
Where the line is: Reported as a syntax error, and the program cannot compile until it is corrected.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
The compiler stage that checks your tokens obey the language's grammar rules, and refuses the program if they don't.
What you need to know
- A compiler translates a high-level language program, and syntax analysis is one of the stages it carries out along the way.
- Syntax analysis doesn't work on raw characters. The earlier stage has already cut your source code into tokens, and tokens are its input.
Have a goThe line int n = 7; is about to be syntax-analysed. Does the stage get handed the characters one by one, or something else?
Something else: the line already cut into tokens (int, n, =, 7 and ;).
The earlier stage of compilation produces the tokens, so syntax analysis works on those rather than on raw characters.
- It has a second name: parsing. Same stage, same job.
- Every programming language has grammar rules (syntax rules), and the tokens are checked against them.
- Checking means asking whether the tokens come in an order and combination the language allows, forming valid statements and structures.
Have a goYour classmate announces, very confidently: 'Parsing just checks every word is spelt right.' What is it really checking?
Whether the tokens come in an order and combination the language allows.
The check is about how tokens fit together under the grammar rules, not about each token on its own.
- Each breach of the grammar rules that's found gets reported as a syntax error.
- A program in which syntax analysis reports errors cannot be successfully compiled until those errors are corrected.
Have a goA program gets two syntax errors. You correct one and recompile. Can it be successfully compiled now?
No. Not until the other error is corrected too.
A program in which syntax analysis reports errors cannot be successfully compiled until those errors are corrected.
- It checks grammar only. A program can obey every rule and still not do what you meant.
The big picture
Syntax analysis (also called parsing) is one of the stages of compilation. It works on the tokens produced from your source code by the earlier stage and checks them against the grammar rules of the programming language: are they in an order and combination the language allows? Any breach is reported as a syntax error, and the program cannot be successfully compiled until those errors are corrected.
Key points
Worked example
Problem
Play the parser on this Java line, using the simplified rule 'a type, a name, =, a value, then ;'. int score = 10 10; Say what happens and why.
⚠ Watch out
Believing syntax analysis finds every mistake. It only checks that tokens obey the grammar rules. A line can pass it and still be the wrong instruction: it would accept 4 + 3 even if you meant to multiply.
Memory hook
Think of the parser as grammar police for tokens: tokens in, rules applied, errors out. One breach and nothing leaves the station.
Check yourself
Without looking back: what goes into syntax analysis, what is it checked against, and what happens to a program whose tokens breach the rules?
Flashcards
(10)What is syntax analysis?
What is another name for syntax analysis?
What does syntax analysis work on?
What are the tokens checked against?
What does it mean to check tokens against the grammar rules?
What happens to a breach of the grammar rules?
Can a program with syntax errors be successfully compiled?
Why is x = = 5; a syntax error?
A program passes syntax analysis. Does that prove it does what you meant?
In int score = 10 (no semicolon), why does the compiler report a syntax error?
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.