Syntax Versus Semantics

Most writing on programming errors distinguishes between two basic types of errors: syntax errors and semantic errors.

Syntax errors involve the precise definition of how valid programs are formed. For example, in Python, the following code fragment

if i == 5

is syntactically incorrect because Python syntax specifies that an if statement must have a colon at the end of the line.

This book does not deal with syntax errors. Spotting them can involve more detailed knowledge of the language than what this book requires. More importantly, they won't sneak in unnoticed; when a compiler or interpreter encounters a syntax error, it reports an error to the user. Although one single syntax error can often cause a cascade of related ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.