[prog] Yacc - double errors
Sue Stones
suzo at spin.net.au
Mon Feb 9 23:32:02 EST 2004
I am back to my Yacc program after an enforced break (uni presures).
I ahve been trying to sort out error reporting but i have rewrtiten it
multitple times, but I still getting double errors.
I will just include a sample of the code, and hope that someone can give me
some clues as to what might be wrong. If I really need to send the whole
program I will!
---------------------------------------
end_statement: END SEMI { fprintf(stdout, "end;\n"); }
| END error {
errorstr = strdup("Missing semicolon after \"end\"");
yyerror(errorstr); }
;
---------------------------------------
void yyerror(const char *str)
{
errors_found++;
fprintf(stderr,"%s:%d: %s \n", filename, lineno, str);
} // yyerror
----------------------------------------
main(int argc, char *argv[])
{
if(argc > 1)
{
yyin = fopen(argv[1], "r");
filename = strdup(argv[1]);
yyparse();
if (errors_found > 0)
fprintf(stderr, "%d errors\n", errors_found);
else
fprintf(stderr, "Program Parsed\n");
} // if
else
{
fprintf(stderr, "usage: %s filename.b\n", argv[0]);
return 0;
} // else
} // main
_______________________________
More information about the Programming
mailing list