Reflex supports two types of global variable, and it supports a single scope of variables within reflex and routine declarations. Because reflexes are limited to a single variable scope. A declared variable is visible anywhere within the routine. Redeclaring a reflex variable will cause a compile time error. In addition, variables must be declared at the beginning of the routine, before any other type of statement.
All “Global” variables are declared as specification on Scratchpad elements. Or as module declarations See the Scratchpad section of the reference for more information about the usage of the scratchpad. Module declarations are used to declare any BrainStem modules on the BrainStem bus that will be accessed by the reflexes and routines in the reflex map.
A module declaration allows a reflex or routine to interace with a specific BrainStem module on the BrainStem network. These module declarations must come before any reflex routine definitions.
a40PinModule stem; // or a40PinModule stem(address);
The first example above declares the module that the reflex is running on, the address in the first example is implicit, and will be the module address of the current module. The second form allows an explicit module address to be given. This is particularly usefull for communicating with other modules on the BrainStem BUS.
Module Declaration EBNF¶
module_declaration ::= model_def , ID , ";" model_def ::= "Model definitions are included in the reflex" " map via #include directives" " for example; #include <a40PinModule.reflex>"
The Scratchpad allows reflex routines, and the host to share information and state. the Reflex language provides a way for a user to declare a typed variable to be stored at an offset within the Scratchpad.
pad[0:3] unsigned int value;
pad starts the declaration, the range declaration
[0:3], defines the indices of the pad that will be allocated for the variable. The type specification
unsigned int follows the pad declaration and finally the variable name is given.
This fully specifies a pad variable. Pad variables cannot overlap in offset within the pad. An int declaration of
pad[0:3] and a second of
pad[2:5] would fail at compile time.
Pad Declaration EBNF¶
pad_declaration ::= 'pad' , "[" , INT , ":" , INT , "]" , type_specifier , ID , ";" ;
Variables can be declared within a routine or reflex block. They must be declared at the beginning of the block before any other expression or statement. Routine variable declarations should be familiar developers familiar with C-like languages. Variables may be intitialized when they are declared but initialization at decleration is not required.
char value; // or char value = 12;
Routine Variable Declaration EBNF¶
variable_declaration ::= type_specifier , ID , [ "=" , INT ] , ";" ;