Here we describe the meaning of Ticc expressions. For the precise syntax of expressions, and the keywords and symbols, refer to the input grammar. In the next section we discuss how the expressions are created.

Declaration of Types

Ticc has the following types:

Constants

Operators

Precedence and Associativity of Operators

Precedence

Operator

Associativity

Lowest

& and | or -> impl

left

~ not

left

= != < <= => >

left

mod

not associative, and not functional {2}

Highest

+ -

left

{2} See this bug.

Expression evaluation and types

The typing rule during expression evaluation are as follows. <!> Read them: they are not what you might expect!

Boolean to integer casts

Boolean "true" and "false" values are cast to the integer value 1 and 0 respectively in numerical expressions.

Casts among range types

In Ticc, the following basic principles apply:

Let us illustrate the consequences of these design decisions. Consider the following expression:

 x' = y + z - 3

and assume that the ranges are as follows:

 var x: [0..4]
 var y: [0..5]
 var z: [0..5]

The rules imply the following:

For example:

Automatic term reordering

<!> <!> Consider now the following expression:

 x' = y - z + 3

If x is 2, y is 2, and z is 3, then the expression would yield value false, even though 2 = 2 - 3 + 3! In fact, Ticc would evaluate y - z, obtain a negative number, and say that the whole expression is false. To mitigate (but not eliminate) this, after parsing, Ticc tries to reorder the expressions, so that whenever possible, negative results are avoided. For instance, the above expression would be internally transformed into the following expression:

 x' = y + 3 - z

so that a negative result would occur only if the total result is negative. Ticc is somewhat limited in the reorderings it can perform: it can do basic expression simplification, and it reorders the terms of a sum so that positive terms occur before negative terms. If you are interested in knowing what reorderings occurred, you can (better: should) print the modules you parse. Indeed, it is in general a good habit to print the modules after parsing, to check that Ticc has interpreted them correctly.

Ticc/Expressions (last edited 2006-08-10 16:53:18 by LucaDeAlfaro)