]> ocean-lang.org Git - ocean/commitdiff
oceani: indent grammar more consistently.
authorNeilBrown <neil@brown.name>
Mon, 29 Nov 2021 08:39:06 +0000 (19:39 +1100)
committerNeilBrown <neil@brown.name>
Mon, 29 Nov 2021 08:39:06 +0000 (19:39 +1100)
- all products are not indented, whether they start with a non-term or a
  '|'.
- Code is indented once - plus internal indents.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani.mdc

index 5a728b6086463bf76cadcc0d52ffc6f7be90b93c..7371535bf7c555ec127028eb89f3113901be0561 100644 (file)
@@ -1185,44 +1185,38 @@ executable.
 
        $*val
        Value ->  True ${
-                       $0 = new_val(Tbool, $1);
-                       $0->val.bool = 1;
-                       }$
-               | False ${
-                       $0 = new_val(Tbool, $1);
-                       $0->val.bool = 0;
-                       }$
-               | NUMBER ${
-                       $0 = new_val(Tnum, $1);
-                       {
-                       char tail[3];
-                       if (number_parse($0->val.num, tail, $1.txt) == 0)
-                               mpq_init($0->val.num);  // UNTESTED
-                               if (tail[0])
-                                       tok_err(c, "error: unsupported number suffix",
-                                               &$1);
-                       }
-                       }$
-               | STRING ${
-                       $0 = new_val(Tstr, $1);
-                       {
-                       char tail[3];
-                       string_parse(&$1, '\\', &$0->val.str, tail);
-                       if (tail[0])
-                               tok_err(c, "error: unsupported string suffix",
-                                       &$1);
-                       }
-                       }$
-               | MULTI_STRING ${
-                       $0 = new_val(Tstr, $1);
-                       {
-                       char tail[3];
-                       string_parse(&$1, '\\', &$0->val.str, tail);
+               $0 = new_val(Tbool, $1);
+               $0->val.bool = 1;
+       }$
+       | False ${
+               $0 = new_val(Tbool, $1);
+               $0->val.bool = 0;
+       }$
+       | NUMBER ${ {
+               char tail[3];
+               $0 = new_val(Tnum, $1);
+               if (number_parse($0->val.num, tail, $1.txt) == 0)
+                       mpq_init($0->val.num);  // UNTESTED
                        if (tail[0])
-                               tok_err(c, "error: unsupported string suffix",
+                               tok_err(c, "error: unsupported number suffix",
                                        &$1);
-                       }
-                       }$
+       } }$
+       | STRING ${ {
+               char tail[3];
+               $0 = new_val(Tstr, $1);
+               string_parse(&$1, '\\', &$0->val.str, tail);
+               if (tail[0])
+                       tok_err(c, "error: unsupported string suffix",
+                               &$1);
+       } }$
+       | MULTI_STRING ${ {
+               char tail[3];
+               $0 = new_val(Tstr, $1);
+               string_parse(&$1, '\\', &$0->val.str, tail);
+               if (tail[0])
+                       tok_err(c, "error: unsupported string suffix",
+                               &$1);
+       } }$
 
 ###### print exec cases
        case Xval:
@@ -1999,7 +1993,7 @@ correctly.
                                 v->where_decl, NULL, 0, NULL);
                }
        } }$
-           | IDENTIFIER :: ${ {
+       | IDENTIFIER :: ${ {
                struct variable *v = var_decl(c, $1.txt);
                $0 = new_pos(var, $1);
                $0->var = v;
@@ -2015,7 +2009,7 @@ correctly.
                                 v->where_decl, NULL, 0, NULL);
                }
        } }$
-           | IDENTIFIER : Type ${ {
+       | IDENTIFIER : Type ${ {
                struct variable *v = var_decl(c, $1.txt);
                $0 = new_pos(var, $1);
                $0->var = v;
@@ -2033,7 +2027,7 @@ correctly.
                                 v->where_decl, NULL, 0, NULL);
                }
        } }$
-           | IDENTIFIER :: Type ${ {
+       | IDENTIFIER :: Type ${ {
                struct variable *v = var_decl(c, $1.txt);
                $0 = new_pos(var, $1);
                $0->var = v;
@@ -2067,7 +2061,7 @@ correctly.
                        }
                }
                cast(var, $0)->var = v;
-               } }$
+       } }$
 
 ###### print exec cases
        case Xvar:
@@ -2177,8 +2171,8 @@ simple "Value" (to be explained later).
 ###### Grammar
        $*exec
        Term ->  Value ${ $0 = $<1; }$
-               | Variable ${ $0 = $<1; }$
-               ## term grammar
+       | Variable ${ $0 = $<1; }$
+       ## term grammar
 
 Thus far the complex types we have are arrays and structs.
 
