From: ceriel Date: Tue, 18 Aug 1987 10:05:18 +0000 (+0000) Subject: an attempt to improve error correction on unknown type identifiers. X-Git-Tag: release-5-5~3886 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=1c85c44fadf5382254ac3e1fcf07c37e6e1b1141;p=ack.git an attempt to improve error correction on unknown type identifiers. Also, a minor fix to ival.g --- diff --git a/lang/cem/cemcom/declar.g b/lang/cem/cemcom/declar.g index 2a04c2f87..15bdb1d64 100644 --- a/lang/cem/cemcom/declar.g +++ b/lang/cem/cemcom/declar.g @@ -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) | diff --git a/lang/cem/cemcom/expression.g b/lang/cem/cemcom/expression.g index 94fced415..d17c783fa 100644 --- a/lang/cem/cemcom/expression.g +++ b/lang/cem/cemcom/expression.g @@ -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); diff --git a/lang/cem/cemcom/ival.g b/lang/cem/cemcom/ival.g index 40e7ea3fd..77d3fd13e 100644 --- a/lang/cem/cemcom/ival.g +++ b/lang/cem/cemcom/ival.g @@ -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) { diff --git a/lang/cem/cemcom/program.g b/lang/cem/cemcom/program.g index 4d8d05c20..968fee0c0 100644 --- a/lang/cem/cemcom/program.g +++ b/lang/cem/cemcom/program.g @@ -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 diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index 4257c9b47..81d3daceb 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -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