diff --git a/a1/main b/a1/main index f534ddc..c4fcfac 100755 Binary files a/a1/main and b/a1/main differ diff --git a/a1/program.c b/a1/program.c index 4cd5e11..c936066 100644 --- a/a1/program.c +++ b/a1/program.c @@ -26,6 +26,16 @@ char matching_bracket(char ch) { } } +char expected_closing(char ch) { + switch (ch) { + case '(': return ')'; + case '{': return '}'; + case '[': return ']'; + case '<': return '>'; + default: return 0; + } +} + void check_brackets(const char *line) { StackItem stack[MAX_LEN]; int stack_top = -1; @@ -51,14 +61,19 @@ void check_brackets(const char *line) { stack_top--; } else { printf("Crossed bracket %c in %d, expected %c\n", ch, i, - matching_bracket(stack[stack_top].bracket)); + expected_closing(stack[stack_top].bracket)); return; } } } if (stack_top >= 0) { - printf("Unmatched bracket %c in %d\n", stack[stack_top].bracket, stack[stack_top].position); + printf("Missing closing brackets:"); + while (stack_top >= 0) { + printf(" %c", expected_closing(stack[stack_top].bracket)); + stack_top--; + } + printf("\n"); } else { printf("All brackets OK\n"); }