Difference between revisions of "expression"

From Lazarus wiki
Jump to navigationJump to search
Line 4: Line 4:
 
They consist of at least one operand, and additional operands may be linked via non-unary operators.
 
They consist of at least one operand, and additional operands may be linked via non-unary operators.
 
An operand may be
 
An operand may be
* a literal value of any type
+
* a literal value of any type,
* a [[Variable|variable]] or [[Constant|constant]] [[Identifier|identifier]], or
+
* a [[Variable|variable]] or [[Constant|constant]] referred to by its [[Identifier|identifier]], or
 
* a [[Function|function]] call.
 
* a [[Function|function]] call.
  
 
Examples of expressions are:
 
Examples of expressions are:
* <syntaxhighlight lang="pascal" enclose="none">x + 5</syntaxhighlight>
+
* <syntaxhighlight lang="pascal" inline>+ 5</syntaxhighlight>
* <syntaxhighlight lang="pascal" enclose="none">'Z'</syntaxhighlight>
+
* <syntaxhighlight lang="pascal" inline>'Z'</syntaxhighlight>
* <syntaxhighlight lang="pascal" enclose="none">response</syntaxhighlight> [[Not_equal|<syntaxhighlight lang="pascal" enclose="none"><></syntaxhighlight>]] <syntaxhighlight lang="pascal" enclose="none">42</syntaxhighlight>
+
* <syntaxhighlight lang="pascal" inline>response</syntaxhighlight> [[Not_equal|<syntaxhighlight lang="pascal" inline><></syntaxhighlight>]] <syntaxhighlight lang="pascal" inline>42</syntaxhighlight>
  
 
Expressions, and parts thereof, can be classified by their result type.
 
Expressions, and parts thereof, can be classified by their result type.
Line 20: Line 20:
 
== remarks ==
 
== remarks ==
 
With [[Compiler directive|compiler directive]]
 
With [[Compiler directive|compiler directive]]
<syntaxhighlight lang="pascal" enclose="none">{$extendedSyntax on}</syntaxhighlight> a function call as an expression can appear as a statement, too.
+
<syntaxhighlight lang="pascal" inline>{$extendedSyntax on}</syntaxhighlight> a function call as an expression can appear as a statement, too.
 +
This is useful if the function triggers side-effects, but the return value is not needed.
  
 
== see also ==
 
== see also ==
 
* [https://en.wikipedia.org/wiki/Expression_(computer_science) article „expression“] in Wikipedia, the free online encyclopedia
 
* [https://en.wikipedia.org/wiki/Expression_(computer_science) article „expression“] in Wikipedia, the free online encyclopedia
 
* Tutorial: [[Boolean Expressions|Boolean expressions]]
 
* Tutorial: [[Boolean Expressions|Boolean expressions]]
 +
* Tutorial: [[How To Use TFPExpressionParser|How to use <syntaxhighlight lang="pascal" inline>tFPExpressionParser</syntaxhighlight>]] (if an expression entered by the user shall be interpreted)

Revision as of 03:06, 25 June 2020

English (en) suomi (fi)

An expression is a non-productive rule that resolves by calculation into a value. They consist of at least one operand, and additional operands may be linked via non-unary operators. An operand may be

Examples of expressions are:

  • x + 5
  • 'Z'
  • response <> 42

Expressions, and parts thereof, can be classified by their result type. Usually primarily arithmetic and logic expressions are distinguished. An arithmetic expression results in a numeric value. A logic expression results in a Boolean value.

remarks

With compiler directive {$extendedSyntax on} a function call as an expression can appear as a statement, too. This is useful if the function triggers side-effects, but the return value is not needed.

see also