Search code examples
expressionprogramming-languagescomputer-sciencetheorystatements

Are operators a subset of statements?


Basically in all high-level languages (as I know) we have two main categories of language mechanisms to create a program: statements and expressions.

Usually statements are represented by some subset of language's keywords: if/else/switch, for/foreach/while, {} (or BEGIN/END), etc.

Expressions are represented by literals (which represent some data) and operators: literals: 1, 2, -100, testTest, etc; operators: +, -, /, *, ==, ===, etc.

If we think deeper, we can notice that statements usually answer on question "what?" and expressions -- on question "how?". Statements represent actions, expressions represent the context of actions.

Then we may look in expressions' parts again: literals and operators. Operators are actions too.

And here is my question again: are operators a subset of statement?

P.S. Generally, I understand that statements and expression are used together to aim some programming target. Separation of this categories is mostly theoretical.


Solution

  • In general, "operator" describes a kind of syntactic form, which can be used to produce an expression, a statement, or some other class of language entity. So, technically, the answer to your question is, "no".

    For example, Haskell uses a | operator to generate an algebraic type spec, which is neither an expression nor a statement:

    data Maybe a = Just a | Nothing