HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, a syntax error is an error in the
syntax In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
of a sequence of characters that is intended to be written in a particular
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
. For
compiled language Compiled language categorizes a programming language as used with a compiler and generally implies not used with an interpreter. But, since any language can theoretically be compiled or interpreted the term lacks clarity. In practice, for some lan ...
s, syntax errors are detected at compile-time. A program will not compile until all syntax errors are corrected. For
interpreted language In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An inter ...
s, a syntax error may be detected during program execution, and an interpreter's error messages might not differentiate syntax errors from errors of other kinds. There is some disagreement as to just what errors are "syntax errors". For example, some would say that the use of an uninitialized variable's value in Java code is a syntax error, but many others would disagree and would classify this as a (static) semantic error. In 8-bit
home computer Home computers were a class of microcomputers that entered the market in 1977 and became common during the 1980s. They were marketed to consumers as affordable and accessible computers that, for the first time, were intended for the use of a s ...
s that used
BASIC Basic or BASIC may refer to: Science and technology * BASIC, a computer programming language * Basic (chemistry), having the properties of a base * Basic access authentication, in HTTP Entertainment * Basic (film), ''Basic'' (film), a 2003 film ...
interpreter as their primary user interface, the error message became somewhat notorious, as this was the response to any command or user input the interpreter could not parse. A syntax error can occur or take place, when an invalid equation is being typed on a calculator. This can be caused, for instance, by opening brackets without closing them, or less commonly, entering several
decimal point FIle:Decimal separators.svg, alt=Four types of separating decimals: a) 1,234.56. b) 1.234,56. c) 1'234,56. d) ١٬٢٣٤٫٥٦., Both a comma and a full stop (or period) are generally accepted decimal separators for international use. The apost ...
s in one number. In
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
the following is a syntactically correct statement: :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 A word is a basic element of language that carries meaning, can be used on its own, and is uninterruptible. Despite the fact that language speakers often have an intuitive grasp of what a word is, there is no consensus among linguists on its ...
"Hello World". 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. It is common to classify such errors as (static) semantic errors instead.Semantic Errors in Java
/ref> Exercise 1.3, pp.27–28.


Syntax errors on calculators

A syntax error is one of several types of errors on
calculator An electronic calculator is typically a portable electronic device used to perform calculations, ranging from basic arithmetic to complex mathematics. The first solid-state electronic calculator was created in the early 1960s. Pocket-si ...
s (most commonly found on
scientific calculator A scientific calculator is an Electronics, electronic calculator, either desktop or handheld, designed to perform calculations using basic (addition, subtraction, multiplication, Division (mathematics), division) and advanced (Trigonometric fun ...
s and
graphing calculator Graphing Calculator may refer to: * Graphing calculators, calculators that are able to display and/or analyze mathematical function graphs * NuCalc, a computer software program able to perform many graphing calculator functions * Grapher, th ...
s), representing that the
equation In mathematics, an equation is a mathematical formula that expresses the equality of two expressions, by connecting them with the equals sign . The word ''equation'' and its cognates in other languages may have subtly different meanings; for ...
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 A bracket is either of two tall fore- or back-facing punctuation marks commonly used to isolate a segment of text or data from its surroundings. They come in four main pairs of shapes, as given in the box to the right, which also gives their n ...
without closing parenthesis (unless missing closing parenthesis is at very end of equation) *Using
minus sign The plus sign () and the minus sign () are mathematical symbols used to denote positive and negative functions, respectively. In addition, the symbol represents the operation of addition, which results in a sum, while the symbol represent ...
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

* Tag soup


References

{{Reflist
Error An error (from the Latin , meaning 'to wander'Oxford English Dictionary, s.v. “error (n.), Etymology,” September 2023, .) is an inaccurate or incorrect action, thought, or judgement. In statistics, "error" refers to the difference between t ...
Computer errors Parsing Programming language theory