an attempt to improve error correction on unknown type identifiers.
authorceriel <none@none>
Tue, 18 Aug 1987 10:05:18 +0000 (10:05 +0000)
committerceriel <none@none>
Tue, 18 Aug 1987 10:05:18 +0000 (10:05 +0000)
Also, a minor fix to ival.g

lang/cem/cemcom/declar.g
lang/cem/cemcom/expression.g
lang/cem/cemcom/ival.g
lang/cem/cemcom/program.g
lang/cem/cemcom/statement.g

index 2a04c2f..15bdb1d 100644 (file)
@@ -68,7 +68,8 @@ decl_specifiers       /* non-empty */ (register struct decspecs *ds;)
 :
 [
        other_specifier(ds)+
-       [%prefer /* the thin ice in R.M. 11.1 */
+       [%if (DOT != IDENTIFIER || AHEAD == IDENTIFIER)
+               /* the thin ice in R.M. 11.1 */
                single_type_specifier(ds) other_specifier(ds)*
        |
                empty
@@ -121,6 +122,11 @@ type_specifier(struct type **tpp;)
 single_type_specifier(register struct decspecs *ds;):
        TYPE_IDENTIFIER         /* this includes INT, CHAR, etc. */
        {idf2type(dot.tk_idf, &ds->ds_type);}
+|
+       IDENTIFIER
+       {error("%s is not a type identifier", dot.tk_idf->id_text);
+        ds->ds_type = error_type;
+       }
 |
        struct_or_union_specifier(&ds->ds_type)
 |
index 94fced4..d17c783 100644 (file)
@@ -96,7 +96,7 @@ postfixed(struct expr **expp;)
 unary(register struct expr **expp;)
        {struct type *tp; int oper;}
 :
-%if (first_of_type_specifier(AHEAD))
+%if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER)
        cast(&tp) unary(expp)
        {       ch7cast(expp, CAST, tp);
                (*expp)->ex_flags |= EX_CAST;
@@ -114,7 +114,7 @@ size_of(register struct expr **expp;)
        {struct type *tp;}
 :
        SIZEOF
-       [%if (first_of_type_specifier(AHEAD))
+       [%if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER)
                cast(&tp)
                {
                        *expp = intexpr(size_of_type(tp, "type"), INT);
index 40e7ea3..77d3fd1 100644 (file)
@@ -193,6 +193,10 @@ gen_tphead(tpp, nest)
        register struct e_stack *p;
        register struct sdef *sd;
 
+       if (tpp && *tpp == error_type) {
+               gen_error = 1;
+               return 0;
+       }
        if (gen_error) return tpp;
        p = new_e_stack();
        p->next = p_stack;
@@ -217,6 +221,13 @@ gen_tphead(tpp, nest)
                        sd = next_field(sd, p);
                }
 #endif
+               if (! sd) {
+                       /* something wrong with this struct */
+                       gen_error = 1;
+                       p_stack = p->next;
+                       free_e_stack(p);
+                       return 0;
+               }
                p->s_def = sd;
                if (AHEAD != '{' && aggregate_type(sd->sd_type)) {
                        return gen_tphead(&(sd->sd_type), 1);
@@ -236,7 +247,10 @@ gen_tpmiddle()
        register struct sdef *sd;
        register struct e_stack *p = p_stack;
 
-       if (gen_error) if (p) return p->s_tpp; else return 0;
+       if (gen_error) {
+               if (p) return p->s_tpp;
+               return 0;
+       }
 again:
        tp = *(p->s_tpp);
        switch(tp->tp_fund) {
index 4d8d05c..968fee0 100644 (file)
@@ -140,7 +140,7 @@ external_definition
 ;
 
 ext_decl_specifiers(struct decspecs *ds;) :
-%prefer /* the thin ice in  R.M. 11.1 */
+%if (DOT != IDENTIFIER || AHEAD == IDENTIFIER) /* the thin ice in  R.M. 11.1 */
        decl_specifiers(ds)
 |
        empty
index 4257c9b..81d3dac 100644 (file)
@@ -358,7 +358,9 @@ compound_statement:
                {
                        stack_level();
                }
-       [%while (AHEAD != ':')          /* >>> conflict on TYPE_IDENTIFIER */
+       [%while ((DOT != IDENTIFIER && AHEAD != ':') ||
+                (DOT == IDENTIFIER && AHEAD == IDENTIFIER))
+                       /* >>> conflict on TYPE_IDENTIFIER, IDENTIFIER */
                declaration
        ]*
        [%persistent