![]() |
|||||||||||||
|
Syntax of programming languages |
In computer science, the syntax of a programming language is the set of rules that the symbols within source code must follow to be considered a syntactically conforming program in that language. Text based programming languages are based on sequences of characters, while visual programming languages are based on the spatial layout and connections between symbols (which may be textual or graphical).
The lexical grammar of a textual language specifies how characters must be chunked into tokens. Other syntax rules specify the permissible sequences of these tokens and the process of assigning meaning to these token sequences is part of semantics.
The syntactic analysis of source code usually entails the transformation of the linear sequence of tokens into a hierarchical syntax tree (abstract syntax trees are one convenient form of syntax tree). This process is called parsing, as it is in syntactic analysis in linguistics. Tools have been written that automatically generate parsers from a specification of a language grammar written in Backus-Naur form, e.g., Yacc (yet another compiler compiler).
The syntax of many computer languages is at level-2 (i.e., a context-free grammar) in the Chomsky hierarchy (constructs such as regular expressions are at level-1).