[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

Basic Assignment and Expressions

Values can be assigned in an assignment statement or in a declaration.

The Assignment Statement (:=)

Values are assigned to variables with the assignment statement (:=). Unlike some languages, assignment is not an operator: it cannot be used in an expression.

=> x := 5 * ( 7 + 2 );
=> s := "hello " & "there!";

Assignments and Limited Types

Some built-in types are "limited". This means they cannot be assigned using the assignment statement.

Boolean True Shortcut

As a special exception, stating a boolean's name implies that the boolean is assigned true. This only applies to boolean or subtypes of boolean. The shortcut only assigns true (not false). It can only be used with scalar variables (not arrays or records)

done : boolean := false;
loop
  -- ...do something
  if end_of_file( f ) then
    done; -- same as done := true
    exit;
  end if;
end loop;
if done then
  -- ...do something
end if;

Under pragma ada_95, the boolean true shortcut is not allowed.

Primitive Operators

AdaScript expressions can contain the following operators:

  • uniary: +, -, not
  • exponentiation: **
  • arithmetic: +, -, *, /, & (string concatenation), rem (remainder), mod (modulo), and (bitwise and), or (bitwise or), xor (bitwise exclusive or), * (string duplication)
  • relational: =, /= (not equals), >=, >, <=, <, in, not in
  • boolean: and, or, xor (exclusive OR)

The bitwise operators are identical to the boolean operators: SparForte choses which to use on the context of the expression.

in and not in test for membership in a range. (In Ada, the range can be a type but under AdaScript types have no bounds.) The range can be an pair of numbers, characters (not strings) or a pair of enumerated items.

=> b := green in red..blue;
=> b := 5 not in 10..20;

in and not in are technically not operators.

Ada: and then and or else not yet implemented. Character ranges not yet implemented.

Expressions and Order of Operations

An expression is a combination of operands and operators used to compute a result value.

Expression operators are evaluated in the following order:

  • Factors: literals, variables are other values, uniary +, uniary -, subexpressions
  • Power Terms: **
  • Terms: /, mod, rem, *, &
  • Simple Expressions: +, -
  • Relations: =, /=, >=, >, <=, < in, not in
  • Boolean Expressions: and, or, xor

Subexpressions can be created using parantheses.

If pragma ada_95 is used, expression parantheses are required in certain cases.

Ada: SparForte has looser restrictions on parantheses unless pragma ada_95 is used.


 

[Right Submenu]

 AdaScript versus GCC

 Case Sensitivity

 Reserved Words

 Comments

 Literals

 Bourne Shell Word Expansions

 Fundamental Types

 User-defined Types

 Enumerated Types

 Arrays

 Records

 Basic Assignment

 The @ and % Operands

 Command Argument Shortcuts

 Redirection and Pipelines

 Command Line Interaction

 Built-in Shell Commands

 The Current Directory

 Database Commands

 Flow of Control

 Other Statements/ Subprograms

 External Commands

 Block Statements and Subprograms

 TCP/IP Sockets

 Numeric Formatting with Put

 Interpreter Directives

 Command Line Options

 Command Reference

 ASCII and Latin_1 Character Sets

 Common Error Messages

 Common PHP Functions and the SparForte Equivalent

[Back to Top] Back To Top [Small Forte Symbol]