@@ -2682,79 +2676,79 @@ function will be needed.
 
 ###### top level grammar
        DeclareStruct -> struct IDENTIFIER FieldBlock Newlines ${ {
-                       struct type *t =
-                               add_type(c, $2.txt, &structure_prototype);
-                       int cnt = 0;
-                       struct fieldlist *f;
-
-                       for (f = $3; f; f=f->prev)
-                               cnt += 1;
-
-                       t->structure.nfields = cnt;
-                       t->structure.fields = calloc(cnt, sizeof(struct field));
-                       f = $3;
-                       while (cnt > 0) {
-                               int a = f->f.type->align;
-                               cnt -= 1;
-                               t->structure.fields[cnt] = f->f;
-                               if (t->size & (a-1))
-                                       t->size = (t->size | (a-1)) + 1;
-                               t->structure.fields[cnt].offset = t->size;
-                               t->size += ((f->f.type->size - 1) | (a-1)) + 1;
-                               if (a > t->align)
-                                       t->align = a;
-                               f->f.init = NULL;
-                               f = f->prev;
-                       }
-               } }$
+               struct type *t =
+                       add_type(c, $2.txt, &structure_prototype);
+               int cnt = 0;
+               struct fieldlist *f;
+
+               for (f = $3; f; f=f->prev)
+                       cnt += 1;
+
+               t->structure.nfields = cnt;
+               t->structure.fields = calloc(cnt, sizeof(struct field));
+               f = $3;
+               while (cnt > 0) {
+                       int a = f->f.type->align;
+                       cnt -= 1;
+                       t->structure.fields[cnt] = f->f;
+                       if (t->size & (a-1))
+                               t->size = (t->size | (a-1)) + 1;
+                       t->structure.fields[cnt].offset = t->size;
+                       t->size += ((f->f.type->size - 1) | (a-1)) + 1;
+                       if (a > t->align)
+                               t->align = a;
+                       f->f.init = NULL;
+                       f = f->prev;
+               }
+       } }$
 
        $*fieldlist
        FieldBlock -> { IN OptNL FieldLines OUT OptNL } ${ $0 = $<FL; }$
-               | { SimpleFieldList } ${ $0 = $<SFL; }$
-               | IN OptNL FieldLines OUT ${ $0 = $<FL; }$
-               | SimpleFieldList EOL ${ $0 = $<SFL; }$
+       | { SimpleFieldList } ${ $0 = $<SFL; }$
+       | IN OptNL FieldLines OUT ${ $0 = $<FL; }$
+       | SimpleFieldList EOL ${ $0 = $<SFL; }$
 
        FieldLines -> SimpleFieldList Newlines ${ $0 = $<SFL; }$
-               | FieldLines SimpleFieldList Newlines ${
-                       $SFL->prev = $<FL;
-                       $0 = $<SFL;
-               }$
+       | FieldLines SimpleFieldList Newlines ${
+               $SFL->prev = $<FL;
+               $0 = $<SFL;
+       }$
 
        SimpleFieldList -> Field ${ $0 = $<F; }$
-               | SimpleFieldList ; Field ${
-                       $F->prev = $<SFL;
-                       $0 = $<F;
-               }$
-               | SimpleFieldList ; ${
-                       $0 = $<SFL;
-               }$
-               | ERROR ${ tok_err(c, "Syntax error in struct field", &$1); }$
+       | SimpleFieldList ; Field ${
+               $F->prev = $<SFL;
+               $0 = $<F;
+       }$
+       | SimpleFieldList ; ${
+               $0 = $<SFL;
+       }$
+       | ERROR ${ tok_err(c, "Syntax error in struct field", &$1); }$
 
        Field -> IDENTIFIER : Type = Expression ${ {
-                       int ok;
+               int ok;
 
-                       $0 = calloc(1, sizeof(struct fieldlist));
-                       $0->f.name = $1.txt;
-                       $0->f.type = $<3;
-                       $0->f.init = NULL;
-                       do {
-                               ok = 1;
-                               propagate_types($<5, c, &ok, $3, 0);
-                       } while (ok == 2);
-                       if (!ok)
-                               c->parse_error = 1;     // UNTESTED
-                       else {
-                               struct value vl = interp_exec(c, $5, NULL);
-                               $0->f.init = global_alloc(c, $0->f.type, NULL, &vl);
-                       }
-               } }$
-               | IDENTIFIER : Type ${
-                       $0 = calloc(1, sizeof(struct fieldlist));
-                       $0->f.name = $1.txt;
-                       $0->f.type = $<3;
-                       if ($0->f.type->prepare_type)
-                               $0->f.type->prepare_type(c, $0->f.type, 1);
-               }$
+               $0 = calloc(1, sizeof(struct fieldlist));
+               $0->f.name = $1.txt;
+               $0->f.type = $<3;
+               $0->f.init = NULL;
+               do {
+                       ok = 1;
+                       propagate_types($<5, c, &ok, $3, 0);
+               } while (ok == 2);
+               if (!ok)
+                       c->parse_error = 1;     // UNTESTED
+               else {
+                       struct value vl = interp_exec(c, $5, NULL);
+                       $0->f.init = global_alloc(c, $0->f.type, NULL, &vl);
+               }
+       } }$
+       | IDENTIFIER : Type ${
+               $0 = calloc(1, sizeof(struct fieldlist));
+               $0->f.name = $1.txt;
+               $0->f.type = $<3;
+               if ($0->f.type->prepare_type)
+                       $0->f.type->prepare_type(c, $0->f.type, 1);
+       }$
 
 ###### forward decls
        static void structure_print_type(struct type *t, FILE *f);
