from Wikipedia, the free encyclopedia

A literal is a special part of a formal language .

Literals in programming languages

Role of literals in programming languages

In programming languages, a literal ( Latin littera , letter ') is a character string that is defined or permitted for the direct representation of the values ​​of basic types (e.g. integers, floating point numbers, character strings).

A distinction is made between logical (true, not true), numeric and character literals. Depending on the programming language, there are further and more detailed categorizations for literals. In order for literals to be identified by the compiler , they must meet certain syntactic rules, e. B. (depending on the language and in certain cases) must be enclosed in quotation marks.

Literals as part of commands are also called literal constants or not named constants called because both literal and constants to maturity are invariably the program. In assignment operators, literals may only be coded as a send expression (usually right-hand; 'lines = 60'), as an argument of a function or as the value of a constant.

In functional programming , functions can also be written as literals. These are known as anonymous functions or lambda functions .

Similar to the literal term, some programming languages ​​know so-called "figurative constants". These are (e.g. in Cobol ) acc. "Cobol words [in different spellings, e.g. B. in plural form] for which the compiler generates certain values ​​“: Zero, Space, High-Value and Low-Value, Quote and 'ALL Literal'.

As an aspect of the programming style , it is sometimes recommended not to use literals in the command part of the program code, but instead to use constants that can be addressed as often as desired in the source text - instead of always using the same literal. This regulation should lead to greater transparency and ease of maintenance.

In JavaScript structured data such as arrays and objects can be written as literals, in Tcl on the other hand lists and dictionaries .

Examples of literals

Truth values : true , false (in many languages ​​as reserved words)
Integers : 1200, +1200, −12 (only digits and + or -)
Floating point numbers : 12.34, -12e34, 12.e-34 (Digits, sign, period, e)
Single character: 'a' (any single character in quotes)
Strings : "ABCD (12) $ is a string" (multiple characters in double quotes)
  {"vName":"Jonas", "fName":"Dörfner"},
  {"vName":"Anna Lena", "fName":"Schmitz"},
  {"vName":"Peter", "fName":"Meier"}
(an object that contains an array with multiple objects)
Dictionary in Tcl:
{mitarbeiter {
  {vName Jonas fName Dörfner}
  {vName {Anna Lena} fName Schmitz}
  {vName Peter fName Meier}
(identical in content to the JSON example above, instead of the array it is a list with 3 elements in Tcl)
List in Tcl:
{{rote Grütze} gelb {grüne Soße}}
(three list elements)
S-Expressions (symbolic expressions) in Lisp :
  (:vname "Jonas"     :fname "Dörfner")
  (:vname "Anna Lena" :fname "Schmitz")
  (:vname "Peter"     :fname "Meier")))
nested lists of symbols and strings, quoted as literal

Literals in Mathematical Logic

In mathematical logic , a literal is an atomic statement (atom) or the negation of an atomic statement. So you have positive literals and negative literals . A disjunctive combination of literals is called a disjunction term or a clause . A purely conjunctive combination of literals is called a conjunction term or a monomial .

Web links

Wiktionary: Literal  - explanations of meanings, word origins, synonyms, translations

Individual evidence

  1. General Cobol program structure ( PDF  ( page no longer available , search in web archivesInfo: The link was automatically marked as defective. Please check the link according to the instructions and then remove this notice. )@1@ 2Template: Dead Link /