+### The `const` section
+
+As well as being defined in with the code that uses them, constants
+can be declared at the top level. These have full-file scope, so they
+are always `InScope`. The value of a top level constant can be given
+as an expression, and this is evaluated immediately rather than in the
+later interpretation stage. Once we add functions to the language, we
+will need rules concern which, if any, can be used to define a top
+level constant.
+
+Constants are defined in a sectiont that starts with the reserved word
+`const` and then has a block with a list of assignment statements.
+For syntactic consistency, these must use the double-colon syntax to
+make it clear that they are constants. Type can also be given: if
+not, the type will be determined during analysis, as with other
+constants.
+
+###### top level grammar
+
+ DeclareConstant -> const Open ConstList Close
+ | const Open Newlines ConstList Close
+ | const Open SimpleConstList }
+ | const Open Newlines SimpleConstList }
+ | const : ConstList
+ | const SimpleConstList
+
+ ConstList -> ComplexConsts
+ ComplexConsts -> ComplexConst ComplexConsts
+ | ComplexConst
+ ComplexConst -> SimpleConstList NEWLINE
+ SimpleConstList -> Const ; SimpleConstList
+ | Const
+ | Const ; SimpleConstList ;
+
+ $*type
+ CType -> Type ${ $0 = $<1; }$
+ | ${ $0 = NULL; }$
+ $void
+ Const -> IDENTIFIER :: CType = Expression ${ {
+ int ok;
+ struct variable *v;
+
+ v = var_decl(config2context(config), $1.txt);
+ if (v) {
+ struct var *var = new_pos(var, $1);
+ v->where_decl = var;
+ v->where_set = var;
+ var->var = v;
+ v->constant = 1;
+ } else {
+ v = var_ref(config2context(config), $1.txt);
+ tok_err(config2context(config), "error: name already declared", &$1);
+ type_err(config2context(config), "info: this is where '%v' was first declared",
+ v->where_decl, NULL, 0, NULL);
+ }
+ do {
+ ok = 1;
+ propagate_types($5, config2context(config), &ok, $3, 0);
+ } while (ok == 2);
+ if (!ok)
+ config2context(config)->parse_error = 1;
+ else if (v) {
+ v->val = interp_exec($5);
+ }
+ } }$
+
+