@@ -2993,50 +2987,50 @@ further detailed when Expression Lists are introduced.
 
        $*variable
        FuncName -> IDENTIFIER ${ {
-                       struct variable *v = var_decl(c, $1.txt);
-                       struct var *e = new_pos(var, $1);
+               struct variable *v = var_decl(c, $1.txt);
+               struct var *e = new_pos(var, $1);
+               e->var = v;
+               if (v) {
+                       v->where_decl = e;
+                       $0 = v;
+               } else {
+                       v = var_ref(c, $1.txt);
                        e->var = v;
-                       if (v) {
-                               v->where_decl = e;
-                               $0 = v;
-                       } else {
-                               v = var_ref(c, $1.txt);
-                               e->var = v;
-                               type_err(c, "error: function '%v' redeclared",
-                                       e, NULL, 0, NULL);
-                               type_err(c, "info: this is where '%v' was first declared",
-                                       v->where_decl, NULL, 0, NULL);
-                               free_exec(e);
-                       }
-               } }$
+                       type_err(c, "error: function '%v' redeclared",
+                               e, NULL, 0, NULL);
+                       type_err(c, "info: this is where '%v' was first declared",
+                               v->where_decl, NULL, 0, NULL);
+                       free_exec(e);
+               }
+       } }$
 
        $*binode
        Args -> ArgsLine NEWLINE ${ $0 = $<AL; }$
-               | Args ArgsLine NEWLINE ${ {
-                       struct binode *b = $<AL;
-                       struct binode **bp = &b;
-                       while (*bp)
-                               bp = (struct binode **)&(*bp)->left;
-                       *bp = $<A;
-                       $0 = b;
-               } }$
+       | Args ArgsLine NEWLINE ${ {
+               struct binode *b = $<AL;
+               struct binode **bp = &b;
+               while (*bp)
+                       bp = (struct binode **)&(*bp)->left;
+               *bp = $<A;
+               $0 = b;
+       } }$
 
        ArgsLine -> ${ $0 = NULL; }$
