>>14955
>"ундефайнед бехейвор"
Не знаю, откуда ему быть.
Вот код для проверки на ошибки:
#include <stdio.h>
#define OTHER 0
#define SINGLEQUOTE 1
#define DOUBLEQUOTE 2
#define COMMENT 3
#define SLASH 4
#define STAR 5
#define BACKSLASHSINQ 6
#define BACKSLASHDOUQ 7
main()
{
int c, state, nparenthesis, nbrace, nbracket, line, cn;
state = OTHER;
nparenthesis = nbrace = nbracket = 0;
cn = line = 1;
while ((c = getchar()) != EOF) {
if (state == OTHER)
if (c == '\'')
state = SINGLEQUOTE;
else if (c == '\"')
state = DOUBLEQUOTE;
else if (c == '/')
state = SLASH;
else if (c == '(')
nparenthesis++;
else if (c == ')')
if (nparenthesis == 0)
printf("Error at %d.%d position: this right parenthesis has not corresponding left parenthesis.", line, cn);
else
nparenthesis--;
else if (c == '{')
nbrace++;
else if (c == '}')
if (nbrace == 0)
printf("Error at %d.%d position: this right brace has not corresponding left brace.\n", line, cn);
else
nbrace--;
else if (c == '[')
nbracket++;
else if (c == ']')
if (nbracket == 0)
printf("Error at %d.%d position: this right bracket has not corresponding left bracket.\n", line, cn);
else
nbracket--;
else;
else if (state == SINGLEQUOTE)
if (c == '\'')
state = OTHER;
else if (c == '\\')
state = BACKSLASHSINQ;
else;
else if (state == DOUBLEQUOTE)
if (c == '\"')
state = OTHER;
else if (c == '\\')
state = BACKSLASHDOUQ;
else;
else if (state == COMMENT)
if (c == '*')
state = STAR;
else;
else if (state == SLASH)
if (c == '*')
state = COMMENT;
else if (c != '/') {
state = OTHER;
if (c == '(')
nparenthesis++;
else if (c == ')')
if (nparenthesis == 0)
printf("Error at %d.%d position: this right parenthesis has not corresponding left parenthesis.", line, cn);
else
nparenthesis--;
else if (c == '{')
nbrace++;
else if (c == '}')
if (nbrace == 0)
printf("Error at %d.%d position: this right brace has not corresponding left brace.\n", line, cn);
else
nbrace--;
else if (c == '[')
nbracket++;
else if (c == ']')
if (nbracket == 0)
printf("Error at %d.%d position: this right bracket has not corresponding left bracket.\n", line, cn);
else
nbracket--;
}
else;
else if (state == STAR)
if (c == '/')
state = OTHER;
else if (c != '*')
state = COMMENT;
else if (state == BACKSLASHSINQ)
state = SINGLEQUOTE;
else if (state == BACKSLASHDOUQ)
state = DOUBLEQUOTE;
if (c == '\n') {
line++;
cn = 1;
}
else
cn++;
}
if (nparenthesis != 0)
printf("%d left parentheses have not corresponding right parentheses.\n", nparenthesis);
if (nbrace != 0)
printf("%d left braces have not corresponding right braces.\n", nbrace);
if (nbracket != 0)
printf("%d left brackets have not corresponding right brackets.\n", nbracket);
}