fprintf(stderr, "oceani: no program found.\n");
context.parse_error = 1;
}
- if (context.prog && doprint)
+ if (context.prog && doprint) {
+ ## print decls
print_exec(context.prog, 0, brackets);
+ }
if (context.prog && doexec && !context.parse_error) {
if (!analyse_prog(context.prog, &context)) {
fprintf(stderr, "oceani: type error in program - not running.\n");
not, the type will be determined during analysis, as with other
constants.
+As the types constants are inserted at the head of a list, printing
+them in the same order that they were read is not straight forward.
+We take a quadratic approach here and count the number of constants
+(variables of depth 0), then count down from there, each time
+searching through for the Nth constant for decreasing N.
+
###### top level grammar
DeclareConstant -> const Open ConstList Close
}
} }$
+###### print decls
+ {
+ struct variable *v;
+ int target = -1;
+
+ while (target != 0) {
+ int i = 0;
+ for (v = context.in_scope; v; v=v->in_scope)
+ if (v->depth == 0) {
+ i += 1;
+ if (i == target)
+ break;
+ }
+
+ if (target == -1) {
+ if (i)
+ printf("const:\n");
+ target = i;
+ } else {
+ printf(" %.*s :: ", v->name->name.len, v->name->name.txt);
+ type_print(v->val.type, stdout);
+ printf(" = ");
+ if (v->val.type == Tstr)
+ printf("\"");
+ print_value(v->val);
+ if (v->val.type == Tstr)
+ printf("\"");
+ printf("\n");
+ target -= 1;
+ }
+ }
+ }
### Finally the whole program.