Syntax error
System.out.println("Hello World");
while the following is not:
System.out.println(Hello World);
The second example would theoretically print the variable Hello World
instead of the words "Hello World". However, a variable in Java cannot have a space in between, so the syntactically correct line would be System.out.println(Hello_World)
.
A compiler will flag a syntax error when given source code that does not meet the requirements of the language's grammar.
Type errors (such as an attempt to apply the ++ increment operator to a boolean variable in Java) and undeclared variable errors are sometimes considered to be syntax errors when they are detected at compile-time. However, it is common to classify such errors as (static) semantic errors instead.[1][2][3]
Syntax errors on calculators
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
- ^ Semantic Errors in Java
- ^ 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.
- ^ Louden, Kenneth C. (1997). Compiler Construction: Principles and Practice. Brooks/Cole. ISBN 981-243-694-4. Exercise 1.3, pp.27–28.