Netmond V2. Evaluated expression (calculator)
The Netmond built-in calculator is a simple arbitrary
precision arithmetic system that uses the expressions of C-like
programming language. It writen in YACC.
The most basic element in the calculator is the number. Numbers are
arbitrary precision numbers. This precision is both in the integer part and
the fractional part. All numbers are represented internally as a double and
all computation is done in floating.
The other element is the strings. The strings are represented internally
as a double contained an unique checksum of the each string. The equal strings
has the same checksum. The strings must enclosed in a double quota characters.
The main capability of the calculator is a substitution of Netmond
variables. So it can calculate and compare any data inside the Netmond.
The source form of evaluated expression may contain the references to the
corresponding variables by it names begins with the dollar character.
Since all substitutions is done the resulting numbers and strings are
manipulated by expressions. Full expressions are similar to many other high
level languages.
In the following descriptions of legal expressions, "expr" refers to a
complete expression:
- - expr
- The result is the negation of the expression.
- ~ expr
- The result is the binary inversion of the expression.
- expr + expr
- The result of the expression is the sum of the two expressions.
- expr - expr
- The result of the expression is the difference of the two expressions.
- expr * expr
- The result of the expression is the product of the two expressions.
- expr / expr
- The result of the expression is the quotient of the two expressions.
- expr % expr
- The result of the expression is the "remainder" of the two expressions.
- expr | expr
- The result of the expression is the binary sum of the two expressions.
The casting to unsigned integer of both expressions will be performed.
- expr & expr
- The result of the expression is the binary product of the two expressions.
The casting to unsigned integer of both expressions will be performed.
- expr ^ expr
- The result of the expression is the value of the first raised to the second.
The casting to unsigned integer of both expressions will be performed.
- ( expr )
- This alters the standard precedence to force the evaluation of the expression.
Relational expressions are a special kind of expression that always
evaluate to 0 or 1, 0 if the relation is false and 1 if the relation is true.
These may appear in any legal expression:
- expr1 < expr2
- The result is 1 if expr1 is strictly less than expr2.
- expr1 <= expr2
- The result is 1 if expr1 is less than or equal to expr2.
- expr1 > expr2
- The result is 1 if expr1 is strictly greater than expr2.
- expr1 >= expr2
- The result is 1 if expr1 is greater than or equal to expr2.
- expr1 == expr2
- The result is 1 if expr1 is equal to expr2.
- expr1 != expr2
- The result is 1 if expr1 is not equal to expr2.
Boolean operations are also legal. The result of all boolean operations
are 0 and 1 (for false and true) as in relational expressions.
The boolean operators are:
- !expr
- The result is 1 if expr is 0.
- expr && expr
- The result is 1 if both expressions are non-zero.
- expr || expr
- The result is 1 if either expression is non-zero.
The expression precedence is as follows (lowest to highest):
- || operator, left associative
- && operator, left associative
- Relational operators, left associative
- Binary operations, left associative
- ^ operator, left associative
- + and - operators, left associative
- *, / and % operators, left associative
- ! and ~ operators, nonassociative
- unary - operator, nonassociative
© 1998-2002, Rinet Software
|