| FazBrowse Wikipedia Viewer | Main Page | | |
| Viewing: https://en.wikipedia.org/wiki/Programming_language |
Programming languages have some similarity to natural languages in that they can allow communication of ideas between people. That is, programs are generally human-readable and can express complex ideas. However, the kinds of ideas that programming languages can express are ultimately limited to the domain of computation.
The term computer language is sometimes used interchangeably with programming language but some contend they are different concepts. Some contend that programming languages are a subset of computer languages. Some use computer language to classify a language used in computing that is not considered a programming language.
Parse tree of Python code with inset tokenization
Syntax highlighting is often used to aid programmers in recognizing elements of source code. The language above is Python.
A programming language's surface form is known as its syntax. Most programming languages are purely textual; they use sequences of text including words, numbers, and punctuation, much like written natural languages. In contrast, some programming languages are graphical, using visual relationships between symbols to specify a program.
The syntax of a language describes the possible combinations of symbols that form a syntactically correct program. The meaning given to a combination of symbols is handled by semantics (either formal or hard-coded in a reference implementation). Since most languages are textual, this article discusses textual syntax.
The programming language syntax is usually defined using a combination of regular expressions (for lexical structure) and Backus–Naur form (for grammatical structure). Below is a simple grammar, based on Lisp:
If the type declaration on the first line were omitted, the program would trigger an error on the undefined variable p during compilation. However, the program would still be syntactically correct since type declarations provide only semantic information.
The grammar needed to specify a programming language can be classified by its position in the Chomsky hierarchy. The syntax of most programming languages can be specified using a Type-2 grammar, i.e., they are context-free grammars. Some languages, including Perl and Lisp, contain constructs that allow execution during the parsing phase. Languages that have constructs that allow the programmer to alter the behavior of the parser make syntax analysis an undecidable problem, and generally blur the distinction between parsing and execution. In contrast to Lisp's macro system and Perl's BEGIN blocks, which may contain general computations, C macros are merely string replacements and do not require code execution.
| Logical connectives | |||
|---|---|---|---|
|