04-syntax
TL;DR (5 lines)
- Syntax is about shape before detail.
- A valid block is the smallest useful teaching unit.
- Statements and declarations belong to different layers.
- Invalid examples should isolate shape errors.
- The reader should leave able to recognize a healthy block instantly.
Frequent mistakes
- Teaching surface tokens without explaining block shape.
- Using syntax pages to comment every line instead of naming the pattern.
- Confusing grammar shape with later semantic checks.
Prerequisites: book/chapters/03-projet.html. See also: book/chapters/03-projet.html, book/chapters/27-grammar.html, book/chapters/31-build-errors.html.
Concrete Problem
Syntax pages become noisy when they enumerate tokens without showing how a complete block is supposed to look.
Red Thread (Single Project)
One small block shows declarations, expressions, and returns in a single readable flow.
For what
This chapter helps the reader recognize valid Vitte shapes quickly.
What you are going to do
You will read one valid block, map its parts to grammar roles, then inspect an invalid variant that breaks the shape.
Coherent example
space demo/syntax
proc compute(x: int, y: int) -> int {
let sum: int = x + y
if sum < 0 { give 0 }
give sum
}
entry main at core/app {
return compute(1, 2)
}
Global explanation
Essential syntax is best taught as structure. The reader should see where declarations live, where statements live, and how a block closes with an explicit result.
Invalid case
proc broken(x: int) -> int
give x
}
This invalid case is intentionally small. It exists to isolate the contract failure that the chapter is trying to teach.
Common pitfalls
- Teaching surface tokens without explaining block shape.
- Using syntax pages to comment every line instead of naming the pattern.
- Confusing grammar shape with later semantic checks.
Short exercise
Add one extra branch and one extra local binding while preserving the same readable block structure.
Summary in 5 points
- Syntax is about shape before detail.
- A valid block is the smallest useful teaching unit.
- Statements and declarations belong to different layers.
- Invalid examples should isolate shape errors.
- The reader should leave able to recognize a healthy block instantly.
Mini quiz
- What contract is the coherent example trying to make explicit?
- Why does the invalid example fail?
- What boundary should remain visible if you extend the example?
See also
Next best action
Extend the coherent example by one small, justified step and keep the same contract visible from input to output.