void debug_myerror(b)

- set debug flag for debugging purposes only Bool b;

void print_tokenlist(token, tokenlist)

- print debug information about errors int token; int *tokenlist;

debug_myerror() indicates whether debug information about the myerror() must be printed. If an error occurs in the input myerror() is called. The parameters of myerror() are the expected token token and if there are more than one alternatives a list with the possible tokens tokenlist. Both parameters are printed in print_tokenlist() and are used for debug information.

Bool poss_token(elem, token, tokenlist)

- check if elem is possible in parser int elem, token; int *tokenlist;

myerror(token, tokenlist)

- error routine called by parser int token; int *tokenlist;

When a token occurs in the input which is not expected in this place, myerror() is called. This will especially happen for optional endtags because they are generated without optional sign, they are always required considering the parser. Endtags may most of the time be omitted so myerror() must insert an endtag in the inputstream if necessary.

Inclusions can occur in the entire document but the parser knows nothing about them. So when a starttag is encountered that is rejected by the parser, myerror() checks if it is an inclusion and if so calls a parser to parse the inclusion. The endtag of an inclusion may be followed by comments, etc., so that after the inclusion is parsed, a parser for comments, etc. is called.

The function poss_token() checks if elem is among one of the tokens the parser expects at the time of error. It returns TRUE if this is the case, FALSE otherwise.

First, myerror() checks if the required token is EOFILE, this is the case when a parser is called for an inclusion. The parser must end with EOFILE but no EOFILE token appears on the input, so myerror() inputs the EOFILE token. The parser can now reads the EOFILE and ends. The parser for the comments, etc must be ended by the token TOK_XXX followed by EOFILE. The token TOK_XXX is a predefined token and is not possible in the input. myerror() inserts the token and the EOFILE and the comment parser ends.

Next myerror() tries to discover whether the wrong token (contained in LLsymb) is a starttag which is permitted as an inclusion. If this is the case, the inclusion is parsed.

When the list of possible tokens tokenlist contains the endtag of the most recently opened element, myerror() tries to insert the endtag. myerror() checks if the topelement of the open elements-stack (an endtag) is a possible token for the parser. And when it is a possible token, whether the endtag may be omitted. When this is not so, myerror() returns without changing anything and the error-recovery routine of LLgen takes over.

If the current (invalid) token is an endtag of an open element, the endtag of the most recently opened element is pushed onto the inputstream (Standard section 7.3.1.2). Otherwise the invalid token is a starttag or datacharacter, if the invalid token is not part of the content model for the topelement of the stack, the endtag is also generated. In all other cases it is an error to omit the endtag and a proper message is given.

myerror.c myerror.h