const_dcl : 'const' const_type ID '=' const_exp
const_type : integer_type | boolean_type |
floating_pt_type | 'string'
| type_name // must designate a simple type
integer_type : [ 'unsigned' ] ( 'long' | 'short' )
boolean_type : 'boolean'
floating_pt_type : 'float' | 'double'
const_exp : exp1 ( '|' exp1 )*
exp1 : exp2 ( '^' exp2 )*
exp2 : exp3 ( '&' exp3 )*
exp3 : exp4 ( shift_op exp4 )*
exp4 : exp5 ( add_op exp5 )*
exp5 : exp6 ( mul_op exp6 )*
exp6 : [ unary_op ] atom
atom : const_name | literal | '(' const_exp ')'
shift_op : '<<' | '>>'
add_op : '+' | '-'
mul_op : '*' | '/' | '%'
unary_op : '+' | '-' | '~'
literal :
INTEGER_CONSTANT
| STRING_LITERAL
| CHARACTER_CONSTANT
| FLOATING_CONSTANT
| 'true' | 'false'
const_name : scoped_name // must designate a const
A
const_dcl
binds a name to a simple (unstructured) constant value.
Constants may be defined by C-like expressions involving
literals and names of other constants.
The type of the constant is explicitly indicated.
An integer type must be explicitly indicated as
long
or
short;
there is no default integer size.
Only one precision of floating point is supported.
const long Kilobyte = 1<<10;
const long Megabyte = 1<<20;
const long BytesPerPage = 4*Kilobyte;
const long MemSize = 20*Kilobyte;
const long MaxPages = MemSize / BytesPerPage;
const float PI = 3.1415926525;
const float Avogadro = 6.02E24;
const string Message = "Error";