interleaved declaration parts
authorPeter B. Kessler <peter@ucbvax.Berkeley.EDU>
Wed, 3 Sep 1980 13:06:30 +0000 (05:06 -0800)
committerPeter B. Kessler <peter@ucbvax.Berkeley.EDU>
Wed, 3 Sep 1980 13:06:30 +0000 (05:06 -0800)
SCCS-vsn: usr.bin/pascal/src/0.h 1.2
SCCS-vsn: usr.bin/pascal/src/const.c 1.3
SCCS-vsn: usr.bin/pascal/src/fdec.c 1.3
SCCS-vsn: usr.bin/pascal/src/lab.c 1.3
SCCS-vsn: usr.bin/pascal/src/type.c 1.3
SCCS-vsn: usr.bin/pascal/src/var.c 1.3
SCCS-vsn: usr.bin/pascal/src/pas.y 1.3

usr/src/usr.bin/pascal/src/0.h
usr/src/usr.bin/pascal/src/const.c
usr/src/usr.bin/pascal/src/fdec.c
usr/src/usr.bin/pascal/src/lab.c
usr/src/usr.bin/pascal/src/pas.y
usr/src/usr.bin/pascal/src/type.c
usr/src/usr.bin/pascal/src/var.c

index 13fb622..b5e7990 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-/* static      char sccsid[] = "@(#)0.h 1.1 %G%"; */
+/* static      char sccsid[] = "@(#)0.h 1.2 %G%"; */
 
 #define DEBUG
 #define        CHAR
 
 #define DEBUG
 #define        CHAR
@@ -535,17 +535,18 @@ short     cnts;
 
 /*
  * Parts records which declaration parts have been seen.
 
 /*
  * Parts records which declaration parts have been seen.
- * The grammar allows the "const" "type" and "var"
+ * The grammar allows the "label" "const" "type" "var" and routine
  * parts to be repeated and to be in any order, so that
  * they can be detected semantically to give better
  * error diagnostics.
  */
  * parts to be repeated and to be in any order, so that
  * they can be detected semantically to give better
  * error diagnostics.
  */
-short  parts;
+int    parts[ DSPLYSZ ];
 
 
-#define        LPRT    01
-#define        CPRT    02
-#define        TPRT    04
-#define        VPRT    08
+#define        LPRT    1
+#define        CPRT    2
+#define        TPRT    4
+#define        VPRT    8
+#define        RPRT    16
 
 /*
  * Flags for the "you used / instead of div" diagnostic
 
 /*
  * Flags for the "you used / instead of div" diagnostic
index 459b85b..f346948 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-static char sccsid[] = "@(#)const.c 1.2 %G%";
+static char sccsid[] = "@(#)const.c 1.3 %G%";
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -16,7 +16,7 @@ constbeg()
 {
 
 /*
 {
 
 /*
- * PC allows for multiple declaration
+ * this allows for multiple declaration
  * parts, unless the "standard" option
  * has been specified.
  * If a routine segment is being compiled,
  * parts, unless the "standard" option
  * has been specified.
  * If a routine segment is being compiled,
@@ -25,25 +25,23 @@ constbeg()
 
        if (!progseen)
                level1();
 
        if (!progseen)
                level1();
-#    ifdef PC
-       if (opt('s')) {
-               if (parts & (TPRT|VPRT)) {
-                       standard();
-                       error("Constant declarations must precede type and variable declarations");
-               }
-               if (parts & CPRT) {
-                       standard();
-                       error("All constants must be declared in one const part");
-               }
-        }
-#    endif PC
-#    ifdef OBJ
-       if (parts & (TPRT|VPRT))
-               error("Constant declarations must precede type and variable declarations");
-       if (parts & CPRT)
-               error("All constants must be declared in one const part");
-#    endif OBJ
-       parts |= CPRT;
+       if (parts[ cbn ] & (TPRT|VPRT|RPRT)) {
+           if ( opt( 's' ) ) {
+               standard();
+           } else {
+               warning();
+           }
+           error("Constant declarations should precede type, var and routine declarations");
+       }
+       if (parts[ cbn ] & CPRT) {
+           if ( opt( 's' ) ) {
+               standard();
+           } else {
+               warning();
+           }
+           error("All constants should be declared in one const part");
+       }
+       parts[ cbn ] |= CPRT;
 }
 #endif PI1
 
 }
 #endif PI1
 
index 0be3ed1..d9579e3 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-static char sccsid[] = "@(#)fdec.c 1.2 %G%";
+static char sccsid[] = "@(#)fdec.c 1.3 %G%";
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -51,6 +51,7 @@ funchdr(r)
                yyretrieve();   /* kludge */
        }
        pfcnt++;
                yyretrieve();   /* kludge */
        }
        pfcnt++;
