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.

Java
  1. public class Main {
  2. public static void main(String[] args) {
  3. int score = 10
  4. System.out.println(score);
  5. }
  6. }

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.

​

What the parser is handed

The same line, two ways

  1. 1 Explore
  2. 2 Translate

Model. One line of Java, simplified. ␣ marks a space. Which characters make up which token is authored here, not computed by the page.

Step 1 · Explore

Tap a part in one view and watch where it sits in the other. Try a token that is several characters long, then the semicolon.

Linked parts: select one to follow it through every representation

␣␣␣

The line as you type it: a run of characters.

Linked parts tried: 0 of 2.

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.

8 of 8 still to sort.

Watch out: A line that obeys the grammar rules can still be the wrong line for the job. The parser checks the order and combination of tokens, not what you meant.

What does it really check?

Which idea matches what you think?

A program has just been sent to the compiler and the syntax analysis stage is about to look at it.

Which of these is closest to what you believe syntax analysis does?
How sure are you?

Your turn to explain

Say it in your own words

Cover what you know: what goes in, what it is checked against, what counts as a problem, and what happens to the program.

Describe what happens at the syntax analysis stage of compilation. [5 marks]

0 words · your answer stays on this page and is not sent anywhere.

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

1Syntax analysis is also called parsing, and it is one stage of compilation.
2Its input is the tokens from the earlier stage of compilation, not the raw characters of the program.
3It checks the tokens against the grammar rules: valid order, valid combination.
4Breaches are reported as syntax errors, and the program cannot be successfully compiled until they are corrected.

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?
A stage of compilation, carried out by the compiler when it translates a high-level language program.
What is another name for syntax analysis?
Parsing.
What does syntax analysis work on?
The tokens produced from the source code by the earlier stage of compilation, not the raw characters.
What are the tokens checked against?
The grammar rules (syntax rules) of the programming language.
What does it mean to check tokens against the grammar rules?
Checking they appear in an order and combination the language allows, so they form valid statements and structures.
What happens to a breach of the grammar rules?
It is reported as a syntax error.
Can a program with syntax errors be successfully compiled?
No, not until those errors are corrected.
Why is x = = 5; a syntax error?
Two = tokens in a row is a combination the language does not allow.
A program passes syntax analysis. Does that prove it does what you meant?
No. Syntax analysis checks grammar only, so a program can obey the rules and still do the wrong thing.
In int score = 10 (no semicolon), why does the compiler report a syntax error?
The statement's tokens don't end in an order the grammar rules allow: the closing ; is missing.

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 posted

More Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

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.