Syntax refers to the rules that specify the correct combination and sequence of text (characters) and symbolsrequired to be followed to write a correctly structured program for a programming language or markup language (like HTML)
For example, in many languages a function call is denoted by name of the function along with brackets ()
and arguments are passed inside the brackets
Each language defines its own syntactical rules that control which words are recognized, which combinations of words and symbols are acceptable,and what punctuation is necessary to be a correctly structured document
Documents that are syntactically invalid are said to have a syntax error
These are typically identified when a code is compiled
Syntax can be considered to consist of the following three levels :
In lexical analysis, sequence of characters (such as in a computer program or web page) are converted into a sequence of tokens (strings with an assigned and thus identified meaning
The syntax of a language describes the form of a valid program, but does not provide any information about the meaning of the program or the results of executing that program
The meaning given to a combination of symbols is handled by semantics (either formal or hard-coded in a reference implementation)
Not all syntactically correct programs are semantically correct
Many syntactically correct programs are ill-formed as per the language's rules, and might result in an error on translation or execution depending on the language specification