+       parts[ cbn ] |= RPRT;
        line = r[1];
        if (r[3] == NIL && (p=lookup1(r[2])) != NIL && bn == cbn) {
                /*
        line = r[1];
        if (r[3] == NIL && (p=lookup1(r[2])) != NIL && bn == cbn) {
                /*
@@ -399,7 +400,7 @@ funcbody(fp)
        sizes[cbn].om_max = sizes[cbn].om_off = -DPOFF1;
        gotos[cbn] = NIL;
        errcnt[cbn] = syneflg;
        sizes[cbn].om_max = sizes[cbn].om_off = -DPOFF1;
        gotos[cbn] = NIL;
        errcnt[cbn] = syneflg;
-       parts = NIL;
+       parts[ cbn ] = NIL;
        dfiles[ cbn ] = FALSE;
        if (fp == NIL)
                return (NIL);
        dfiles[ cbn ] = FALSE;
        if (fp == NIL)
                return (NIL);
@@ -1015,7 +1016,10 @@ level1()
 
        cbn++;
        sizes[cbn].om_max = sizes[cbn].om_off = -DPOFF1;
 
        cbn++;
        sizes[cbn].om_max = sizes[cbn].om_off = -DPOFF1;
-       parts = NIL;
+       gotos[cbn] = NIL;
+       errcnt[cbn] = syneflg;
+       parts[ cbn ] = NIL;
+       dfiles[ cbn ] = FALSE;
        progseen++;
 }
 
        progseen++;
 }
 
index 8933366..58528c8 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-static char sccsid[] = "@(#)lab.c 1.2 %G%";
+static char sccsid[] = "@(#)lab.c 1.3 %G%";
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -33,25 +33,23 @@ label(r, l)
        }
        line = l;
 #ifndef PI1
        }
        line = l;
 #ifndef PI1
-#ifdef PC
-    if (opt('s')) {
-       if (parts & (CPRT|TPRT|VPRT)){
+       if (parts[ cbn ] & (CPRT|TPRT|VPRT|RPRT)){
+           if ( opt( 's' ) ) {
                standard();
                standard();
-               error("Label declarations must precede const, type and var declarations");
+           } else {
+               warning();
+           }
+           error("Label declarations should precede const, type, var and routine declarations");
        }
        }
-       if (parts & LPRT) {
+       if (parts[ cbn ] & LPRT) {
+           if ( opt( 's' ) ) {
                standard();
                standard();
-               error("All labels must be declared in one label part");
+           } else {
+               warning();
+           }
+           error("All labels should be declared in one label part");
        }
        }
-    }
-#endif PC
-#ifdef OBJ
-       if (parts & (CPRT|TPRT|VPRT))
-               error("Label declarations must precede const, type and var declarations");
-       if (parts & LPRT)
-               error("All labels must be declared in one label part");
-#endif OBJ
-       parts |= LPRT;
+       parts[ cbn ] |= LPRT;
 #endif
 #ifndef PI0
        for (ll = r; ll != NIL; ll = ll[2]) {
 #endif
 #ifndef PI0
        for (ll = r; ll != NIL; ll = ll[2]) {
index 2f0c4dc..6795507 100644 (file)
@@ -64,8 +64,8 @@
        YSET            YSTRING         YTHEN           YDOWNTO
        YTYPE           YUNTIL          YVAR            YWHILE
        YWITH           YBINT           YOCT            YHEX
        YSET            YSTRING         YTHEN           YDOWNTO
        YTYPE           YUNTIL          YVAR            YWHILE
        YWITH           YBINT           YOCT            YHEX
-       YASSERT         YCASELAB        YILLCH          YLAST
-       YEXTERN
+       YASSERT         YCASELAB        YILLCH          YEXTERN
+       YLAST
 
 /*
  * PRECEDENCE DECLARATIONS
 
 /*
  * PRECEDENCE DECLARATIONS
@@ -89,7 +89,7 @@
 
 /* Copyright (c) 1979 Regents of the University of California */
 
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-/* static      char sccsid[] = "@(#)pas.y 1.2 %G%"; */
+/* static      char sccsid[] = "@(#)pas.y 1.3 %G%"; */
 
 /*
  * The following line marks the end of the yacc
 
 /*
  * The following line marks the end of the yacc
@@ -99,7 +99,7 @@
 ##
 /* Copyright (c) 1979 Regents of the University of California */
 
 ##
 /* Copyright (c) 1979 Regents of the University of California */
 
-static char sccsid[] = "@(#)pas.y 1.2 %G%";
+static char sccsid[] = "@(#)pas.y 1.3 %G%";
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -120,10 +120,10 @@ static    char sccsid[] = "@(#)pas.y 1.2 %G%";
  */
 
 goal:
  */
 
 goal:
-       prog_hedr decls procs block '.'
-               = funcend($1, $4, lineof($5));
+       prog_hedr decls block '.'
+               = funcend($1, $3, lineof($4));
                |
                |
-       decls procs
+       decls
                = segend();
                ;
        
                = segend();
                ;
        
@@ -181,6 +181,8 @@ decl:
                |
        var_decl
                = varend();
                |
        var_decl
                = varend();
+               |
+       proc_decl
                ;
 \f
 /*
                ;
 \f
 /*
@@ -269,21 +271,15 @@ Verror:
  * PROCEDURE AND FUNCTION DECLARATION PART
  */
 
  * PROCEDURE AND FUNCTION DECLARATION PART
  */
 
-procs:
-       /* lambda */
-               |
-       procs proc
-               = trfree();
-               ;
-proc:
+proc_decl:
        phead YFORWARD ';'
                = funcfwd($1);
                |
        phead YEXTERN ';'
                = funcext($1);
                |
        phead YFORWARD ';'
                = funcfwd($1);
                |
        phead YEXTERN ';'
                = funcext($1);
                |
-       pheadres decls procs block ';'
-               = funcend($1, $4, lineof($5));
+       pheadres decls block ';'
+               = funcend($1, $3, lineof($4));
                ;
 pheadres:
        phead
                ;
 pheadres:
        phead
index 5f2542f..2094cd1 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-static char sccsid[] = "@(#)type.c 1.2 %G%";
+static char sccsid[] = "@(#)type.c 1.3 %G%";
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -14,7 +14,7 @@ typebeg()
 {
 
 /*
 {
 
 /*
- * PC allows for multiple
+ * this allows for multiple
  * declaration parts unless
  * standard option has been
  * specified.
  * declaration parts unless
  * standard option has been
  * specified.
@@ -23,27 +23,25 @@ typebeg()
  */
 
 #ifndef PI1
  */
 
 #ifndef PI1
-if (!progseen)
-       level1();
-#ifdef PC
-   if (opt('s')) {
-       if (parts & VPRT) {
+       if (!progseen)
+               level1();
+       if ( parts[ cbn ] & ( VPRT | RPRT ) ) {
+           if ( opt( 's' ) ) {
                standard();
                standard();
-               error("Type declarations must precede var declarations");
+           } else {
+               warning();
+           }
+           error("Type declarations should precede var and routine declarations");
        }
        }
-       if (parts & TPRT) {
+       if (parts[ cbn ] & TPRT) {
+           if ( opt( 's' ) ) {
                standard();
                standard();
-               error("All types must be declared in one type part");
+           } else {
+               warning();
+           }
+           error("All types should be declared in one type part");
        }
        }
-   }
-#endif PC
-#ifdef OBJ
-       if (parts & VPRT)
-               error("Type declarations must precede var declarations");
-       if (parts & TPRT)
-               error("All types must be declared in one type part");
-#endif OBJ
-       parts |= TPRT;
+       parts[ cbn ] |= TPRT;
 #endif
        /*
         * Forechain is the head of a list of types that
 #endif
        /*
         * Forechain is the head of a list of types that
index d29ce24..2f8aff8 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-static char sccsid[] = "@(#)var.c 1.2 %G%";
+static char sccsid[] = "@(#)var.c 1.3 %G%";
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -21,7 +21,7 @@ static        char sccsid[] = "@(#)var.c 1.2 %G%";
 varbeg()
 {
 
 varbeg()
 {
 
-/* PC allows for multiple declaration
+/* this allows for multiple declaration
  * parts except when the "standard"
  * option has been specified.
  * If routine segment is being compiled,
  * parts except when the "standard"
  * option has been specified.
  * If routine segment is being compiled,
@@ -29,21 +29,25 @@ varbeg()
  */
 
 #ifndef PI1
  */
 
 #ifndef PI1
-if (!progseen)
-       level1();
-#ifdef PC
-    if (opt('s')) {
-       if (parts & VPRT){
+       if (!progseen)
+               level1();
+       if ( parts[ cbn ] & RPRT ) {
+           if ( opt( 's' ) ) {
                standard();
                standard();
-               error("All variables must be declared in one var part");
+           } else {
+               warning();
+           }
+           error("Variable declarations should precede routine declarations");
        }
        }
-    }
-#else
-       if (parts & VPRT)
-               error("All variables must be declared in one var part");
-#endif PC
-
-       parts |= VPRT;
+       if ( parts[ cbn ] & VPRT ) {
+           if ( opt( 's' ) ) {
+               standard();
+           } else {
+               warning();
+           }
+           error("All variables should be declared in one var part");
+       }
+       parts[ cbn ] |= VPRT;
 #endif
     /*
      *  #ifndef PI0
 #endif
     /*
      *  #ifndef PI0