diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-08-29 11:54:46 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-08-29 11:54:46 -0400 |
commit | 6f3310ddead0a00c6b8c1d2085fd0e83a1ada827 (patch) | |
tree | 6dfd285f68cad9b0cda2aee07e6b5b2d6bdef6eb | |
parent | 227b13eccaecc05d76ca8dceb922a9d280ead0c4 (diff) |
Fix consolidate yyerror calls to after switch
Any failed type checking now sets buf string to error message and
breaks out of switch case and will then call yyerror with buf string.
-rw-r--r-- | sem_check.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/sem_check.c b/sem_check.c index c5e9fb6..88f41ad 100644 --- a/sem_check.c +++ b/sem_check.c @@ -65,20 +65,19 @@ ptree *t; "Cannot use boolean " "operator on type %s\n", pretty_type(type)); - yyerror(buf); + break; } } if (t->r->ret_type == t->l->ret_type) return t->r->ret_type; - else { + else snprintf(buf, 100, "Mismached types: " "Type %s " "cannot be used with type %s\n", pretty_type(t->r->ret_type), pretty_type(t->l->ret_type)); - yyerror(buf); - } + break; case RELOP : if (!(t->r && t->l)) @@ -91,7 +90,6 @@ ptree *t; "cannot be compared to type %s\n", pretty_type(t->r->ret_type), pretty_type(t->l->ret_type)); - yyerror(buf); break; case NOT: if (t->l && t->l->ret_type == BOOL) @@ -108,15 +106,14 @@ ptree *t; if (t->l->ret_type == t->r->ret_type) return 1; - else { + else snprintf(buf, 100, "Mismached types: " "Cannot assign type %s " "to variable \"%s\" of type %s\n", pretty_type(t->r->ret_type), t->l->attr.nval->name, pretty_type(t->l->attr.nval->var_type)); - yyerror(buf); - } + break; @@ -128,7 +125,7 @@ ptree *t; snprintf(buf, 100, "Cannot access array" "with type %s\n", pretty_type(t->r->ret_type)); - yyerror(buf); + break; } type = t->l->attr.nval -> var_type; @@ -149,9 +146,9 @@ ptree *t; default: return -200; snprintf(buf, 100, "Unknown tree node: %d...\n", t->type); - yyerror(buf); } + yyerror(buf); return -1; } |