-               | Varlist ${ $0 = $<1; }$
-               | Varlist ; ${ $0 = $<1; }$
+       | Varlist ${ $0 = $<1; }$
+       | Varlist ; ${ $0 = $<1; }$
 
        Varlist -> Varlist ; ArgDecl ${
-                       $0 = new(binode);
-                       $0->op = List;
-                       $0->left = $<Vl;
-                       $0->right = $<AD;
-               }$
-               | ArgDecl ${
-                       $0 = new(binode);
-                       $0->op = List;
-                       $0->left = NULL;
-                       $0->right = $<AD;
-               }$
+               $0 = new(binode);
+               $0->op = List;
+               $0->left = $<Vl;
+               $0->right = $<AD;
+       }$
+       | ArgDecl ${
+               $0 = new(binode);
+               $0->op = List;
+               $0->left = NULL;
+               $0->right = $<AD;
+       }$
 
        $*var
        ArgDecl -> IDENTIFIER : FormalType ${ {
@@ -3173,7 +3167,7 @@ Term - others will follow.
 
        $*exec
        Expression -> Term ${ $0 = $<Term; }$
-               ## expression grammar
+       ## expression grammar
 
 ### Expressions: Conditional
 
@@ -3288,17 +3282,17 @@ lists.  In that case a separate function is used to print them.
 
        $*binode
        ExpressionList -> ExpressionList , Expression ${
-                       $0 = new(binode);
-                       $0->op = List;
-                       $0->left = $<1;
-                       $0->right = $<3;
-               }$
-               | Expression ${
-                       $0 = new(binode);
-                       $0->op = List;
-                       $0->left = NULL;
-                       $0->right = $<1;
-               }$
+               $0 = new(binode);
+               $0->op = List;
+               $0->left = $<1;
+               $0->right = $<3;
+       }$
+       | Expression ${
+               $0 = new(binode);
+               $0->op = List;
+               $0->left = NULL;
+               $0->right = $<1;
+       }$
 
 ### Expressions: Boolean
 
@@ -3320,42 +3314,42 @@ evaluate the second expression if not necessary.
        $LEFT not
 
 ###### expression grammar
-               | Expression or Expression ${ {
-                       struct binode *b = new(binode);
-                       b->op = Or;
-                       b->left = $<1;
-                       b->right = $<3;
-                       $0 = b;
-               } }$
-               | Expression or else Expression ${ {
-                       struct binode *b = new(binode);
-                       b->op = OrElse;
-                       b->left = $<1;
-                       b->right = $<4;
-                       $0 = b;
-               } }$
+       | Expression or Expression ${ {
+               struct binode *b = new(binode);
+               b->op = Or;
+               b->left = $<1;
+               b->right = $<3;
+               $0 = b;
+       } }$
+       | Expression or else Expression ${ {
+               struct binode *b = new(binode);
+               b->op = OrElse;
+               b->left = $<1;
+               b->right = $<4;
+               $0 = b;
+       } }$
 
-               | Expression and Expression ${ {
-                       struct binode *b = new(binode);
-                       b->op = And;
-                       b->left = $<1;
-                       b->right = $<3;
-                       $0 = b;
-               } }$
-               | Expression and then Expression ${ {
-                       struct binode *b = new(binode);
-                       b->op = AndThen;
-                       b->left = $<1;
-                       b->right = $<4;
-                       $0 = b;
-               } }$
+       | Expression and Expression ${ {
+               struct binode *b = new(binode);
+               b->op = And;
+               b->left = $<1;
+               b->right = $<3;
+               $0 = b;
+       } }$
+       | Expression and then Expression ${ {
+               struct binode *b = new(binode);
+               b->op = AndThen;
+               b->left = $<1;
+               b->right = $<4;
+               $0 = b;
+       } }$
 
-               | not Expression ${ {
-                       struct binode *b = new(binode);
-                       b->op = Not;
-                       b->right = $<2;
-                       $0 = b;
-               } }$
+       | not Expression ${ {
+               struct binode *b = new(binode);
+               b->op = Not;
+               b->right = $<2;
+               $0 = b;
+       } }$
 
 ###### print binode cases
        case And:
@@ -3477,12 +3471,12 @@ expression operator, and the `CMPop` non-terminal will match one of them.
 ###### Grammar
 
        $eop
-       CMPop ->   < ${ $0.op = Less; }$
-               |  > ${ $0.op = Gtr; }$
-               |  <= ${ $0.op = LessEq; }$
-               |  >= ${ $0.op = GtrEq; }$
-               |  == ${ $0.op = Eql; }$
-               |  != ${ $0.op = NEql; }$
+       CMPop ->  < ${ $0.op = Less; }$
+       |         > ${ $0.op = Gtr; }$
+       |         <= ${ $0.op = LessEq; }$
+       |         >= ${ $0.op = GtrEq; }$
+       |         == ${ $0.op = Eql; }$
+       |         != ${ $0.op = NEql; }$
 
 ###### print binode cases
 
@@ -3622,17 +3616,17 @@ parentheses around an expression converts it into a Term,
 ###### Grammar
 
        $eop
-       Eop ->    + ${ $0.op = Plus; }$
-               | - ${ $0.op = Minus; }$
+       Eop ->   + ${ $0.op = Plus; }$
+       |        - ${ $0.op = Minus; }$
 
-       Uop ->    + ${ $0.op = Absolute; }$
-               | - ${ $0.op = Negate; }$
-               | $ ${ $0.op = StringConv; }$
+       Uop ->   + ${ $0.op = Absolute; }$
+       |        - ${ $0.op = Negate; }$
+       |        $ ${ $0.op = StringConv; }$
 
-       Top ->    * ${ $0.op = Times; }$
-               | / ${ $0.op = Divide; }$
-               | % ${ $0.op = Rem; }$
-               | ++ ${ $0.op = Concat; }$
+       Top ->   * ${ $0.op = Times; }$
+       |        / ${ $0.op = Divide; }$
+       |        % ${ $0.op = Rem; }$
+       |        ++ ${ $0.op = Concat; }$
 
 ###### print binode cases
        case Plus:
@@ -3869,78 +3863,78 @@ the common header for all reductions to use.
 
        $*binode
        Block -> { IN OptNL Statementlist OUT OptNL } ${ $0 = $<Sl; }$
-               | { SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
-               | SimpleStatements ; ${ $0 = reorder_bilist($<SS); }$
-               | SimpleStatements EOL ${ $0 = reorder_bilist($<SS); }$
-               | IN OptNL Statementlist OUT ${ $0 = $<Sl; }$
+       |        { SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
+       |        SimpleStatements ; ${ $0 = reorder_bilist($<SS); }$
+       |        SimpleStatements EOL ${ $0 = reorder_bilist($<SS); }$
+       |        IN OptNL Statementlist OUT ${ $0 = $<Sl; }$
 
        OpenBlock -> OpenScope { IN OptNL Statementlist OUT OptNL } ${ $0 = $<Sl; }$
-               | OpenScope { SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
-               | OpenScope SimpleStatements ; ${ $0 = reorder_bilist($<SS); }$
-               | OpenScope SimpleStatements EOL ${ $0 = reorder_bilist($<SS); }$
-               | IN OpenScope OptNL Statementlist OUT ${ $0 = $<Sl; }$
+       |        OpenScope { SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
+       |        OpenScope SimpleStatements ; ${ $0 = reorder_bilist($<SS); }$
+       |        OpenScope SimpleStatements EOL ${ $0 = reorder_bilist($<SS); }$
+       |        IN OpenScope OptNL Statementlist OUT ${ $0 = $<Sl; }$
 
        UseBlock -> { OpenScope IN OptNL Statementlist OUT OptNL } ${ $0 = $<Sl; }$
-               | { OpenScope SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
-               | IN OpenScope OptNL Statementlist OUT ${ $0 = $<Sl; }$
+       |        { OpenScope SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
+       |        IN OpenScope OptNL Statementlist OUT ${ $0 = $<Sl; }$
 
        ColonBlock -> { IN OptNL Statementlist OUT OptNL } ${ $0 = $<Sl; }$
-               | { SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
-               | : SimpleStatements ; ${ $0 = reorder_bilist($<SS); }$
-               | : SimpleStatements EOL ${ $0 = reorder_bilist($<SS); }$
-               | : IN OptNL Statementlist OUT ${ $0 = $<Sl; }$
+       |        { SimpleStatements } ${ $0 = reorder_bilist($<SS); }$
+       |        : SimpleStatements ; ${ $0 = reorder_bilist($<SS); }$
+       |        : SimpleStatements EOL ${ $0 = reorder_bilist($<SS); }$
+       |        : IN OptNL Statementlist OUT ${ $0 = $<Sl; }$
 
        Statementlist -> ComplexStatements ${ $0 = reorder_bilist($<CS); }$
 
        ComplexStatements -> ComplexStatements ComplexStatement ${
-                       if ($2 == NULL) {
-                               $0 = $<1;
-                       } else {
-                               $0 = new(binode);
-                               $0->op = Block;
-                               $0->left = $<1;
-                               $0->right = $<2;
-                       }
-               }$
-               | ComplexStatement ${
-                       if ($1 == NULL) {
-                               $0 = NULL;
-                       } else {
-                               $0 = new(binode);
-                               $0->op = Block;
-                               $0->left = NULL;
-                               $0->right = $<1;
-                       }
-               }$
-
-       $*exec
-       ComplexStatement -> SimpleStatements Newlines ${
-                       $0 = reorder_bilist($<SS);
-                       }$
-               |  SimpleStatements ; Newlines ${
-                       $0 = reorder_bilist($<SS);
-                       }$
-               ## ComplexStatement Grammar
-
-       $*binode
-       SimpleStatements -> SimpleStatements ; SimpleStatement ${
+               if ($2 == NULL) {
+                       $0 = $<1;
+               } else {
                        $0 = new(binode);
                        $0->op = Block;
                        $0->left = $<1;
-                       $0->right = $<3;
-                       }$
-               | SimpleStatement ${
+                       $0->right = $<2;
+               }
+       }$
+       | ComplexStatement ${
+               if ($1 == NULL) {
+                       $0 = NULL;
+               } else {
                        $0 = new(binode);
                        $0->op = Block;
                        $0->left = NULL;
                        $0->right = $<1;
-                       }$
+               }
+       }$
+
+       $*exec
+       ComplexStatement -> SimpleStatements Newlines ${
+               $0 = reorder_bilist($<SS);
+       }$
+       |  SimpleStatements ; Newlines ${
+               $0 = reorder_bilist($<SS);
+       }$
+       ## ComplexStatement Grammar
+
+       $*binode
+       SimpleStatements -> SimpleStatements ; SimpleStatement ${
+               $0 = new(binode);
+               $0->op = Block;
+               $0->left = $<1;
+               $0->right = $<3;
+       }$
+       | SimpleStatement ${
+               $0 = new(binode);
+               $0->op = Block;
+               $0->left = NULL;
+               $0->right = $<1;
+       }$
 
        $TERM pass
        $*exec
        SimpleStatement -> pass ${ $0 = NULL; }$
-               | ERROR ${ tok_err(c, "Syntax error in statement", &$1); }$
-               ## SimpleStatement Grammar
+       | ERROR ${ tok_err(c, "Syntax error in statement", &$1); }$
+       ## SimpleStatement Grammar
 
 ###### print binode cases
        case Block:
@@ -4111,31 +4105,31 @@ it is declared, and error will be raised as the name is created as
 
 ###### SimpleStatement Grammar
        | Term = Expression ${
-                       $0 = b= new(binode);
-                       b->op = Assign;
-                       b->left = $<1;
-                       b->right = $<3;
-               }$
+               $0 = b= new(binode);
+               b->op = Assign;
+               b->left = $<1;
+               b->right = $<3;
+       }$
        | VariableDecl = Expression ${
-                       $0 = b= new(binode);
-                       b->op = Declare;
-                       b->left = $<1;
-                       b->right =$<3;
-               }$
+               $0 = b= new(binode);
+               b->op = Declare;
+               b->left = $<1;
+               b->right =$<3;
+       }$
 
        | VariableDecl ${
-                       if ($1->var->where_set == NULL) {
-                               type_err(c,
-                                        "Variable declared with no type or value: %v",
-                                        $1, NULL, 0, NULL);
-                               free_var($1);
-                       } else {
-                               $0 = b = new(binode);
-                               b->op = Declare;
-                               b->left = $<1;
-                               b->right = NULL;
-                       }
-               }$
+               if ($1->var->where_set == NULL) {
+                       type_err(c,
+                                "Variable declared with no type or value: %v",
+                                $1, NULL, 0, NULL);
+                       free_var($1);
+               } else {
+                       $0 = b = new(binode);
+                       b->op = Declare;
+                       b->left = $<1;
+                       b->right = NULL;
+               }
+       }$
 
 ###### print binode cases
 
@@ -4420,136 +4414,136 @@ casepart` to track a list of case parts.
        // ForPart, SwitchPart, and IfPart open scopes, o we have to close
        // them.  WhilePart opens and closes its own scope.
        CondStatement -> ForPart OptNL ThenPart OptNL WhilePart CondSuffix ${
-                       $0 = $<CS;
-                       $0->forpart = $<FP;
-                       $0->thenpart = $<TP;
-                       $0->looppart = $<WP;
-                       var_block_close(c, CloseSequential, $0);
-                       }$
-               | ForPart OptNL WhilePart CondSuffix ${
-                       $0 = $<CS;
-                       $0->forpart = $<FP;
-                       $0->looppart = $<WP;
-                       var_block_close(c, CloseSequential, $0);
-                       }$
-               | WhilePart CondSuffix ${
-                       $0 = $<CS;
-                       $0->looppart = $<WP;
-                       }$
-               | SwitchPart OptNL CasePart CondSuffix ${
-                       $0 = $<CS;
-                       $0->condpart = $<SP;
-                       $CP->next = $0->casepart;
-                       $0->casepart = $<CP;
-                       var_block_close(c, CloseSequential, $0);
-                       }$
-               | SwitchPart : IN OptNL CasePart CondSuffix OUT Newlines ${
-                       $0 = $<CS;
-                       $0->condpart = $<SP;
-                       $CP->next = $0->casepart;
-                       $0->casepart = $<CP;
-                       var_block_close(c, CloseSequential, $0);
-                       }$
-               | IfPart IfSuffix ${
-                       $0 = $<IS;
-                       $0->condpart = $IP.condpart; $IP.condpart = NULL;
-                       $0->thenpart = $IP.thenpart; $IP.thenpart = NULL;
-                       // This is where we close an "if" statement
-                       var_block_close(c, CloseSequential, $0);
-                       }$
+               $0 = $<CS;
+               $0->forpart = $<FP;
+               $0->thenpart = $<TP;
+               $0->looppart = $<WP;
+               var_block_close(c, CloseSequential, $0);
+       }$
+       | ForPart OptNL WhilePart CondSuffix ${
+               $0 = $<CS;
+               $0->forpart = $<FP;
+               $0->looppart = $<WP;
+               var_block_close(c, CloseSequential, $0);
+       }$
+       | WhilePart CondSuffix ${
+               $0 = $<CS;
+               $0->looppart = $<WP;
+       }$
+       | SwitchPart OptNL CasePart CondSuffix ${
+               $0 = $<CS;
+               $0->condpart = $<SP;
+               $CP->next = $0->casepart;
+               $0->casepart = $<CP;
+               var_block_close(c, CloseSequential, $0);
+       }$
+       | SwitchPart : IN OptNL CasePart CondSuffix OUT Newlines ${
+               $0 = $<CS;
+               $0->condpart = $<SP;
+               $CP->next = $0->casepart;
+               $0->casepart = $<CP;
+               var_block_close(c, CloseSequential, $0);
+       }$
+       | IfPart IfSuffix ${
+               $0 = $<IS;
+               $0->condpart = $IP.condpart; $IP.condpart = NULL;
+               $0->thenpart = $IP.thenpart; $IP.thenpart = NULL;
+               // This is where we close an "if" statement
+               var_block_close(c, CloseSequential, $0);
+       }$
 
        CondSuffix -> IfSuffix ${
-                       $0 = $<1;
-               }$
-               | Newlines CasePart CondSuffix ${
-                       $0 = $<CS;
-                       $CP->next = $0->casepart;
-                       $0->casepart = $<CP;
-               }$
-               | CasePart CondSuffix ${
-                       $0 = $<CS;
-                       $CP->next = $0->casepart;
-                       $0->casepart = $<CP;
-               }$
+               $0 = $<1;
+       }$
+       | Newlines CasePart CondSuffix ${
+               $0 = $<CS;
+               $CP->next = $0->casepart;
+               $0->casepart = $<CP;
+       }$
+       | CasePart CondSuffix ${
+               $0 = $<CS;
+               $CP->next = $0->casepart;
+               $0->casepart = $<CP;
+       }$
 
        IfSuffix -> Newlines ${ $0 = new(cond_statement); }$
-               | Newlines ElsePart ${ $0 = $<EP; }$
-               | ElsePart ${$0 = $<EP; }$
+       | Newlines ElsePart ${ $0 = $<EP; }$
+       | ElsePart ${$0 = $<EP; }$
 
        ElsePart -> else OpenBlock Newlines ${
-                       $0 = new(cond_statement);
-                       $0->elsepart = $<OB;
-                       var_block_close(c, CloseElse, $0->elsepart);
-               }$
-               | else OpenScope CondStatement ${
-                       $0 = new(cond_statement);
-                       $0->elsepart = $<CS;
-                       var_block_close(c, CloseElse, $0->elsepart);
-               }$
+               $0 = new(cond_statement);
+               $0->elsepart = $<OB;
+               var_block_close(c, CloseElse, $0->elsepart);
+       }$
+       | else OpenScope CondStatement ${
+               $0 = new(cond_statement);
+               $0->elsepart = $<CS;
+               var_block_close(c, CloseElse, $0->elsepart);
+       }$
 
        $*casepart
        CasePart -> case Expression OpenScope ColonBlock ${
-                       $0 = calloc(1,sizeof(struct casepart));
-                       $0->value = $<Ex;
-                       $0->action = $<Bl;
-                       var_block_close(c, CloseParallel, $0->action);
-               }$
+               $0 = calloc(1,sizeof(struct casepart));
+               $0->value = $<Ex;
+               $0->action = $<Bl;
+               var_block_close(c, CloseParallel, $0->action);
+       }$
 
        $*exec
        // These scopes are closed in CondStatement
        ForPart -> for OpenBlock ${
-                       $0 = $<Bl;
-               }$
+               $0 = $<Bl;
+       }$
 
        ThenPart -> then OpenBlock ${
-                       $0 = $<OB;
-                       var_block_close(c, CloseSequential, $0);
-               }$
+               $0 = $<OB;
+               var_block_close(c, CloseSequential, $0);
+       }$
 
        $*binode
        // This scope is closed in CondStatement
        WhilePart -> while UseBlock OptNL do OpenBlock ${
-                       $0 = new(binode);
-                       $0->op = Loop;
-                       $0->left = $<UB;
-                       $0->right = $<OB;
-                       var_block_close(c, CloseSequential, $0->right);
-                       var_block_close(c, CloseSequential, $0);
-               }$
-               | while OpenScope Expression OpenScope ColonBlock ${
-                       $0 = new(binode);
-                       $0->op = Loop;
-                       $0->left = $<Exp;
-                       $0->right = $<CB;
-                       var_block_close(c, CloseSequential, $0->right);
-                       var_block_close(c, CloseSequential, $0);
-               }$
+               $0 = new(binode);
+               $0->op = Loop;
+               $0->left = $<UB;
+               $0->right = $<OB;
+               var_block_close(c, CloseSequential, $0->right);
+               var_block_close(c, CloseSequential, $0);
+       }$
+       | while OpenScope Expression OpenScope ColonBlock ${
+               $0 = new(binode);
+               $0->op = Loop;
+               $0->left = $<Exp;
+               $0->right = $<CB;
+               var_block_close(c, CloseSequential, $0->right);
+               var_block_close(c, CloseSequential, $0);
+       }$
 
        $cond_statement
        IfPart -> if UseBlock OptNL then OpenBlock ${
-                       $0.condpart = $<UB;
-                       $0.thenpart = $<OB;
-                       var_block_close(c, CloseParallel, $0.thenpart);
-               }$
-               | if OpenScope Expression OpenScope ColonBlock ${
-                       $0.condpart = $<Ex;
-                       $0.thenpart = $<CB;
-                       var_block_close(c, CloseParallel, $0.thenpart);
-               }$
-               | if OpenScope Expression OpenScope OptNL then Block ${
-                       $0.condpart = $<Ex;
-                       $0.thenpart = $<Bl;
-                       var_block_close(c, CloseParallel, $0.thenpart);
-               }$
+               $0.condpart = $<UB;
+               $0.thenpart = $<OB;
+               var_block_close(c, CloseParallel, $0.thenpart);
+       }$
+       | if OpenScope Expression OpenScope ColonBlock ${
+               $0.condpart = $<Ex;
+               $0.thenpart = $<CB;
+               var_block_close(c, CloseParallel, $0.thenpart);
+       }$
+       | if OpenScope Expression OpenScope OptNL then Block ${
+               $0.condpart = $<Ex;
+               $0.thenpart = $<Bl;
+               var_block_close(c, CloseParallel, $0.thenpart);
+       }$
 
        $*exec
        // This scope is closed in CondStatement
        SwitchPart -> switch OpenScope Expression ${
-                       $0 = $<Ex;
-               }$
-               | switch UseBlock ${
-                       $0 = $<Bl;
-               }$
+               $0 = $<Ex;
+       }$
+       | switch UseBlock ${
+               $0 = $<Bl;
+       }$
 
 ###### print binode cases
        case Loop:
@@ -4809,20 +4803,21 @@ various declarations in the parse context.
        ## declare terminals
 
        OptNL ->
-               | OptNL NEWLINE
+       | OptNL NEWLINE
+
        Newlines -> NEWLINE
-               | Newlines NEWLINE
+       | Newlines NEWLINE
 
        DeclarationList -> Declaration
-               | DeclarationList Declaration
+       | DeclarationList Declaration
 
        Declaration -> ERROR Newlines ${
-                       tok_err(c,      // UNTESTED
-                               "error: unhandled parse error", &$1);
-               }$
-               | DeclareConstant
-               | DeclareFunction
-               | DeclareStruct
+               tok_err(c,      // UNTESTED
+                       "error: unhandled parse error", &$1);
+       }$
+       | DeclareConstant
+       | DeclareFunction
+       | DeclareStruct
 
        ## top level grammar
 
@@ -4856,21 +4851,24 @@ searching through for the Nth constant for decreasing N.
        $TERM const
 
        DeclareConstant -> const { IN OptNL ConstList OUT OptNL } Newlines
-               | const { SimpleConstList } Newlines
-               | const IN OptNL ConstList OUT Newlines
-               | const SimpleConstList Newlines
+       | const { SimpleConstList } Newlines
+       | const IN OptNL ConstList OUT Newlines
+       | const SimpleConstList Newlines
 
        ConstList -> ConstList SimpleConstLine
-               | SimpleConstLine
+       | SimpleConstLine
+
        SimpleConstList -> SimpleConstList ; Const
-               | Const
-               | SimpleConstList ;
+       | Const
+       | SimpleConstList ;
+
        SimpleConstLine -> SimpleConstList Newlines
-               | ERROR Newlines ${ tok_err(c, "Syntax error in constant", &$1); }$
+       | ERROR Newlines ${ tok_err(c, "Syntax error in constant", &$1); }$
 
        $*type
        CType -> Type   ${ $0 = $<1; }$
-               |       ${ $0 = NULL; }$
+       |               ${ $0 = NULL; }$
+
        $void
        Const -> IDENTIFIER :: CType = Expression ${ {
                int ok;
@@ -5024,32 +5022,32 @@ is a bit more interesting at this level.
 
        $*variable
        DeclareFunction -> func FuncName ( OpenScope ArgsLine ) Block Newlines ${
-                       $0 = declare_function(c, $<FN, $<Ar, Tnone, NULL, $<Bl);
-               }$
-               | func FuncName IN OpenScope Args OUT OptNL do Block Newlines ${
-                       $0 = declare_function(c, $<FN, $<Ar, Tnone, NULL, $<Bl);
-               }$
-               | func FuncName NEWLINE OpenScope OptNL do Block Newlines ${
-                       $0 = declare_function(c, $<FN, NULL, Tnone, NULL, $<Bl);
-               }$
-               | func FuncName ( OpenScope ArgsLine ) : Type Block Newlines ${
-                       $0 = declare_function(c, $<FN, $<Ar, $<Ty, NULL, $<Bl);
-               }$
-               | func FuncName ( OpenScope ArgsLine ) : ( ArgsLine ) Block Newlines ${
-                       $0 = declare_function(c, $<FN, $<AL, NULL, $<AL2, $<Bl);
-               }$
-               | func FuncName IN OpenScope Args OUT OptNL return Type Newlines do Block Newlines ${
-                       $0 = declare_function(c, $<FN, $<Ar, $<Ty, NULL, $<Bl);
-               }$
-               | func FuncName NEWLINE OpenScope return Type Newlines do Block Newlines ${
-                       $0 = declare_function(c, $<FN, NULL, $<Ty, NULL, $<Bl);
-               }$
-               | func FuncName IN OpenScope Args OUT OptNL return IN Args OUT OptNL do Block Newlines ${
-                       $0 = declare_function(c, $<FN, $<Ar, NULL, $<Ar2, $<Bl);
-               }$
-               | func FuncName NEWLINE OpenScope return IN Args OUT OptNL do Block Newlines ${
-                       $0 = declare_function(c, $<FN, NULL, NULL, $<Ar, $<Bl);
-               }$
+               $0 = declare_function(c, $<FN, $<Ar, Tnone, NULL, $<Bl);
+       }$
+       | func FuncName IN OpenScope Args OUT OptNL do Block Newlines ${
+               $0 = declare_function(c, $<FN, $<Ar, Tnone, NULL, $<Bl);
+       }$
+       | func FuncName NEWLINE OpenScope OptNL do Block Newlines ${
+               $0 = declare_function(c, $<FN, NULL, Tnone, NULL, $<Bl);
+       }$
+       | func FuncName ( OpenScope ArgsLine ) : Type Block Newlines ${
+               $0 = declare_function(c, $<FN, $<Ar, $<Ty, NULL, $<Bl);
+       }$
+       | func FuncName ( OpenScope ArgsLine ) : ( ArgsLine ) Block Newlines ${
+               $0 = declare_function(c, $<FN, $<AL, NULL, $<AL2, $<Bl);
+       }$
+       | func FuncName IN OpenScope Args OUT OptNL return Type Newlines do Block Newlines ${
+               $0 = declare_function(c, $<FN, $<Ar, $<Ty, NULL, $<Bl);
+       }$
+       | func FuncName NEWLINE OpenScope return Type Newlines do Block Newlines ${
+               $0 = declare_function(c, $<FN, NULL, $<Ty, NULL, $<Bl);
+       }$
+       | func FuncName IN OpenScope Args OUT OptNL return IN Args OUT OptNL do Block Newlines ${
+               $0 = declare_function(c, $<FN, $<Ar, NULL, $<Ar2, $<Bl);
+       }$
+       | func FuncName NEWLINE OpenScope return IN Args OUT OptNL do Block Newlines ${
+               $0 = declare_function(c, $<FN, NULL, NULL, $<Ar, $<Bl);
+       }$
 
 ###### print func decls
        {