Cind programming language

Language definition Examples Download Contact

Expression in preprocessor directives

An expression used by a preprocessor directive #if is parsed by the preprocessor to retrieve a boolean value.
For example:

#if ((2+X)>=7) and (Y<0))

is a preprocessor directive with expression to resolve by the preprocessor.
To resolves that expression, preprocessor makes operation on the values, converts them, applies an operators of arithmetic instructions, and so on, to finally receive a single boolean value, which will be used in a directive. Values and operators used in the syntax of this expression are decribed below.

For more about directives see Language text preprocessor.

Values and types

There are allowed three kinds of the data type: boolean, integer and string.
A type of the value is automatically detected by the expression parser.

There are two values of boolean type: true and false,
and they can be written: true, TRUE, True, false, FALSE, False .

An integer type value is a 64-bit integer number with sign.
Notation allows decimal, hexadecimal and binary form.
Examples: 0, 17, -234, 0X4f5a, -0xFEDCBA0, 0b110010 .
There are no floating point numbers, nor any others.

A string type object is a text inserted between quotation marks: " ... " or single quotes: ' ... ' .
Example: "Hello!" .

Operations

List of the allowed operations in the preprocessor expression:
operator syntax meaning
++ ++x, x++ x+1
-- --x, x-- x-1
! !x logical not x
+ a + b sum
- a - b difference
* a * b product
/ a / b quotient
% a % b modulo
== a == b is equal
!= a != b is not equal
<> a <> b is not equal
< a < b is less than
> a > b is greater than
<= a <= b is less than or equal to
>= a >= b is greater than or equal to
&& a && b logical and
|| a || b logical or
& a & b bitwise and
| a | b bitwise or
^ a ^ b bitwise xor
~ ~a bitwise not
<< a << b bitwise left shift
>> a >> b bitwise right shift
?: a ? b : c ternary conditional

Priority of operators

priority level operator or statement selecting from
0 brackets (...) left
1 a++, a-- left
2 !a, ++a, --a, ~a right
3 * / % left
4 + - left
5 << >> left
6 < <= > >= left
7 == != <> left
8 & left
9 ^ left
10 | left
11 && left
12 || left
13 a ? b : c left

Column "selecting from" says if the expression statement is interpreted from left-to-right or from right-to-left.

Type conversion

A data values are converted to expected type, that depends on the first argument of the operator.
For example:

2 + "3" --> 5 "2" + 3 --> "23"

And finally, value of whole expression is converted to the boolean value.



Cind programming language 1.0.4