0
votes

I'm parsing an XML file using Lex and YACC.My grammar is like.

START_TAG attributes AN_CLOSE childelements data END_TAG AN_CLOSE 
{
    if(strcmp(getSubStr($1,1,strlen($1)-1),getSubStr($6,2,strlen($6)-1))==0)
        {
            //Here comes action to be performed if elements match
        }
        else
        {
            yyerror("Invalid Input File");
            //In such message should be printed and parsing should stop 
        }
}

where START_TAG, AN_CLOSE, END_TAG, and AN_CLOSE are tokens returned by lex file. What each token identifies is given below:

START_TAG :<element 
AN_CLOSE : > 
END_TAG :</element

Now to check if input XML file is valid, I'm checking text of element' element' of START_TAG ie $1 with 'element' of END_TAG ie $6. In case if elements mismatch I have to print message and stop parsing. My error message is getting printed however parsing continues. Any suggestion on how to stop parsing would be appreciated.

Thanks.

1

1 Answers

1
votes

Use the YYABORT macro, which will cause yyparse to return with status 1.