Jump to content

Syntax error

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Stevebroshar (talk | contribs) at 14:54, 9 July 2025 (if we're going to include calculators, then it's not just about programming languages; organize info). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A syntax error is a mismatch in the syntax of data input to a computer system that requires a specific syntax. For source code in a programming language, a compiler detects syntax errors before the software is run; at compile-time, whereas an interpreter detects syntax errors at run-time. A syntax error can occur based on syntax rules other than those defined by a programming language. For example, typing an invalid equation into a calculator (an interpreter) is a syntax error.

Some errors that occur during the translation of source code may be considered syntax errors by some but not by others. For example, some say that an uninitialized variable in Java is a syntax error, but others disagree[1][2] – classifying it as a static semantic error.[2][3][4]

Example

The Java compiler generates a syntax error for the following code since the string is not quoted.

System.out.println(Hello World);

Valid syntax is:

System.out.println("Hello World");

Syntax errors on calculators

Syntax error in a scientific calculator

A syntax error is one of several types of errors on calculators (most commonly found on scientific calculators and graphing calculators), representing that the equation that has been input has incorrect syntax of numbers, operations and so on. It can result in various ways, including but not limited to:

  • An open bracket without closing parenthesis (unless missing closing parenthesis is at very end of equation)
  • Using minus sign instead of negative symbol (or vice versa), which are distinct on most scientific calculators. Note that while some scientific calculators allow a minus sign to stand in for a negative symbol, the reverse is less common.

See also

References

  1. ^ Issue of syntax or semantics?
  2. ^ a b Semantic Errors in Java
  3. ^ Aho, Alfred V.; Monica S. Lam; Ravi Sethi; Jeffrey D. Ullman (2007). Compilers: Principles, Techniques, and Tools (2nd ed.). Addison Wesley. ISBN 978-0-321-48681-3. Section 4.1.3: Syntax Error Handling, pp.194–195.
  4. ^ Louden, Kenneth C. (1997). Compiler Construction: Principles and Practice. Brooks/Cole. ISBN 981-243-694-4. Exercise 1.3, pp.27–28.